Skip to content

Commit e32db0c

Browse files
Merge pull request #119 from charles-plessy/annot_from_TxDB
annotateCTSS method for TxDB objects Closes #30, #53
2 parents be47c26 + 00ef961 commit e32db0c

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Imports:
1818
formula.tools,
1919
GenomeInfoDb,
2020
GenomicAlignments,
21+
GenomicFeatures,
2122
GenomicRanges (>= 1.37.16),
2223
ggplot2 (>= 2.2.0),
2324
gtools,

NAMESPACE

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ importFrom(GenomeInfoDb,seqnames)
105105
importFrom(GenomeInfoDb,sortSeqlevels)
106106
importFrom(GenomicAlignments,qwidth)
107107
importFrom(GenomicAlignments,readGAlignments)
108+
importFrom(GenomicFeatures,exons)
109+
importFrom(GenomicFeatures,genes)
110+
importFrom(GenomicFeatures,promoters)
111+
importFrom(GenomicFeatures,transcripts)
108112
importFrom(GenomicRanges,GPos)
109113
importFrom(GenomicRanges,GRanges)
110114
importFrom(GenomicRanges,GRangesList)

R/Annotations.R

+45
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ msScope_annotation <- function(libs) {
440440
#' annotateCTSS(exampleCAGEexp, exampleZv9_annot)
441441
#' colData(exampleCAGEexp)
442442
#'
443+
#' @importFrom GenomicFeatures genes
444+
#'
443445
#' @export
444446

445447
setGeneric("annotateCTSS", function(object, ranges, upstream=500, downstream=500)
@@ -459,6 +461,22 @@ setMethod("annotateCTSS", c("CAGEexp", "GRanges"), function (object, ranges, ups
459461
object
460462
})
461463

464+
#' @rdname annotateCTSS
465+
466+
setMethod("annotateCTSS", c("CAGEexp", "TxDb"), function (object, ranges){
467+
g <- genes(ranges)
468+
g$gene_name <- g$gene_id
469+
annotateCTSS(object, g)
470+
CTSScoordinatesGR(object)$genes <- ranges2genes(CTSScoordinatesGR(object), g)
471+
CTSScoordinatesGR(object)$annotation <- txdb2annot(CTSScoordinatesGR(object), ranges)
472+
473+
annot <- sapply( CTSStagCountDF(object)
474+
, function(X) tapply(X, CTSScoordinatesGR(object)$annotation, sum))
475+
colData(object)[levels(CTSScoordinatesGR(object)$annotation)] <- DataFrame(t(annot))
476+
validObject(object)
477+
object
478+
})
479+
462480
#' `annotateTagClusters` annotates the _tag clusters_ of a _CAGEr_ object.
463481
#'
464482
#' @return `annotateTagClusters` returns the input object with the same
@@ -619,6 +637,33 @@ ranges2annot <- function(ranges, annot, upstream=500, downstream=500) {
619637
Rle(annot)
620638
}
621639

640+
#' @name txdb2annot
641+
#'
642+
#' @rdname ranges2annot
643+
#'
644+
#' @importFrom GenomicFeatures promoters exons transcripts
645+
646+
txdb2annot <- function(ranges, annot) {
647+
findOverlapsBool <- function(A, B) {
648+
overlap <- findOverlaps(A, B)
649+
overlap <- as(overlap, "List")
650+
any(overlap)
651+
}
652+
653+
classes <- c("promoter", "exon", "intron", "unknown")
654+
p <- findOverlapsBool(ranges, trim(suppressWarnings(promoters(annot, 500, 500))))
655+
e <- findOverlapsBool(ranges, exons(annot))
656+
t <- findOverlapsBool(ranges, transcripts(annot))
657+
annot <- sapply( 1:length(ranges), function(i) {
658+
if (p[i]) {classes[1]}
659+
else if (e[i]) {classes[2]}
660+
else if (t[i]) {classes[3]}
661+
else {classes[4]}
662+
})
663+
664+
annot <- factor(annot, levels = classes)
665+
Rle(annot)
666+
}
622667

623668
#' ranges2genes
624669
#'

man/annotateCTSS.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ranges2annot.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)