Metadata-Version: 2.4
Name: pirlygenes
Version: 6.4.3
Summary: Curated cancer gene sets and reference expression data. Analysis lives in `trufflepig`.
Author-email: Alex Rubinsteyn <alex.rubinsteyn@unc.edu>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/pirl-unc/pirlygenes
Project-URL: Bug Tracker, https://github.com/pirl-unc/pirlygenes
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Environment :: Console
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: datacache<2.0.0,>=1.38.0
Requires-Dist: matplotlib>=3.7.0
Requires-Dist: numpy>=2.0.0
Requires-Dist: oncoref<2.0.0,>=1.52.0
Requires-Dist: openpyxl>=3.1.0
Requires-Dist: pandas<4,>=3
Requires-Dist: pyarrow>=10
Requires-Dist: pyensembl>=2.32.3
Requires-Dist: PyYAML>=6.0
Requires-Dist: tqdm
Requires-Dist: tsarina>=1.36.0
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: pytest-xdist; extra == "test"
Requires-Dist: pypdf>=5; extra == "test"
Requires-Dist: reportlab>=4; extra == "test"
Provides-Extra: viz
Requires-Dist: matplotlib_venn>=1.0; extra == "viz"
Requires-Dist: pypdf>=5; extra == "viz"
Requires-Dist: reportlab>=4; extra == "viz"
Dynamic: license-file

# pirlygenes

> Curated cancer gene knowledge and reference expression data.

`pirlygenes` is the curated data layer for cancer RNA analysis:

- **Curated gene-set panels** — therapy targets (ADC, CAR-T, TCR-T, bispecifics, radioligands, TCEs), cancer-testis antigens, surfaceome, cancer-key panels, lineage/family panels, rule tables, and narrative gene sets.
- **ENSG-keyed gene families** — mtDNA, NUMTs, rRNA + pseudogenes, ribosomal proteins, histones, hemoglobins, immune-receptor segments, small ncRNAs, and MALAT1/NEAT1.
- **Reference expression matrices** — pan-cancer TCGA × HPA panel, HPA cell-type expression, ESTIMATE signatures, and compatibility wrappers over [`oncoref`](https://github.com/pirl-unc/oncoref) tumor cohorts.
- **Mechanical transforms & QC** — `pan_cancer_expression(normalize=...)`, `fpkm_to_tpm`, `renormalize_to_million`, `tpm_to_housekeeping_normalized`, `classify_gene_qc`, and `aggregate_gene_expression`.

Low-level reference ingestion, source matrices, empirical summaries, and canonical clean-TPM 16/9/75 mechanics are owned by [`oncoref`](https://github.com/pirl-unc/oncoref). Per-sample analysis (deconvolution, signature scoring, QC narration, reports) lives in [`pirl-trufflepig`](https://github.com/pirl-unc/trufflepig).

## Install

Requires Python 3.11–3.14 (pandas 3 + current `oncoref` / `pyensembl`).

```bash
pip install pirlygenes
```

For per-sample analysis, install [`pirl-trufflepig`](https://github.com/pirl-unc/trufflepig) (the bare `trufflepig` PyPI name is unrelated; the CLI command and Python import are `trufflepig`):

```bash
pip install pirl-trufflepig
trufflepig run --sample expr.tsv --workspace out --cancer-type PRAD
```

## Documentation

Start with the [documentation map](docs/README.md):

- [Available gene sets and expression references](docs/gene-sets.md)
- [Gene canonicalization contract](docs/gene-canonicalization.md)
- [Cancer-classification ontology](docs/cancer-classification-ontology.md)
- [Reference-expression ownership and parity](docs/reference-expression-parity.md)
- [Normalization and mapping audit](docs/normalization-and-mapping-audit.md)
- [CTA curation and provenance](docs/cta-curation.md)

## Quickstart

Most accessors are re-exported at the top level (`from pirlygenes import pan_cancer_expression` works for any of the ~140 names in `pirlygenes.__all__`); submodule paths are the canonical homes.

### Gene-set panels, identifiers, and families

```python
from pirlygenes.gene_sets_cancer import (
    CTA_gene_names,                   # ~360 cancer-testis antigens (active OncoRef policy)
    surface_protein_gene_names,       # 2,799 surfaceome genes
    cancer_surfaceome_gene_names,     # 147 tumor-specific surface targets
    therapy_target_gene_names,        # "ADC", "CAR-T", "TCR-T", "bispecific-antibodies",
                                      # "radioligand", "multispecific-TCE" (+ approved/trials)
    cancer_type_registry,             # cancer-type registry DataFrame
    resolve_cancer_type,              # "prostate" / "PRAD" / "SARC_DDLPS" → registry code
    CANCER_TYPE_NAMES,                # registry-backed {code: display_name} view
    lineage_genes_by_cancer_type,     # per-cancer lineage panels
    cancer_family_panel,              # broad-family panel, e.g. cancer_family_panel("LUAD")
    therapy_benefit_toxicity_evidence,# curated clinical benefit/toxicity rows
    housekeeping_gene_ids,
    mitochondrial_gene_ids,
    tme_marker_gene_ids,
    TCGA_MEDIAN_PURITY,               # per-cohort median tumor purity (Aran et al., 2015)
)
from pirlygenes.gene_ids import find_canonical_gene_ids_and_names
from pirlygenes.gene_names import display_name, short_gene_name, aliases
from pirlygenes.gene_families import (
    gene_family_names,
    gene_family_ids,
    gene_family_for_ensembl_id,
    rrna_and_pseudogene_ids,
    ribosomal_protein_ids,
)
```

### Reference expression matrices and transforms

```python
from pirlygenes.expression import (
    pan_cancer_expression,                 # 19,784 genes × TCGA/HPA reference columns
    cancer_expression,                     # single cancer type, clean TPM by default
    cancer_enriched_genes,                 # genes enriched in one cancer vs background
    cancer_reference_expression,           # oncoref-backed tumor cohort summaries
    available_cancer_expression_references,
    hpa_cell_type_expression,              # HPA single-cell consensus (via oncoref)
    estimate_signatures,                   # Yoshihara 2013 stromal/immune signatures
    classify_gene_qc,                      # symbol/ENSG → GeneQcClass
    aggregate_gene_expression,             # transcript → gene rollup
)

# Default: normalize="tpm_clean" applies the canonical 16/9/75 clean-TPM transform
# (16% ribosomal protein, 9% technical, 75% biological) and adds *_TPM_clean / *_nTPM_clean.
df = pan_cancer_expression()

# Other normalization modes (combinable as a list; e.g. ["tpm_clean", "hk", "percentile"]):
pan_cancer_expression(normalize=None)                # raw FPKM/nTPM + deterministic *_TPM
pan_cancer_expression(normalize="tpm_clean_log1p")   # natural log1p clean TPM
pan_cancer_expression(normalize="hk")                # housekeeping-normalized TPM
pan_cancer_expression(include_computed_rollups=True) # opt-in BTC/CRC/NET/NSCLC/SGC rollups
```

For multi-source cohorts, `cancer_reference_expression(format="wide")` requires selecting a single `source_cohort=`, passing `pool=True` for comparable sources, or keeping the default long format.

### Dataset discovery and caching

```python
from pirlygenes import clear_dataset_cache, data_roots, dataset_paths, get_data

paths = dataset_paths()                    # read-only CSV/shard map (no downloads)
bundled = dataset_paths(bundled_only=True) # local wheel/checkout files only
roots = data_roots()                       # bundled dir, then active downloaded bundle
clear_dataset_cache()                      # after editing local files in place
```

Small curated CSVs ship inside the wheel under `pirlygenes/data/`. Larger derived matrices (`cohort-expression-matrices/`, `pan-cancer-expression.csv`, `hpa-cell-type-expression.csv`) download lazily from the matching GitHub Release into `~/.cache/pirlygenes/bundled_data/` (override with `PIRLYGENES_BUNDLED_DATA`). Empirical summaries, source matrices, and registries delegate to `oncoref`. See [docs/gene-sets.md](docs/gene-sets.md) for the complete dataset and accessor catalog.

## CLI

`pirlygenes` provides cohort-level data inspection and plotting commands:

```bash
pirlygenes data status
pirlygenes data list
pirlygenes data sources SARC_DDLPS
pirlygenes downloads list
pirlygenes plot patient-coverage --gene-set cta --source all
pirlygenes plot patient-coverage --gene-set cta --threshold-mode percentile --threshold 95
pirlygenes plot cta-curation --out cta_curation_out
```

`patient-coverage` defaults to `threshold_mode="auto"` (clean-TPM threshold 25 for linear-TPM-comparable RNA-seq cohorts, p95 within-sample percentile for microarray/non-comparable cohorts).

## Package boundary

- **`oncoref`** — empirical expression ingestion, source/sample registries, per-sample matrices, empirical summaries, representatives, percentiles, proteoform artifacts, and active CTA target-selection policy.
- **`pirlygenes`** — curated clinical/target gene sets, ENSG gene families, compatibility wrappers, derived pan-cancer/cohort views, and mechanical expression transforms.
- **`pirl-trufflepig`** — per-sample analysis, QC narration, deconvolution, signature scoring, and clinical reports.

For 4.x/5.x migration history (CLI move to `trufflepig`, `cohort_expression_matrices()` rename), see [`docs/README.md`](docs/README.md) and [`pirl-unc/trufflepig#1`](https://github.com/pirl-unc/trufflepig/issues/1).

## License

Apache 2.0 — see [LICENSE](LICENSE).
