"'value' must be a logical vector with no NAs"
"'value' must be NULL or a character vector"
"the width of the collection must be a single non-negative integer"
"the 'nir_list' slot must contain a list of NormalIRanges objects"
"the min and max of the masks must be >= 1 and <= width of the collection"
"the 'active' slot must be a logical vector with no NAs"
"the length of the 'active' slot differs from the length of the object"
"the 'desc' slot must contain a character vector"
"the descriptions must be non-NA strings"
"number of descriptions and number of elements differ"
## The 'width' slot needs to be checked separately and we must return
## if it's invalid. This is because .valid.MaskCollection.nir_list()
## won't work properly if 'x@width' is NA.
### The safe and user-friendly "Mask" constructor.
### The "maskedwidth" and "maskedratio" generics and methods.
### Always behaves like an endomorphism (i.e. ignores the 'drop' argument and
### behaves like if it was actually set to FALSE).
"subscript would generate duplicated elements"
### TODO: Be more consistent with "[" which doesn't allow subscripts with
### duplicated positive values in order to make it harder for the user to
### produce a MaskCollection object with duplicated names.
### The "append" method below makes this too easy (with append(x, x)).
"'x' and 'values' must have the same width"
### Always return a MaskCollection object of length 1 where the mask is active.
### From a MaskCollection object to a NormalIRanges object.
## Explictely specify 'row.names=NULL' otherwise data.frame() will
## try to use the names of the first component that has suitable
## names, which could be 'active(x)' (3rd component) if 'x' has names.

nir_list="list",    # a list of NormalIRanges objects
NAMES="character",  # R doesn't like @names !!
stop("'value' must be a logical vector with no NAs")
function(x) if (length(x@NAMES) == 1 && is.na(x@NAMES)) NULL else x@NAMES
value <- c(value, character(length(x) - length(value)))
function(x) if (length(x@desc) == 1 && is.na(x@desc)) NULL else x@desc
stop("'value' must be NULL or a character vector")
if (!isSingleInteger(width(x)) || width(x) < 0)
return("the width of the collection must be a single non-negative integer")
|| !all(sapply(nir_list(x), function(nir) is(nir, "NormalIRanges"))))
return("the 'nir_list' slot must contain a list of NormalIRanges objects")
if (!all(1 <= min(x)) || !all(max(x) <= width(x)))
return("the min and max of the masks must be >= 1 and <= width of the collection")
return("the 'active' slot must be a logical vector with no NAs")
return("the length of the 'active' slot differs from the length of the object")
return("the names must be non-NA strings")
return("the 'desc' slot must contain a character vector")
return("the descriptions must be non-NA strings")
return("number of descriptions and number of elements differ")
Mask <- function(mask.width, start=NULL, end=NULL, width=NULL)
nir <- asNormalIRanges(IRanges(start=start, end=end, width=width), force=FALSE)
setMethod("maskedratio", "MaskCollection", function(x) maskedwidth(x) / width(x))
if (any(i > 0L)) {  # then 'all(i >= 0)' must be TRUE
stop("subscript would generate duplicated elements")
slot(x, "nir_list", check=FALSE) <- nir_list(x)[i]
slot(x, "active", check=FALSE) <- active(x)[i]
slot(x, "NAMES", check=FALSE) <- names(x)[i]
slot(x, "desc", check=FALSE) <- desc(x)[i]
.append.names.or.desc <- function(nm1, l1, nm2, l2, after)
stop("'x' and 'values' must have the same width")
ans_nir_list <- append(nir_list(x), nir_list(values), after=after)
ans_active <- append(active(x), active(values), after=after)
ans_NAMES <- .append.names.or.desc(names(x), l1, names(values), l2, after)
ans_desc <- .append.names.or.desc(desc(x), l1, desc(values), l2, after)
ranges <- new2("IRanges", start=start1, width=width1, check=FALSE)
" and width ", width(object), "\n", sep="")