Skip to content

Commit 7c5b5ce

Browse files
committed
annotateRanges with TxDb object
1 parent 1609160 commit 7c5b5ce

8 files changed

Lines changed: 93 additions & 16 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Suggests:
6060
rmarkdown,
6161
testthat,
6262
covr,
63+
TxDb.Hsapiens.UCSC.hg19.knownGene,
64+
org.Hs.eg.db,
6365
LinkingTo:
6466
Rcpp,
6567
RcppArmadillo

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export(N)
2020
export(aberrant)
2121
export(addCountsToFraseRDataSet)
2222
export(annotateRanges)
23+
export(annotateRangesWithTxDb)
2324
export(bamFile)
2425
export(bestQ)
2526
export(calculatePSIValues)
@@ -134,6 +135,7 @@ importFrom(GenomeInfoDb,seqnames)
134135
importFrom(GenomicAlignments,junctions)
135136
importFrom(GenomicAlignments,readGAlignments)
136137
importFrom(GenomicAlignments,summarizeJunctions)
138+
importFrom(GenomicFeatures,genes)
137139
importFrom(GenomicFeatures,intronsByTranscript)
138140
importFrom(GenomicFeatures,makeTxDbFromGFF)
139141
importFrom(GenomicRanges,GRanges)

R/FRASER-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#'
1919
### GRange/Experiment/bamFile packages
2020
#' @importFrom BiocGenerics updateObject counts counts<- strand strand<-
21-
#' @importFrom GenomicFeatures makeTxDbFromGFF intronsByTranscript
21+
#' @importFrom GenomicFeatures makeTxDbFromGFF intronsByTranscript genes
2222
#' @importFrom GenomicAlignments junctions readGAlignments summarizeJunctions
2323
#' @importFrom SummarizedExperiment assay assay<- assays assays<- assayNames
2424
#' colData colData<- rowData rowRanges rowRanges<- SummarizedExperiment

