Skip to content

Commit

Permalink
sped up bb_params "gene" parameter data acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole Kramer committed Dec 15, 2020
1 parent 7df58df commit ed50c69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
12 changes: 3 additions & 9 deletions R/bb_getExons.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
bb_getExons <- function(assembly, chromosome = NULL, start = NULL, stop = NULL){
bb_getExons <- function(assembly, chromosome, start, stop){

tx_db <- eval(parse(text = assembly$TxDb))
org_db <- eval(parse(text = assembly$OrgDb))

if (!is.null(chromosome)){
genes_on_chrom <- suppressMessages(genes(tx_db, filter = list(tx_chrom = chromosome))) ## Still GRanges
if (!is.null(start) & !is.null(stop)){
genes_in_range <- genes_on_chrom[genes_on_chrom@ranges@start<=stop&genes_on_chrom@ranges@start+genes_on_chrom@ranges@width>=start]
}
} else {
genes_in_range <- suppressMessages(genes(tx_db))
}

genes_on_chrom <- suppressMessages(genes(tx_db, filter = list(tx_chrom = chromosome))) ## Still GRanges
genes_in_range <- genes_on_chrom[genes_on_chrom@ranges@start<=stop&genes_on_chrom@ranges@start+genes_on_chrom@ranges@width>=start]
txs_wo_symbols <- suppressMessages(select(tx_db, keys = genes_in_range$gene_id, columns = columns(tx_db), keytype = "GENEID"))

if (assembly$gene.id.column == assembly$display.column){
Expand Down
25 changes: 14 additions & 11 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,35 @@
if (txdbChecks == TRUE & orgdbChecks == TRUE){
tx_db <- eval(parse(text = assembly$TxDb))
org_db <- eval(parse(text = assembly$OrgDb))
chromSizes <- seqlengths(tx_db)
idCol <- assembly$gene.id.column
displayCol <- assembly$display.column
genes <- bb_getExons(assembly = assembly)
## Check that gene is in extracted data
if(!gene %%in%% genes[[displayCol]]) {
stop(paste('Gene', shQuote(gene),
'does not exist in assembly', shQuote(assembly)))
}
## convert input gene name to geneID
geneID <- tryCatch(expr = {
suppressMessages(select(org_db, keys = gene, columns = c(idCol), keytype = displayCol))
}, error = function(e) stop(paste('Gene', shQuote(gene), 'does not exist in assembly.'), call. = FALSE))
geneData <- suppressMessages(select(tx_db, keys = geneID[[idCol]], columns = columns(tx_db), keytype = 'GENEID'))
## Check that user has not supplied both gene and chrom, chromstart, or chromend
if(any(!is.null(c(chrom, chromstart, chromend)))) {
stop('Cannot use \\'gene\\' in combination with \\'chrom\\', \\'chromstart\\', or \\'chromend\\'', call. = FALSE)
}
## Subset for gene region
geneRegion <- genes[which(genes[[displayCol]] == object$gene),]
minGeneStart <- min(geneRegion$TXSTART)
maxGeneEnd <- max(geneRegion$TXEND)
## Get info about gene region
minGeneStart <- min(geneData$TXSTART)
maxGeneEnd <- max(geneData$TXEND)
## Set default gene buffer (window = 2X gene length)
## Define buffer
if (is.null(geneBuffer)) geneBuffer <- (maxGeneEnd - minGeneStart) / 2
## Assign values to bb_params object (with buffer)
object$chrom <- unique(geneRegion$TXCHROM)
object$chrom <- unique(geneData$TXCHROM)
object$chromstart <- minGeneStart - geneBuffer
object$chromend <- maxGeneEnd + geneBuffer
object$geneBuffer <- geneBuffer
Expand Down

0 comments on commit ed50c69

Please sign in to comment.