Repository navigation
support_funcs
binarize(X, t=0)
A function to binarize a matrix-like object
Arguments
X: matrix-like (n_samples, n_features)
A matrix like numpy array or sparse matrix.
t: float
The value above which an entry is 1 (x > t = 1, else 0)
Returns a binarized copy of the X
pairwise_similarities(X, query, metric=”euclidean”, knn_metric=None, n_neighbours=None, p=None, metric_params=None)
Returns the similarity matrix of every sample entry in X and the sample entries in the query.
Arguments
X: matrix-like (n_samples, n_features)
A numpy ndarray, pandas dataframe or scripy sparse matrix.
query: list-like
A list of row identifiers.
metric: str
The metric to be used for the distance calculations.
Any metric from sklearn.metrics.pairwise_distances or sklearn.metrics.pairwise.pairwise_kernels is available.
Alternatively, “knn_jaccard” is implemented, where the jaccard similarity over the kNN-graph is calculated.
knn_metric: str
If using “knn_jaccard”, the metric to use for knn-graph construction using sklearn.neighbors.kneighbors_graph
n_neighbours: int
If using “knn_jaccard” the number of nearest neighbours used for kNN-graph construction.
p: int
If using “knn_jaccard” the power parameter to pass to sklearn.neighbors.kneighbors_graph.
metric_params: dict
A dictionary of arguments to pass to sklearn.metrics.pairwise_distances or sklearn.metrics.pairwise.pairwise_kernels.
Returns a matrix (n_samples, query) of pairwise similarities between all samples and the query samples
sig_bool(scores, cutoffs):
Returns a boolean copy of the enrichment score dataframe where True means a feature (row) is significantly enriched in a reference cell (column).
Arguments
scores: pandas dataframe
A pandas dataframe of enrichment scores obtained from enrichment_scoring.calculate_escores()
cutoffs: dict
A dictionary of significance cut-offs obtained from enrichment_scoring.sig_interval()
Returns a boolean dataframe with each entry indicating significance (True) or non-significance (False).
sig_dictionary(scores, cutoffs, retrieve=”rows”, sign=”both”)
Retrieve either the genes that are significantly enriched in a certain cell (retrieve=”rows”) or the cells in which a feature is significantly enriched (retrieve=”cols”).
Arguments
scores: pandas dataframe
A pandas dataframe of enrichment scores obtained from enrichment_scoring.calculate_escores().
cutoffs: dict
A dictionary of significance cut-offs obtained from enrichment_scoring.sig_interval()
retrieve: “rows” or “cols”
If “rows”, a dictionary where keys are cells and values are the features that are significantly enriched in this cell are returned.
If “cols”, the keys are features and the values are the cells in which these features are significantly enriched.
sign: “positive”, “negative”, or “both”
If “positive”, only positive enrichment scores will be considered for significance.
If “negative”, only negative enrichment scores will be considered for significance.
If “both”, both positive and negative enrichment scores will be considered for significance.
Returns a dictionary of {cell: enriched features} if retrieve is “rows” or {feature: cells} if retrieve is “cols”
get_sets(sigs, n, get_list=False)
Get a dictionary of all possible n-element sets from all features in “sigs”.
Arguments
sigs: dictionary
A dictionary of {cell: iterable} where the iterable is an iterable of the elements from which sets should be constructed.
Could be the output of sig_dictionary() if retrieve=”rows” was used.
n: int
The number of elements in each set
get_list: boolean
Whether to return the sets iterable as a list or not
Returns a dictionary of {cell: sets} for all keys (cells) in sigs
load_sparse_h5(node, filename)
Load a scipy sparse CSR matrix save in the hdf5 format. Adapted from harryscholes answer @ stackoverflow.
Arguments
node: str
The node identifier used to save the sparse CSR matrix.
filename: str
The path to the location of the file.
Returns a scipy CSR matrix
save_sparse_h5_(X, node, filename)*
Save a scipy sparse CSR matrix. Adapted from harryscholes answer @ stackoverflow.
Arguments
X: scipy CSR matrix
-
node: str
The node identifier of the matrix in the hdf5 file.
filename: str
The path to the location of the file.
Returns -