R/annotationOfRanges.R

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,32 @@
1414
#' @param featureName Name of the feature in the FraseRDataSet mcols.
1515
#' @param biotype The biotype.
1616
#' @param ensembl The ensembl that should be used. If NULL, the default one is
17-
#' used (hsapiens_gene_ensembl, GRCh38).
18-
#' @param GRCh GRCh version to connect to if not the current GRCh38,
19-
#' currently this can only be 37
17+
#' used (hsapiens_gene_ensembl, GRCh37).
18+
#' @param GRCh GRCh version to connect to. If this is NULL, then the current
19+
#' GRCh38 is used. Otherwise, this can only be 37 (default) at the moment
20+
#' (see \code{\link{useEnsebml}}).
21+
#' @param txdb A TxDb object (default: TxDb.Hsapiens.UCSC.hg19.knownGene).
22+
#' @param orgDb An orgDb object (default: org.Hs.eg.db).
2023
#'
2124
#' @return FraseRDataSet
2225
#'
2326
#' @examples
2427
#'
2528
#' fds <- makeExampleFraseRDataSet()
26-
#' fds <- annotateRanges(fds)
29+
#' fds <- annotateRanges(fds, GRCh=NULL)
30+
#'
31+
#' require(TxDb.Hsapiens.UCSC.hg19.knownGene)
32+
#' txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
33+
#' require(org.Hs.eg.db)
34+
#' orgDb <- org.Hs.eg.db
35+
#' fds <- annotateRangesWithTxDb(fds, txdb=txdb, orgDb=orgDb)
2736
#'
2837
#' rowRanges(fds, type="psi5")[,"hgnc_symbol"]
2938
#'
39+
#' @rdname annotateRanges
3040
#' @export
3141
annotateRanges <- function(fds, feature="hgnc_symbol", featureName=feature,
32-
biotype=list("protein_coding"), ensembl=NULL, GRCh=NULL){
42+
biotype=list("protein_coding"), ensembl=NULL, GRCh=37){
3343

3444
# check input
3545
stopifnot(is(fds, "FraseRDataSet"))
@@ -73,6 +83,39 @@ annotateRanges <- function(fds, feature="hgnc_symbol", featureName=feature,
7383
return(fds)
7484
}
7585

86+
#' @rdname annotateRanges
87+
#' @export
88+
annotateRangesWithTxDb <- function(fds, feature="SYMBOL",
89+
featureName="hgnc_symbol",
90+
txdb=TxDb.Hsapiens.UCSC.hg19.knownGene,
91+
orgDb=org.Hs.eg.db){
92+
93+
# check input
94+
stopifnot(is(fds, "FraseRDataSet"))
95+
if(length(fds) == 0) return(fds)
96+
97+
for(i in c("psi3", "psiSite")){
98+
# get GRanges object with the split reads which should be annotated
99+
gr <- rowRanges(fds, type=i)
100+
101+
# get the annotation to compare to
102+
anno <- genes(txdb)
103+
mcols(anno)[[featureName]] <-
104+
select(orgDb, keys=mcols(anno)[,"gene_id"], columns=feature,
105+
keytype="ENTREZID")[,feature]
106+
anno <- anno[!is.na(mcols(anno)[,featureName]),]
107+
anno <- anno[mcols(anno)[,featureName] != "",]
108+
if(any(strand(gr) == "*")){
109+
strand(anno) <- "*"
110+
}
111+
112+
# retrieve the feature of interest for the split reads
113+
mcols(fds, type=i)[[featureName]] <-
114+
getAnnotationFeature(gr, featureName, anno)
115+
}
116+
117+
return(fds)
118+
}
76119

77120
#'
78121
#' use biomart to extract the current feature annotation

R/methods-makeExampleObj.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#' Create example data sets for FraseR
33
#'
44
#' Creates an example data set from files with example counts.
5-
#' \Rfunction{makeFittedExampleFraseRDataSet} additionally runs the FRASER
5+
#' \code{makeFittedExampleFraseRDataSet} additionally runs the FRASER
66
#' pipeline.
77
#'
88
#' @return FraseRDataSet

man/annotateRanges.Rd

Lines changed: 25 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/makeExampleFraseRDataSet.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/FraseR.Rnw

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ fds <- calculatePSIValues(fds)
204204
# use PCA to speed up the tutorial
205205
fds <- FraseR(fds, q=2, correction="PCA")
206206
207-
fds <- annotateRanges(fds)
207+
# fds <- annotateRanges(fds) # uses biomart
208+
require(TxDb.Hsapiens.UCSC.hg19.knownGene)
209+
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
210+
require(org.Hs.eg.db)
211+
orgDb <- org.Hs.eg.db
212+
fds <- annotateRangesWithTxDb(fds, txdb=txdb, orgDb=orgDb)
208213
209214
# get results: usually, using p-value cutoff is recommended, but on the small
210215
# example dataset, this would give no results, so we use z-scores here instead
@@ -477,8 +482,13 @@ cutoff or a cutoff on the $\Delta\Psi$ values between the observed and expected
477482
$\Psi$ values or both.
478483

479484
<<result table, echo=TRUE>>=
480-
# annotate
481-
fds <- annotateRanges(fds)
485+
# annotate introns with the hgnc symbols of the corresponding gene
486+
require(TxDb.Hsapiens.UCSC.hg19.knownGene)
487+
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
488+
require(org.Hs.eg.db)
489+
orgDb <- org.Hs.eg.db
490+
fds <- annotateRangesWithTxDb(fds, txdb=txdb, orgDb=orgDb)
491+
# fds <- annotateRanges(fds) # alternative way using biomart
482492
483493
# retrive results
484494
res <- results(fds, padjCutoff=0.05, zScoreCutoff=NA, deltaPsiCutoff=0.3)

0 commit comments

Comments
 (0)