scimilarity.interpreter#

class scimilarity.interpreter.Interpreter(encoder, gene_order)[source]#

Bases: object

A class that interprets significant genes.

Parameters:
  • encoder (torch.nn.Module) –

  • gene_order (list) –

get_attributions(anchors, negatives)[source]#

Returns attributions, which can later be aggregated. High attributions for genes that are expressed more highly in the anchor and that affect the distance between anchors and negatives strongly.

Parameters:
  • anchors (numpy.ndarray, scipy.sparse.csr_matrix, torch.Tensor) – Tensor for anchor or positive cells.

  • negatives (numpy.ndarray, scipy.sparse.csr_matrix, torch.Tensor) – Tensor for negative cells.

Returns:

A 2D numpy array of attributions [num_cells x num_genes].

Return type:

numpy.ndarray

Examples

>>> attr = interpreter.get_attributions(anchors, negatives)
get_ranked_genes(attrs)[source]#

Get the ranked gene list based on highest attributions.

Parameters:
  • attr (numpy.ndarray) – Attributions matrix.

  • attrs (numpy.ndarray) –

Returns:

A pandas dataframe containing the ranked attributions for each gene

Return type:

pandas.DataFrame

Examples

>>> attrs_df = interpreter.get_ranked_genes(attrs)
plot_ranked_genes(attrs_df, n_plot=15, filename=None)[source]#

Plot the ranked gene attributions.

Parameters:
  • attrs_df (pandas.DataFrame) – Dataframe of ranked attributions.

  • n_plot (int) – The number of top genes to plot.

  • filename (str, optional) – The filename to save to plot as.

Examples

>>> interpreter.plot_ranked_genes(attrs_df)
class scimilarity.interpreter.SimpleDist(encoder)[source]#

Bases: Module

Calculates the distance between representations

Parameters:

encoder (torch.nn.Module) –

forward(anchors, negatives)[source]#

Forward.

Parameters:
  • anchors (torch.Tensor) – Tensor for anchor or positive cells.

  • negatives (torch.Tensor) – Tensor for negative cells.

Returns:

Sum of squares distance for the encoded tensors.

Return type:

float