\HeaderA{MaskCollection-class}{MaskCollection objects}{MaskCollection.Rdash.class}
\aliasA{active}{MaskCollection-class}{active}
\aliasA{active,MaskCollection-method}{MaskCollection-class}{active,MaskCollection.Rdash.method}
\aliasA{active<\Rdash}{MaskCollection-class}{active<.Rdash.}
\aliasA{active<-,MaskCollection-method}{MaskCollection-class}{active<.Rdash.,MaskCollection.Rdash.method}
\aliasA{append,MaskCollection,MaskCollection-method}{MaskCollection-class}{append,MaskCollection,MaskCollection.Rdash.method}
\aliasA{class:MaskCollection}{MaskCollection-class}{class:MaskCollection}
\aliasA{coerce,MaskCollection,NormalIRanges-method}{MaskCollection-class}{coerce,MaskCollection,NormalIRanges.Rdash.method}
\aliasA{collapse}{MaskCollection-class}{collapse}
\aliasA{collapse,MaskCollection-method}{MaskCollection-class}{collapse,MaskCollection.Rdash.method}
\aliasA{desc}{MaskCollection-class}{desc}
\aliasA{desc,MaskCollection-method}{MaskCollection-class}{desc,MaskCollection.Rdash.method}
\aliasA{desc<\Rdash}{MaskCollection-class}{desc<.Rdash.}
\aliasA{desc<-,MaskCollection-method}{MaskCollection-class}{desc<.Rdash.,MaskCollection.Rdash.method}
\aliasA{gaps,MaskCollection-method}{MaskCollection-class}{gaps,MaskCollection.Rdash.method}
\aliasA{length,MaskCollection-method}{MaskCollection-class}{length,MaskCollection.Rdash.method}
\aliasA{Mask}{MaskCollection-class}{Mask}
\aliasA{MaskCollection}{MaskCollection-class}{MaskCollection}
\aliasA{MaskCollection.show\_frame}{MaskCollection-class}{MaskCollection.show.Rul.frame}
\aliasA{maskedratio}{MaskCollection-class}{maskedratio}
\aliasA{maskedratio,MaskCollection-method}{MaskCollection-class}{maskedratio,MaskCollection.Rdash.method}
\aliasA{maskedwidth}{MaskCollection-class}{maskedwidth}
\aliasA{maskedwidth,MaskCollection-method}{MaskCollection-class}{maskedwidth,MaskCollection.Rdash.method}
\aliasA{max,MaskCollection-method}{MaskCollection-class}{max,MaskCollection.Rdash.method}
\aliasA{min,MaskCollection-method}{MaskCollection-class}{min,MaskCollection.Rdash.method}
\aliasA{names,MaskCollection-method}{MaskCollection-class}{names,MaskCollection.Rdash.method}
\aliasA{names<-,MaskCollection-method}{MaskCollection-class}{names<.Rdash.,MaskCollection.Rdash.method}
\aliasA{nir\_list}{MaskCollection-class}{nir.Rul.list}
\aliasA{nir\_list,MaskCollection-method}{MaskCollection-class}{nir.Rul.list,MaskCollection.Rdash.method}
\aliasA{show,MaskCollection-method}{MaskCollection-class}{show,MaskCollection.Rdash.method}
\aliasA{subseq,MaskCollection-method}{MaskCollection-class}{subseq,MaskCollection.Rdash.method}
\aliasA{width,MaskCollection-method}{MaskCollection-class}{width,MaskCollection.Rdash.method}
\aliasA{[,MaskCollection-method}{MaskCollection-class}{[,MaskCollection.Rdash.method}
\aliasA{[[,MaskCollection-method}{MaskCollection-class}{[[,MaskCollection.Rdash.method}
\keyword{methods}{MaskCollection-class}
\keyword{classes}{MaskCollection-class}
\begin{Description}\relax
The MaskCollection class is a container for storing a collection of masks
that can be used to mask regions in a sequence.
\end{Description}
\begin{Details}\relax
In the context of the Biostrings package, a mask is a set of regions
in a sequence that need to be excluded from some computation.
For example, when calling \code{\LinkA{alphabetFrequency}{alphabetFrequency}}
or \code{\LinkA{matchPattern}{matchPattern}} on a chromosome sequence,
you might want to exclude some regions like the centromere or the repeat
regions. This can be achieved by putting one or several masks on the sequence
before calling \code{\LinkA{alphabetFrequency}{alphabetFrequency}} on it.

A MaskCollection object is a vector-like object that represents
such set of masks.
Like standard R vectors, it has a "length" which is the number of
masks contained in it. But unlike standard R vectors, it also has
a "width" which determines the length of the sequences it can be "put on".
For example, a MaskCollection object of width 20000 can only be put on
an \LinkA{XString}{XString} object of 20000 letters.

Each mask in a MaskCollection object \code{x} is just a finite set of
integers that are >= 1 and <= \code{width(x)}.
When "put on" a sequence, these integers indicate the positions of the
letters to mask.
Internally, each mask is represented by a \LinkA{NormalIRanges}{NormalIRanges}
object.
\end{Details}
\begin{Section}{Basic accessor methods}
In the code snippets below, \code{x} is a MaskCollection object.

\describe{
\item[] \code{length(x)}:
The number of masks in \code{x}.

\item[] \code{width(x)}:
The common with of all the masks in \code{x}.
This determines the length of the sequences that \code{x} can be
"put on".

\item[] \code{active(x)}:
A logical vector of the same length as \code{x} where each
element indicates whether the corresponding mask is active or not.

\item[] \code{names(x)}:
\code{NULL} or a character vector of the same length as \code{x}.

\item[] \code{desc(x)}:
\code{NULL} or a character vector of the same length as \code{x}.

\item[] \code{nir\_list(x)}:
A list of the same length as \code{x}, where each element is
a \LinkA{NormalIRanges}{NormalIRanges} object representing a mask in \code{x}.

}
\end{Section}
\begin{Section}{Constructor}
\describe{
\item[] \code{Mask(mask.width, start=NULL, end=NULL, width=NULL)}:
Return a single mask (i.e. a MaskCollection object of length 1)
of width \code{mask.width} (a single integer >= 1)
and masking the ranges of positions specified by \code{start},
\code{end} and \code{width}.
See the \code{\LinkA{IRanges}{IRanges}} constructor (\code{?\LinkA{IRanges}{IRanges}})
for how \code{start}, \code{end} and \code{width} can be specified.
Note that the returned mask is active and unnamed.

}
\end{Section}
\begin{Section}{Other methods}
In the code snippets below, \code{x} is a MaskCollection object.

\describe{
\item[] \code{isEmpty(x)}:
Return a logical vector of the same length as \code{x}, indicating,
for each mask in \code{x}, whether it's empty or not.

\item[] \code{max(x)}:
The greatest (or last, or rightmost) masked position for each mask.
This is a numeric vector of the same length as \code{x}.

\item[] \code{min(x)}:
The smallest (or first, or leftmost) masked position for each mask.
This is a numeric vector of the same length as \code{x}.

\item[] \code{maskedwidth(x)}:
The number of masked position for each mask.
This is an integer vector of the same length as \code{x} where
all values are >= 0 and <= \code{width(x)}.

\item[] \code{maskedratio(x)}:
\code{maskedwidth(x) / width(x)}

}
\end{Section}
\begin{Section}{Subsetting and appending}
In the code snippets below,
\code{x} and \code{values} are MaskCollection objects.

\describe{
\item[] \code{x[i]}:
Return a new MaskCollection object made of the selected masks.
Subscript \code{i} can be a numeric, logical or character vector.

\item[] \code{x[[i, exact=TRUE]]}:
Extract the mask selected by \code{i} as a \LinkA{NormalIRanges}{NormalIRanges} object.
Subscript \code{i} can be a single integer or a character string.

\item[] \code{append(x, values, after=length(x))}:
Add masks in \code{values} to \code{x}.

}
\end{Section}
\begin{Section}{Other methods}
In the code snippets below, \code{x} is a MaskCollection object.

\describe{
\item[] \code{collapse(x)}:
Return a MaskCollection object of length 1 obtained by collapsing
all the active masks in \code{x}.

\item[] \code{gaps(x)}:
Invert the masks in \code{x}.

\item[] \code{subseq(x, start=NA, end=NA, width=NA)}:
If \code{y} is a sequence that \code{x} has been put on top of,
then \code{subseq} will return the set of submasks that go on top
of the subsequence obtained by calling \code{subseq} on \code{y}
(\code{subseq} must be called on \code{x} with the same arguments
that have been used when called on \code{y}).

}
\end{Section}
\begin{Author}\relax
H. Pages
\end{Author}
\begin{SeeAlso}\relax
\LinkA{NormalIRanges-class}{NormalIRanges.Rdash.class},
\LinkA{read.Mask}{read.Mask},
\LinkA{MaskedXString-class}{MaskedXString.Rdash.class},
\code{\LinkA{alphabetFrequency}{alphabetFrequency}},
\code{\LinkA{reverse}{reverse}},
\code{\LinkA{matchPattern}{matchPattern}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  ## Making a MaskCollection object:
  mask1 <- Mask(mask.width=29, start=c(11, 25, 28), width=c(5, 2, 2))
  mask2 <- Mask(mask.width=29, start=c(3, 10, 27), width=c(5, 8, 1))
  mask3 <- Mask(mask.width=29, start=c(7, 12), width=c(2, 4))
  mymasks <- append(append(mask1, mask2), mask3)
  mymasks
  length(mymasks)
  width(mymasks)
  collapse(mymasks)
  gaps(mymasks)

  ## Names and descriptions:
  names(mymasks) <- c("A", "B", "C")  # names should be short and unique...
  mymasks
  mymasks[c("C", "A")]  # ...to make subsetting by names easier
  desc(mymasks) <- c("you can be", "more verbose", "here")
  mymasks[-2]

  ## Activate/deactivate masks:
  active(mymasks)["B"] <- FALSE
  mymasks
  collapse(mymasks)
  active(mymasks) <- FALSE  # deactivate all masks
  mymasks
  active(mymasks)[-1] <- TRUE  # reactivate all masks except mask 1
  active(mymasks) <- !active(mymasks)  # toggle all masks

  ## Other advanced operations:
  mymasks[[2]]
  length(mymasks[[2]])
  mymasks[[2]][-3]
  append(mymasks[-2], gaps(mymasks[2]))
  mymasks2 <- subseq(mymasks, start=8)
  mymasks2
  mymasks2[[2]]
\end{ExampleCode}
\end{Examples}

