Created
July 29, 2016 20:50
-
-
Save mtmorgan/bcacbea1b46445769f1cb91f87e25c30 to your computer and use it in GitHub Desktop.
Extract ranges of genes, and map ranges to corresponding genes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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