File: methods-getTranscriptSeqs.R

package info (click to toggle)
r-bioc-variantannotation 1.10.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,172 kB
  • ctags: 109
  • sloc: ansic: 1,088; sh: 4; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
### =========================================================================
### getTranscriptSeqs methods 
### =========================================================================

setMethod("getTranscriptSeqs",  c("GRangesList", "BSgenome"),
    function(query, subject, ...)
    {
    extractTranscriptSeqs(subject, query)
    }
)

setMethod("getTranscriptSeqs",  c("GRangesList", "FaFile"),
    function(query, subject, ...)
    {
        ## order by exon rank, check for mixed chromosomes, mixed strand 
        txlist <- GenomicFeatures:::.makeUCSCTxListFromGRangesList(query,
            decreasing.rank.on.minus.strand=FALSE)

        ## back to GRanges for getSeq method 
        widthEL <- elementLengths(query)
        gr <- GRanges(
                seqnames=Rle(txlist$chrom, widthEL), 
                ranges=IRanges(start=unlist(txlist$exonStarts), 
                               end=unlist(txlist$exonEnds)), 
                strand=Rle(txlist$strand, widthEL))

        seqs <- callGeneric(gr, subject, ...)
        oneseq <- unlist(seqs)
        widthView <- sum(width(query)) 
        vws <- successiveViews(oneseq, widthView)
        txseq <- as(vws, "DNAStringSet") 
        names(txseq) <- names(query) 
        txseq
    }
)
 
setMethod("getTranscriptSeqs",  c("GRanges", "FaFile"),
    function(query, subject, ...)
    {
        fa <- open(subject)
        idx <- scanFaIndex(fa)
        seqmatch <- seqlevels(query) %in% seqlevels(idx) 
        if (any(seqmatch == FALSE)){
            missingSeq <- seqlevels(subject)[seqmatch == FALSE]
            stop(paste("sequence ", missingSeq, 
                " not found in 'query' \n", sep=""))
        }
 
        dna <- getSeq(fa, query) 
        close(fa)
        dna 
    }
)