FlowCal.transform module

Functions for transforming flow cytometry data

All transformations are of the following form:

data_t = transform(data, channels, *args, **kwargs):

where data and data_t are NxD FCSData objects or numpy arrays, representing N events with D channels, channels indicate the channels in which to apply the transformation, and args and kwargs are transformation-specific parameters. Each transformation function can apply its own restrictions or defaults on channels.

If data is an FCSData object, transform should rescale data.range if necessary.

FlowCal.transform.to_mef(data, channels, sc_list, sc_channels=None)

Transform flow cytometry data using a standard curve function.

This function accepts a list of standard curves (sc_list) and a list of channels to which those standard curves should be applied (sc_channels). to_mef automatically checks whether a standard curve is available for each channel specified in channels, and throws an error otherwise.

This function is intended to be reduced to the following signature:

to_mef_reduced(data, channels)

by using functools.partial once a list of standard curves and their respective channels is available.

Parameters:
data : FCSData or numpy array

NxD flow cytometry data where N is the number of events and D is the number of parameters (aka channels).

channels : int, str, list of int, list of str

Channels on which to perform the transformation. If channels is None, perform transformation in all channels specified on sc_channels.

sc_list : list of functions

Functions implementing the standard curves for each channel in sc_channels.

sc_channels : list of int or list of str, optional

List of channels corresponding to each function in sc_list. If None, use all channels in data.

Returns:
FCSData or numpy array

NxD transformed flow cytometry data.

Raises:
ValueError

If any channel specified in channels is not in sc_channels.

FlowCal.transform.to_rfi(data, channels=None, amplification_type=None, amplifier_gain=None, resolution=None)

Transform flow cytometry data to Relative Fluorescence Units (RFI).

If amplification_type[0] is different from zero, data has been taken using a log amplifier. Therefore, to transform to RFI, the following operation is applied:

y = a[1]*10^(a[0] * (x/r))

Where x and y are the original and transformed data, respectively; a is amplification_type argument, and r is resolution. This will transform flow cytometry data taken with a log amplifier and an ADC of range r to linear RFIs, such that it covers a[0] decades of signal with a minimum value of a[1].

If amplification_type[0]==0, however, a linear amplifier has been used and the following operation is applied instead:

y = x/g

Where g is amplifier_gain. This will transform flow cytometry data taken with a linear amplifier of gain g back to RFIs.

Parameters:
data : FCSData or numpy array

NxD flow cytometry data where N is the number of events and D is the number of parameters (aka channels).

channels : int, str, list of int, list of str, optional

Channels on which to perform the transformation. If channels is None, perform transformation in all channels.

amplification_type : tuple or list of tuple

The amplification type of the specified channel(s). This should be reported as a tuple, in which the first element indicates how many decades the logarithmic amplifier covers, and the second indicates the linear value that corresponds to a channel value of zero. If the first element is zero, the amplification type is linear. This is similar to the $PnE keyword from the FCS standard. If None, take amplification_type from data.amplification_type(channel).

amplifier_gain : float or list of floats, optional

The linear amplifier gain of the specified channel(s). Only used if amplification_type[0]==0 (linear amplifier). If None, take amplifier_gain from data.amplifier_gain(channel). If data does not contain amplifier_gain(), use 1.0.

resolution : int, float, or list of int or float, optional

Maximum range, for each specified channel. Only needed if amplification_type[0]!=0 (log amplifier). If None, take resolution from len(data.domain(channel)).

Returns:
FCSData or numpy array

NxD transformed flow cytometry data.

FlowCal.transform.transform(data, channels, transform_fxn, def_channels=None)

Apply some transformation function to flow cytometry data.

This function is a template transformation function, intended to be used by other specific transformation functions. It performs basic checks on channels and data. It then applies transform_fxn to the specified channels. Finally, it rescales data.range and if necessary.

Parameters:
data : FCSData or numpy array

NxD flow cytometry data where N is the number of events and D is the number of parameters (aka channels).

channels : int, str, list of int, list of str, optional

Channels on which to perform the transformation. If channels is None, use def_channels.

transform_fxn : function

Function that performs the actual transformation.

def_channels : int, str, list of int, list of str, optional

Default set of channels in which to perform the transformation. If def_channels is None, use all channels.

Returns:
data_t : FCSData or numpy array

NxD transformed flow cytometry data.