cytoflow.operations.channel_stat¶
Creates a new statistic. channel_stat has one class:
ChannelStatisticOp – applies a function to subsets of a data set,
and adds the resulting statistic to the Experiment
- class cytoflow.operations.channel_stat.ChannelStatisticOp[source]¶
Bases:
traits.has_traits.HasStrictTraitsApply a function to subsets of a data set, and add it as a statistic to the experiment.
The
applyfunction groups the data by the variables inby, then applies thefunctioncallable to thechannelseries in each subset. The callable should take a singlepandas.Seriesas an argument. The return type is arbitrary, but to be used with the rest ofcytoflowit should probably be a numeric type or an iterable of numeric types.- name¶
The operation name. Becomes the first element in the
Experiment.statisticskey tuple.- Type
Str
- channel¶
The channel to apply the function to.
- Type
Str
- function¶
The function used to compute the statistic.
functionmust take apandas.Seriesas its only parameter. The return type is arbitrary, but to be used with the rest ofcytoflowit should probably be a numeric type or an iterable of numeric types. Ifstatistic_nameis unset, the name of the function becomes the second in element in theExperiment.statisticskey tuple.Warning
Be careful! Sometimes this function is called with an empty input! If this is the case, poorly-behaved functions can return
NaNor throw an error. If this happens, it will be reported.- Type
Callable
- statistic_name¶
The name of the function; if present, becomes the second element in the
Experiment.statisticskey tuple. Particularly useful iffunctionis a lambda expression.- Type
Str
- by¶
A list of metadata attributes to aggregate the data before applying the function. For example, if the experiment has two pieces of metadata,
TimeandDox, settingby = ["Time", "Dox"]will applyfunctionseparately to each subset of the data with a unique combination ofTimeandDox.- Type
List(Str)
- subset¶
A Python expression sent to
Experiment.queryto subset the data before computing the statistic.- Type
Str
- fill¶
The value to use in the statistic if a slice of the data is empty.
- Type
Any (default = 0)
Examples
Make a little data set.
>>> import cytoflow as flow >>> import_op = flow.ImportOp() >>> import_op.tubes = [flow.Tube(file = "Plate01/RFP_Well_A3.fcs", ... conditions = {'Dox' : 10.0}), ... flow.Tube(file = "Plate01/CFP_Well_A4.fcs", ... conditions = {'Dox' : 1.0})] >>> import_op.conditions = {'Dox' : 'float'} >>> ex = import_op.apply()
Create and parameterize the operation.
>>> ch_op = flow.ChannelStatisticOp(name = 'MeanByDox', ... channel = 'Y2-A', ... function = flow.geom_mean, ... by = ['Dox']) >>> ex2 = ch_op.apply(ex)
View the new operation
>>> print(ex2.statistics.keys()) dict_keys([('MeanByDox', 'geom_mean')])
>>> print(ex2.statistics[('MeanByDox', 'geom_mean')]) Dox 1.0 19.805601 10.0 446.981927 dtype: float64
- apply(experiment)[source]¶
Apply the operation to an
Experiment.- Parameters
experiment – The
Experimentto apply this operation to.- Returns
A new
Experiment, containing a new entry inExperiment.statistics. The key of the new entry is a tuple(name, function)(or(name, statistic_name)ifstatistic_nameis set.- Return type