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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
### =========================================================================
### VariantType class methods
### =========================================================================
### 'show' methods
setMethod("show", "VariantType",
function(object)
{
cat("class:", class(object), "\n")
}
)
setMethod("show", "AllVariants",
function(object)
{
cat("class:", class(object), "\n")
cat("promoter: \n")
cat(" upstream: ", upstream(promoter(object)), "\n")
cat(" downstream: ", downstream(promoter(object)), "\n")
cat("intergenic: \n")
cat(" upstream: ", upstream(intergenic(object)), "\n")
cat(" downstream: ", downstream(intergenic(object)), "\n")
}
)
setMethod("show", "PromoterVariants",
function(object)
{
cat("class:", class(object), "\n")
cat("upstream:", upstream(object), "\n")
cat("downstream:", downstream(object), "\n")
}
)
setMethod("show", "IntergenicVariants",
function(object)
{
cat("class:", class(object), "\n")
cat("upstream:", upstream(object), "\n")
cat("downstream:", downstream(object), "\n")
}
)
### constructors
CodingVariants <- function() new("CodingVariants")
IntronVariants <- function() new("IntronVariants")
UTRVariants <- function() new("UTRVariants")
ThreeUTRVariants <- function() new("ThreeUTRVariants")
FiveUTRVariants <- function() new("FiveUTRVariants")
SpliceSiteVariants <- function() new("SpliceSiteVariants")
### .checkArgs() takes the place of a validity method.
### 'upstream' and 'downstream' are forced to integers
### which changes the object and can't be done a validity
### method.
.checkArgs <- function(x, argName)
{
if (!isSingleNumber(x) | x < 0)
stop(paste0("'", argName, "'", " must be a single integer >= 0"))
if (!is.integer(x))
as.integer(x)
else
x
}
IntergenicVariants <- function(upstream=1e+06L, downstream=1e+06L)
{
upstream <- .checkArgs(upstream, "upstream")
downstream <- .checkArgs(downstream, "downstream")
new("IntergenicVariants", upstream=upstream,
downstream=downstream)
}
PromoterVariants <- function(upstream=2000L, downstream=200L)
{
upstream <- .checkArgs(upstream, "upstream")
downstream <- .checkArgs(downstream, "downstream")
new("PromoterVariants", upstream=upstream,
downstream=downstream)
}
AllVariants <- function(promoter=PromoterVariants(),
intergenic=IntergenicVariants())
{
new("AllVariants", promoter=promoter, intergenic=intergenic)
}
### getters and setters
setMethod("upstream", "PromoterVariants",
function(x) slot(x, "upstream"))
setReplaceMethod("upstream", "PromoterVariants",
function(x, value)
{
slot(x, "upstream") <- .checkArgs(value, "upstream")
x
})
setMethod("downstream", "PromoterVariants",
function(x) slot(x, "downstream"))
setReplaceMethod("downstream", "PromoterVariants",
function(x, value)
{
slot(x, "downstream") <- .checkArgs(value, "downstream")
x
})
setMethod("upstream", "IntergenicVariants",
function(x) slot(x, "upstream"))
setReplaceMethod("upstream", "IntergenicVariants",
function(x, value)
{
slot(x, "upstream") <- .checkArgs(value, "upstream")
x
})
setMethod("downstream", "IntergenicVariants",
function(x) slot(x, "downstream"))
setReplaceMethod("downstream", "IntergenicVariants",
function(x, value)
{
slot(x, "downstream") <- .checkArgs(value, "downstream")
x
})
setMethod("promoter", "AllVariants",
function(x) slot(x, "promoter"))
setReplaceMethod("promoter", "AllVariants",
function(x, value)
{
if (class(value) != "PromoterVariants")
stop("'value' must be a 'PromoterVariants' object")
slot(x, "promoter") <- value
x
})
setMethod("intergenic", "AllVariants",
function(x) slot(x, "intergenic"))
setReplaceMethod("intergenic", "AllVariants",
function(x, value)
{
if (class(value) != "IntergenicVariants")
stop("'value' must be a 'IntergenicVariants' object")
slot(x, "intergenic") <- value
x
})
|