topact.classifier

Mehods and classes for training gene expression classifiers.

Module Contents

Classes

Classifier

Abstract class for a gene expression classifier.

SVCClassifier

Based on the implementation of Abdelaal et al. 2019

Functions

normalize_rows(matrix[, r])

train_from_countmatrix(classifier, countmatrix, label)

topact.classifier.normalize_rows(matrix, r=5)
Parameters
  • matrix (scipy.sparse.spmatrix | np.matrix) –

  • r (int) –

Return type

scipy.sparse.spmatrix

class topact.classifier.Classifier

Bases: abc.ABC

Abstract class for a gene expression classifier.

trained

True if and only if the classifier has been trained.

classes

If trained, then an ordered list of all classes.

abstract classify(samples)

Takes gene expression samples and returns a classification.

Parameters

samples (scipy.sparse.spmatrix | np.matrix) – A matrix of gene expressions. Each row represents a single sample.

Returns

An matrix of probabilities, of shape (samples, classes). Each row records the confidence that the respective sample came from each class.

Return type

numpy.typing.NDArray

abstract train(X_train, y_train)

Trains the classifier on annotated samples.

Parameters
  • X_train (scipy.sparse.spmatrix) – A matrix of gene expressions. Each row represents a single sample.

  • y_train (Sequence[str]) – A label for each sample.

class topact.classifier.SVCClassifier(r_value=5)

Bases: Classifier

Based on the implementation of Abdelaal et al. 2019

Parameters

r_value (int) –

train(X_train, y_train)

Trains the classifier on annotated samples.

Parameters
  • X_train (scipy.sparse.spmatrix) – A matrix of gene expressions. Each row represents a single sample.

  • y_train (Sequence[str]) – A label for each sample.

classify(samples)

Takes gene expression samples and returns a classification.

Parameters

samples (scipy.sparse.spmatrix | np.matrix) – A matrix of gene expressions. Each row represents a single sample.

Returns

An matrix of probabilities, of shape (samples, classes). Each row records the confidence that the respective sample came from each class.

topact.classifier.train_from_countmatrix(classifier, countmatrix, label)
Parameters