Skip to content

Gene-Expression Signatures

TCRsift defines gene-expression signatures across two modules:

  • tcrsift.signatures (T_CELL_SIGNATURES): compact unsigned marker panels for per-cell and per-clone state scoring, plus cell-type registries for annotate_cells.
  • tcrsift.signature_methods (SIGNATURES and NEOANTIGEN_SIGNATURES): signed z-score panels and published neoantigen-reactivity gene sets used by tcrsift prioritize and score_by_name.

Signature scores quantify transcriptional state rather than epitope specificity, and depend on tissue context: AIM and AcuteActivation reflect recent stimulation in culture, whereas TumorReactive and exhaustion panels reflect chronic antigen exposure in fresh TIL.

Compact functional programs (T_CELL_SIGNATURES)

Human signatures follow HGNC nomenclature (T_CELL_SIGNATURES); mouse counterparts (MOUSE_T_CELL_SIGNATURES, retrieved via t_cell_signatures_for_species("mouse")) use MGI orthologs (dropping GNLY and CXCL13, which lack 1:1 murine T-cell orthologs).

Name Genes Intended readout
effector IFNG, GZMB, PRF1, GNLY, NKG7 Cytotoxic effector differentiation
activation Deprecated alias of effector Retained for backward compatibility
naive_stem TCF7, LEF1, CCR7, SELL, IL7R, CD27, CD28 Naive and stem-like memory state
antigen_response TNFRSF9, MKI67 Recent activation and proliferation
aim TNFRSF9, TNFRSF4, IL2RA, MKI67 Activation-induced-marker response in stimulated culture
cytolytic PRF1, GZMB Minimal perforin/granzyme B readout
exhaustion PDCD1, TOX, LAG3, HAVCR2, TIGIT Chronic stimulation / exhaustion in TIL
tumor_reactive CXCL13, ENTPD1 Minimal two-gene tumor-reactive TIL readout
expansion_core MKI67, TNFRSF9, EGR2, IFNG, CXCL13, HAVCR2 Cross-compartment expansion-associated markers

MARKER_PANEL_HGNC is the combined gene extraction list used by til-select rather than a standalone biological signature.

Signatures scored by tcrsift prioritize (SIGNATURES)

tcrsift prioritize selects panels by these names (--signatures, --context), scoring each cell as the mean of within-sample z-scored positive genes minus negative genes:

Name Up genes Down genes Provenance
Differentiated IFNG, GZMB, PRF1, GNLY, NKG7 TCF7, LEF1, CCR7, SELL Canonical effector minus naive/stem markers, fixed on the two-donor MART-1 pilot (reproducibility map)
AntigenExperienced IFNG, GZMB, PRF1, GNLY, NKG7 — Positive arm of Differentiated
Cytolytic PRF1, GZMB — Perforin and granzyme B (Caushi 2021, Krishna 2020, Hanada 2022)
AcuteActivation TNFRSF9, MKI67 — 4-1BB and Ki-67, separated from AntigenExperienced after the MART-1 pilot
Proliferation MKI67 — Ki-67 alone
AIM TNFRSF9, TNFRSF4 — 4-1BB and OX40 mRNAs corresponding to surface AIM sorting
TumorReactive CXCL13, ENTPD1, PDCD1, LAG3, HAVCR2, TIGIT, TOX, CTLA4, ITGAE — CD39 and CD103 (Simoni 2018, Duhen 2018) plus CXCL13 and six TIL exhaustion markers

Broad variants and CirculatingMemory are also registered in SIGNATURES. Note that nine-gene TumorReactive above is broader than the two-gene tumor_reactive entry in T_CELL_SIGNATURES. Empirical AUROCs across five public tumor datasets are reported in Benchmark on public TIL data.

Published neoantigen-reactivity registry (NEOANTIGEN_SIGNATURES)

score_by_name dispatches each signature using its registered scoring method:

Name Reference TCRsift scoring rule
MANAscore Zeng et al., Nat Commun 2025 (PMID 39900903) Unweighted three-gene signed-z proxy: (z(CXCL13) + z(ENTPD1) - z(IL7R)) / sqrt(3). Does not run the paper's fitted random-forest/linear ensemble.
NeoTCR8 Lowery et al., Science 2022 (PMID 35113651) Published 243-gene CD8 set via Scanpy score_genes
NeoTCR4 Lowery et al., Science 2022 (PMID 35113651) Published 40-gene CD4 set via Scanpy score_genes
NeoTCR_PBL Yossef et al., Cancer Cell 2023 (PMID 38039963) Published 151-gene circulating CD8 set via Scanpy score_genes (blood-tumor preset)

