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: HasStrictTraits

Apply a functions to subsets of a data set, and add it as a statistic to the experiment.

The apply function groups the data by the variables in by, then applies the function callable to each group in the channel specified by channel.

The function callable should take a single pandas.Series of float as an argument and return a float, a value that can be cast to float, or a pandas.Series of float. If function returns a float or a value that can be cast to float, then the resulting statistic has one column and its name is set to channel. If function returns a pandas.Series, then the Series’ index labels become the column names. (If used this way, each call to function must always return a pandas.Series with 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. function must take a pandas.Series as its only parameter and return either a float, a value that can be cast to float, or a pandas.Series.

Warning

Be careful! Sometimes this function is called with an empty input! If this is the case, poorly-behaved functions can return NaN or 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, Time and Dox, setting by = ["Time", "Dox"] will apply function separately to each subset of the data with a unique combination of Time and Dox.

Type:

List(Str)

subset#

A Python expression sent to Experiment.query to 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 Experiment to apply this operation to.

Returns:

A new Experiment, containing a new entry in Experiment.statistics. The key of the new entry is name.

Return type:

Experiment