txdb_file <- system.file("extdata", "hg19_knownGene_sample.sqlite",
package="GenomicFeatures")
txdb <- loadDb(txdb_file)
## ---------------------------------------------------------------------
## transcripts()
## ---------------------------------------------------------------------
tx <- transcripts(txdb)
tx
## A sanity check:
stopifnot(identical(mcols(tx)$tx_id, seq_along(tx)))
filter <- list(tx_chrom = c("chr3", "chr5"), tx_strand = "+")
transcripts(txdb, filter=filter)
## ---------------------------------------------------------------------
## exons()
## ---------------------------------------------------------------------
exons(txdb, columns=c("EXONID", "TXNAME"),
filter=list(exon_id=1))
exons(txdb, columns=c("EXONID", "TXNAME"),
filter=list(tx_name="uc009vip.1"))
## ---------------------------------------------------------------------
## genes()
## ---------------------------------------------------------------------
genes(txdb) # a GRanges object
cols <- c("tx_id", "tx_chrom", "tx_strand",
"exon_id", "exon_chrom", "exon_strand")
single_strand_genes <- genes(txdb, columns=cols)
## Because we've returned single strand genes only, the "tx_chrom"
## and "exon_chrom" metadata columns are guaranteed to match
## 'seqnames(single_strand_genes)':
stopifnot(identical(as.character(seqnames(single_strand_genes)),
as.character(mcols(single_strand_genes)$tx_chrom)))
stopifnot(identical(as.character(seqnames(single_strand_genes)),
as.character(mcols(single_strand_genes)$exon_chrom)))
## and also the "tx_strand" and "exon_strand" metadata columns are
## guaranteed to match 'strand(single_strand_genes)':
stopifnot(identical(as.character(strand(single_strand_genes)),
as.character(mcols(single_strand_genes)$tx_strand)))
stopifnot(identical(as.character(strand(single_strand_genes)),
as.character(mcols(single_strand_genes)$exon_strand)))
all_genes <- genes(txdb, columns=cols, single.strand.genes.only=FALSE)
all_genes # a GRangesList object
multiple_strand_genes <- all_genes[elementNROWS(all_genes) >= 2]
multiple_strand_genes
mcols(multiple_strand_genes)
## ---------------------------------------------------------------------
## promoters()
## ---------------------------------------------------------------------
## This:
promoters(txdb, upstream=100, downstream=50)
## is equivalent to:
promoters(transcripts(txdb), upstream=100, downstream=50)
## Extra arguments are passed to transcripts(). So this:
promoters(txdb, upstream=100, downstream=50,
columns=c("tx_name", "gene_id"))
## is equivalent to:
promoters(transcripts(txdb, columns=c("tx_name", "gene_id")),
upstream=100, downstream=50)
Run the code above in your browser using DataLab