Scoring notes for NeoTCR4, NeoTCR8, and NeoTCR_PBL:

  • AnnData inputs: pass an AnnData whose .X contains the full log1p(CP10K)-normalized transcriptome with log1p=False (score_by_name always reads .X rather than .raw, and does not apply a second logarithm). Scores are Scanpy score_genes module scores (signature mean minus expression-matched control-gene mean), not single-cell GSEA; numeric scGSEA cutoffs from the original papers do not transfer.
  • DataFrame inputs: because a subset DataFrame lacks the full gene universe needed for expression-matched control bins, score_by_name warns and falls back to mean per-gene z-scores (applying log1p first by default; pass log1p=False if values are already log-normalized).

Usage

Compact unsigned panels:

from tcrsift import compute_signature_scores_per_cell

compute_signature_scores_per_cell(adata)
print([col for col in adata.obs if col.startswith("signature_")])

Signed and published signatures:

import scanpy as sc
from tcrsift import score_by_name

sc.pp.normalize_total(adata, target_sum=10_000)
sc.pp.log1p(adata)

for name in ("MANAscore", "NeoTCR8", "NeoTCR4"):
    score_by_name(adata, name, log1p=False, key_added=f"signature_{name}")

In multi-sample cohorts, normalize and score within each sample before aggregating clonotypes so sample-wide baseline shifts do not dominate rankings; see Clone Prioritization.

Cell-type and state registries

Used by tcrsift.annotate_cells:

Registry constant Contents
CELL_TYPE_SIGNATURES / PBMC_CELL_TYPE_SIGNATURES Default blood/PBMC immune and basic stromal cell-type markers
SOLID_TUMOR_CELL_TYPE_SIGNATURES PBMC lineages plus solid-tissue stromal, neural, muscle, mesothelial, and osteoclast markers
T_STATE_SIGNATURES, B_STATE_SIGNATURES T-cell and B-cell functional sub-state markers
PBMC_CULTURE_TYPES Cell-type allow-list for Ficoll-isolated PBMC cultures

Malignant clusters are typed with tumor_override / MarkerCountOverride rather than a fixed signature in these registries.

signatures

Canonical T-cell and single-cell lineage gene-set signatures (human & mouse).

Single source of truth for the gene sets used across clone prioritization, TIL selection, per-sample scatter plots, and single-cell cluster annotation.

Gene symbols are stored uppercase to match :func:tcrsift.genes.adata_symbol_array uniformly across human HGNC (GZMB, CD8B) and mouse MGI (Gzmb → GZMB, Cd8b1 → CD8B1). Species-specific registries handle genes that lack 1:1 orthologs across species (for example, human GNLY, GZMH, FGFBP2, KLRF1, NCR3, FCN1, CD1C, LILRA4, FCGR3B have no mouse ortholog, and mouse NK cells express Ncr1/Klrb1c/Itga2/Klra* rather than NCAM1/KIR*).

EFFECTOR_GENES_HGNC module-attribute

EFFECTOR_GENES_HGNC: tuple[str, ...] = ('IFNG', 'GZMB', 'PRF1', 'GNLY', 'NKG7')

ACTIVATION_GENES_HGNC module-attribute

ACTIVATION_GENES_HGNC: tuple[str, ...] = EFFECTOR_GENES_HGNC

NAIVE_STEM_GENES_HGNC module-attribute

NAIVE_STEM_GENES_HGNC: tuple[str, ...] = ('TCF7', 'LEF1', 'CCR7', 'SELL', 'IL7R', 'CD27', 'CD28')

ANTIGEN_RESPONSE_GENES_HGNC module-attribute

ANTIGEN_RESPONSE_GENES_HGNC: tuple[str, ...] = ('TNFRSF9', 'MKI67')

AIM_GENES_HGNC module-attribute

AIM_GENES_HGNC: tuple[str, ...] = ('TNFRSF9', 'TNFRSF4', 'IL2RA', 'MKI67')

CYTOLYTIC_GENES_HGNC module-attribute

CYTOLYTIC_GENES_HGNC: tuple[str, ...] = ('PRF1', 'GZMB')

