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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
### =========================================================================
### Sequence reversing and complementing
### -------------------------------------------------------------------------
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### The "reverse" methods.
###
setMethod("reverse", "MaskedXString",
function(x, ...)
{
x@unmasked <- reverse(unmasked(x))
x@masks <- reverse(masks(x))
x
}
)
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### The "complement" generic and methods.
###
setGeneric("complement", signature="x",
function(x, ...) standardGeneric("complement")
)
setMethod("complement", "DNAString",
function(x, ...) xvcopy(x, lkup=getDNAComplementLookup())
)
setMethod("complement", "RNAString",
function(x, ...) xvcopy(x, lkup=getRNAComplementLookup())
)
setMethod("complement", "DNAStringSet",
function(x, ...) xvcopy(x, lkup=getDNAComplementLookup())
)
setMethod("complement", "RNAStringSet",
function(x, ...) xvcopy(x, lkup=getRNAComplementLookup())
)
setMethod("complement", "XStringViews",
function(x, ...)
{
x@subject <- complement(subject(x))
x
}
)
setMethod("complement", "MaskedDNAString",
function(x, ...)
{
x@unmasked <- complement(unmasked(x))
x
}
)
setMethod("complement", "MaskedRNAString",
function(x, ...)
{
x@unmasked <- complement(unmasked(x))
x
}
)
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### The "reverseComplement" generic and methods.
###
### We could just do this:
### reverseComplement <- function(x) reverse(complement(x))
### But we want to perform only 1 copy of the sequence data!
### With the above implementation, reverseComplement(x) would copy the
### sequence data in 'x' twice: a first (temporary) copy to get the
### complement, followed by a second (final) copy to reverse it. Remember
### that the sequence data can be very big e.g. 250MB for Human chr1!
###
setGeneric("reverseComplement", signature="x",
function(x, ...) standardGeneric("reverseComplement")
)
setMethod("reverseComplement", "DNAString",
function(x, ...) xvcopy(x, lkup=getDNAComplementLookup(), reverse=TRUE)
)
setMethod("reverseComplement", "RNAString",
function(x, ...) xvcopy(x, lkup=getRNAComplementLookup(), reverse=TRUE)
)
setMethod("reverseComplement", "DNAStringSet",
function(x, ...) xvcopy(x, lkup=getDNAComplementLookup(), reverse=TRUE)
)
setMethod("reverseComplement", "RNAStringSet",
function(x, ...) xvcopy(x, lkup=getRNAComplementLookup(), reverse=TRUE)
)
setMethod("reverseComplement", "XStringViews",
function(x, ...)
{
x@subject <- reverseComplement(subject(x))
x@ranges <- reverse(ranges(x), start=1L, end=length(subject(x)))
x
}
)
setMethod("reverseComplement", "MaskedDNAString",
function(x, ...)
{
x@unmasked <- reverseComplement(unmasked(x))
x@masks <- reverse(masks(x))
x
}
)
setMethod("reverseComplement", "MaskedRNAString",
function(x, ...)
{
x@unmasked <- reverseComplement(unmasked(x))
x@masks <- reverse(masks(x))
x
}
)
|