Skip to content

Clustering Pipeline

Groups immune receptor sequences into clusters across a whole cohort. It runs in two stages: first it pools every subject’s sequences and collapses near-identical ones into sub-graphs, then it builds a hierarchical tree over those sub-graphs to merge related ones into final clusters — so you can see which sequence groups are shared across people.

Web app slug: clustering-pipeline


Use this pipeline when you have a multi-subject cohort in AIRR format and want to find sequence clusters that recur across subjects


Clustering happens at two levels of granularity, both over the pooled sequences of the entire cohort:

Stage 1 — tight grouping Stage 2 — loose grouping
────────────────────────────── ──────────────────────────────
ALL subjects' sequences pooled → distances between sub-graphs
into one similarity graph; near- computed with the chosen metric,
identical sequences (sid + cov) agglomerated into a tree, then
become connected "sub-graphs" cut at height_cutoff → clusters
(≈ clonal families) (≈ shared specificity groups)
  1. Validate & ingest — the cohort sheet and every referenced AIRR file are validated up front (before any heavy compute).

  2. Stage 1 — Sub-graph (subG) clustering: all subjects’ paratope sequences are pooled into a single similarity graph. Two sequences are linked when they clear both the sequence-identity (sid) and coverage (cov) thresholds, computed position-by-position over the alignment. The connected components of that graph are the sub-graphs. Because the default thresholds are high (sid 0.9 / cov 0.95), a sub-graph is essentially a clonal family. The Sub-graph Method selects how sub-graphs are formed: gsc (connected components of the similarity graph, the default), clonotype (exact-clonotype grouping, no similarity graph), or louvain (community detection).

  3. Stage 2 — Hierarchical clustering of sub-graphs A distance is computed between sub-graphs using the chosen metrics, agglomerated with the chosen linkage method , and the resulting dendrogram is cut at height_cutoff to produce the final flat clusters. Because everything was pooled in Stage 1, a single cluster can contain sequences contributed by many subjects — that is what makes a cluster “public.”

  4. Stage 2b — Map clusters back Cluster membership (stored as global sequence indices) is joined back to subjects and sequences, yielding the key cohort-level table: which subjects populate which cluster.

The distance metric controls what “similar” means when building the cohort tree:

  • Identity-basedsid, sid_cov, hamming, hamming_norm: fast, count identical/mismatched aligned positions (the _norm variants divide by alignment length).
  • Substitution-awareblosum_ave, blosum_norm, blosum_ave_norm, blosum_dist, blosum_dist_centrality, blosum_RPD: score amino-acid similarity with BLOSUM62 so conservative substitutions cost less than disruptive ones — better for grouping functionally related sequences rather than just literal-identical ones.
  • TCR-specializedtcrdist: a position-weighted, capped BLOSUM62-based distance (the TCRdist metric).

blosum_RPD is a reciprocal BLOSUM62 distance and additionally requires the RPD_method parameter (an integer 1–4, selecting among alternative distance-decay formulas); setting RPD_method with any other metric is rejected at validation time.

These run alongside the main path and upload their own outputs — if one fails it surfaces as a DAG failure (so you’re alerted) but it does not block the main results.zip:

  • Threshold diagnostics (run_threshold_diagnostics) — plots the pairwise sid/cov distributions from Stage 1 so you can pick sensible thresholds.
  • HTML report (generate_html_report) — a self-contained interactive report (cluster network, CLR/norm-transformed abundance charts, optional Wilcoxon filtering between two arms). Uploaded separately as report.html, not included in results.zip.

Navigate to Dashboard → Clustering Pipeline → New Job.

FieldDescription
Job nameA label for this run
Input bundle (zip)A zip containing the cohort sheet plus one AIRR TSV per subject

The cohort sheet (default filename cohort.tsv, set via Cohort Sheet Filename) needs at minimum a subject column and an airr_file column; any extra metadata columns pass through. If no cohort sheet is found in the bundle, a minimal one is auto-generated from the discovered *.tsv files (one subject per file). Each referenced AIRR TSV must contain sequence_id, v_call, j_call, and sequence_aa (or the alternative set cell_id, v_gene, j_gene, sequence_aa). airr_file paths resolve against the sheet’s own directory inside the bundle and must point at a plain TSV present there — remote s3:// URIs and zips fail validation. Full contract: Cohort TSV.