EXHAUSTION_GENES_HGNC module-attribute

EXHAUSTION_GENES_HGNC: tuple[str, ...] = ('PDCD1', 'TOX', 'LAG3', 'HAVCR2', 'TIGIT')

TUMOR_REACTIVE_GENES_HGNC module-attribute

TUMOR_REACTIVE_GENES_HGNC: tuple[str, ...] = ('CXCL13', 'ENTPD1')

EXPANSION_CORE_GENES_HGNC module-attribute

EXPANSION_CORE_GENES_HGNC: tuple[str, ...] = ('MKI67', 'TNFRSF9', 'EGR2', 'IFNG', 'CXCL13', 'HAVCR2')

MARKER_PANEL_HGNC module-attribute

MARKER_PANEL_HGNC: tuple[str, ...] = ('CD4', 'CD8A', 'CD8B', 'MKI67', 'TNFRSF9', 'TNFRSF4', 'IL2RA', 'TNFRSF18', 'NR4A1', 'NR4A2', 'EGR2', 'CTLA4', 'PRF1', 'GZMB', 'GZMK', 'NKG7', 'GNLY', 'IFNG', 'PDCD1', 'TOX', 'LAG3', 'HAVCR2', 'TIGIT', 'ENTPD1', 'CXCL13', 'ITGAE')

T_CELL_SIGNATURES module-attribute

T_CELL_SIGNATURES: dict[str, tuple[str, ...]] = {'effector': EFFECTOR_GENES_HGNC, 'activation': ACTIVATION_GENES_HGNC, 'naive_stem': NAIVE_STEM_GENES_HGNC, 'antigen_response': ANTIGEN_RESPONSE_GENES_HGNC, 'aim': AIM_GENES_HGNC, 'cytolytic': CYTOLYTIC_GENES_HGNC, 'exhaustion': EXHAUSTION_GENES_HGNC, 'tumor_reactive': TUMOR_REACTIVE_GENES_HGNC, 'expansion_core': EXPANSION_CORE_GENES_HGNC}

signature_methods

Gene-expression signatures as synthetic selection methods.

The selection language (:mod:tcrsift.selection) is method-agnostic — a "method" is just a value in the per-(clone, sample) table carrying a tier + frequency. A method need not be a physical sort: this module scores cells on a gene set, calls signature-positive cells, and emits them as a synthetic method so the rules can use a signature like a sort.

Signatures are signed (genes_up − genes_down, so loss-of-naive axes work). Canonical scoring (defaults): per gene, the z-score across cells of log(1 + TPM), then the mean of those z-scores across the signature (combine="mean" instead averages the values directly). Small "focal" and larger "broad" panels are offered per axis.

NOTE: a signature's meaning still depends on the sample source — e.g. TumorReactive (CD39/CD103/TOX) only reads "chronic in-situ antigen exposure" in fresh tissue TILs, not in PBMC culture. That caveat lives in each signature's description; it is documentation, not an enforced guard, so you can still score any signature on any data (and should, when exploring). Gene memberships are literature-backed defaults for tuning.

SIGNATURES module-attribute

SIGNATURES: dict[str, Signature] = {s.name: s for s in _INVARIANT_SIGNATURES + _COMPOSITE_SIGNATURES}

NEOANTIGEN_SIGNATURES module-attribute

NEOANTIGEN_SIGNATURES: dict[str, Signature] = {'MANAscore': Signature('MANAscore', MANASCORE_UP_HGNC, MANASCORE_DOWN_HGNC, panel='focal', units='log1p', method='weighted_z', citation='Zeng/Smith, Nat Commun 2025 (PMID 39900903)', description='Transparent signed-z proxy for MANAscore: (z(CXCL13)+z(ENTPD1)-z(IL7R))/sqrt(3) on log1p CP10K. The published model is a trained RF+linear ensemble with NO closed-form per-gene weights; only the gene directions (+CXCL13,+ENTPD1,-IL7R) and input units (log-normalized) are reproducible, and that is what this scores. The faithful pickled ensemble is deliberately NOT shipped (deserializing a third-party pickle is an arbitrary-code-execution risk).'), 'NeoTCR8': Signature('NeoTCR8', NEOTCR8_GENES_HGNC, panel='broad', units='log1p', method='geneset_enrichment', citation='Lowery/Rosenberg, Science 2022 (PMID 35113651)', description="243-gene CD8 neoantigen-reactive set (Table S10). An unweighted gene set scored here with Scanpy's expression-matched control subtraction. This is not the paper's scGSEA implementation and does not inherit its thresholds."), 'NeoTCR4': Signature('NeoTCR4', NEOTCR4_GENES_HGNC, panel='broad', units='log1p', method='geneset_enrichment', citation='Lowery/Rosenberg, Science 2022 (PMID 35113651)', description="40-gene CD4 neoantigen-reactive set (Table S10). An unweighted gene set scored here with Scanpy's expression-matched control subtraction, not the paper's scGSEA implementation."), 'NeoTCR_PBL': Signature('NeoTCR_PBL', NEOTCRPBL_GENES_HGNC, panel='broad', units='log1p', method='geneset_enrichment', citation='Yossef/Rosenberg, Cancer Cell 2023 (PMID 38039963)', description="151-gene signature of circulating (peripheral-blood) neoantigen-reactive CD8 T cells (cluster C9, avg_log2FC>=0.5; Table S2D). An unweighted gene set scored here with Scanpy's expression-matched control subtraction. Distinct from Lowery's TIL-derived NeoTCR8/4 — a separate blood-derived signature.")}

Signature dataclass

A named, optionally-signed gene signature.

