sctk Architecture#
Goals#
Keep the package importable in a normal Python single-cell environment.
Isolate R/Bioconductor tools behind an explicit backend.
Use stable, shared argument names across preprocessing, tools, and plotting.
Prefer AnnData/scverse conventions over custom side effects.
Make each module small enough to test and replace independently.
Package Layout#
src/sctk/
pp/ preprocessing: QC, normalization, clustering, integration
tl/ analysis tools: pseudobulk, enrichment, expression summaries
pl/ plotting helpers; no heavy imports at package import time
r/ optional R bridge and R-backed methods
_core/ shared validation, matrix access, optional dependency helpers
API Conventions#
Use
adataforAnnData.Use
layer=Noneto mean.X; use"counts"for raw-count layers.Use
groupbyfor generic observation grouping.Use
sample_key,condition_key,batch_key, andcell_type_keyfor common biological metadata.Use
key_addedfor new.obs,.var,.obsm,.obsp, or.unsfields.Use
copy=Falsefor functions that can either mutate or return a copy.Never overwrite
.Xtemporarily when alayerargument can be passed through.
Optional Dependencies#
Optional packages are imported inside the functions that need them. The package
root should not import rpy2, decoupler, pydeseq2, matplotlib, or
Bioconductor-backed code. This keeps environment problems local and debuggable.
Recommended extras:
sctk[enrichment]: GSEApy enrichment plus decoupler-backed resourcessctk[r]: R bridge via rpy2/anndata2risctk[de]: Python DESeq2 through pydeseq2sctk[plot]: plotting helperssctk[integration]: optional Harmony and scVI integration backendssctk[ccc]: LIANA consensus cell-cell communication
Installation is intentionally simple:
environment.yml: preferred conda/mamba environment for Python + R + Jupyterrequirements.txt: pip fallback for Python-only installsrequirements-r.R: fallback R/Bioconductor install script outside condarequirements-dev.txt: pip fallback for tests and packaging tools
Migration Order#
Move generic utilities into
_core.Rebuild
ppfunctions with consistent layer and key handling.Replace old decoupler calls with
dc.mt.*anddc.pp.*.Move R-backed methods into
sctk.rand fail with actionable errors when R packages are missing.Port plotting after data-producing functions stabilize.
Extract non-single-cell modules, especially survival analysis, to a separate package or notebook utilities folder.