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
-
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”
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.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.
-
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.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.smart_train module¶
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
Module contents¶
This package implements the scae and related analyzing tools.