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:
HasStrictTraitsApply a functions 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 each group in the channel specified bychannel.The
functioncallable should take a singlepandas.Seriesoffloatas an argument and return afloat, a value that can be cast tofloat, or apandas.Seriesoffloat. Iffunctionreturns afloator a value that can be cast tofloat, then the resulting statistic has one column and its name is set tochannel. Iffunctionreturns apandas.Series, then theSeries’ index labels become the column names. (If used this way, each call tofunctionmust always return apandas.Serieswith the same index.)- name#
The operation name. Becomes the name of the new statistic.
- Type:
Str
- channel#
The channel to apply the function to. By default, the channel name becomes the column (feature) name in the new statistic.
- Type:
Str
- function#
The function used to compute the statistic.
functionmust take apandas.Seriesas its only parameter and return either afloat, a value that can be cast tofloat, or apandas.Series.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
- 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
Examples
Make a little data set.
>>> import cytoflow as flow >>> import pandas as pd >>> 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 statistic
>>> print(ex2.statistics.keys()) dict_keys(['MeanByDox'])
>>> print(ex2.statistics['MeanByDox']) Y2-A Dox 1.0 19.805601 10.0 446.981927
- 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 isname.- Return type: