Skip to content

Instantly share code, notes, and snippets.

View mikelove's full-sized avatar

Michael Love mikelove

View GitHub Profile
@mikelove
mikelove / biocmask_examples.R
Last active August 7, 2024 23:50
Trying out Justin's biocmask implementation of tidyomics for SE
load_all("../biocmask")
suppressPackageStartupMessages(library(airway))
data(airway)
rowData(airway)$group <- sort(rep(1:10, length=nrow(airway)))
library(tibble)
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(purrr))
airway |>
@mikelove
mikelove / mpra_json.R
Last active July 23, 2024 13:20
file to make JSON format
library(jsonlite)
library(readr)
dat <- read_csv("IGVF MPRA FG designed sequence metadata - Sheet1.csv")
dat$constraints <- as.list(dat$constraints)
dat$constraints[[1]] <- list(required=TRUE)
dat$constraints[[2]] <- list(required=TRUE)
dat$constraints[[3]] <- list(
required=TRUE,
enum=strsplit(sub(".*enum: \\[(.*)\\]","\\1",dat$constraints[[3]]),", ")[[1]]
)
@mikelove
mikelove / fluent-genomics-v2.qmd
Last active June 11, 2024 20:54
fluent genomics update
---
title: "Differential chromatin accessibility and gene expression"
format: html
---
# Differential expression from RNA-seq
```{r}
#| eval: FALSE
dir <- system.file("extdata", package="macrophage")
@mikelove
mikelove / hg38_seqlens.tsv
Created June 9, 2024 11:03
Speed testing plyranges joins at various numbers of features 1e3 to 1e6
chr1 248956422
chr2 242193529
chr3 198295559
chr4 190214555
chr5 181538259
chr6 170805979
chr7 159345973
chr8 145138636
chr9 138394717
chr10 133797422
@mikelove
mikelove / segment_example.R
Created May 10, 2024 12:12
Example of producing simple segmentation
library(plyranges)
library(nullranges)
x <- data.frame(
seqnames=rep(c("1","2","3"), each=10),
start=rep(c(0:4, 10:14) * 1000 + 1, times=3),
width=100) |>
as_granges()
seqlengths(x) <- c("1"=20123, "2"=20123, "3"=20123)
@mikelove
mikelove / join_se.R
Last active May 11, 2024 11:05
Example code for joining two range sets where second one is also attached to an SE
library(SummarizedExperiment)
library(plyranges)
# example data
m <- matrix(rnorm(600), nrow=100)
r1 <- data.frame(seqnames=1, start=1:50 * 100 + 2501,
width=5, id1=paste0("u",formatC(1:50,width=3,flag="0"))) |>
as_granges()
r2 <- data.frame(seqnames=1, start=1:100 * 100 + 1,
width=5, id2=paste0("v",formatC(1:100,width=3,flag="0"))) |>
@mikelove
mikelove / IGVF_ancestry_app.R
Last active August 6, 2024 14:16
IGVF ancestry dashboard sketch
library(shiny)
library(UpSetR)
library(dplyr)
library(tidyr)
library(readr)
library(ggplot2)
library(pheatmap)
dat <- read_delim("ancestry_dataframe.tsv")
ui <- fluidPage(
@mikelove
mikelove / frozen_vst.R
Created February 19, 2024 14:02
Frozen variance stabilizing transformation for count data
mat <- matrix(rnbinom(2e5, mu=100, size=1/.01), ncol=100)
library(DESeq2)
d <- DESeqDataSetFromMatrix(mat, DataFrame(x=rep(1,100)), ~1)
# library size correction, centered log ratio to reference sample
d <- estimateSizeFactors(d)
# variance
d <- estimateDispersionsGeneEst(d)
# trend
@mikelove
mikelove / element_level.R
Last active February 9, 2024 20:00
Element level analysis with mpralm
set.seed(5)
n <- 1000
reps <- 10
rna <- matrix(
rnbinom(n * reps, mu = 10, size = 100),
ncol=reps
)
dna <- matrix(
rnbinom(n * reps, mu = 10, size = 100),
@mikelove
mikelove / R_Bioc_tidy_data.R
Created November 3, 2023 02:51
Demonstration of various classes in R
# dataframes vs lm S3 vs Bioc S4
# Michael Love
# Nov 1 2023
dat <- data.frame(genotype=c("wt","wt","mut","mut"),
count=c(10,20,30,40),
score=c(-1.2,0,3.4,-5),
gene=c("Abc","Abc","Xyz","Xyz"))
library(tibble)
dat |> as_tibble()