CATranS: Clinical Acute Transcriptomic Stratification
CATranS is a robust bioinformatics and machine learning pipeline written in Python designed to stratify acute clinical cohorts using transcriptomic count data.
Through an iterative, semi-supervised learning approach, CATranS combines data normalization, batch correction, correlation-based feature selection, and class prediction to refine classifications of patient cohorts (e.g., separating acute from non-acute states, or predicting survival outcomes).
Key Features
- Iterative Semi-Supervised Relabeling: Safely expands training cohorts by predicting clinical labels on unclassified/unlabeled samples using high-confidence thresholds.
- Generalized Custom Classes: Supports user-defined positive and negative class labeling (e.g.,
Survivor/NonSurvivor,Mild/Severe,Responders/NonResponders) with robust Categorical ordering to fix Wald contrast directions in DESeq2. - Batch Correction: Integrated with
inmoosefor ComBat-seq count batch effect correction. - DESeq2-style Normalization: Leverages the high-performance
pydeseq2implementation for median-of-ratios normalization. - Correlation-Based Feature Learning: Custom graph-theory based gene selection utilizing
igraph. Filters out highly redundant co-expressed genes and selects optimal representative biomarkers correlating with clinical outcomes. - Flexible Estimator Integration: Compatible with any Scikit-Learn classifier exposing a
predict_probamethod.
Workflow Overview
graph TD
A[Raw Count Matrix & Metadata] --> B[Data Normalization & Optional ComBat-seq Batch Correction]
B --> C[Feature Selection: Spearman Correlation with Labels]
C --> D[Graph Construction: Pearson Gene-Gene Network]
D --> E[Redundant Feature Compression: Connected Components Vertex Selection]
E --> F[Iterative Semi-Supervised Model Training]
F --> G[Fit Classifier & Predict Unlabeled Samples]
G --> H{Meets Threshold?}
H -- Yes --> I[Relabel Samples & Run DESeq2 Differential Expression Analysis]
I --> J{Are there new DEGs?}
J -- Yes --> F
J -- No --> K[Final Output Classifications & Iteration History]
H -- No --> K
Installation
We recommend using uv or pip for rapid virtual environment setup and dependency management.
# Clone the repository
git clone https://github.com/ruben-canas-ivi/CATranS.git
cd CATranS
# Install dependencies and the package using uv
uv sync
Dependencies
- Python
>=3.11 numpy>=2.3.0pandas>=2.3.3scipy>=1.14.0scikit-learn>=1.8.0pydeseq2>=0.5.4igraph>=1.0.0inmoose>=0.9.1
API Reference & Usage Scenarios
Core Classes & Functions
1. CatransClasses
Defines the names of the binary classes.
positive(default"Dead"): The target/case class.negative(default"Alive"): The reference/control class.
2. correlation_based_feature_selection
Identifies representative biomarker genes by correlating expression levels with labels, building a gene-gene correlation network, and selecting one representative gene per connected component.
3. run_catrans
Runs the iterative semi-supervised relabeling pipeline.
raw_counts(pd.DataFrame): Genes (rows) by Samples (columns).metadata(pd.DataFrame): Samples (rows) with metadata.acute_classification(pd.DataFrame): Samples (rows) with initially known labels under the column"class"(unlabeled samples should beNaN).model: Any Scikit-Learn compatible classifier (e.g.RandomForestClassifier,SVC(probability=True)).classes(CatransClasses, Optional): Custom positive/negative class names.batch_col(str, Optional): Metadata column to use for ComBat-seq batch correction.model_threshold(float, default0.8): Confidence threshold to assign a label.signature_genes(list[str], Optional): Genes to use for training the model. IfNone,correlation_based_feature_selectionruns automatically.
Usage Scenarios
Scenario 1: Normal Workflow (Two-step Feature Selection + Stratification)
This is the recommended workflow where you first find a non-redundant gene signature, then pass it to the CATranS pipeline.
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
import catrans
# 1. Load your transcriptomics and clinical datasets
counts = pd.read_csv("data/raw_counts.tsv", sep="\t", index_col=0)
metadata = pd.read_csv("data/metadata.tsv", sep="\t", index_col=0)
initial_classes = pd.read_csv("data/initial_classes.tsv", sep="\t", index_col=0)
# 2. Define custom labels: "Survivor" (negative) and "NonSurvivor" (positive)
my_classes = catrans.CatransClasses(positive="NonSurvivor", negative="Survivor")
# 3. Perform correlation-based feature selection to identify candidate biomarkers
signature = catrans.correlation_based_feature_selection(
data=counts,
acute_classification=initial_classes,
classes=my_classes,
pval=0.05,
cutoff_corr=0.5,
cutoff_corr_genes=0.8,
n_cpus=4
)
# 4. Run the semi-supervised relabeling pipeline using the selected signature
results = catrans.run_catrans(
raw_counts=counts,
metadata=metadata,
acute_classification=initial_classes,
classes=my_classes,
model=RandomForestClassifier(random_state=42),
model_threshold=0.75,
signature_genes=signature,
n_cpus=4
)
print(results.final_classification)
Scenario 2: Predefined/Custom Gene Signature (Direct Stratification)
If you already have a target gene signature (e.g., from literature or a previous experiment), you can bypass the feature selection step entirely and run the stratification pipeline directly.
import pandas as pd
from sklearn.svm import SVC
import catrans
counts = pd.read_csv("data/raw_counts.tsv", sep="\t", index_col=0)
metadata = pd.read_csv("data/metadata.tsv", sep="\t", index_col=0)
initial_classes = pd.read_csv("data/initial_classes.tsv", sep="\t", index_col=0)
# Custom predefined signature from literature
custom_signature = ["ENSG00000034693.15", "ENSG00000101188.5", "ENSG00000104870.13"]
# Run the CATranS pipeline directly with the custom signature
results = catrans.run_catrans(
raw_counts=counts,
metadata=metadata,
acute_classification=initial_classes,
model=SVC(probability=True, random_state=42),
model_threshold=0.8,
signature_genes=custom_signature,
n_cpus=4
)
print(f"Completed in {results.number_of_iterations} iterations.")
Scenario 3: Implicit Feature Selection (Defaulting Signature Genes)
If you do not specify a list of signature_genes, run_catrans will automatically execute correlation_based_feature_selection under the hood using default parameters.
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
import catrans
counts = pd.read_csv("data/raw_counts.tsv", sep="\t", index_col=0)
metadata = pd.read_csv("data/metadata.tsv", sep="\t", index_col=0)
initial_classes = pd.read_csv("data/initial_classes.tsv", sep="\t", index_col=0)
# Run CATranS (it will automatically perform feature selection internally)
results = catrans.run_catrans(
raw_counts=counts,
metadata=metadata,
acute_classification=initial_classes,
model=RandomForestClassifier(random_state=42),
model_threshold=0.75,
n_cpus=4
)
Scenario 4: Default Thresholds & Core Settings
You can omit optional arguments like model_threshold or classes if you wish to use the defaults (model_threshold=0.8, classes defaulting to "Dead"/"Alive").
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
import catrans
counts = pd.read_csv("data/raw_counts.tsv", sep="\t", index_col=0)
metadata = pd.read_csv("data/metadata.tsv", sep="\t", index_col=0)
initial_classes = pd.read_csv("data/initial_classes.tsv", sep="\t", index_col=0)
# Minimal parameters
results = catrans.run_catrans(
raw_counts=counts,
metadata=metadata,
acute_classification=initial_classes,
model=RandomForestClassifier(random_state=42)
)
Scenario 5: Running with Batch Correction
To normalize and batch-correct raw counts concurrently, specify the name of the batch column in your metadata dataframe:
results = catrans.run_catrans(
raw_counts=counts,
metadata=metadata,
acute_classification=initial_classes,
model=RandomForestClassifier(random_state=42),
batch_col="batch" # ComBat-seq batch effect correction column
)
Testing & Quality Assurance
CATranS utilizes pytest for automated test suites, ruff for code style consistency, and mypy for strict type checking.
# Run tests
uv run pytest
# Check code format and style
uv run ruff check .
# Perform static type checks
uv run mypy src/catrans
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for CATranS 0.1.0
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 |
|---|---|---|---|---|
| catrans-0.1.0.tar.gz | 14.1 kB | Without provenance | Details for catrans-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| catrans-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for catrans-0.1.0-py3-none-any.whl |
Total release size: 27.5 kB
Release files / catrans-0.1.0.tar.gz
| Download URL | catrans-0.1.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4a0917985e39f89fe9ba6aca93703d06057977b3d92845a530ad6894c052d8e
|
|
BLAKE2b-256 checksum How to use checksums |
768f8d97a08d1f2922a49e50b760469fb022f0ba33c75fc1eb9d72a05cee6c2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / catrans-0.1.0-py3-none-any.whl
| Download URL | catrans-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4800d2951f185080889229ad0a72ce6fd70c1c8db8a105275b801a94cf82b001
|
|
BLAKE2b-256 checksum How to use checksums |
e1c7803e0ac39152f72359bf0aefcbe74b735b78214e149922c4c4f980718d71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for CATranS 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.