genes_down subtracts (loss-of-naive etc.). panel is a "focal"/"broad" label for the small-vs-large variants. description carries the biological caveat (e.g. which sample source it's meaningful in) as prose.

units, method and citation (#309) record how a published signature is meant to be scored, so heterogeneous signatures (MANAscore-style signed-z proxies vs. unweighted control-subtracted gene sets) can live in one registry and be dispatched correctly by :func:score_by_name rather than all being treated as weighted sums:

  • units — the input space the score is defined on: "log1p" (log1p CP10K, the default), "cp10k", "scaled" or "ranks".
  • method — the scoring rule: "zscore" (mean of per-gene z-scores, the default and what :func:score_signature computes), "weighted_z" (signed-sum of per-gene z-scores / sqrt(n) — the transparent MANAscore proxy), or "geneset_enrichment" (Scanpy control-subtracted module score for published sets like NeoTCR4/8).
  • citation — the source paper (free text, incl. PMID).

Defaults keep every pre-existing signature a plain zscore / log1p signature, so this is backward compatible.

Source code in tcrsift/signature_methods.py
@dataclass(frozen=True)
class Signature:
    """A named, optionally-signed gene signature.

    ``genes_down`` subtracts (loss-of-naive etc.). ``panel`` is a
    "focal"/"broad" label for the small-vs-large variants. ``description``
    carries the biological caveat (e.g. which sample source it's meaningful
    in) as prose.

    ``units``, ``method`` and ``citation`` (#309) record how a *published*
    signature is meant to be scored, so heterogeneous signatures
    (MANAscore-style signed-z proxies vs. unweighted control-subtracted gene
    sets) can live in one registry and be dispatched correctly by
    :func:`score_by_name` rather than all being treated as weighted sums:

    - ``units`` — the input space the score is defined on: ``"log1p"``
      (log1p CP10K, the default), ``"cp10k"``, ``"scaled"`` or ``"ranks"``.
    - ``method`` — the scoring rule: ``"zscore"`` (mean of per-gene
      z-scores, the default and what :func:`score_signature` computes),
      ``"weighted_z"`` (signed-sum of per-gene z-scores / ``sqrt(n)`` — the
      transparent MANAscore proxy), or ``"geneset_enrichment"`` (Scanpy
      control-subtracted module score for published sets like NeoTCR4/8).
    - ``citation`` — the source paper (free text, incl. PMID).

    Defaults keep every pre-existing signature a plain ``zscore`` /
    ``log1p`` signature, so this is backward compatible.
    """

    name: str
    genes_up: tuple[str, ...]
    genes_down: tuple[str, ...] = ()
    panel: str = "focal"
    description: str = ""
    units: str = "log1p"
    method: str = "zscore"
    citation: str = ""

    @property
    def all_genes(self) -> tuple[str, ...]:
        return tuple(dict.fromkeys(self.genes_up + self.genes_down))

score_by_name

score_by_name(data, name, *, registry: dict[str, Signature] | None = None, log1p: bool | None = None, background: DataFrame | None = None, groups: Series | None = None, on_missing: str = 'warn', layer: str | None = None, key_added: str | None = None, species: str | None = None) -> pd.Series

Score a registered signature on cells, dispatched by its method (#309).

data is either an AnnData (per-cell scores from .X / layer, symbol resolution via the shared resolver) or a cells × genes symbol-keyed DataFrame. name is a registry key (case-insensitive) or a :class:Signature. Routing:

  • weighted_z → :func:score_weighted_z (MANAscore-style signed-z),
  • zscore / mean → :func:score_signature,
  • geneset_enrichment → scanpy score_genes on an AnnData (control-subtracted module score), or a mean-z proxy on a bare frame.

log1p defaults from the signature's units (applied for log1p/cp10k inputs, skipped for scaled/ranks); pass a bool to override. key_added (AnnData only) writes the score to adata.obs[key_added] in addition to returning it.

Source code in tcrsift/signature_methods.py
def score_by_name(
    data,
    name,
    *,
    registry: dict[str, Signature] | None = None,
    log1p: bool | None = None,
    background: pd.DataFrame | None = None,
    groups: pd.Series | None = None,
    on_missing: str = "warn",
    layer: str | None = None,
    key_added: str | None = None,
    species: str | None = None,
) -> pd.Series:
    """Score a registered signature on cells, dispatched by its ``method`` (#309).

    ``data`` is either an ``AnnData`` (per-cell scores from ``.X`` / ``layer``,
    symbol resolution via the shared resolver) or a cells × genes symbol-keyed
    ``DataFrame``. ``name`` is a registry key (case-insensitive) or a
    :class:`Signature`. Routing:

    - ``weighted_z`` → :func:`score_weighted_z` (MANAscore-style signed-z),
    - ``zscore`` / ``mean`` → :func:`score_signature`,
    - ``geneset_enrichment`` → scanpy ``score_genes`` on an AnnData
      (control-subtracted module score), or a mean-z proxy on a bare frame.

    ``log1p`` defaults from the signature's ``units`` (applied for
    ``log1p``/``cp10k`` inputs, skipped for ``scaled``/``ranks``); pass a bool
    to override. ``key_added`` (AnnData only) writes the score to
    ``adata.obs[key_added]`` in addition to returning it.
    """
    from .species import resolve_species

    is_adata = hasattr(data, "obs") and hasattr(data, "var_names")
    if species is None:
        if is_adata:
            uns_sp = getattr(data, "uns", {}).get("species")
            sp = resolve_species(uns_sp or "auto", adata=data, warn_mismatch=False)
        else:
            sp = "human"
    else:
        sp = resolve_species(
            species,
            adata=data if is_adata else None,
            warn_mismatch=False,
        )
    sig = _lookup_signature(name, registry, species=sp)
    if log1p is None:
        already_logged = is_adata and layer is None and "log1p" in getattr(data, "uns", {})
        apply_log1p = (sig.units in ("log1p", "cp10k")) and not already_logged
    else:
        apply_log1p = log1p
    if is_adata:
        index = data.obs_names.astype(str)
        if sig.method == "geneset_enrichment":
            series = _score_genes_adata(
                data, sig.all_genes, on_missing=on_missing,
                layer=layer, groups=groups, apply_log1p=apply_log1p,
                explicit_log1p=(log1p is True),
            )
        else:
            expr = expression_frame_from_adata(
                data, sig.all_genes, layer=layer, on_missing=on_missing
            )
            # Match geneset_enrichment: CP10K-normalize raw counts before log1p
            # when scoring AnnData without a caller-provided background frame.
            if apply_log1p and background is None and not expr.empty and data.n_obs and data.n_vars:
                src_mat = data.layers[layer] if (layer is not None and layer in data.layers) else data.X
                x_min = float(src_mat.min())
                x_max = float(src_mat.max())
                if x_min >= 0 and (x_max > 25 or layer == "counts"):
                    totals = np.asarray(src_mat.sum(axis=1)).ravel().astype(float)
                    scale = np.where(totals > 0, 1e4 / totals, 0.0)
                    expr = expr.mul(scale, axis=0)
            series = _score_frame(
                expr, sig, log1p=apply_log1p, background=background,
                groups=groups, on_missing=on_missing,
            )
        series = pd.Series(series.to_numpy(), index=index)
        if key_added is not None:
            data.obs[key_added] = series.to_numpy()
        return series
    return _score_frame(
        data, sig, log1p=apply_log1p, background=background, groups=groups,
        on_missing=on_missing,
    )