Skip to contents

Execute Database Operation with Automatic Connection Management

Usage

# S4 method for class 'character,function'
withTxDb(x, expr, ...)

Arguments

x

The genome name or object to operate on

expr

Expression to evaluate with database connection

...

Additional arguments

Value

Result of the database operation

Examples

requireNamespace("TxDb.Hsapiens.UCSC.hg38.knownGene")
requireNamespace("org.Hs.eg.db")
result <- withTxDb("hg38", function(src) {
  genes <- Organism.dplyr::genes(src)
  return(genes)
})
print(result)
#> GRanges object with 37105 ranges and 0 metadata columns:
#>                      seqnames              ranges strand
#>                         <Rle>           <IRanges>  <Rle>
#>       [1]               chr19   58345178-58362751      -
#>       [2]                chr8   18386311-18401218      +
#>       [3]               chr20   44584896-44652252      -
#>       [4]               chr18   27932879-28177946      -
#>       [5]                chr1 243488233-243851079      -
#>       ...                 ...                 ...    ...
#>   [37101]               chr21   34364006-34371381      +
#>   [37102]               chr22   19036282-19122454      -
#>   [37103]                chr6   89829894-89874436      +
#>   [37104] chr6_KV766194v1_fix         25225-72124      +
#>   [37105]               chr22   50523568-50526461      -
#>   -------
#>   seqinfo: 711 sequences (1 circular) from hg38 genome