Skip to main content

A package for fast diversity-preserving subsampling of large-scale single-cell transcriptomic data

Project description

scSampler

Overview

scSampler is a Python pacakge for fast diversity-preserving subsampling of large-scale single-cell transcriptomic data.

Installation

Please install it from PyPI:

pip install scsampler

Quick start

First we load all modules.

import numpy as np
import pandas as pd
import scanpy as sc
from time import time
from scsampler import scsampler
sc.settings.verbosity = 3             # verbosity: errors (0), warnings (1), info (2), hints (3)
sc.logging.print_header()
sc.settings.set_figure_params(dpi=80, facecolor='white')

Read in data

The example data can be downloaded from https://doi.org/10.5281/zenodo.5811787 in the anndata format by scanpy. Here we use the ~68'000 PBMC cells. Please modify the path as your own path.

adata = sc.read_h5ad('/home/dongyuan/scSampler/data/final_h5ad/pbmc68k.h5ad')

anndata as input

Subsample 10% cells and return a new anndata. The space is top PCs.

adata_sub = scsampler(adata, fraction = 0.1, copy = True) 

If you want to speed it up, you can use the random_split. It will lead to slightly less optimal result, of course.

start = time()
adata_sub = scsampler(adata, fraction = 0.1, obsm = 'X_pca', copy = True, random_split = 16)
end = time()
print(end - start)

matrix as input

You can also use the numpy.ndarray as the input.

mat = adata.obsm['X_pca']
print(type(mat))
res = scsampler(mat, fraction = 0.1, copy = True, random_split = 16)
subsample_index = res[1]
subsample_mat = res[0]

Contact

Any questions or suggestions on scSampler are welcomed! If you have any questions, please report it on issues or contact Dongyuan (dongyuansong@ucla.edu).

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

scsampler-1.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

scsampler-1.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file scsampler-1.0.1.tar.gz.

File metadata

  • Download URL: scsampler-1.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/30.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.61.0 importlib-metadata/4.8.2 keyring/18.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for scsampler-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d1114eab2c3596dfee93a2570cb1d6c2af9db6dacb98051cf8395ef06367ef0d
MD5 dc59f93d8066ca5795b885caa9e2d21c
BLAKE2b-256 ba83861678d1b88fc1e713242ce39e1423eee4c7352c5e93981e7c2d19978172

See more details on using hashes here.

File details

Details for the file scsampler-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: scsampler-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/30.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.61.0 importlib-metadata/4.8.2 keyring/18.0.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for scsampler-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e514e0b58b6df2066dc56c5e935b1c72549a45a3936c436098f4463cea45bbd
MD5 64f86250d90ae98091429ff19f7b34f2
BLAKE2b-256 ac6664e36c412bbc835e0468f6c186a9d6edfe45e729cfc50546f41a6222fd59

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