cytoflow.operations.bleedthrough_piecewise

class cytoflow.operations.bleedthrough_piecewise.BleedthroughPiecewiseOp[source]

Bases: traits.has_traits.HasStrictTraits

Warning

THIS OPERATION IS DEPRECATED.

Apply bleedthrough correction to a set of fluorescence channels.

This is not a traditional bleedthrough matrix-based compensation; it uses a similar set of single-color controls, but instead of computing a compensation matrix, it fits a piecewise-linear spline to the untransformed data and uses those splines to compute the correction factor at each point in a mesh across the color space. The experimental data is corrected using a linear interpolation along that mesh: this is much faster than computing the correction factor for each cell indiviually (an operation that takes 5 msec each.)

To use, set up the controls dict with the single color controls; call estimate() to parameterize the operation; check that the bleedthrough plots look good with the plot() method of the BleedthroughPiecewiseDiagnostic instance returned by default_view(); and then call apply() with an Experiment.

Warning

THIS OPERATION IS DEPRECATED AND WILL BE REMOVED IN A FUTURE RELEASE. TO USE IT, SET :attr:`ignore_deprecated` TO ``True``. IF YOU HAVE A USE CASE WHERE THIS WORKS BETTER THAN THE LINEAR BLEEDTHROUGH CORRECTION, PLEASE EMAIL ME OR FILE A BUG.

controls

The channel names to correct, and corresponding single-color control FCS files to estimate the correction splines with. Must be set to use estimate().

Type:Dict(Str, File)
num_knots

The number of internal control points to estimate, spaced log-evenly from 0 to the range of the channel. Must be set to use estimate().

Type:Int (default = 12)
mesh_size

The size of each axis in the mesh used to interpolate corrected values.

Type:Int (default = 32)
ignore_deprecated
Type:Bool (default = False)

Notes

We use an interpolation-based scheme to estimate corrected bleedthrough. The algorithm is as follows:

  • Fit a piecewise-linear spline to each single-color control’s bleedthrough into other channels. Because we want to fit the spline to untransfomed data, but capture both the negative, positive-linear and positive-log portions of a traditional flow data set, we distribute the spline knots evenly on an hlog-transformed axis for each color we’re correcting.
  • At each point on a regular mesh spanning the entire range of the instrument, estimate the mapping from (raw colors) –> (actual colors). The mesh points are also distributed evenly along the hlog-transformed color axes; this captures negative data as well as positive This is quite slow: ~30 seconds for a mesh size of 32 in 3-space. Remember that additional channels expand the number of mesh points exponentially!
  • Use these estimates to paramaterize a linear interpolator (in linear space, this time). There’s one interpolator per output channel (so for a 3-channel correction, each interpolator is R^3 –> R). For each measured cell, run each interpolator to give the corrected output.

Examples

Create a small experiment:

>>> import cytoflow as flow
>>> import_op = flow.ImportOp()
>>> import_op.tubes = [flow.Tube(file = "tasbe/rby.fcs")]
>>> ex = import_op.apply()

Create and parameterize the operation

>>> bl_op = flow.BleedthroughPiecewiseOp()
>>> bl_op.controls = {'Pacific Blue-A' : 'tasbe/ebfp.fcs',
...                   'FITC-A' : 'tasbe/eyfp.fcs',
...                   'PE-Tx-Red-YG-A' : 'tasbe/mkate.fcs'}
>>> bl_op.ignore_deprecated = True

Estimate the model parameters

>>> bl_op.estimate(ex)

Plot the diagnostic plot

>>> bl_op.default_view().plot(ex)

Apply the operation to the experiment

>>> ex2 = bl_op.apply(ex)
estimate(experiment, subset=None)[source]

Estimate the bleedthrough from the single-channel controls in controls

apply(experiment)[source]

Applies the bleedthrough correction to an experiment.

Parameters:experiment (Experiment) – the old_experiment to which this op is applied
Returns:
  • A new Experiment with the bleedthrough subtracted out.
  • Corrected channels have the following additional metadata
  • - **bleedthrough_channels** (List(Str)) – The channels that were used to correct this one.
  • - **bleedthrough_fn** (Callable (Tuple(Float) –> Float)) – The function that will correct one event in this channel. Pass it the values specified in bleedthrough_channels and it will return the corrected value for this channel.
default_view(**kwargs)[source]

Returns a diagnostic plot to see if the bleedthrough spline estimation is working.

Returns:An IView, call plot() to see the diagnostic plots
Return type:IView
class cytoflow.operations.bleedthrough_piecewise.BleedthroughPiecewiseDiagnostic[source]

Bases: traits.has_traits.HasStrictTraits

Plots a scatterplot of each channel vs every other channel and the bleedthrough spline

op

The operation whose parameters we’re viewing. If this instance was created with BleedthroughPiecewiseOp.default_view(), this attribute is already set for you.

Type:Instance(BleedthroughPiecewiseOp)
subset

Only plot this subset of the bleedthrough controls.

Type:str (default = None)
plot(experiment=None, **kwargs)[source]

Plot a faceted histogram view of a channel