This pipeline supports input bundle preflight — the web app can check the bundle against the requirements above in your browser, before it uploads, and flag any AIRR file that would be rejected or quietly dropped.

Stage 1 — sub-graph clustering

FieldDefaultDescription
Receptor chainTRBOne of IGH, IGL, IGK, TRB, TRA
Specieshumanhuman, mouse, or none (affects germline V/J calls)
Sequence identity (sid)0.9Identity cutoff for pairwise similarity, 0 < sid ≤ 1. Ignored when auto-tune is on
Coverage (cov)0.95Alignment coverage cutoff, 0 < cov ≤ 1. Ignored when auto-tune is on
Clustering methodgscSub-graph algorithm: gsc, louvain, or clonotype
Minimum clones1Skip AIRR files with fewer clones than this
Keep singletonsfalseRetain sequences that fall in no sub-graph
CPU cores0Threads for the pairwise similarity computation; 0 uses all available cores
Auto-tune sid/covfalseDetect thresholds from the data (valley search over a random pair sample) instead of using the fixed values
Auto-tune sample size100000Random pairs sampled for valley detection. Only used when auto-tune is on

Stage 2 — hierarchical clustering

FieldDefaultDescription
Linkage methodaveragesingle, complete, average, weighted, centroid, median, or ward
Distance metricsid_covSee Choosing a Stage 2 metric for the full list
Height cutoff0.1Tree-cut height (> 0); units depend on the chosen metric
RPD methodRequired only when metric is blosum_RPD (integer 1–4); must be unset otherwise
fastcluster backendtrueFaster linkage computation
Use sparse linkage backendfalseCluster very large sub-graphs that the default path cannot handle. Changes results — see Sparse linkage
Enable S1 lookup tablefalseNo effect. Every run already takes the lookup-table path, so this flag is accepted and ignored. Kept only so existing presets keep loading

By default Stage 2 enumerates the distance between every pair of members in a sub-graph. That is exact, but the work grows with the square of the sub-graph size, and a sufficiently large sub-graph simply will not fit.

Use sparse linkage backend clusters from the edge list Stage 1 already produced instead, treating any pair that Stage 1 never recorded as maximally distant. This is what lets a sub-graph of a few hundred thousand members complete at all.

It applies only to metrics sid and sid_cov combined with linkage methods single, complete, average, or weighted. Any other combination silently falls back to the exact path, so the flag is safe to leave set on a run where it does not apply — but check your run parameters if you expected it to take effect.

Reports & lifecycle

FieldDefaultDescription
Run threshold diagnosticsfalsePlot sid/cov distributions (side branch)
Generate HTML reportfalseEmit the interactive report.html (side branch, supports two-arm contrasts)
Cleanup temporary filestrueRemove the run’s temp directory after upload

HTML report contents — all ignored unless Generate HTML report is on

FieldDefaultDescription
Positive armcondition value naming the positive arm of the primary contrast (e.g. the responder label)
Negative armcondition value naming the negative arm
Serology positive / negative armOptional second contrast, layered on top of the primary one
Count metricUMIsCount column driving the bar and heatmap panels: UMIs, Reads, or Clones (Clones weights every clonotype equally)
Transformclrclr (centered log-ratio, compositional) or norm (relative abundance)
Top-N clusters in network25How many clusters the membership network view draws
Patient sample key / Healthy-control sample keySubstrings identifying the two arms of the Wilcoxon differential-abundance filter
Wilcoxon confidence0Confidence threshold for that filter — the p-value cutoff is 1 − conf. Requires both sample keys; 0 disables filtering
Reference sample keySubstring picking the reference samples for the CLR scatter panels
Pre-transform cluster filter0Drop clusters seen in fewer than N subjects (integer) or fewer than f × n_subjects (fraction 0 < f < 1), before transforming
Post-transform cluster filter0Same, applied after the transform
Dataset label / GSC labelStrings shown in the report title. Left unset, both are derived automatically

