cytoflow.operations.mst#

Apply a polygon gate to a minimum spanning tree. mst has two classes:

ConditionSelectionOp – Applies a gate to a (categorical) condition, creating

a new (boolean) condition that is True if the event’s value for the categorical condition is in the values attribute.

MSTOp – Applies a gate based on a polygon drawn on an MST.

MSTSelectionView – an IView that allows you to view the polygon and/or interactively set the vertices on an MST.

class cytoflow.operations.mst.ConditionSelectionOp[source]#

Bases: HasTraits

Apply a gate to a categorical condition. Creates a new boolean condition named name, which is True if the event’s value for condition is in condition_values.

name#

The operation name. Used to name the new metadata field in the experiment that’s created by apply

Type:

Str

condition#

The condition to apply the gate to.

Type:

Str

condition_values#

The values for which to set the new name condition to True.

Type:

List(Any)

Notes

This is intended to be a base class for MSTOp. I’m not sure if it will be useful for additional derived classes, but I figured I’d architect it to make that straightforward.

apply(experiment)[source]#

Applies the gate to an experiment.

Parameters:

experiment (Experiment) – the old Experiment to which this op is applied

Returns:

a new ‘Experiment`, the same as experiment but with a new column of type bool with the same as the operation name. The bool is True if the event’s value of the condition condition is in condition_values, and False otherwise.

Return type:

Experiment

Raises:

CytoflowOpError – if for some reason the operation can’t be applied to this experiment. The reason is in the args attribute.

class cytoflow.operations.mst.MSTOp[source]#

Bases: ConditionSelectionOp

Apply a gate to a polygon drawn around a minimum spanning tree.

The only attribute is name – everything else is set by the default view, which inherits MSTView.

name#

The operation name. Used to name the new metadata field in the experiment that’s created by apply

Type:

Str

condition#

The condition to apply the gate to.

Type:

Str

condition_values#

The values for which to set the new name condition to True.

Type:

List(Any)

apply(experiment)[source]#

Applies the gate to an experiment.

Parameters:

experiment (Experiment) – the old Experiment to which this op is applied

Returns:

a new ‘Experiment`, the same as experiment but with a new column of type bool with the same as the operation name. The bool is True if the event’s value of the condition condition is in condition_values, and False otherwise.

Return type:

Experiment

Raises:

CytoflowOpError – if for some reason the operation can’t be applied to this experiment. The reason is in the args attribute.

default_view(**kwargs)[source]#

Returns an IView that allows a user to view the polygon or interactively draw it.

class cytoflow.operations.mst.MSTSelectionView[source]#

Bases: MSTView

op#

The IOperation that this view is associated with. If you created the view using default_view, this is already set.

Type:

Instance(IOperation)

statistic#

The statistic to plot. Must be a key in Experiment.statistics.

Type:

Str

locations#

A statistic whose levels are the same as statistic and whose features are the dimensions of the locations of each node to plot.

Type:

Str

.. note

same as the levels of locations. If style is pie or petal, the levels of statistic must be the levels of locations plus variable.

Type:

: If style is heat, then the levels of statistic must be the

locations_level#

Which level in the locations statistic is different at each location? The values of the others must be specified in the plot_name parameter of plot. Optional if there is only one level in locations.

Type:

Str

locations_features#

Which features in locations to use. By default, use all of them.

Type:

List(Str)

.. warning

The KMeansOp statistic is mostly locations, but also has the a Proportion feature. You likely don’t want to use it as a location for laying out the minimum spanning tree!

Type:

:

variable#

The variable used for plotting pie and petal plots. Must be left empty for a heatmap.

Type:

Str

feature#

The column in the statistic to plot (often a channel name.)

Type:

Str

style#

What kind of plot to make?

Type:

Enum(heat, pie, petal) (default = heat)

scale#

For a heat map, how should the color of feature be scaled before plotting? For pie and petal maps, how should the input data be normalized to [0,1] before plotting?

Type:

{‘linear’, ‘log’, ‘logicle’}

size_function#

If set, separate the Experiment into subsets by levels of locations, compute a function on them, and scale the size of each tree node by those values. The callable should take a single pandas.DataFrame argument and return a positive float or value that can be cast to float (such as int). Of particular use is len, which will scale the cells by the number of events in each subset.

Type:

Callable (default: None)

metric#

What metric should be used to compute distance in the tree? Must be one of braycurtis, canberra, chebyshev, cityblock, correlation, cosine, dice, euclidean, hamming, jaccard, jensenshannon, kulczynski1, mahalanobis, matching, minkowski, rogerstanimoto, russellrao, seuclidean, sokalmichener, sokalsneath, sqeuclidean, yule. Suggestion: use euclidean for small numbers of dimensions (location features) and cosine for larger numbers.

Type:

Str (default: euclidean)

subset#

An expression that specifies the subset of the statistic to plot. Passed unmodified to pandas.DataFrame.query.

Type:

str

plot(experiment, **kwargs)[source]#

Plot a chart of a variable’s values against a statistic.

Parameters:
  • experiment (Experiment) – The Experiment to plot using this view.

  • plot_name (str) – If this IView can make multiple plots, plot_name is the name of the plot to make. Must be one of the values retrieved from enum_plots.

  • title (str) – Set the plot title

  • legend (bool) – Plot a legend or color bar? Defaults to True.

  • legendlabel (str) – Set the label for the color bar or legend

  • palette (palette name) – Colors to use for the different levels of the hue variable. Should be something that can be interpreted by seaborn.color_palette. If plotting a heat map, this should be a continuous color map (‘viridis’ is the default.) Otherwise, choose either a discrete color map (‘deep’ is the default) or a continuous color map from which equi-spaced colors will be drawn.

  • radius (float) – The radius of the circle or pie plots, on a scale from 0 to 1.

  • All other parameters are passed to the `matplotlib.patches.Circle` or

  • `matplotlib.patches.Wedge` construtors (ie, they should be patch attributes).