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.2.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.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scsampler-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 02ce808d051ddd33bfea193df9fca1f8254ae33b3ae1242627343b17eadc90ee
MD5 8a685539e5cafabd726c251392d358a5
BLAKE2b-256 576bcc964f96bcb4733df006b560ab95253ed1e8afa04b72b71d54ccf2006c0a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scsampler-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b72607b7b99b4300dbc64e31c34cee1940c1f5f5262e83ba9912db948bf7d76
MD5 e9475e26e031b04411974309ceb13dab
BLAKE2b-256 5ea03af5d6b273cce4f5e3f378dd2ce6d897ff218c5d721273efa97d98bf34a3

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