Title: | Hierarchical Gating Pipeline for flow cytometry data |
---|---|
Description: | This package is designed to facilitate the automated gating methods in sequential way to mimic the manual gating strategy. |
Authors: | Mike Jiang, John Ramey, Greg Finak, Raphael Gottardo |
Maintainer: | Mike Jiang <[email protected]> |
License: | AGPL-3.0-only |
Version: | 2.19.0 |
Built: | 2024-11-29 06:58:06 UTC |
Source: | https://github.com/bioc/openCyto |
It is the inverse function of gatingTemplate constructor.
## S3 method for class 'gatingTemplate' as.data.table(x, keep.rownames = FALSE)
## S3 method for class 'gatingTemplate' as.data.table(x, keep.rownames = FALSE)
x |
gatingTemplate object |
keep.rownames |
not used |
a data.table
get gating method dimensions
## S4 method for signature 'gtMethod' dims(x)
## S4 method for signature 'gtMethod' dims(x)
x |
|
It is generated automatically by the csv template preprocessing to handle the gating function that returns multiple gates.
rewritten in c++, till eval stats::lm.wfit r function in underlying cpp11 code It is internally used for singletGate, thus its output format may not be generic enough for common model fitting . e.g. it doesn't take formula as input
fast_rlm(x, y, maxit = 20)
fast_rlm(x, y, maxit = 20)
x |
matrix with first column as weight (default can be 1s), the rest columns are predict variable |
y |
numeric vector as response |
maxit |
maximum iterations |
fcEllipsoidGate
constuctor for fcEllipsoidGate
fcEllipsoidGate(x, priors, posts)
fcEllipsoidGate(x, priors, posts)
x |
a |
priors |
a |
posts |
a |
It stores priors and posteriors as well as the actual ellipsoidGate.
Bascially it extends flowCore 'filter classes to have extra slot to store priors and posteriors
fcFilterList
constuctor for fcFilterList
fcFilterList(x)
fcFilterList(x)
x |
|
filterList
class.Each filter in the filterList must extends the fcFilter
class
fcPolygonGate
constuctor for fcPolygonGate
fcPolygonGate(x, priors, posts)
fcPolygonGate(x, priors, posts)
x |
a |
priors |
a |
posts |
a |
It stores priors and posteriors as well as the actual polygonGate.
fcRectangleGate
constuctor for fcRectangleGate
fcRectangleGate(x, priors, posts)
fcRectangleGate(x, priors, posts)
x |
a |
priors |
a |
posts |
a |
It stores priors and posteriors as well as the actual rectangleGate.
fcTree
It adds an extra node data slot "fList"(which is a filterList
object) to the gatingTemplate
fcTree(gt)
fcTree(gt)
gt |
a |
It is a graphNEL used as a container to store priors and posteriors for each flowClust gate that can be visualized for the purpose of fine-tunning parameters for flowClust algorithm
We cluster the observations in fr
into K
clusters.
gate_flowclust_1d( fr, params, filterId = "", K = NULL, trans = 0, min.count = -1, max.count = -1, nstart = 1, prior = NULL, criterion = c("BIC", "ICL"), cutpoint_method = c("boundary", "min_density", "quantile", "posterior_mean", "prior_density"), neg_cluster = 1, cutpoint_min = NULL, cutpoint_max = NULL, min = NULL, max = NULL, quantile = 0.99, quantile_interval = c(0, 10), plot = FALSE, debug = FALSE, ... )
gate_flowclust_1d( fr, params, filterId = "", K = NULL, trans = 0, min.count = -1, max.count = -1, nstart = 1, prior = NULL, criterion = c("BIC", "ICL"), cutpoint_method = c("boundary", "min_density", "quantile", "posterior_mean", "prior_density"), neg_cluster = 1, cutpoint_min = NULL, cutpoint_max = NULL, min = NULL, max = NULL, quantile = 0.99, quantile_interval = c(0, 10), plot = FALSE, debug = FALSE, ... )
fr |
a |
params |
|
filterId |
A |
K |
the number of clusters to find |
trans , min.count , max.count , nstart
|
some flowClust parameters. see |
prior |
list of prior parameters for the Bayesian
|
criterion |
a character string stating the criterion used to choose the
best model. May take either "BIC" or "ICL". This argument is only relevant
when |
cutpoint_method |
How should the cutpoint be chosen from the fitted
|
neg_cluster |
integer. The index of the negative cluster. The cutpoint
is computed between clusters |
cutpoint_min |
numeric value that sets a minimum thresold for the
cutpoint. If a value is provided, any cutpoint below this value will be set
to the given minimum value. If |
cutpoint_max |
numeric value that sets a maximum thresold for the
cutpoint. If a value is provided, any cutpoint above this value will be set
to the given maximum value. If |
min |
a numeric value that sets the lower bound for data filtering. If
|
max |
a numeric value that sets the upper bound for data filtering. If
|
quantile |
the quantile for which we will find the cutpoint using
the quantile |
quantile_interval |
a vector of length 2 containing the end-points of
the interval of values to find the quantile cutpoint. If the
|
plot |
logical value indicating that the fitted |
debug |
|
... |
additional arguments that are passed to |
By default, the cutpoint is chosen to be the boundary of the first two
clusters. That is, between the first two cluster centroids, we find the
midpoint between the largest observation from the first cluster and the
smallest observations from the second cluster. Alternatively, if the
cutpoint_method
is min_density
, then the cutpoint is the point
at which the density between the first and second smallest cluster centroids
is minimum.
a rectangleGate
object consisting of all values beyond the
cutpoint calculated
## Not run: gate <- gate_flowclust_1d(fr, params = "APC-A", K =2) # fr is a flowFrame ## End(Not run)
## Not run: gate <- gate_flowclust_1d(fr, params = "APC-A", K =2) # fr is a flowFrame ## End(Not run)
We cluster the observations in fr
into K
clusters. We set the
cutpoint to be the point at which the density between the first and second
smallest cluster centroids is minimum.
gate_flowclust_2d( fr, xChannel, yChannel, filterId = "", K = 2, usePrior = "no", prior = list(NA), trans = 0, min.count = -1, max.count = -1, nstart = 1, plot = FALSE, target = NULL, transitional = FALSE, quantile = 0.9, translation = 0.25, transitional_angle = NULL, min = NULL, max = NULL, ... )
gate_flowclust_2d( fr, xChannel, yChannel, filterId = "", K = 2, usePrior = "no", prior = list(NA), trans = 0, min.count = -1, max.count = -1, nstart = 1, plot = FALSE, target = NULL, transitional = FALSE, quantile = 0.9, translation = 0.25, transitional_angle = NULL, min = NULL, max = NULL, ... )
fr |
a |
xChannel , yChannel
|
|
filterId |
A |
K |
the number of clusters to find |
usePrior |
Should we use the Bayesian version of |
prior |
list of prior parameters for the Bayesian version of
|
trans , min.count , max.count , nstart
|
some flowClust parameters. see |
plot |
a logical value indicating if the fitted mixture model should be plotted. By default, no. |
target |
a numeric vector of length |
transitional |
logical value indicating if a transitional gate should be
constructed from the target |
quantile |
the contour level of the target cluster from the
|
translation |
a numeric value between 0 and 1 used to position a
transitional gate if |
transitional_angle |
the angle (in radians) of the transitional
gate. It is also used to determine which quadrant the final gate resides in.
See details. Ignored if |
min |
A vector of length 2. Truncate observations less than this minimum
value. The first value truncates the |
max |
A vector of length 2. Truncate observations greater than this
maximum value. The first value truncates the |
... |
additional arguments that are passed to |
The cluster for the population of interest is selected as the one with
cluster centroid nearest the target
in Euclidean distance. By default,
the largest cluster (i.e., the cluster with the largest proportion of
observations) is selected as the population of interest.
We also provide the option of constructing a transitional
gate from
the selected population of interest. The location of the gate can be
controlled with the translation
argument, which translates the gate
along the major axis of the targest cluster as a function of the appropriate
chi-squared coefficient. The larger translation
is, the more gate is
shifted in a positive direction. Furthermore, the width of the
transitional
gate can be controlled with the quantile
argument.
The direction of the transitional gate can be controlled with the
transitional_angle
argument. By default, it is NULL
, and we use
the eigenvector of the target
cluster that points towards the first
quadrant (has positive slope). If transitional_angle
is specified, we
rotate the eigenvectors so that the angle between the x-axis (with the cluster
centroid as the origin) and the major eigenvector (i.e., the eigenvector with
the larger eigenvalue) is transitional_angle
.
So based on range that the angle falls in, the final rectangleGate will be constructed
at the corresponding quadrant. i.e. Clockwise, [0,pi/2] UR, (pi/2, pi] LR,
(pi, 3/2 * pi] LL, (3/2 * pi, 2 * pi] UL
a polygonGate
object containing the contour (ellipse) for 2D
gating.
## Not run: gate <- gate_flowclust_2d(fr, xChannel = "FSC-A", xChannel = "SSC-A", K = 3) # fr is a flowFrame ## End(Not run)
## Not run: gate <- gate_flowclust_2d(fr, xChannel = "FSC-A", xChannel = "SSC-A", K = 3) # fr is a flowFrame ## End(Not run)
We fit a kernel density estimator to the cells in the flowFrame
and
identify the two largest peaks. We then
select as the cutpoint the value at which the minimum density is attained
between the two peaks of interest.
gate_mindensity( fr, channel, filterId = "", positive = TRUE, gate_range = NULL, min = NULL, max = NULL, peaks = NULL, ... )
gate_mindensity( fr, channel, filterId = "", positive = TRUE, gate_range = NULL, min = NULL, max = NULL, peaks = NULL, ... )
fr |
a |
channel |
TODO |
filterId |
TODO |
positive |
If |
gate_range |
numeric vector of length 2. If given, this sets the bounds
on the gate applied. If no gate is found within this range, we set the gate to
the minimum value within this range if |
min |
a numeric value that sets the lower boundary for data filtering |
max |
a numeric value that sets the upper boundary for data filtering |
peaks |
|
... |
Additional arguments for peak detection. |
In the default case, the two peaks of interest are the two largest peaks
obtained from the link{density}
function.
In the special case that there is only one peak, we are conservative and set
the cutpoint as the min(x)
if positive
is TRUE
, and the
max(x)
otherwise.
a rectangleGate
object based on the minimum density cutpoint
## Not run: gate <- gate_mindensity(fr, channel = "APC-A") # fr is a flowFrame ## End(Not run)
## Not run: gate <- gate_mindensity(fr, channel = "APC-A") # fr is a flowFrame ## End(Not run)
Analogous to the original openCyto::mindensity(), mindensity2 operates on a standard flowFrame. Its behavior is closely modeled on the original mindensity() whenever possible. However, the underlying peak-finding algorithm (improvedMindensity) behaves significantly differently.
gate_mindensity2( fr, channel, filterId = "", gate_range = NULL, min = NULL, max = NULL, peaks = NULL, ... )
gate_mindensity2( fr, channel, filterId = "", gate_range = NULL, min = NULL, max = NULL, peaks = NULL, ... )
fr |
a |
channel |
the channel to operate on |
filterId |
a name to refer to this filter |
gate_range |
numeric vector of length 2. If given, this sets the bounds on the gate applied. |
min |
a numeric value that sets the lower boundary for data filtering |
max |
a numeric value that sets the upper boundary for data filtering |
peaks |
|
... |
Additional arguments for peak detection. |
a rectangleGate
object based on the minimum density cutpoint
Greg Finak, Phu T. Van
## Not run: gate <- gate_mindensity2(fr, channel = "APC-A") # fr is a flowFrame ## End(Not run)
## Not run: gate <- gate_mindensity2(fr, channel = "APC-A") # fr is a flowFrame ## End(Not run)
The order of 1d-gating is determined so that the gates better capture the distributions of flow data.
gate_quad_sequential(fr, channels, gFunc, min = NULL, max = NULL, ...)
gate_quad_sequential(fr, channels, gFunc, min = NULL, max = NULL, ...)
fr |
|
channels |
|
gFunc |
the name of the 1d-gating function to be used for either dimension |
min |
a numeric vector that sets the lower bounds for data filtering |
max |
a numeric vector that sets the upper bounds for data filtering |
... |
other arguments passed to |
a filters
that contains four rectangleGates
This gating method identifies two quadrants (first, and third quadrants) by fitting the data with tmixture model. It is particually useful when the two markers are not well resolved thus the regular quadGate method based on 1d gating will not find the perfect cut points on both dimensions.
gate_quad_tmix( fr, channels, K, usePrior = "no", prior = list(NA), quantile1 = 0.8, quantile3 = 0.8, trans = 0, plot = FALSE, ... )
gate_quad_tmix( fr, channels, K, usePrior = "no", prior = list(NA), quantile1 = 0.8, quantile3 = 0.8, trans = 0, plot = FALSE, ... )
fr |
|
channels |
|
K |
|
usePrior |
|
prior |
|
quantile1 |
|
quantile3 |
|
trans |
|
plot |
logical whether to plot flowClust clustering results |
... |
other arguments passed to flowClust |
a filters
object that contains four polygonGate
s following the order of (-+,++,+-,–)
It is possible that the cutpoint calculated by quantile function may not produce the exact the probability set by 'probs' argument if there are not enough cell events to reach that precision. Sometime the difference could be significant.
gate_quantile( fr, channel, probs = 0.999, plot = FALSE, filterId = "", min = NULL, max = NULL, ... )
gate_quantile( fr, channel, probs = 0.999, plot = FALSE, filterId = "", min = NULL, max = NULL, ... )
fr |
a |
channel |
the channel from which the cytokine gate is constructed |
probs |
probabilities passed to 'stats::quantile' function. |
plot |
whether to plot the gate result |
filterId |
the name of the filter |
min |
a numeric value that sets the lower boundary for data filtering |
max |
a numeric value that sets the upper boundary for data filtering |
... |
additional arguments passed to 'stats::quantile' function. |
a rectangleGate
## Not run: gate <- gate_quantile(fr, Channel = "APC-A", probs = 0.995) # fr is a flowFrame ## End(Not run)
## Not run: gate <- gate_quantile(fr, Channel = "APC-A", probs = 0.995) # fr is a flowFrame ## End(Not run)
We construct a singlet gate by applying a robust linear model. By default, we model the forward-scatter height
(FSC-H)as a function of forward-scatter area (FSC-A). If sidescatter
is given, forward-scatter height is as a function of area
+
sidescatter
+ sidescatter / area
.
gate_singlet( x, area = "FSC-A", height = "FSC-H", sidescatter = NULL, prediction_level = 0.99, subsample_pct = NULL, wider_gate = FALSE, filterId = "singlet", maxit = 5, ... )
gate_singlet( x, area = "FSC-A", height = "FSC-H", sidescatter = NULL, prediction_level = 0.99, subsample_pct = NULL, wider_gate = FALSE, filterId = "singlet", maxit = 5, ... )
x |
a |
area |
character giving the channel name that records the signal intensity as peak area |
height |
character giving the channel name that records the signal intensity as peak heightchannel name of height |
sidescatter |
character giving an optional channel name for the sidescatter signal. By default, ignored. |
prediction_level |
a numeric value between 0 and 1 specifying the level to use for the prediction bands |
subsample_pct |
a numeric value between 0 and 1 indicating the percentage
of observations that should be randomly selected from |
wider_gate |
logical value. If |
filterId |
the name for the filter that is returned |
maxit |
the limit on the number of IWLS iterations |
... |
additional arguments (not used) |
Because rlm
relies on iteratively reweighted least
squares (IRLS), the runtime to construct a singlet gate is dependent in part
on the number of observations in x
. To improve the runtime, we provide
an option to subsample randomly a subset of x
. A percentage of
observations to subsample can be given in subsample_pct
. By default, no
subsampling is applied.
a polygonGate
object with the singlet gate
Each cell population is stored in graph node and is connected with its parent population or its reference node for boolGate or refGate.
It parses the csv file that specifies the gating scheme for a particular staining pannel.
gatingTemplate(x, ...) ## S4 method for signature 'character' gatingTemplate( x, name = "default", strict = TRUE, strip_extra_quotes = FALSE, ... ) ## S4 method for signature 'data.table' gatingTemplate( x, name = "default", strict = TRUE, strip_extra_quotes = FALSE, ... )
gatingTemplate(x, ...) ## S4 method for signature 'character' gatingTemplate( x, name = "default", strict = TRUE, strip_extra_quotes = FALSE, ... ) ## S4 method for signature 'data.table' gatingTemplate( x, name = "default", strict = TRUE, strip_extra_quotes = FALSE, ... )
x |
|
... |
other arguments passed to |
name |
|
strict |
|
strip_extra_quotes |
|
This csv must have the following columns:
'alias': a name used label the cell population, the path composed by the alias and its precedent nodes (e.g. /root/A/B/alias) has to be uniquely identifiable. So alias can not contain '/' character, which is reserved as path delimiter.
'pop': population patterns of '+/-‘ or ’+/-+/-', which tells the algorithm which side (postive or negative) of 1d gate or which quadrant of 2d gate to be kept.
'parent': the parent population alias, its path has to be uniquely identifiable.
'dims': characters seperated by comma specifying the dimensions(1d or 2d) used for gating. It can be either channel name or stained marker name (or the substrings of channel/marker names as long as they are uniquely identifiable.).
'gating_method': the name of the gating function (e.g. 'flowClust'). It is invoked by a wrapper function that has the identical function name prefixed with a dot.(e.g. '.flowClust')
'gating_args': the named arguments passed to gating function (Note that double quotes are often used as text delimiter by some csv editors. So try to use single quote instead if needed.)
'collapseDataForGating': When TRUE, data is collapsed (within groups if 'groupBy' specified) before gating and the gate is replicated across collapsed samples. When set FALSE (or blank),then 'groupBy' argument is only used by 'preprocessing' and ignored by gating.
'groupBy': If given, samples are split into groups by the unique combinations of study variable (i.e. column names of pData,e.g."PTID:VISITNO"). when split is numeric, then samples are grouped by every N samples
'preprocessing_method': the name of the preprocessing function(e.g. 'prior_flowclust'). It is invoked by a wrapper function that has the identical function name prefixed with a dot.(e.g. '.prior_flowclust') the preprocessing results are then passed to gating wrapper function through 'pps_res' argument.
'preprocessing_args': the named arguments passed to preprocessing function.
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) plot(gt) ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) plot(gt) ## End(Not run)
fcTree
get gates saved in fcTree
## S4 method for signature 'fcTree,character' getGate(obj, y, ...)
## S4 method for signature 'fcTree,character' getGate(obj, y, ...)
obj |
|
y |
|
... |
other arguments (not used) |
fcTree
get nodes from fcTree
## S4 method for signature 'fcTree' getNodes(x, y)
## S4 method for signature 'fcTree' getNodes(x, y)
x |
|
y |
|
To ease the process of replicating the existing (usually a manual one) gating schemes,
this function populate an empty gating template with the 'alias', 'pop', 'parent' and 'dims'
columns that exacted from an GatingHierarchy
, and leave the other columns (e.g. 'gating_method') blank.
So users can make changes to that template instead of writing from scratch.
gh_generate_template(gh)
gh_generate_template(gh)
gh |
a |
a gating template in data.frame
format that requires further edition after output to csv
library(flowWorkspace) dataDir <- system.file("extdata",package="flowWorkspaceData") gs <- load_gs(list.files(dataDir, pattern = "gs_manual",full = TRUE)) gh_generate_template(gs[[1]])
library(flowWorkspace) dataDir <- system.file("extdata",package="flowWorkspaceData") gs <- load_gs(list.files(dataDir, pattern = "gs_manual",full = TRUE)) gh_generate_template(gs[[1]])
When specified, the flow data is grouped by the grouping variable (column names in pData).
Within each group, when isCollapse
is set to TRUE, the gating method is applied to the collapsed data.
Otherwise, it is done indepentently for each indiviudal sample(flowFrame).
Grouping variable is also used by preprocessing method
.
## S4 method for signature 'gtMethod' groupBy(object)
## S4 method for signature 'gtMethod' groupBy(object)
object |
|
GatingSet
When interacting with the existing gated data, this function provides an alternative way to interact with the GatingSet by supplying the gating description directly through arguments without the need to write the complete csv gating template.
gs_add_gating_method( gs, alias = "*", pop = "+", parent, dims = NA, gating_method, gating_args = NA, collapseDataForGating = NA, groupBy = NA, preprocessing_method = NA, preprocessing_args = NA, strip_extra_quotes = FALSE, ... )
gs_add_gating_method( gs, alias = "*", pop = "+", parent, dims = NA, gating_method, gating_args = NA, collapseDataForGating = NA, groupBy = NA, preprocessing_method = NA, preprocessing_args = NA, strip_extra_quotes = FALSE, ... )
gs |
GatingSet or GatingSetList |
alias , pop , parent , dims , gating_method , gating_args , collapseDataForGating , groupBy , preprocessing_method , preprocessing_args
|
see details in gatingTemplate |
strip_extra_quotes |
|
... |
other arguments
|
Calls to gs_add_gating_method
can also be easily reversed with gs_remove_gating_method
. Note, however, that it is not possible
to differentiate between different GatingSet
objects loaded from the same directory with
load_gs
within a session. Thus, to guarantee a clean history for gs_remove_gating_method
,
it is necessary to call gs_add_gating_method_init
on the loaded GatingSet
immediately after re-loading it.
See the documentation for gs_add_gating_method_init
for more details.
This will not be an issue for GatingSet
objects created directly using the constructor.
gs_remove_gating_method
gs_add_gating_method_init
## Not run: # add quad gates gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") # polyfunctional gates (boolean combinations of exsiting marginal gates) gs_add_gating_method(gs, gating_method = "polyFunctions", parent = "cd8", gating_args = "cd8/IFNg:cd8/IL2:cd8/TNFa") #boolGate method gs_add_gating_method(gs, alias = "IL2orIFNg", gating_method = "boolGate", parent = "cd4", gating_args = "cd4/IL2|cd4/IFNg") ## End(Not run)
## Not run: # add quad gates gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") # polyfunctional gates (boolean combinations of exsiting marginal gates) gs_add_gating_method(gs, gating_method = "polyFunctions", parent = "cd8", gating_args = "cd8/IFNg:cd8/IL2:cd8/TNFa") #boolGate method gs_add_gating_method(gs, alias = "IL2orIFNg", gating_method = "boolGate", parent = "cd4", gating_args = "cd4/IL2|cd4/IFNg") ## End(Not run)
gs_add_gating_method
calls for a given GatingSet
or GatingSetList
Repeated calls to the load_gs
method in the same session
will yield indistinguishable objects that can result in overlapping history
of gs_add_gating_method
calls. This method allows for the history to be cleared
if the user would like to reload the GatingSet
and start fresh. Calling
gs_add_gating_method_init
without an argument will clear the entire gs_add_gating_method
history.
gs_add_gating_method_init(gs)
gs_add_gating_method_init(gs)
gs |
a |
## Not run: # load in a GatingSet gs <- load_gs(path) # Add some nodes using gs_add_gating_method gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") gs_add_gating_method(gs, gating_method = "polyFunctions", parent = "cd8", gating_args = "cd8/IFNg:cd8/IL2:cd8/TNFa") # Remove the effect of the last gs_add_gating_method call using gs_remove_gating_method (note that the first call's effects remain) gs_remove_gating_method(gs) # Re-load the GatingSet to start over gs <- load_gs(path) # At this point, gs will still see the history of the first gs_add_gating_method call above # which will cause problems for later calls to gs_remove_gating_method. # To fix that, just call gs_add_gating_method_init() to start a clean history gs_add_gating_method_init(gs) # Now you can continue using gs_add_gating_method and gs_remove_gating_method from scratch gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") ## End(Not run)
## Not run: # load in a GatingSet gs <- load_gs(path) # Add some nodes using gs_add_gating_method gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") gs_add_gating_method(gs, gating_method = "polyFunctions", parent = "cd8", gating_args = "cd8/IFNg:cd8/IL2:cd8/TNFa") # Remove the effect of the last gs_add_gating_method call using gs_remove_gating_method (note that the first call's effects remain) gs_remove_gating_method(gs) # Re-load the GatingSet to start over gs <- load_gs(path) # At this point, gs will still see the history of the first gs_add_gating_method call above # which will cause problems for later calls to gs_remove_gating_method. # To fix that, just call gs_add_gating_method_init() to start a clean history gs_add_gating_method_init(gs) # Now you can continue using gs_add_gating_method and gs_remove_gating_method from scratch gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") ## End(Not run)
gs_add_gating_method
This function provides an easy way to remove the gates and nodes created by the most
recent call to gs_add_gating_method
on the specified GatingSet
or GatingSetList
,
with a separate history being maintained for each such object. gs_remove_gating_method
allows
for repeated use, effectively serving as a multi-level undo function for gs_add_gating_method
.
gs_remove_gating_method(gs)
gs_remove_gating_method(gs)
gs |
The |
gs_add_gating_method
gs_add_gating_method_init
## Not run: # add quad gates gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") # Remove the gates and nodes resulting from that gs_add_gating_method call gs_remove_gating_method(gs) ## End(Not run)
## Not run: # add quad gates gs_add_gating_method(gs, gating_method = "mindensity", dims = "CCR7,CD45RA", parent = "cd4-cd8+", pop = "CCR7+/-CD45RA+/-") # Remove the gates and nodes resulting from that gs_add_gating_method call gs_remove_gating_method(gs) ## End(Not run)
It loads the gating methods by topological order and applies them to GatingSet
.
gt_gating(x, y, ...)
gt_gating(x, y, ...)
x |
a |
y |
a |
... |
|
Nothing. As the side effect, gates generated by gating methods are saved in GatingSet
.
## Not run: gt <- gatingTemplate(file.path(path, "data/ICStemplate.csv"), "ICS") gs <- GatingSet(fs) #fs is a flowSet/ncdfFlowSet gt_gating(gt, gs) gt_gating(gt, gs, stop.at = "v") #proceed the gating until population 'v' gt_gating(gt, gs, start = "v") # start from 'v' gt_gating(gt, gs, parallel_type = "multicore", mc.cores = 8) #parallel gating using multicore #parallel gating by using cluster cl1 <- makeCluster (8, type = "MPI") gt_gating(gt, gs, parallel_type = "cluster", cl = cl1) stopCluster ( cl1 ) ## End(Not run)
## Not run: gt <- gatingTemplate(file.path(path, "data/ICStemplate.csv"), "ICS") gs <- GatingSet(fs) #fs is a flowSet/ncdfFlowSet gt_gating(gt, gs) gt_gating(gt, gs, stop.at = "v") #proceed the gating until population 'v' gt_gating(gt, gs, start = "v") # start from 'v' gt_gating(gt, gs, parallel_type = "multicore", mc.cores = 8) #parallel gating using multicore #parallel gating by using cluster cl1 <- makeCluster (8, type = "MPI") gt_gating(gt, gs, parallel_type = "cluster", cl = cl1) stopCluster ( cl1 ) ## End(Not run)
get children nodes
gt_get_children(obj, y)
gt_get_children(obj, y)
obj |
|
y |
|
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, "/nonDebris") gt_get_children(gt, "/nonDebris") ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, "/nonDebris") gt_get_children(gt, "/nonDebris") ## End(Not run)
get gating method from the node
gt_get_gate(obj, y, z)
gt_get_gate(obj, y, z)
obj |
|
y |
|
z |
|
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, only.names = TRUE) gt_get_nodes(gt, "/nonDebris") gt_get_children(gt, "/nonDebris") gt_get_gate(gt, "/nonDebris", "/nonDebris/singlets") ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, only.names = TRUE) gt_get_nodes(gt, "/nonDebris") gt_get_children(gt, "/nonDebris") gt_get_gate(gt, "/nonDebris", "/nonDebris/singlets") ## End(Not run)
get nodes from gatingTemplate object
gt_get_nodes( x, y, order = c("default", "bfs", "dfs", "tsort"), only.names = FALSE )
gt_get_nodes( x, y, order = c("default", "bfs", "dfs", "tsort"), only.names = FALSE )
x |
|
y |
|
order |
|
only.names |
|
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt)[1:2] gt_get_nodes(gt, only.names = TRUE) gt_get_nodes(gt, "/nonDebris") ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt)[1:2] gt_get_nodes(gt, only.names = TRUE) gt_get_nodes(gt, "/nonDebris") ## End(Not run)
get parent nodes
gt_get_parent(obj, y, isRef = FALSE)
gt_get_parent(obj, y, isRef = FALSE)
obj |
|
y |
|
isRef |
|
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, "/nonDebris") gt_get_parent(gt, "/nonDebris/singlets") ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, "/nonDebris") gt_get_parent(gt, "/nonDebris/singlets") ## End(Not run)
Print a list of the registered gating methods
gt_list_methods()
gt_list_methods()
Does not return anything. Prints a list of the available gating methods.
The helper gates are defined as the referred gates in csv template. And all the chidlren of referred gates are also referred gates thus they are considered the helper gates and can usually be hidden to simply the final gating tree.
gt_toggle_helpergates(gt, gs) gt_get_helpergates(gt, gs) gt_delete_helpergates(gt, gs)
gt_toggle_helpergates(gt, gs) gt_get_helpergates(gt, gs) gt_delete_helpergates(gt, gs)
gt |
gatingTemplate object |
gs |
GatingSet |
Note that delete action is NOT reversible.
## Not run: gt <- gatingTemplate(gtFile) #run the gating gt_gating(gt, gs) #hide the gates that are not of interest gt_toggle_helpergates(gt, gs) #or simply remove them if you are sure they will not be useful in future gt_delete_helpergates(gt, gs) ## End(Not run)
## Not run: gt <- gatingTemplate(gtFile) #run the gating gt_gating(gt, gs) #hide the gates that are not of interest gt_toggle_helpergates(gt, gs) #or simply remove them if you are sure they will not be useful in future gt_delete_helpergates(gt, gs) ## End(Not run)
A gating method object contains the specifics for generating the gates.
a character
specifying the name of the gating method
a character
vector specifying the dimensions (channels or markers) of the gate
a list
specifying the arguments passed to gating function
a character
or integer
specifying how to group the data.
If character
, group the data by the study variables (columns in pData
).
If integer
, group the data by every N
samples.
a logical
specifying wether to collapse the data within group before gating.
it is only valid when groupBy
is specified
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gh_pop_get_gate(gt, '2', '3') ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gh_pop_get_gate(gt, '2', '3') ## End(Not run)
A class to represent a cell population that will be generated by a gating method.
numeric
unique ID that is consistent with node label of graphNEL in gating template
character
the name of population
character
the more user friendly name of population
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, '2') ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gt_get_nodes(gt, '2') ## End(Not run)
When TRUE, the flow data(multiple flowFrames) is collapsed into one and the gating method is applied on the collapsed data. Once the gate is generated, it is thenreplicated and applied to the each single flowFrame.
## S4 method for signature 'gtMethod' isCollapse(object)
## S4 method for signature 'gtMethod' isCollapse(object)
object |
|
logical
get gating method name
## S4 method for signature 'gtMethod' names(x)
## S4 method for signature 'gtMethod' names(x)
x |
|
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gtMthd <- gt_get_gate(gt, "/nonDebris/singlets", "/nonDebris/singlets/lymph") names(gtMthd) dims(gtMthd) parameters(gtMthd) isCollapse(gtMthd) groupBy(gtMthd) gtPop <- gt_get_nodes(gt, "/nonDebris/singlets/lymph/cd3/cd4+cd8-/CD38+") names(gtPop) alias(gtPop) ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) gtMthd <- gt_get_gate(gt, "/nonDebris/singlets", "/nonDebris/singlets/lymph") names(gtMthd) dims(gtMthd) parameters(gtMthd) isCollapse(gtMthd) groupBy(gtMthd) gtPop <- gt_get_nodes(gt, "/nonDebris/singlets/lymph/cd3/cd4+cd8-/CD38+") names(gtPop) alias(gtPop) ## End(Not run)
get population name
## S4 method for signature 'gtPopulation' names(x)
## S4 method for signature 'gtPopulation' names(x)
x |
|
the class that carries event indices as well
constructor for ocRectRefGate
ocRectRefGate(rectGate, boolExprs)
ocRectRefGate(rectGate, boolExprs)
rectGate |
|
boolExprs |
|
special gate type that mix the rectangleGate with boolean gate
Hierarchical Gating Pipeline for flow cytometry data.
openCyto is a package designed to facilitate the automated gating methods in sequential way to mimic the manual gating strategy.
Package: | openCyto |
Type: | Package |
Version: | 1.2.8 |
Date: | 2014-04-10 |
License: | GPL (>= 2) |
LazyLoad: | yes |
Mike Jiang [email protected], John Ramey [email protected], Greg Finak [email protected]
Maintainer: Mike Jiang [email protected]
See gt_gating
,
gate_flowclust_1d
,
for an overview of gating functions.
## Not run: gatingTemplate('test.csv')
## Not run: gatingTemplate('test.csv')
add_pop
–> gs_add_gating_method
add_pop_init
–> gs_add_gating_method_init
prior_flowClust
–> prior_flowclust
templateGen
–> gh_generate_template
gate_flowClust_1d
–> gate_flowclust_1d
gate_flowClust_2d
–> gate_flowclust_2d
quantileGate
–> gate_quantile
quadGate.seq
–> gate_quad_sequential
quadGate.tmix
–> gate_quad_tmix
gating
–> gt_gating
getNodes
–> gt_get_nodes
getChildren
–> gt_get_children
getParent
–> gt_get_parent
getGate
–> gt_get_gate
listgtMethods
–> gt_list_methods
registerPlugins
–> register_plugins
remove_pop
–> gs_remove_gating_method
toggle.helperGates
–> gt_toggle_helpergates
get.helperGates
–> gt_get_helpergates
delete.helperGates
–> gt_delete_helpergates
Get/set some global options for openCyto
opt <- getOption("openCyto") #the threshold of minimum cell events required for the gating algorithm to proceed opt[["gating"]][["minEvents"]] #to change the threshold opt[["gating"]][["minEvents"]] <- 100 options(openCyto = opt) #switch off the validity check flags(Not recommended) opt[["check.pop"]] <- FALSE options(openCyto = opt)
opt <- getOption("openCyto") #the threshold of minimum cell events required for the gating algorithm to proceed opt[["gating"]][["minEvents"]] #to change the threshold opt[["gating"]][["minEvents"]] <- 100 options(openCyto = opt) #switch off the validity check flags(Not recommended) opt[["check.pop"]] <- FALSE options(openCyto = opt)
get parameters of the gating method/function
## S4 method for signature 'gtMethod' parameters(object)
## S4 method for signature 'gtMethod' parameters(object)
object |
|
fcFilterList
It is usually called by plot
method for fcTree
instead of directly by users.
## S4 method for signature 'fcFilterList,ANY' plot( x, y, samples = NULL, posteriors = FALSE, xlim = NULL, ylim = NULL, node = NULL, data = NULL, breaks = 20, lwd = 1, ... )
## S4 method for signature 'fcFilterList,ANY' plot( x, y, samples = NULL, posteriors = FALSE, xlim = NULL, ylim = NULL, node = NULL, data = NULL, breaks = 20, lwd = 1, ... )
x |
|
y |
|
samples |
|
posteriors |
|
xlim , ylim
|
scale settings for x,y axises |
node |
|
data |
|
breaks |
passed to hist |
lwd |
line width |
... |
other arguments passed to base |
## Not run: env1<-new.env(parent=emptyenv()) #gt is a gatingTemplate, gs is a GatingSet gt_gating(gt,gs,env1) #the flowClust gating results are stored in env1 plot(env1$fct,"nonDebris",post=T) #plot the priors as well as posteriors for the "nonDebris" gate ## End(Not run)
## Not run: env1<-new.env(parent=emptyenv()) #gt is a gatingTemplate, gs is a GatingSet gt_gating(gt,gs,env1) #the flowClust gating results are stored in env1 plot(env1$fct,"nonDebris",post=T) #plot the priors as well as posteriors for the "nonDebris" gate ## End(Not run)
This provides the priors and posteriors as well as the gates for the purpose of debugging flowClust gating algorithm
## S4 method for signature 'fcTree,character' plot(x, y, channel = NULL, data = NULL, ...)
## S4 method for signature 'fcTree,character' plot(x, y, channel = NULL, data = NULL, ...)
x |
|
y |
|
channel |
|
data |
|
... |
other arguments |
plot the gating scheme using Rgraphviz
## S4 method for signature 'gatingTemplate,missing' plot(x, y, ...)
## S4 method for signature 'gatingTemplate,missing' plot(x, y, ...)
x |
|
y |
either |
... |
other arguments graphAttr, nodeAttr: graph rendering attributes passed to renderGraph
showRef |
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) plot(gt) #plot entire tree plot(gt, "lymph") #only plot the subtree rooted from "lymph" ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) plot(gt) #plot entire tree plot(gt, "lymph") #only plot the subtree rooted from "lymph" ## End(Not run)
It extends boolMethod
class and will be expanded to multiple boolMethod
object.
to support adding gate along with indices without loading flow data and computing
to support adding rectangleGate yet gating through boolean operations without loading flow data
## S3 method for class 'ocRectangleGate' pop_add(gate, gh, recompute, ...) ## S3 method for class 'ocRectRefGate' pop_add(gate, gh, recompute, ...)
## S3 method for class 'ocRectangleGate' pop_add(gate, gh, recompute, ...) ## S3 method for class 'ocRectRefGate' pop_add(gate, gh, recompute, ...)
gate |
|
gh |
|
recompute |
|
... |
see add in |
however it is proven that logical indices are too big to be efficiently passed around
fcFilter
objectget posteriors from a fcFilter
object
## S4 method for signature 'fcFilter,ANY' posteriors(x, y = "missing")
## S4 method for signature 'fcFilter,ANY' posteriors(x, y = "missing")
x |
|
y |
|
It extends gtMethod
class.
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) ppMethod(gt, '3', '4') ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) ppMethod(gt, '3', '4') ## End(Not run)
get preprocessing method from the node
## S4 method for signature 'gatingTemplate,character' ppMethod(obj, y, z)
## S4 method for signature 'gatingTemplate,character' ppMethod(obj, y, z)
obj |
|
y |
|
z |
|
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) ppMethod(gt, "/nonDebris/singlets", "/nonDebris/singlets/lymph") ## End(Not run)
## Not run: gt <- gatingTemplate(system.file("extdata/gating_template/tcell.csv",package = "openCyto")) ppMethod(gt, "/nonDebris/singlets", "/nonDebris/singlets/lymph") ## End(Not run)
GatingSet
apply a ppMethod to the GatingSet
## S4 method for signature 'ppMethod,GatingSet' preprocessing(x, y, ...)
## S4 method for signature 'ppMethod,GatingSet' preprocessing(x, y, ...)
x |
|
y |
|
... |
other arguments |
We elicit data-driven prior parameters from a flowSet
object for
specified channels. For each sample in the flowSet
object, we apply the
given prior_method
to elicit the priors parameters.
prior_flowclust( flow_set, channels, prior_method = c("kmeans"), K = 2, nu0 = 4, w0 = c(10, 10), shrink = 1e-06, ... )
prior_flowclust( flow_set, channels, prior_method = c("kmeans"), K = 2, nu0 = 4, w0 = c(10, 10), shrink = 1e-06, ... )
flow_set |
a |
channels |
a character vector containing the channels in the
|
prior_method |
the method to elicit the prior parameters |
K |
the number of mixture components to identify |
nu0 |
prior degrees of freedom of the Student's t mixture components. |
w0 |
the number of prior pseudocounts of the Student's t mixture components. (only the first element is used and the rest is ignored at the moment) |
shrink |
the amount of eigenvalue shrinkage to add in the case the prior covariance matrices are singular. See details. |
... |
Additional arguments passed to the prior elicitation method selected |
Currently, we have implemented only two methods. In the case that one channel
is given, we use the kernel-density estimator (KDE) approach for each sample
to obtain K
peaks from which we elicit prior parameters. Otherwise,
if more than one channel is specified, we apply K-Means to each of the samples
in the flowSet
and aggregate the clusters to elicit the prior
parameters.
In the rare case that a prior covariance matrix is singular, we shrink the
eigenvalues of the matrix slightly to ensure that it is positive definite. For
instance, if the flow_set
has two samples, this case can occur. The
amount of shrinkage is controlled in shrink
.
list of the necessary prior parameters
## Not run: library(flowCore) data(GvHD) prior_flowclust(GvHD[1:3], c("FSC-H", "SSC-H")) ## End(Not run)
## Not run: library(flowCore) data(GvHD) prior_flowclust(GvHD[1:3], c("FSC-H", "SSC-H")) ## End(Not run)
fcFilter
objectget priors from a fcFilter
object
## S4 method for signature 'fcFilter,ANY' priors(x, y = "missing")
## S4 method for signature 'fcFilter,ANY' priors(x, y = "missing")
x |
|
y |
|
It extends gtMethod
class.
character
specifying the reference nodes
Function registers a new gating or preprocessing method with openCyto so that it may be used in the csv template.
register_plugins(fun = NA, methodName, dep = NA, ...)
register_plugins(fun = NA, methodName, dep = NA, ...)
fun |
|
methodName |
|
dep |
|
... |
other arguments
type |
The fun
argument should be a wrapper function definition for the gating or preprocessing method.
Gating method must have formal arguments:
fr a flowFrame
pp_res a pre-processing result
xChannel character
(optional)
yChannel character
(required)
filterId character
... ellipses for the additional parameters.
Preprocessing method must have formal arguments:
fs a flowSet
that stores the flow data (could be subgrouped data if groupBy
column is defined in the csv template
gs a GatingSet
gm a gtMethod
object that stores the information from gating method
xChannel character
(required)
yChannel character
(required)
... ellipses for the additional parameters.
The gating function must return a filter (i.e. polygonGate or other instance) from flowCore. The preprocessing can return anything and it will be passed on to the gating function. So it is up to gating function to use and interpret the results of preprocessing. Not all formal parameters need to be used. Additional arguments are passed via the ... and can be processed in the wrapper
logical
TRUE if successful and prints a message. FALSE otherwise.
rewrite huber estimator
robust_m_estimator(x, sd)
robust_m_estimator(x, sd)
show method for boolMethod
## S4 method for signature 'boolMethod' show(object)
## S4 method for signature 'boolMethod' show(object)
object |
|
show method for fcFilter
## S4 method for signature 'fcFilter' show(object)
## S4 method for signature 'fcFilter' show(object)
object |
|
show method for gatingTemplate
## S4 method for signature 'gatingTemplate' show(object)
## S4 method for signature 'gatingTemplate' show(object)
object |
|
show method for gtMethod
## S4 method for signature 'gtMethod' show(object)
## S4 method for signature 'gtMethod' show(object)
object |
|