cytopy.flow.cell_classifier.cell_classifier

This module contains the base class CellClassifier for using supervised classification methods, trained on some labeled FileGroup (has existing Populations) to predict single cell classifications.

Copyright 2020 Ross Burton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Classes:

CellClassifier(features, target_populations, …)

Use supervised machine learning to predict the classification of single cell data.

class cytopy.flow.cell_classifier.cell_classifier.CellClassifier(features: list, target_populations: list, multi_label: bool = False, logging_level: int = 20, log: Optional[str] = None, population_prefix: str = 'CellClassifier_')

Use supervised machine learning to predict the classification of single cell data. This is the base class used by SklearnCellClassifier and KerasCellClassifier. Training data should be provided in the form of a FileGroup with existing Populations. Supports multi-class and multi-label classification; if multi-label classification is chosen, the tree structure of training data is NOT conserved - all resulting populations will have the same parent population.

Parameters
  • features (list) – List of channels/markers to use as features in prediction

  • target_populations (list) – List of populations from training data to predict

  • multi_label (bool (default=False)) – If True, single cells can belong to more than one population. The tree structure of training data is NOT conserved - all resulting populations will have the same parent population.

  • logging_level (int (default=logging.INFO)) – Level to log events at

  • log (str, optional) – Path to log output to; if not given, will log to stdout

  • population_prefix (str (default=”CellClassifier_”)) – Prefix applied to populations generated

scaler

Scaler object

Type

Scaler

transformer

Transformer object

Type

Transformer

class_weights

Sample class weights; key is sample index, value is weight. Set by calling compute_class_weights.

Type

dict

x

Training feature space

Type

Pandas.DataFrame

y

Target labels

Type

numpy.ndarray

logger
Type

logging.Logger

features
Type

list

target_populations
Type

list

Methods:

load_training_data(experiment, reference, …)

Load a FileGroup with existing Populations to serve as training data

load_validation(experiment, validation_id, …)

Load a FileGroup that has existing populations equivalent but not the same as the target populations e.g.

load_training_data(experiment: cytopy.data.experiment.Experiment, reference: str, root_population: str)

Load a FileGroup with existing Populations to serve as training data

Parameters
  • experiment (Experiment) –

  • reference (str) – Name of the FileGroup to use as training data

  • root_population (str) – Root population from which all target populations inherit

Returns

Return type

self

Raises

AssertionError – If FileGroup is invalid for reasons of missing target populations or an invalid hierarchy; populations must be downstream of the chosen root_population

load_validation(experiment: cytopy.data.experiment.Experiment, validation_id: str, root_population: str)

Load a FileGroup that has existing populations equivalent but not the same as the target populations e.g. identified by some other method (must share the same name as the target populations!). This will generate data from the FileGroup that can be used to validate the model.

Parameters
  • experiment (Experiment) –

  • validation_id (str) – Name of the FileGroup to load as validation data

  • root_population (str) – Name of the root population from which the target populations descend

Returns

Feature space, labels

Return type

Pandas.DataFrame, numpy.ndarray

Raises

AssertionError – If target populations are missing in validation data