Skip to content

Instantly share code, notes, and snippets.

@mtmorgan
Created July 29, 2016 20:50
Show Gist options
  • Save mtmorgan/bcacbea1b46445769f1cb91f87e25c30 to your computer and use it in GitHub Desktop.
Save mtmorgan/bcacbea1b46445769f1cb91f87e25c30 to your computer and use it in GitHub Desktop.
Extract ranges of genes, and map ranges to corresponding genes
geneRanges <-
function(db, column="ENTREZID")
{
g <- genes(db, columns=column)
col <- mcols(g)[[column]]
genes <- granges(g)[rep(seq_along(g), elementNROWS(col))]
mcols(genes)[[column]] <- as.character(unlist(col))
genes
}
splitColumnByOverlap <-
function(query, subject, column="ENTREZID", ...)
{
olaps <- findOverlaps(query, subject, ...)
f1 <- factor(subjectHits(olaps),
levels=seq_len(subjectLength(olaps)))
splitAsList(mcols(query)[[column]][queryHits(olaps)], f1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment