Tools: tl#
This module provides various tools for analyzing proteomics data.
Annotation#
Every annotator writes the same slots, so a result can be read, scored and plotted without knowing which one produced it:
slot |
contents |
|---|---|
|
one column per compartment, named |
|
the call, |
|
the probability of that call |
|
which annotator, and what it was told |
|
in the category order of |
uns[f"{key_added}_params"]["kind"] says how to read the matrix. "simplex" means the
compartments competed for one unit of mass, so the rows sum to 1 and an argmax is a
call. "per_term" means each column is an independent membership probability; the rows
do not sum to anything in particular, and resolving them into a call is a separate step.
Which annotator? If you have marker proteins and want one compartment each, use
competitive_diffusion() (graph) or svm_annotation() /
tagm_map_predict() (feature-space classifiers). If your labels overlap
or nest — GO-CC, UniProt-SL — use independent_diffusion(), which does
not force them to compete. If you have clusters and an enrichment table rather than
markers, use soft_cluster_annotation().
Graph label propagation#
Mutually exclusive labels spread over the k-NN graph and compete, giving a simplex.
Propagate categorical annotations along the k-NN graph. |
Marker-supervised classifiers#
Fitted in feature space on marker proteins rather than on the graph.
Grid-search the SVM's C and gamma over marker proteins. |
|
Classify proteins using SVM with marker-based training. |
|
Train a TAGM-MAP (T-Augmented Gaussian Mixture, MAP variant) model. |
|
Predict sub-cellular localization for unlabelled proteins using a fitted TAGM-MAP model. |
|
Fetch the stored TAGM model, preferring the current key. |
|
Predict compartment class contributions with the C-COMPASS neural network. |
|
Return (and optionally save) the default C-COMPASS hyperparameters used by |
Ontology-aware annotation#
Overlapping or hierarchical labels, diffused one-vs-rest so they do not compete. The result is a per-term membership probability, and resolving it into a call is explicit.
Annotate a map with overlapping / hierarchical labels by one-vs-rest diffusion. |
|
(Re)resolve stored diffusion probabilities into a per-protein label, in place. |
|
Resolve a gene-set source into a |
Soft cluster annotation#
Propagate the uncertainty of a per-cluster enrichment rather than one hard top term.
Listed in pipeline order; soft_cluster_annotation ties all three together.
Turn a per-cluster enrichment table into soft label distributions. |
|
Convert a per-cluster MGSA posterior matrix into a soft-label distribution. |
|
Soft, uncertainty-aware version of the cluster-annotation pipeline. |
|
Resolve soft propagated probabilities into single / multi / unresolved labels. |
Marker QC and evaluation#
Clean a marker set before annotating, and score any annotation against ground truth.
These take (gt_col, pred_col) and work for every annotator above.
Remove "outliers" from marker proteins whose compartment label is not supported by their k-NN neighbourhood. |
|
F1 score of a predicted annotation against ground-truth labels. |
|
Confusion matrix of a predicted annotation against ground-truth labels. |
|
Return a balanced subset with equally sized clusters. |
Clustering#
Automated sweep to pick a Leiden resolution that keeps mitochondria intact. |
|
Run Markov Clustering (MCL) on the neighbour graph. |
|
Quantify interfacialness: how much a protein sits between two compartments. |
|
Per-group silhouette scores. |
|
Calinski–Harabasz score of cluster compactness vs separation. |
|
QSep cluster-separation metric for spatial proteomics. |
Cluster Merging#
Consolidate overclustered Leiden solutions using PAGA connectivity and ontology enrichment.
Iteratively merge overclustered Leiden clusters using PAGA and GO enrichment. |
|
Iteratively merge small clusters into their most-connected neighbor. |
|
Build a dendrogram from PAGA connectivity and store it in |
|
Return all candidate merge pairs from the dendrogram, expanding ties. |
Ontology Enrichment#
Gene-set enrichment for each cluster. |
Model-based Gene Set Analysis#
MGSA explains an observed protein set with a sparse set of ontology terms, rather than testing each term independently.
Run model-based gene set analysis. |
|
Model-based gene-set analysis (MGSA) per cluster. |
|
Container for MGSA posterior summaries and diagnostics. |
Integration#
Return copies of several |
|
Aligned UMAP embedding for matched datasets. |
|
Compute per-protein remodeling score from two aligned datasets. |
|
M/R score for detecting protein translocation. |
Graph analysis#
Convert the k-NN graph stored in |
|
Return the set of closest neighbours for a node in a graph. |
Deprecated#
Kept for one release each so existing code keeps running; both emit a
DeprecationWarning and forward to :func:~grassp.tl.competitive_diffusion.
Deprecated alias for |
|
Deprecated alias for |