FlowCytometryTools.FCMeasurement

class FlowCytometryTools.FCMeasurement(ID, datafile=None, readdata=False, readdata_kwargs={}, metafile=None, readmeta=True, readmeta_kwargs={})

A class for holding flow cytometry data from a single well or a single tube.

Methods

ID_from_data([ID_field]) Returns the well ID from the src keyword in the FCS file. (e.g., A2)
apply(func[, applyto, noneval, setdata]) Apply func either to self or to associated data.
copy([deep]) Make a copy of this object
gate(gate) Apply given gate and return new gated sample (with assigned data).
get_data(**kwargs) Get the measurement data.
get_meta(**kwargs) Get the measurement metadata.
get_meta_fields(fields[, kwargs]) Return a dictionary of metadata fields
load(path) Loads object from a pickled file.
plot(channel_names[, transform, kind, ...]) Plots the flow cytometry data associated with the sample on the current axis.
read_data(**kwargs) Read the datafile specified in Sample.datafile and
read_meta(**kwargs)
save(path) Saves objec to a pickled file.
set_data([data, datafile]) Assign values to self.data and self.meta.
set_meta([meta, metafile]) Assign values to self.data and self.meta.
transform(transform[, direction, channels, ...]) Applies a transformation to the specified channels.
view() Loads the current FCS sample viewer
ID_from_data(ID_field='$SRC')

Returns the well ID from the src keyword in the FCS file. (e.g., A2) This keyword may not appear in FCS files generated by other machines, in which case this function will raise an exception.

channel_names None

A tuple containing the channel names.

channels None

A DataFrame containing complete channel information

counts None

Returns total number of events.

gate(gate)

Apply given gate and return new gated sample (with assigned data). Note that no transformation is done by this funciton.

Parameters:gate : [ThresholdGate, IntervalGate, QuadGate, PolyGate ]
get_meta_fields(fields, kwargs={})

Return a dictionary of metadata fields

plot(channel_names, transform=(None, None), kind='histogram', gates=None, transform_first=True, apply_gates=True, plot_gates=True, gate_colors=None, **kwargs)

Plots the flow cytometry data associated with the sample on the current axis.

To produce the plot, follow up with a call to matplotlib’s show() function.

Parameters:

channel_names : [str | iterable of str]

The name (or names) of the channels to plot. When one channel is specified, then a 1d histogram is plotted.

kind : [‘scatter’ | ‘histogram’]

Specifies the kind of plot to use for plotting the data (only applies to 2D plots).

autolabel : [False | True]

If True the x and y axes are labeled automatically.

colorbar : [False | True]

Adds a colorbar. Only relevant when plotting a 2d histogram.

xlabel_kwargs : dict

kwargs to be passed to the xlabel() command

ylabel_kwargs : dict

kwargs to be passed to the ylabel() command

transform : [valid transform | tuple of valid transforms | None]

Transform to be applied to corresponding channels using the FCMeasurement.transform function. If a single transform is given, it will be applied to all plotted channels.

gates : [None | Gate | iterable of Gate]

Gate should be in [ThresholdGate, IntervalGate, QuadGate, PolyGate ]. When supplied, the gates are drawn on the plot. The gates are applied by default.

transform_first : bool

Apply transforms before gating.

ax : [None | ax]

Specifies which axis to plot on. If None, will plot on the current axis.

gates : [None, Gate, list of Gate]

Gate must be of type [ThresholdGate, IntervalGate, QuadGate, PolyGate ].

kwargs : dict

Additional keyword arguments to be passed to graph.plotFCM

Returns:

None : if no data is present

plot_output : output of plot command used to draw (e.g., output of hist)

Examples

>>> sample.plot('Y2-A', bins=100, alpha=0.7, color='green', normed=1) # 1d histogram
>>> sample.plot(['B1-A', 'Y2-A'], cmap=cm.Oranges, colorbar=False) # 2d histogram
read_data(**kwargs)

Read the datafile specified in Sample.datafile and return the resulting object. Does NOT assign the data to self.data

read_meta(**kwargs)
transform(transform, direction='forward', channels=None, return_all=True, auto_range=True, use_spln=True, get_transformer=False, ID=None, args=(), **kwargs)

Applies a transformation to the specified channels.

The transformation parameters are shared between all transformed channels. If different parameters need to be applied to different channels, use several calls to transform.

Parameters:

transform : [‘hlog’ | ‘tlog’ | ‘glog’ | callable]

Specifies the transformation to apply to the data.

  • callable : a callable that does a transformation (should accept a number or array), or one of the supported named transformations.

direction : [‘forward’ | ‘inverse’]

Direction of transformation.

channels : str | list of str | None

Names of channels to transform. If None is given, all channels will be transformed.

Warning

Remember that transforming all channels does not always make sense. For example, when working with the time channel, one should probably keep the data as is.

return_all : bool

True - return all columns, with specified ones transformed. False - return only specified columns.

auto_range : bool

If True data range (machine range) is automatically extracted from $PnR field of metadata.

Warning

If the data has been previously transformed its range may not match the $PnR value. In this case, auto_range should be set to False.

use_spln : bool

If True th transform is done using a spline. See Transformation.transform for more details.

get_transformer : bool

If True the transformer is returned in addition to the new Measurement.

args : :

Additional positional arguments to be passed to the Transformation.

kwargs : :

Additional keyword arguments to be passed to the Transformation.

ID : hashable | None

ID for the resulting collection. If None is passed, the original ID is used.

Returns:

new : FCMeasurement

New measurement containing the transformed data.

transformer : Transformation

The Transformation applied to the input measurement. Only returned if get_transformer=True.

Examples

>>> trans = original.transform('hlog')
>>> trans = original.transform('tlog', th=2)
>>> trans = original.transform('hlog', d=log10(2**18), auto_range=False)
>>> trans = original.transform('hlog', r=1000, use_spln=True, get_transformer=True)
>>> trans = original.transform('hlog', channels=['FSC-A', 'SSC-A'], b=500).transform('hlog', channels='B1-A', b=100)
view()

Loads the current FCS sample viewer

Parameters:

channel_names : str | list of str

(Not implemented yet) Names of channels to load by default

Returns:

TODO: Implement channel_names :