|
14 | 14 | #' @param featureName Name of the feature in the FraseRDataSet mcols. |
15 | 15 | #' @param biotype The biotype. |
16 | 16 | #' @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). |
20 | 23 | #' |
21 | 24 | #' @return FraseRDataSet |
22 | 25 | #' |
23 | 26 | #' @examples |
24 | 27 | #' |
25 | 28 | #' 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) |
27 | 36 | #' |
28 | 37 | #' rowRanges(fds, type="psi5")[,"hgnc_symbol"] |
29 | 38 | #' |
| 39 | +#' @rdname annotateRanges |
30 | 40 | #' @export |
31 | 41 | 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){ |
33 | 43 |
|
34 | 44 | # check input |
35 | 45 | stopifnot(is(fds, "FraseRDataSet")) |
@@ -73,6 +83,39 @@ annotateRanges <- function(fds, feature="hgnc_symbol", featureName=feature, |
73 | 83 | return(fds) |
74 | 84 | } |
75 | 85 |
|
| 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 | +} |
76 | 119 |
|
77 | 120 | #' |
78 | 121 | #' use biomart to extract the current feature annotation |
|
0 commit comments