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

Apply a function 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 the channel series in each subset. The callable should take a single pandas.Series as an argument. The return type is arbitrary, but to be used with the rest of cytoflow it should probably be a numeric type or an iterable of numeric types.

name

The operation name. Becomes the first element in the Experiment.statistics key tuple.

Type

Str

channel

The channel to apply the function to.

Type

Str

function

The function used to compute the statistic. function must take a pandas.Series as its only parameter. The return type is arbitrary, but to be used with the rest of cytoflow it should probably be a numeric type or an iterable of numeric types. If statistic_name is unset, the name of the function becomes the second in element in the Experiment.statistics key tuple.

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

statistic_name

The name of the function; if present, becomes the second element in the Experiment.statistics key tuple. Particularly useful if function is 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, 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

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 Experiment to apply this operation to.

Returns

A new Experiment, containing a new entry in Experiment.statistics. The key of the new entry is a tuple (name, function) (or (name, statistic_name) if statistic_name is set.

Return type

Experiment