Claude (Anthropic) develops, tests and pushes all code in this repository, and keeps it up to date as its dependencies change.
spaclone
Spatial BCR and TCR analysis, from raw tables to biology, with every position checked against random placement
Each figure below is the spaclone function named in its header, on an AIR-SPACE mouse lymph node (public, GEO GSE286452) and, as a showcase, the StereoIR mouse spleen (Stereo-seq, BGI; data not yet public), drawn by make_homepage.py.
Every other figure, with the code that draws it, is in the tutorials.
Related tools
Spatial immune-repertoire analysis is young. The closest public work (October 2026):
- Stereo-XCR-seq analysis code (Zhan et al., Nat Commun 2026, doi): Stereo-seq BCR maps, a Gi* SHM hotspot map and per-cell class switching.
- AIR-SPACE (Jiang et al., PNAS 2026, doi): bead-level BCR maps, regional SHM and IgPhyML trees with tips on beads.
- Spatial VDJ (Engblom et al., Science 2023): Visium BCR/TCR, isotype regions, putative class-switch events and trees split by follicle.
- BAITS (2026): a Python package for per-location QC, clone families and B-cell aggregates.
- McEnany, Good & Cvijović (bioRxiv 2025, doi): lineage trees with follicle-labelled tips and a migration model.
- Platypus had a Visium spatial module in 2022 (isotype and SHM on the image, lineage arrows); it was removed in version 3.6.0.
- Single-cell building blocks: sciCSR and Dowser (class-switch models and tests on trees), scirpy, Dandelion and Immcantation.
spaclone adds the following, and the public record shows none of it elsewhere:
- location-trust tests against depth-matched random placement;
- CSR and SHM hotspots with family-wise thresholds and clone-level nulls, and tested overlap regions with their transcriptome identity;
- class-switch potential, transitions and fluxes on spatial graphs;
- Threadfin clone states on tissue;
- one package across sequencing technologies.
Get started
pip install spaclone # core: reading, QC, trust tests, BCR and TCR analysis, plots
pip install "spaclone[datasets]" # + the downloader of the public example data used below
pip install "spaclone[full]" # + every package in "Integrates" below (the downloader included)
import spaclone as spc
# a public AIR-SPACE lymph node, day 21 (GEO GSE286452): 78 MB, downloaded once and checked by sha256
data = spc.read(*spc.datasets.airspace("D21")) # your own section: spc.read("section.h5ad", "airr.tsv")
report = spc.run(data)
print(report.verdict)
Cell-type columns and own types are detected when unambiguous (cell_type_key="auto", own_types="auto") and
otherwise named in the report. From the shell, spaclone run writes the same report
(command line).
spc.read recognises both files from their contents: the transcriptome (h5ad from scanpy, squidpy or Stereopy, Space
Ranger Visium SD / HD, Stereo-seq GEF / GEM, Xenium, Slide-seq, SpatialData) and the receptor table (AIRR from Cell
Ranger, TRUST4, IgBLAST / Change-O, MiXCR, scirpy or Dandelion; 10x contigs; MiXCR 3 / 4; TRUST4 reports; Change-O;
Dandelion; scirpy). Other tables (immunoSEQ, BD, Parse, VDJtools, immunarch …) read with a column mapping;
spc.io.sniff(path) shows what was detected. spc.run filters the records and runs every location-trust test the
data allow:
| You get back | |
|---|---|
report.verdict |
Can clone positions be trusted? With report.verdict_molecule and report.verdict_clone, one per level |
report.tests() |
One row per test and locus: observed, chance, ratio, p, BH q, verdict |
report.plot() |
The one-page trust report |
report.methods() |
A methods paragraph with every parameter and reference |
Then the biology. Class switching and hypermutation, on the same AIR-SPACE node:
hot = spc.bcr.hotspot_workflow(data) # CSR and SHM hotspots, their regions, GEX identity
spc.pl.hotspot_atlas(hot) # the flagship figure
spc.pl.csr_map(hot) # isotypes and class switches along the IgH locus
Lineage trees need each record's contig and its V alignment (the AIRR fields sequence, v_sequence_alignment,
v_germline_alignment and v_germline_start, as IgBLAST (-outfmt 19) and TRUST4 write them). Clone tables without
sequences, such as AIR-SPACE's, cannot give trees, and bcr.lineage_workflow says so. A synthetic section has them,
with lineages planted to check the trees against:
# synthetic section (simulated, no download): contigs with V alignments and planted B-cell lineages
syn = spc.datasets.synthetic_example(sequences=True)
trees = spc.bcr.lineage_workflow(syn) # lineage trees with every tip on the section
spc.pl.lineage_gallery(trees, "lineages") # one figure per tree and an index table
spc.sim.score_lineages(trees, syn) # each tree against the planted one
What it does
| Read anything Spatial transcriptome and receptor files, detected automatically |
Trust first Molecule- and clone-level tests against random placement that keeps local Ig RNA depth |
Class switching and hypermutation Switched- and mutated-share maps with family-wise hotspots |
| Hotspot atlas Where CSR and SHM hotspots overlap, and the transcriptome identity of each region |
CSR dynamics sciCSR's CSR potential, transition models and fluxes, on tissue |
Lineages Germline-rooted trees with every tip on the section |
| Repertoire in space Expansion, diversity, overlap, networks and public clonotypes by region |
Where clones gather Calibrated clonal scans, niche profiles and clone states |
Your own test Any statistic against random placement with nulls.placebo |
Every statistic reproduces the numbers of the analyses it came from (AIR-SPACE and Stereo-XCR-seq LUAD, public; StereoIR, BGI data not yet public): of 4,001 recorded values, 3,302 are equal, 310 agree within Monte-Carlo tolerance, 17 have no archived value, 7 differ for documented reasons and 365 are new or informational (validation).
Integrates
| Package | What spaclone does with it, spatially | Install |
|---|---|---|
| scanpy · anndata | Transcriptome workflow on spots: QC, clusters, regions (germinal centres, ASC foci, T zones), DE with regions as replicates; one container for spots and receptor records | core |
| squidpy | Neighbourhood enrichment, co-occurrence and spatial autocorrelation of receptor-derived labels (ext.squidpy) |
[squidpy] |
| scirpy | Clonotypes, expansion, diversity, overlap and V(D)J usage per spatial unit, mapped back to tissue (ext.scirpy) |
[scirpy] |
| SpatialData | SpatialData in and out: records as points, spots as shapes (io.to_spatialdata) |
[spatialdata] |
| Dandelion | Clone calls written back to records and loci, and compared with spaclone's (ext.dandelion) |
[dandelion] |
| Immcantation: IgBLAST · Change-O · SHazaM · dowser · IgPhyML | Germlines, mutation counts and lineage trees that keep their tissue positions (ext.immcantation) |
[immcantation] + IgBLAST, R |
| sciCSR | CSR potential, SHM score, transition models and transition-path fluxes on tissue (bcr.csr_potential, tl.tpt_flux, pl.csr_flow), and a bridge to the R package (ext.scicsr; 103 of 103 parity checks match sciCSR 0.3.5) |
[scicsr] |
| CellRank · deeptime | Transition kernels on spatial neighbour graphs (tl.transition_model) |
[scicsr] |
| Threadfin | Clone-state landscapes on spots and loci, with calibrated spatial readouts (ext.threadfin) |
[threadfin] |
| OLGA | Generation probabilities of public TCR clonotypes (tl.public) |
[tcr] |
spc.check_install() shows which of these work on your machine and the command that enables each missing one.
Tutorials
| Quick start | One call on data with and without real positions |
| Is my data spatial? | AIR-SPACE against Stereo-XCR-seq LUAD; a published QC metric under placebo |
| Class switching and mutation | CSR maps and hotspots, SHM, lineages in germinal centres |
| Transcriptome and repertoire | GEX workflow, regions, DE, diversity, networks, niches |
| Your own placebo | Test any statistic against random placement |
| Hotspots and lineages | Showcase: the flagship on a Stereo-seq spleen (trust report, CSR/SHM hotspot atlas, lineage trees, sciCSR flow, Threadfin states). BGI data, not yet public: the notebook cannot be re-run until they are released; tutorial 08 runs the same functions on data anyone can get |
| AIR-SPACE time course | Every analysis on all six public AIR-SPACE lymph nodes, Mock to day 21, with the package defaults and one table of the key numbers |
| Lineages, zooms and clone states | Lineage trees on a synthetic section with planted lineages, checked against the truth; a region zoom, the sciCSR stationary distribution and Threadfin clone-axis profiles and spanning clones on a public AIR-SPACE node |
Running them needs Jupyter and the extras each notebook names in its first cell (pip install "spaclone[full]" jupyter covers all).
Reading data, the command line, concepts and the full API: docs.
How to cite
Please cite spaclone as in CITATION.cff (GitHub: "Cite this repository") and also cite the packages you use through it; docs/citing.md lists which function uses which package. spaclone is MIT-licensed; optional packages and programs keep their own licences (install).
Credits
Chen Satoshi (@Reynold4k) and Claude Opus 5.5 (Anthropic)
Licence
MIT, see LICENSE.
Metadata
Release files for spaclone 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spaclone-1.0.2.tar.gz | 1.4 MB | With provenance | Details for spaclone-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spaclone-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for spaclone-1.0.2-py3-none-any.whl |
Total release size: 2.4 MB
Release files / spaclone-1.0.2.tar.gz
| Download URL | spaclone-1.0.2.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ae5ab8482f39ccab899010db4c90ae517bb481a372013bcd74440b4daccf7e5
|
|
BLAKE2b-256 checksum How to use checksums |
7c06fee74a2e6fbc59a069b9aaa68829a892acd2dc576cfb8848b1d99996e4b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / spaclone-1.0.2-py3-none-any.whl
| Download URL | spaclone-1.0.2-py3-none-any.whl |
|---|---|
| Size | 940.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0204d8810610a75baa524d731b0a0391edaf1f0073b6d93e3d6b83d6fea81e93
|
|
BLAKE2b-256 checksum How to use checksums |
a64a555a2496e0b1fc874d10a9a1688d518835e8631d53f00cb0c7a03c9ee064
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for spaclone 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for spaclone-1.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.