Package: shannon-ca
SCA (Shannon Components Analysis)Shannon Components Analysis (formerly called scalpel) is a dimensionality reduction technique for single-cell data which leverages mathematical information theory to identify biologically informative axes of variation in single-cell transcriptomic data, enabling recovery of rare and common cell types at superior resolution. It is written in Python. The pre-print can be foundhere.Required packages: scanpy, sklearn, numpy, scipy, fbpca, itertoolsUsageDimensionality ReductionSCA generates information score matrices, which are used to generate linear combinations of genes (metagenes) that are biologically informative. The package includes workflows both with and without Scanpy undersca.dimred.Without ScanpyThereducefunction accepts a (num genes) x (num cells) matrix X, and outputs a dimensionality-reduced version with fewer features. The input matrix may be normalized or otherwise processed, but a zero in the input matrix must indicate zero recorded transcripts.from sca.dimred import reduce

X = mmread('mydata.mtx').transpose() # read some dataset

reduction = reduce(X, n_comps=50, n_pcs=50, iters=1, max_bins=float('inf'))reductionis an (num cells) x (comps)-dimensional matrix. The function optionally returns SCA's score matrix (if keep_scores=True), metagene loadings (if keep_loadings=True), or intermediate results (if iters>1 and keep_all_iters=True). If at least one of these is returned, the return type is a dictionary with keys for 'reduction', 'scores', and 'loadings'. If keep_all_iters=True, the reductions after each iteration will be keyed by 'reduction_i' for each iteration number i.The starting representation by default is a PCA representation with 50 components, but the user can specify their own usingrep. Starting neighborhoods are computed by default using cosine distance in this representation (controlled bymetric). See the docstring for more detailed and comprehensive parameter descriptions.With ScanpyScanpy (https://github.com/theislab/scanpy) is a commonly-used single-cell workflow. To compute a reduction in place on a scanpy AnnData object, usereduce_scanpy:import scanpy as sc
from sca.dimred import reduce_scanpy

adata = sc.AnnData(X)
reduce_scanpy(adata, keep_scores=True, keep_loadings=True, keep_all_iters=True, layer=None, key_added='sca', iters=1, n_comps=50, n_pcs=50)This function shares all parameters withreduce, but instead of returning the output, it updates the input AnnData object. Dimensionality reductions are stored inadata.obsm[key_added], or, if keep_all_iters=True, inadata.obsm['key_added_i']for each iteration number i. Ifkeep_scores=Truein the reducer constructor, the information scores of each gene in each cell are stored inadata.layers[key_added]. Iflayer=None, the algorithm is run onadata.X; otherwise, it is run onadata.layers[layer].[Deprecated] Curried versionFirst, construct a reducer using theinfo_pcafunction.from sca.dimred import info_pca
reducer = info_pca(nbhd_size=15, n_neighbors=15, n_init_pcs=50, n_info_pcs=50, key_added='info_pca', metric='cosine',
             max_bins=float('inf'), iters=1)Shown are the default parameters.nbhd_sizedetermines the size of local neighborhoods used in comparing local vs. global expression of each gene.n_neighborsdetermines the number of neighbors in the NN graph computed at the end.n_init_pcsdetermines how many PCs to use in computing initial locales.n_info_pcsdetermines the dimensionality of the final reduction.itersdetermines the number of iterations; more iterations generally gives results more different from PCA.The resulting reducer can be called on a scanpy objectadata, which adds information in place. Simply runreducer(adata)Dimensionality reductions are stored inadata.obsm[key_added]. Ifkeep_scores=Truein the reducer constructor, the information scores of each gene in each cell are stored inadata.layers[key_added]. Finally, then_neighbors-nearest neighbor graph in the sca representation under the specified metric is stored in `adata.uns[key_added]'.Batch correctionSCA implements batch correction via selection of genes that have high within-batch information scores. The procedure is implemented  in thesca.integratesubmodule bycorrectandcorrect_scanpy. The former takes a list of matrices from each batch, whereas the latter takes an AnnData object with a column indicating batch in.obs. They return tuples containing the corrected data, and the list of features retained.