Skip to content

Instantly share code, notes, and snippets.

View mikelove's full-sized avatar

Michael Love mikelove

View GitHub Profile
@mikelove
mikelove / import_map_reduce.R
Last active August 29, 2015 14:07
example: GenomicFiles MAP on GRangesList
library(GenomicFiles)
register(SerialParam())
# use 4 BigWigs from
# ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeCshlLongRnaSeq/
files <- list.files("~/data/bigwig/",full=TRUE)
ranges0 <- GRanges("chr1",IRanges(11:20 * 1e6, width=1e5))
f <- factor(rep(1:2, each=length(ranges0)/2))
ranges <- split(ranges0, f)
MAP <- function(range, file) {
rle <- import(file, which = range, as = "Rle", format = "bw")[range]
@mikelove
mikelove / broom_ggplot2.R
Created October 7, 2014 15:30
broom and ggplot2
library(broom)
library(ggplot2)
tidyfit <- tidy(fit)
tidyfit$xmin <- with(tidyfit, estimate - stderror)
tidyfit$xmax <- with(tidyfit, estimate + stderror)
ggplot(tidyfit, aes(x=estimate,y=term,xmin=xmin,xmax=xmax,height=0)) +
geom_point() + geom_vline(xintercept=0) + geom_errorbarh()
@mikelove
mikelove / null.R
Last active August 29, 2015 14:07
FDR calculations care about ratios of null/total
# make 10 small p-values (p = 0.01)
# and 90 big p-values (p = 0.99)
p = rep(c(.01,.99), c(10,90))
# adjust the p-values with Benjamini-Hochberg method
# and then tabulate them
table(p.adjust(p, method="BH"))
0.1 0.99
10 90
@mikelove
mikelove / batch.R
Created October 22, 2014 20:05
does batch average out?
batch <- factor(rep(1:3,length=10))
beta2 <- 2
beta3 <- 4
mu <- (batch == "2") * beta2 + (batch == "3") * beta3
n <- 100000
y <- t(replicate(n, rnorm(6, mean=sample(mu,6), sd=1)))
condition <- factor(rep(1:2,each=3))
library(genefilter)
ts <- rowttests(y, condition)
hist(ts$p.value, breaks=100, col="grey")
@mikelove
mikelove / recommended_chunk.R
Last active August 29, 2015 14:09
recommended chunk
@mikelove
mikelove / som.R
Created December 3, 2014 19:55
som
n <- 20^2
p <- 4
col <- rep(1:2,each=n/2)
x <- matrix(rnorm(n*p),ncol=p)
x[,1] <- c(rnorm(n/2,0,1),rnorm(n/2,4,.1))
x[,2] <- c(rnorm(n/2,0,1),rnorm(n/2,4,.1))
par(mfrow=c(2,2))
plot(x[,1:2],col=col)
plot(prcomp(x)$x[,1:2],col=col,asp=1)
library(kohonen)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
t <- transcriptsBy(txdb, by="gene")
e <- exonsBy(txdb, by="tx")
t2 <- unlist(t)
gene2t <- data.frame(gene=names(t2), tx=t2$tx_id)
g <- unique(names(t2))
set.seed(1)
random.genes <- sample(g, 2000, replace=FALSE)
set.seed(1)
@mikelove
mikelove / ubuntu
Last active May 23, 2016 20:11
setting up new computer
​sudo ​chown ​-R all the R library locations
cairo​ (libcairo2-dev)
​pango (libpango1.0-dev)​
​XML​ (libxml2-dev)
​x11 toolkit (libxt-dev)
texinfo
texlive​ (texlive-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra)
java (default-jdk)
curl (libcurl4-openssl-dev)
openssl (libssl-dev)
use_xft yes
xftfont Terminus:size=8
xftalpha 0.8
update_interval 1.0
total_run_times 0
own_window yes
own_window_transparent yes
own_window_argb_visual yes
own_window_type normal
own_window_class conky-semi
@mikelove
mikelove / redcarpetkramdown.md
Last active July 5, 2018 06:46
redcarpet vs kramdown play nice with mathjax

Issues with latex math in markdown files, for display on Github Pages (using jekyll)

Our solution: use kramdown parser, with GFM option (Github flavored Markdown). In the .Rmd, use $$ for display math and $ for inline math. then have a script which turns the inline math demarkation in the .md file from $ into $$ when appropriate (avoiding data frame usage), before uploading the .md to Github. This way, RStudio preview looks the same as the Github Pages version.

redcarpet math

  • doesn't respect $ or $$ (will parse characters within these, such as _), but has workarounds:
  • has a useful option, no_intra_emphasis, so underscores between ascii characters are not converted to <em> tags, so $x_1$ is fine
  • need to escape underscores after non-ascii characters, for example $\mathbf{x}\_1$
  • need to double escape curly bracket: \\{