File: MaskCollection-class.Rd

package info (click to toggle)
r-bioc-iranges 2.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,808 kB
  • sloc: ansic: 4,789; sh: 4; makefile: 2
file content (245 lines) | stat: -rw-r--r-- 7,280 bytes parent folder | download | duplicates (3)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
\name{MaskCollection-class}
\docType{class}

% Classes:
\alias{class:MaskCollection}
\alias{MaskCollection-class}
\alias{MaskCollection}

% Basic accessor methods:
\alias{nir_list}
\alias{nir_list,MaskCollection-method}
\alias{length,MaskCollection-method}
\alias{width,MaskCollection-method}
\alias{active}
\alias{active,MaskCollection-method}
\alias{active<-}
\alias{active<-,MaskCollection-method}
\alias{names,MaskCollection-method}
\alias{names<-,MaskCollection-method}
\alias{desc}
\alias{desc,MaskCollection-method}
\alias{desc<-}
\alias{desc<-,MaskCollection-method}

% Constructor:
\alias{Mask}

% Other methods:
\alias{max,MaskCollection-method}
\alias{min,MaskCollection-method}
\alias{maskedwidth}
\alias{maskedwidth,MaskCollection-method}
\alias{maskedratio}
\alias{maskedratio,MaskCollection-method}

% Subsetting and appending:
\alias{append,MaskCollection,MaskCollection-method}

% Endomorphisms:
\alias{collapse}
\alias{collapse,MaskCollection-method}

% Coercion:
\alias{coerce,MaskCollection,NormalIRanges-method}

% "show" method:
\alias{MaskCollection.show_frame}
\alias{show,MaskCollection-method}


\title{MaskCollection objects}

\description{
  The MaskCollection class is a container for storing a collection of masks
  that can be used to mask regions in a sequence.
}

\details{
  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{\link[Biostrings:letterFrequency]{alphabetFrequency}}
  or \code{\link[Biostrings]{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{\link[Biostrings:letterFrequency]{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 \link[Biostrings:XString-class]{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 \link{NormalIRanges}
  object.
}

\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 \link{NormalIRanges} object representing a mask in \code{x}.
    }
  }
}

\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{\link{IRanges}} constructor (\code{?\link{IRanges}})
      for how \code{start}, \code{end} and \code{width} can be specified.
      Note that the returned mask is active and unnamed.
    }
  }
}

\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)}
    }
  }
}

\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 \link{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}.
    }
  }
}

\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}.
    }
  }
}

\author{Hervé Pagès}

\seealso{
  \link{NormalIRanges-class},
  \link{read.Mask},
  \link[Biostrings]{MaskedXString-class},
  \code{\link{reverse}},
  \code{\link[Biostrings]{alphabetFrequency}},
  \code{\link[Biostrings]{matchPattern}}
}

\examples{
  ## 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)

  ## 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]))
}

\keyword{methods}
\keyword{classes}