Cyclum Package

Submodules

cyclum.core module

This module implements the scae core. Current version is a fast implementation

class cyclum.core.Cyclum[source]

Bases: object

Wraps the mathematical method up and provide more functions.

class cyclum.core.PreloadCyclum(Y, q_circular=3, q_linear=0, seed=0, verbose=True)[source]

Bases: object

The core of Cyclum. The data is preloaded into graphic memory to run it as fast as possible. Before fit()

Parameters:
  • Y (numpy matrix) – each row is a cell and each column is a gene.
  • q_circular – number of
  • q_linear
  • seed – random seed
  • verbose (bool) – if True, show the training progress
close()[source]

Close the TensorFlow Session. All information about the model will be deleted.

Returns:None
correct()[source]

Correct the input expression matrix wrt cell cycle.

Returns:
fit()[source]

Fits the model and give the inferred pseudotime, and also its relationship to the gene expression. These outputs are essential for downstream analysis.

Returns:pseudotime: the pseudo-time for each cell, in the same order as the input, in a [0, 2pi] scale. rotation: the rotation matrix
generate(pseudotime=None)[source]

Given a pseudo-time, generate a “ideal cycling cell”

Parameters:pseudotime (float or numpy.matrix) – the pseudo-time. If not specified it will use the whole inferred pseudotime.
Returns:the gene expression of a “ideal cycling cell”
predict()[source]

Given a cell, predict its pseudo-time, given a fitted model. The model will not be fitted again.

Returns:
save()[source]

Save the Tensorflow Session for future use

Returns:
class cyclum.core.PreloadCyclum2(Y)[source]

Bases: cyclum.core._BaseCyclum

train()[source]

train the model

Returns:
class cyclum.core.PreloadNaiveCyclum(Y, q_circular=3, q_linear=0, seed=0)[source]

Bases: object

fit()[source]

cyclum.evaluation module

cyclum.evaluation.parzen_estimate(x, lim, half_granularity=100, window=<function <lambda>>, scale=0.5)[source]

Calculate parzen window estimation (a non-parametric density estimation method) :param x: instances :param lim: limit of domain :param half_granularity: :param window: :param scale: :return:

cyclum.evaluation.periodic_parzen_estimate(x, period=3.14, half_granularity=100, window=<function <lambda>>, scale=0.5)[source]

Calculate parzen window estimation specifically for periodic domain :param x: :param period: :param half_granularity: :param window: :param scale: :return:

cyclum.evaluation.precision_estimate(distr_vector_list, label_vector, possible_label_list)[source]
Parameters:
  • distr_vector_list
  • label_vector
  • possible_label_list
Returns:

cyclum.filter module

Provides filters to filter out genes and cells.

cyclum.filter.cell_sparsity(data, ratio=None, count=None, threshold=0.5, return_mask=False)[source]

filter cells by how many 0 genes they have :param data: :param ratio: ratio of non-zero entries. Either a number or a pair of numbers. Treat as [ ). :param count: number of non-zero entries. Treat as [ ). :param threshold: threshold to decide what is considered 0 :param return_mask: if set to True, output mask instead of matrix You must supply ratio XOR number, i.e. one of them and only one of them. :return:

cyclum.filter.gene_sparsity(data, ratio=None, count=None, threshold=0.5, return_mask=False)[source]

filter cells by how many 0 genes they have :param linear_data: data :param ratio: ratio of non-zero entries. Either a number or a pair of numbers. Treat as [ ). :param count: number of non-zero entries. Treat as [ ). :param threshold: threshold to decide what is considered 0 :param return_mask: if set to True, output mask instead of matrix You must supply ratio XOR number, i.e. one of them and only one of them. :return:

cyclum.illustration module

class cyclum.illustration.FigureWriter(pdf_name: str)[source]

Bases: object

keep and write figures into a pdf file.

add_figure(figure, title=None)[source]

add a figure, but not write to file :param figure: :param title: :return:

add_figure_and_write(figure, title=None)[source]
write()[source]
cyclum.illustration.plot_cell_sparsity(linear_data, use_ratio=True)[source]

Return a figure of #{cell, none_zero_genes(cell) > x} :param linear_data: data :param use_ratio: plot as ratio or :return:

cyclum.illustration.plot_gene_sparsity(linear_data, use_ratio=True)[source]

Return a figure of #{cell, none_zero_genes(cell) > x} :param linear_data: data :param use_ratio: plot as ratio or :return:

cyclum.illustration.plot_multi_distr(xs, ys, colors, labels)[source]
cyclum.illustration.plot_pair_color(a, b, color)[source]

either plot an embedding, two dimensions at a time or compare two embeddings :param a: :param b: :param color: :return:

cyclum.illustration.plot_round_color(flat, color)[source]
cyclum.illustration.plot_round_distr_color(flat, label, color_dict)[source]
cyclum.illustration.plot_round_distr_color2(flat, label1, label2, color_dict1, color_dict2)[source]

cyclum.preproc module

Provide transformation from count matrix to TPM/PKM. It also supports transforming data frames

cyclum.preproc.calc_pkm(count_matrix, gene_length_vector, is_cell_row=True)[source]

Transformation from count matrix to PKM matrix.

Parameters:
  • count_matrix – count matrix
  • gene_length_vector – lengths of genes
  • is_cell_row – if true, cells should be rows
Returns:

cyclum.preproc.calc_pkm_for_df(df, gene_length_vector, is_cell_row=True)
cyclum.preproc.calc_tpm(count_matrix, gene_length_vector, is_cell_row=True)[source]

Transformation from count matrix to TPM matrix.

Parameters:
  • count_matrix – count matrix
  • gene_length_vector – lengths of genes
  • is_cell_row – if true, cells should be rows
Returns:

cyclum.preproc.calc_tpm_for_df(df, gene_length_vector, is_cell_row=True)
cyclum.preproc.for_df(func)[source]

cyclum.smart_train module

class cyclum.smart_train.SmartModel(seed, q_circular, q_linear, Y, verbose=True)[source]

Bases: object

train(rec_file_name)[source]

cyclum.writer module

Writer gives a very fast way of saving and loading float value matrices. It saves matrices in binary and in very rigid format. This avoids overheads in csv reading functions. The R counterpart is also available.

cyclum.writer.int32_to_bytes(x)[source]

Convert an 32 bit int number to little endian 4 byte binary format. This helps writing a integer to a binary file.

Parameters:x (int32) – number to be converted
Returns:4 byte binary
cyclum.writer.read_df_from_binary(file_name_mask)[source]

Read a data frame from a binary file defined by this module

Parameters:file_name_mask
Returns:the data frame
cyclum.writer.read_matrix_from_binary(file_name)[source]

Read a matrix from a binary file defined by this module.

Parameters:file_name (str) – the file to read
Returns:the matrix
cyclum.writer.write_df_to_binary(file_name_mask, df)[source]

Write a data frame to a file. Compared with matrix, it has column and row names Besides the row names and column names, the data frame must contain only float values.

Two files will be saved. For exmaple, a call write_df_to_binary(“example”, df) will output an “example-value.bin” and “example-name.txt”. They store the matrix and the column and row names separately.

Parameters:
  • file_name_mask (str) – the stem of the file name
  • df – the data frame to write
Returns:

None

cyclum.writer.write_matrix_to_binary(file_name, val)[source]

Write an (unnamed) matrix to a file. The matrix should contain only float values, or at least convertible to float.

Parameters:
  • file_name (str) – name of file
  • val – The matrix to write
Returns:

None

Module contents

This package implements the scae and related analyzing tools.