Skip to main content

Python implementation of the simspec algorithm

Project description

pysimspec

Python implementation of simspec (for RSS/CSS). The paper about the method detailed is published in Genome Biology in 2020. The original R implementation is available at GitHub.

Installation

First, clone the codebase to your local environment

git clone https://github.com/quadbio/pysimspec.git

Next, install the package with pip

cd pysimspec
pip install .

Just to mention, this project uses uv for fast Python package management.

uv venv
uv pip install -e '.[dev]'

Quick example

import scanpy as sc
import anndata
from pysimspec import Simspec, set_log_level, load

# Set up logging
set_log_level("INFO")

# Load and concatenate data
adata_DS1 = sc.read_h5ad('DS1_raw.h5ad')
adata_DS2 = sc.read_h5ad('DS2_raw.h5ad')
adata_DS1.obs['batch'] = 'DS1'
adata_DS2.obs['batch'] = 'DS2'
adata = anndata.concat([adata_DS1, adata_DS2], join='inner', keys=['DS1','DS2'], index_unique="_")

# Data preprocessing
adata.layers['counts'] = adata.X.copy()
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata, flavor='seurat_v3', layer='counts', n_top_genes=3000, batch_key='batch')
sc.pp.pca(adata, n_comps=20, mask_var='highly_variable')

# Run CSS
simspec = Simspec()
simspec.compute_references(adata, batch = 'batch', use_rep = 'X_pca')
simspec.compute_simspec(adata)
simspec.compute_PCA(n_pcs = 10)
adata.obsm['X_css'] = simspec.get_result()
adata.obsm['X_csspca'] = simspec.get_transformed_result()

# Use CSS representation for followup analysis
sc.pp.neighbors(adata, use_rep='X_css')
sc.tl.umap(adata)
sc.pl.umap(adata, color='batch')

# Save the Simspec object
simspec.save('simspec.pkl')

# Calculate projected CSS representation for the new data
adata_DS3 = sc.read_h5ad('DS3_raw.h5ad')
adata_DS3.layers['counts'] = adata_DS3.X.copy()
sc.pp.normalize_total(adata_DS3, target_sum=1e4)
sc.pp.log1p(adata_DS3)

simspec = load('simspec.pkl') # load the saved Simspec object
simspec.compute_simspec(adata_DS3)
adata_DS3.obsm['X_css_proj'] = simspec.get_result()
adata_DS3.obsm['X_csspca_proj'] = simspec.get_transformed_result()

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysimspec-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysimspec-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pysimspec-0.1.0.tar.gz.

File metadata

  • Download URL: pysimspec-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pysimspec-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0740b99fae0b23223128646c4bf0896418e4b0d1b8831accc587b10e0697cd9d
MD5 92077d92c44a51bb60ffdde4d018516f
BLAKE2b-256 58090d4fe674772ccb3f0976f9e0444c9ac1b3f4da824036943e9e6bda9acdae

See more details on using hashes here.

File details

Details for the file pysimspec-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pysimspec-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pysimspec-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3408cf9f2c27c4264ec3640f0356137136f8c83e91cd953dfeafca1f017108e2
MD5 9887c0797a3eca002e20663d6a639551
BLAKE2b-256 4d829bd9f73f154e142210d2c933107aea5bf7d285b9bc8e6da4a4a276181c3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page