Skip to content

Instantly share code, notes, and snippets.

@mikelove
Last active December 3, 2015 15:10
Show Gist options
  • Save mikelove/e82b8af80afc7d61f1b5 to your computer and use it in GitHub Desktop.
Save mikelove/e82b8af80afc7d61f1b5 to your computer and use it in GitHub Desktop.
gene length factor
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
g <- keys(txdb, "GENEID")
df <- select(txdb, keys=g, keytype="GENEID", columns="TXID")
ebt <- exonsBy(txdb, by="tx")
set.seed(1)
random.genes <- sample(g, 500, replace=FALSE)
res <- sapply(random.genes, function(gene) {
txs <- df$TXID[df$GENEID == gene]
if (length(txs) == 1) return(NA)
lengths <- sum(width(ebt[txs]))
idx <- sample(length(txs), 2)
lengths[idx[1]] / lengths[idx[2]]
})
round(2^quantile(abs(log2(res)),1:3/4,na.rm=TRUE),2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment