FCM Library Documentation

Classes and functions from fcm

setup all things exported from FCM

class fcm.FCMdata(name, pnts, channels, scatters=None, notes=None)

Object representing flow cytometry data FCMdata.pnts : a numpy array of data points FCMdata.channels : a list of which markers/scatters are on which column of the array. FCMdata.scatters : a list of which indexes in fcmdata.channels are scatters


add a new node to the view tree


returns dictionary of fraction of events in first and last channel for each channel

compensate(sidx=None, spill=None)

Compensate the fcm data


return a copy of fcm data object


return the current node


export out current view to a fcs file

gate(g, chan=None)

return gated region of fcm data


Return the data associated with specific channel names


get current node


return the data associated with all the markers


return the spillover matrix from the original fcs used in compisating

hyperlog(channels, b, d, r, order=2, intervals=1000.0)

return hyperlog transformed channels


return log base 10 transformed channels

logicle(channels=None, T=262144, m=4.5, r=None, scale_max=100000.0, scale_min=0)

return logicle transformed channels


Return the channel indexes for the named channels


return subsampled/sliced fcm data


returns summary of current view


return the current view of the data


Switch current view of the data

class fcm.FCMcollection(name, fcms=None, notes=None)

Represent collection of FCMdata objects. Attributes: note = collection level annotations tree = tree of operations


Checks for channel name consistency.

Returns dictionary of (fcmcollecion.name, [bool] | dictionary) where True = all fcm have same name for the channel and False = at least one different name.


classify each fcs object in the collection using a mixture model

compensate(*args, **kwargs)

apply compensation to the fcs objects in a collection

fit(model, *args, **kwargs)

fit a mixture model to each fcs object in a collection

gate(*args, **kwargs)

apply a gate to the fcs objects in a collection

keys() → list of D's keys
log(*args, **kwargs)

apply log transform the fcs objects in the collection

logicle(*args, **kwargs)

apply logicle transform to the fcs objects in the collection


produce summary statitsics for each fcs object in the collection


return a list of the fcmdata objects contained in the collection

class fcm.PolyGate(vert, channels, name=None)

An object representing a polygonal gatable region

gate(fcm, chan=None, invert=False, name=None)

return gated region of FCM data

class fcm.QuadGate(vert, channels, name=None)

An object to divide a region to four quadrants

gate(fcm, chan=None, name=None, _full=False)

return gated region

class fcm.IntervalGate(vert, channels, name=None)

An objeect to return events within an interval in any one channel.

gate(fcm, chan=None, name=None)

return interval region.

class fcm.ThresholdGate(vert, channels, op='g', name=None)

an object to return events above or below a threshold in any one channel

gate(fcm, chan=None, op=None, name=None)

return all events greater (or less) than a threshold allowed op are ‘g’ (greater) or ‘l’ (less)

class fcm.FCSreader(filename, transform='logicle', sidx=None, spill=None)

class to hold object to read and parse fcs files. main usage is to get a FCMdata object out of a fcs file

fix_lmd(offset, start, stop)

function to handle lmd counting differently then most other FCS data

get_FCMdata(auto_comp=True, **kwargs)

Return the next FCM data set stored in a FCS file

parse_analysis(offset, start, stop)

return parsed analysis segment of fcs file

parse_ascii_data(offset, start, stop, bitwidth, dtype, tot, order)

Parse out ascii encoded data from fcs file

parse_data(offset, start, stop, text)

return numpy.array of data segment of fcs file

parse_float_data(offset, start, stop, dtype, tot, order)

Parse out and return float list data from fcs file


Parse the FCM data in fcs file at the offset (supporting multiple data segments in a file

parse_int_data(offset, start, stop, bitwidth, drange, tot, order)

Parse out and return integer list data from fcs file

parse_text(offset, start, stop)

return parsed text segment of fcs file

read_bytes(offset, start, stop)

Read in bytes from start to stop inclusive.

class fcm.Annotation(annotations=None)

Annotation object for storing metadata about FCM data

copy() → a shallow copy of D
class fcm.FlowjoWorkspace(tubes, comp=None)

Object representing the files, gates, and compensation matricies from a flowjo xml worksapce

logicle(T=262144, m=4.5, r=None, w=0.5, scale_max=100000.0)

convert gate cordinates for all tubes into logicle scale from linear scale

exception fcm.BadFCMPointDataTypeError(data, message)

Exception raised on bad FCM data type

data: the wrong data message: explanation of the error

exception fcm.UnimplementedFcsDataMode(mode)

Exception raised on unimplemented data modes in fcs files

mode: mode

exception fcm.CompensationError(message)

Exception raised on problems with compensation

message: explanation of the error

fcm.generate_f_score_gate(neg_smaple, pos_sample, chan, beta=1, theta=2, high=True)

given a negative and a positive sample, calculate the ‘optimal’ threshold gate position from aproximate f-score calculation

fcm.logicle(fcm, channels, T, m, r=None, scale_max=100000.0, scale_min=0, w=None, rquant=None)

return logicle transformed points in fcm data for channels listed

fcm.hyperlog(fcm, channels, b, d, r, order=2, intervals=1000.0)
fcm.loadFCS(filename, transform='logicle', auto_comp=True, spill=None, sidx=None, **kwargs)

Load and return a FCM data object from an FCS file

fcm.loadMultipleFCS(files, transform='logicle', auto_comp=True, spill=None, sidx=None, **kwargs)

Load a compensation matrix from a text file like those generated by flowjo Returns a list of markers and a compensation matrix


create a FlowjoWorkspace object from a xml file

Graphics convience functions provided by fcm.graphics

fcm.graphics.pair_plot(data, savefile=None, display=True, **kwargs)
fcm.graphics.pseudocolor(fcm, indices, nrows=1, ncols=1, s=1, edgecolors='none', savefile=None, display=True, **kwargs)

Plot a pseudocolor.

indices = list of marker index pairs nrows = number of rows to plot ncols = number of cols to plot nrows * ncols should be >= len(indices) display = boolean indicating whether to show plot save = filename to save plot (e.g. ‘x.png’) **kwargs are passed on to pylab.scatter

fcm.graphics.hist(fcms, index, savefile=None, display=True, **kwargs)

Plot overlay histogram.

fcms is a list of FCMData objects/arrays index is channel to plot

fcm.graphics.pseudocolors(fcm, savefile=None, display=True, **kwargs)

PLot scatter matrix of all pseudocolors.

fcm.graphics.contour(data, indices, savefile=None, display=True, **kwargs)
fcm.graphics.bilinear_interpolate(x, y, bins=None)

Returns interpolated density values on points (x, y).

Ref: http://en.wikipedia.org/wiki/Bilinear_interpolation.

fcm.graphics.trilinear_interpolate(x, y, z, bins=None)

Returns interpolated density values on points (x, y, z).

Ref: http://en.wikipedia.org/wiki/Trilinear_interpolation.

fcm.graphics.set_logicle(ax, xy, T=262144, m=4.5, w=0.5, scale_max=100000)
fcm.graphics.plot_gate(data, gate, ax, chan=None, name=None, **kwargs)

wrapper around several plots aimed at plotting gates (and gating at the same time) see the wrapped functions plot_ploy_gate, plot_threshold_gate, plot_threshold_hist for more information

Clustering and statistical methods

class fcm.statistics.Dime(cluster=None, pi=None, mu=None, sigma=None, cmap=None)

DiME analysis object

drop(target, drop=None)

calculate discriminitory information

class fcm.statistics.DPCluster(pi, mu, sig)

Single component cluster in mixture model


draw a random sample of size n form this cluster

prob(x, logged=False, **kwargs)

DPCluster.prob(x): returns probability of x beloging to this mixture compoent

class fcm.statistics.DPMixture(clusters, niter=1, m=False, s=False, identified=False)

collection of components that describe a mixture model


average over mcmc draws to try and find the ‘average’ weights, means, and covariances

classify(x, **kwargs)

DPMixture.classify(x): returns the classification (which mixture) x is a member of


draw n samples from the represented mixture model


return the last n (defaults to 1) mcmc draws


return the log liklihood of x belonging to this mixture

make_modal(tol=1e-05, maxiter=20)

find the modes and return a modal dp mixture


DPMixture.mus(): returns an array of all cluster means


return an array of all cluster weights/proportions


returns an array of probabilities of x being in each component of the mixture


DPMixture.sigmas(): returns an array of all cluster variance/covariances

class fcm.statistics.ModalDPMixture(clusters, cmap, modes, m=False, s=False)

collection of modal components that describe a mixture model

classify(x, **kwargs)

ModalDPMixture.classify(x): returns the classification (which mixture) x is a member of


ModalDPMixture.modes(): return an array of mode locations


returns an array of probabilities of x being in each mode of the modal mixture

class fcm.statistics.DPMixtureModel(nclusts, niter=1000, burnin=100, last=None, type='mcmc')

Fits a DP Mixture model to a fcm dataset.

fit(fcmdata, verbose=False)

get the last classification from the model


get the results of the fitted mixture model

class fcm.statistics.HDPMixtureModel(nclusts, niter=1000, burnin=100, last=None, type='mcmc')

HDPMixtureModel(nclusts, niter=1000, burnin= 100, last= None) nclusts = number of clusters to fit niter = number of mcmc itterations burning = number of mcmc burnin itterations last = number of mcmc itterations to draw samples from. if None last = niter

fit(datasets, verbose=False, tune_interval=100)

get the results of the fitted mixture model

class fcm.statistics.KMeansModel(k, niter=20, tol=1e-05)

KmeansModel(data, k, niter=20, tol=1e-5) kmeans clustering model

fcm.statistics.mvnormpdf(x, mu, va, **kwargs)

calculate the multi-variate normal pdf D(x, mu, sigma) -> float

fcm.statistics.mixnormpdf(x, prop, mu, Sigma, **kwargs)

Mixture of multivariate normal pdfs

fcm.statistics.mixnormrnd(pi, mu, sigma, k)

Generate random variables from mixture of Guassians

class fcm.statistics.KMeans(centroids)

K means model