scQUEST.classifier module

Summary

Classes:

Classifier

Classifier to classify a cell as epithelial or non-epithelial cell.

ClfLitModule

DefaultCLF

Reference

class DefaultCLF(n_in, hidden=(20,), n_out=2, bias=True, activation=ReLU(), activation_last=Softmax(dim=1), seed=None)[source]

Bases: torch.nn.modules.module.Module

__init__(n_in, hidden=(20,), n_out=2, bias=True, activation=ReLU(), activation_last=Softmax(dim=1), seed=None)[source]

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

__doc__ = None
__module__ = 'scQUEST.classifier'
training: bool
_is_full_backward_hook: Optional[bool]
class ClfLitModule(*args, **kwargs)[source]

Bases: scQUEST.utils.LitModule

__init__(*args, **kwargs)[source]
forward(x)[source]

Same as torch.nn.Module.forward().

Parameters
  • *args – Whatever you decide to pass into the forward method.

  • **kwargs – Keyword arguments are also possible.

Return type

int

Returns

Your model’s output

__doc__ = None
__module__ = 'scQUEST.classifier'
training: bool
_is_full_backward_hook: Optional[bool]
class Classifier(n_in=None, model=None, loss_fn=None, metrics=None, seed=None)[source]

Bases: scQUEST.utils.Estimator

Classifier to classify a cell as epithelial or non-epithelial cell. Classifier uses a shallow neural network to discriminate between epithelial and non-epithelial cells. To fit the classifier a pre-annotated sample is needed.

Parameters
  • n_in – number of features

  • model – Model used to train estimator torch.Module or pytorch_lightning.Module

  • loss_fn – Loss function used for optimization

  • metrics – Metrics tracked during test time

estimator = 'classifier'
__init__(n_in=None, model=None, loss_fn=None, metrics=None, seed=None)[source]

Base estimator class

Parameters
  • n_in – number of feature for estimator

  • model – Model used to train estimator torch.Module or pytorch_lightning.Module

  • loss_fn – Loss function used for optimization

  • metrics – Metrics tracked during test time

  • seed – Seed for model weight initialisation

fit(ad=None, target=None, layer=None, datamodule=None, max_epochs=100, callbacks=None, seed=None, **kwargs)[source]

Fit the estimator on annotated data. Expression profiles in ad.layers[layer] are used to predict the phenotype given in ad.obs[target]. By default the given data is randomly split 90/10 in training and test set. If you wish to customize training provide a datamodule with the given train/validation/test splits.

Parameters
  • ad (Optional[AnnData]) – AnnData object with annotated cell types (given by the target parameter)

  • target (Optional[str]) – numerical column in AnnData.obs that should be used as target variable. The target needs to be numerically encoded \([0,C)\) where \(C\) is the number of classes.

  • layer (Optional[str]) – layer in ad.layers to use instead of ad.X

  • datamodule (Optional[LightningDataModule]) – pytorch lightning data module with custom configurations of train, val and test splits

  • max_epochs (int) – maximum epochs for which the model is trained

  • callbacks (Optional[list]) – additional pytorch_lightning callbacks

  • seed (Optional[int]) – Seed for data split

Return type

None

Returns

None

predict(ad, layer=None, inplace=True)[source]

Predict phenotype class. Uses the trained classifier to predict the phenotype of a given cell expression profile. The result is stored in ad.obs[‘clf_{TARGET_NAME}].

Parameters
  • ad (AnnData) – AnnData object to fit

  • layer (Optional[str]) – AnnData.X layer to use for prediction

  • inplace – whether to manipulate the AnnData object inplace or return a copy

Return type

AnnData

Returns

None or AnnData depending on inplace.

_predict_step(X)[source]
_default_model(*args, **kwargs)[source]

Default model if not provided

Return type

Module

_default_loss()[source]

Default loss if not provided

_default_metric()[source]

Default metrics if not provided

_default_litModule()[source]

Lightning module architecture for classifier

_configure_anndata_class()[source]

Dataset class for estimator

__doc__ = 'Classifier to classify a cell as epithelial or non-epithelial cell. Classifier uses a shallow neural network to discriminate\n    between epithelial and non-epithelial cells. To fit the classifier a pre-annotated sample is needed.\n\n    Args:\n        n_in: number of features\n        model: Model used to train estimator :class:`.torch.Module` or :class:`.pytorch_lightning.Module`\n        loss_fn: Loss function used for optimization\n        metrics: Metrics tracked during test time\n    '
__module__ = 'scQUEST.classifier'