Display Formatting API¶
tcrsift.format converts machine-friendly sample and enrichment_method
identifiers into compact plot labels with Unicode superscripts:
| Raw string | Formatted label | Rule applied |
|---|---|---|
AIMpos |
AIM⁺ |
pos → ⁺ |
CTYneg |
CTY⁻ |
neg → ⁻ |
AIMpos_CTYneg |
AIM⁺CTY⁻ |
Underscore separator removed |
CTYneg_tetpos |
tet⁺CTY⁻ |
Baseline marker (CTY) moved last |
AIMpos_CTYneg-2 |
AIM⁺CTY⁻ |
Trailing donor/replicate suffix stripped |
Built-in overlap heatmaps, method-recovery bar charts, and per-sample scatter plots apply these helpers automatically; call them directly when labeling custom figures.
Usage¶
from tcrsift.format import pretty_method, pretty_samples
pretty_method("AIMpos_CTYneg") # "AIM⁺CTY⁻"
pretty_method("CTYneg_tetpos") # "tet⁺CTY⁻"
pretty_samples(["AIMpos-1", "tetpos-1"]) # ["AIM⁺", "tet⁺"]
format ¶
Display formatters for sample-sheet method names (#77).
The raw enrichment-method strings in tcrsift sample sheets are
pipeline-friendly but ugly in figures: AIMpos, CTYneg,
AIMpos_CTYneg, tetpos, IFNpos. Built-in plots route every
method/sample axis label through :func:pretty_method so figures
show the readable AIM⁺, CTY⁻, AIM⁺CTY⁻ forms.
Rules:
- Suffix
pos→ Unicode superscript⁺. - Suffix
neg→ Unicode superscript⁻. - A name combining several markers (joined by
_, or an N-way set combination joined by+) is reordered so any baseline marker (defaultCTY, an exclusion gate in our cohort) always reads last (CTYneg_tetpos→tet⁺CTY⁻). This gives a consistent label no matter which order the markers happened to appear in the data.
Baseline markers default to :data:BASELINE_MARKERS (("CTY",)) but
can be overridden globally via :func:set_baseline_markers or per call
via the last= argument. An explicit priority= list pins the
leading order of non-baseline markers.
Pass-through behavior: any name that doesn't match the rules is
returned unchanged. Non-string input is coerced via str().
pretty_method ¶
pretty_method(name: str, *, priority: Sequence[str] | None = None, last: Sequence[str] | None = None) -> str
Format a tcrsift enrichment-method string for display.
Markers joined by _ are reordered so baseline markers (default
CTY) read last, for any number of parts (not just two). Override the
baseline set with last= (or globally via :func:set_baseline_markers)
and pin leading order with priority=.
Examples: >>> pretty_method("AIMpos") 'AIM⁺' >>> pretty_method("CTYneg") 'CTY⁻' >>> pretty_method("AIMpos_CTYneg") 'AIM⁺CTY⁻' >>> pretty_method("CTYneg_tetpos") 'tet⁺CTY⁻' >>> pretty_method("CTYneg_AIMpos_IFNpos") 'AIM⁺IFN⁺CTY⁻'
Source code in tcrsift/format.py
pretty_methods ¶
pretty_sample ¶
Format a sample name like AIMpos_CTYneg-2 as the prettified
method (AIM⁺CTY⁻), dropping the trailing -N donor suffix.
Only strips a trailing -<digits> suffix when the stem looks like a
marker/method string (contains a pos/neg token), so non-marker
hyphenated names like Patient1-TIL, Patient1-PBMC, MART-1,
or TRAV12-2 are never collapsed or truncated.
Use in plots that label by sample-of-origin in a single-donor context (the donor is named elsewhere in the figure title).