cytoflow.operations.xform_stat#
Transforms a statistic. xform_stat has one class:
TransformStatisticOp – apply a function to a statistic, making a new statistic.
- class cytoflow.operations.xform_stat.TransformStatisticOp[source]#
Bases:
HasStrictTraitsApply a function to a feature of a statistic, creating a new statistic.
If you set
by, then callingapplywill group the input statistic by unique combinations of the conditions inby, then callfunctionon the column specified byfeaturein each group. Thefunctionshould take apandas.Seriesand it can return afloat, a value that can be cast to afloat, orpandas.Serieswhosedtypeis a floating-point.If
functionreturns afloat, then the resulting statistic will have one column with the name set tofeatureand levels that are the same as the conditions inby.If
functionreturns apandas.Series, then the names of the rows will become the names of the columns in the new statistic and the levels will be the same as the conditions inby.Note
If
functionreturns apandas.Series, it must have an index with only one level – no hierarchical indexing, please!Note
If
functionreturns apandas.Series, it must return a series with the same index each time!Finally, if
byis left empty, thenfunctionmust be a transformation.functionmust take apandas.Seriesas an argument and return apandas.Serieswith exactly the same index. The new statistic will contain thatpandas.Seriesas its only column, with the column name set tofeature.- name#
The operation name. Becomes the name of the new statistic.
- Type:
Str
- function#
The function used to transform the statistic.
functionmust take apandas.Seriesas its only parameter and return afloat, a value that can be cast tofloat, or apandas.Serieswhosedtypeisfloat.- Type:
Callable
- by#
A list of metadata attributes to aggregate the input statistic before applying the function. For example, if the statistic has two indices
TimeandDox, settingby = ["Time", "Dox"]will applyfunctionseparately to each subset of the data with a unique combination ofTimeandDox.- Type:
List(Str)
- ignore_incomplete_groups#
Sometimes, a statistic doesn’t have a row for every possible group of labels. If this flag is true, groups that don’t have all possible labels of the non-grouped levels won’t have
functioncalled – this can make writingfunctioneasier, at the cost of losing some data.- Type:
Bool (default = False)
Examples
Make a little data set.
>>> import cytoflow as flow >>> import pandas as pd >>> import numpy as np >>> 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
Transform the statistic
>>> xform_op = flow.TransformStatisticOp(name = 'LogMean', ... statistic = 'MeanByDox', ... feature = 'Y2-A', ... function = np.log)
>>> ex_3 = xform_op.apply(ex2) >>> ex_3.statistics['LogMean'] Y2-A Dox 1.0 2.985965 10.0 6.102518
- apply(experiment)[source]#
Applies
functionto a statistic.- Parameters:
experiment (
Experiment) – TheExperimentto apply the operation to- Returns:
The same as the old experiment, but with a new statistic that results from applying
functionto the statistic specified instatistic.- Return type: