## ---------------------------------------------------------------------
## 1. Load a toy gene model as a TxDb object
## ---------------------------------------------------------------------
library(GenomicFeatures)
suppressWarnings(
toy_genes_txdb <- makeTranscriptDbFromGFF(toy_genes_gff())
)
## ---------------------------------------------------------------------
## 2. Compute all the splicing graphs (1 graph per gene) and return them
## in a SplicingGraphs object
## ---------------------------------------------------------------------
## Extract the exons grouped by transcript:
ex_by_tx <- exonsBy(toy_genes_txdb, by="tx", use.names=TRUE)
## Extract the transcripts grouped by gene:
tx_by_gn <- transcriptsBy(toy_genes_txdb, by="gene")
sg <- SplicingGraphs(ex_by_tx, tx_by_gn)
sg
## Alternatively 'sg' can be constructed directly from the TxDb
## object:
sg2 <- SplicingGraphs(toy_genes_txdb) # same as 'sg'
sg2
## Note that because SplicingGraphs objects have a slot that is an
## environment (for caching the bubbles), they cannot be compared with
## 'identical()' (will always return FALSE). 'all.equal()' should be
## used instead:
stopifnot(isTRUE(all.equal(sg2, sg)))
## 'sg' has 1 element per gene and 'names(sg)' gives the gene ids:
length(sg)
names(sg)
## ---------------------------------------------------------------------
## 3. Basic manipulation of a SplicingGraphs object
## ---------------------------------------------------------------------
## Basic accessors:
seqnames(sg)
strand(sg)
seqinfo(sg)
## Number of transcripts per gene:
elementLengths(sg)
## The transcripts of a given gene can be extracted with [[. The result
## is an *unnamed* GRangesList object containing the exons grouped by
## transcript:
sg[["geneD"]]
## See '?plotTranscripts' for how to plot those transcripts.
## The transcripts of all the genes can be extracted with unlist(). The
## result is a *named* GRangesList object containing the exons grouped
## by transcript. The names on the object are the gene ids:
ex_by_tx <- unlist(sg)
ex_by_tx
Run the code above in your browser using DataLab