results.zip (under the run’s output prefix) is the complete clustering output tree, not a curated subset — it also carries the intermediate airr/ and db/ directories, the stage-1 sub-graph reports, and a logs/ directory. The files you will actually reach for:

FileDescription
cluster_list.tsvOne row per cluster — size, subject count, diversity, BLOSUM/Hamming means, condition splits, members
cluster_index.tsvFlat expansion of cluster membership: one row per member (cluster_id, Rep_idx, Mem_idx)
subject_cluster_map.tsvOne row per sequence, joining cluster membership back to subjects and AIRR fields
lngs_trees.tsvThe hierarchical tree(s) produced by Stage 2
config.jsonStage-1 sentinel with the resolved run config (including the real sid/cov when auto-tuned)
info_hcluster.txtRun metadata (chain, species, resolved parameters, subject counts)

Column-level schemas for the three cluster tables: Clustering data formats.

Uploaded separately to the same run prefix (not inside results.zip):

FileDescription
report.htmlInteractive cluster report — only when Generate HTML report is enabled
threshold_plots/sid/cov diagnostic plots — only when Run threshold diagnostics is enabled

What does the diversity column in cluster_list.tsv mean, and how is it computed?

Section titled “What does the diversity column in cluster_list.tsv mean, and how is it computed?”

It scores how many distinct sequences a cluster holds — not how far apart they are. The metric is the Gini–Simpson index (Simpson’s index of diversity, 1 − D):

diversity = 1 − Σ pᵢ²

where pᵢ is the frequency of the i-th distinct member sequence within the cluster. Equivalently: the probability that two members drawn at random from the cluster are different sequences.

How to read a value:

ValueMeaning
0Every member is the same sequence. Also the value reported for singleton clusters (size = 1).
1 − 1/sizeEvery member is unique — the maximum attainable for a cluster of that size (e.g. 0.923 at size = 13). Most clusters land exactly here.
Between the twoSome sequence occurs in more than one copy — typically the same pseudo-sequence recovered from several subjects.

Details worth knowing:

  • Not Shannon entropy. Normalized Shannon entropy and the inverse-Simpson (Hill D₂) form were both evaluated; the pipeline ships the Gini–Simpson form.
  • Identity classes only. Two members differing at one position count as “different” exactly as much as two differing at twenty. For how far apart members are, use the companion columns: ave_blosum (mean pairwise BLOSUM62 score — higher means more similar) and ave_hamming (mean pairwise Hamming distance over the alignment — higher means more different).
  • Computed on the aligned pseudo-sequence, the same IMGT-numbered representation used for clustering, gap characters included. Two sequences with identical amino acids but different gap placement therefore count as distinct.
  • One count per sequence row. Frequencies are not weighted by duplicate_count or consensus_count.

diversity is a cluster-level column: it appears in cluster_list.tsv only, not in the per-sequence subject_cluster_map.tsv.


Empty or tiny cluster list Stage 1 sid/cov may be too strict, so few sequences connect into sub-graphs. Lower them (e.g. sid toward 0.8) or enable Auto-tune. If Stage 2 produces a tree but no flat clusters, your height_cutoff may be cutting above every merge — lower it.

metrics='blosum_RPD' but the run fails validation blosum_RPD requires RPD_method set to one of 14. Conversely, leaving RPD_method set while choosing any other metric is also rejected — clear it.

Cohort sheet rejected The sheet must have subject and airr_file columns, unique non-empty subjects, and every airr_file must resolve on disk with the required AIRR columns present. The validation error names the exact missing column or unreadable file.

Stage 1 slow for large cohorts Pairwise similarity scales steeply with sequences per subject. Use Minimum clones to drop tiny repertoires, set CPU cores to 0 (all cores), or pre-filter your AIRR files before upload.

The HTML report / diagnostics failed but I still got results.zip That’s by design — those side branches upload independently and only fail the DAG to alert you; they never block the main clustering output.

v1.41.2