ecotyper.workflows¶
High-level workflows mirroring the R wrapper scripts.
recover_bulk(),recover_bulk_files()↔EcoTyper_recovery_bulk.Rrecover_scrna(),recover_scrna_files()↔EcoTyper_recovery_scRNA.Rrecover_visium_frame(),recover_visium_files()↔EcoTyper_recovery_visium.Rdiscover_from_profiles(),discover_files()↔EcoTyper_discovery_bulk.R(downstream of CIBERSORTx) andEcoTyper_discovery_presorted.Rdiscover_scrna(),discover_scrna_frame()↔EcoTyper_discovery_scRNA.R
The *_frame functions take pandas objects, the *_files functions take the
R wrappers’ input files and write the R output layout, and the unsuffixed
functions take anndata.AnnData and store results in it.
AnnData conventions (key = "ecotyper" by default):
adata.obs[f"{key}_state_{cell_type}"]assigned cell state (
S01…; NaN if the sample’s dominant initial state was filtered out during discovery);adata.obsm[f"{key}_abundance_{cell_type}"]cell state abundances (samples x states, columns
S01…);adata.obs[f"{key}_ecotype"],adata.obs[f"{key}_max_ecotype"],adata.obs[f"{key}_ecotype_q"]ecotype assignment (
Unassignedif not significant), most abundant ecotype and its BH-adjusted p-value (bulk/Visium);adata.obsm[f"{key}_ecotype_abundance"]ecotype abundances (samples x ecotypes);
adata.uns[key]run parameters, number of NMF iterations per cell type, and the full per-step result objects under
"results".
R starts each per-cell-type script in a fresh process. The R reference runs
seed every process with set.seed(seed) (R itself leaves NMFpredict
unseeded); the port reseeds RRandom(seed) for every cell type the same way.
Functions
|
File-based discovery from a folder of per-cell-type profiles (CSx HiRes output or presorted profiles) and a sample annotation file. |
|
Cell state + ecotype discovery from per-cell-type expression profiles ( |
|
scRNA-seq discovery on AnnData (cells x genes, raw-scale expression; |
|
|
|
|
|
Per-cell-type profiles |
|
|
|
Recover cell states and ecotypes in bulk samples ( |
|
File-based equivalent of |
|
Bulk recovery on a genes x samples DataFrame (values as read by R). |
|
Recover cell states in single cells ( |
|
File-based equivalent of |
|
scRNA-seq recovery on a genes x cells DataFrame ( |
|
File-based equivalent of |
|
Returns |
|
Write the R layout |
|
Write the R layout of a scRNA discovery run. |
Classes
Results of a discovery run (attribute access to the dict keys). |
- ecotyper.workflows.recover_bulk_frame(expr, model, annotation=None, *, seed=42, n_jobs=1, r_exact=True, kind='bulk', exact=True)[source]¶
Bulk recovery on a genes x samples DataFrame (values as read by R).
Returns
(state_results, ecotype_result).exact=Falseis the fast mode (BLAS NMF updates, no R text round trips; see the module docstring).
- ecotyper.workflows.recover_bulk(adata, model, *, discovery_root=None, layer=None, seed=42, n_jobs=1, r_exact=True, key='ecotyper', exact=True)[source]¶
Recover cell states and ecotypes in bulk samples (
adata: samples x genes).modelis anEcoTyperModel, a path to a model folder, or a discovery name ("Carcinoma","Lymphoma"…) withdiscovery_rootpointing to theEcoTyperfolder.
- ecotyper.workflows.recover_bulk_files(matrix, annotation, model, out_dir, *, discovery_root=None, recovery_name=None, seed=42, n_jobs=1, r_exact=True, exact=True)[source]¶
File-based equivalent of
Rscript EcoTyper_recovery_bulk.R -m matrix -a annotation.Writes the intermediate
EcoTyper/<discovery>/<fractions>/{Cell_States,Ecotypes}/recoverytree underout_dir/EcoTyperand the user-facing folderout_dir/RecoveryOutput/<recovery_name>.
- ecotyper.workflows.recover_scrna_frame(expr_all, annotation, model, *, seed=42, subsample=-1, n_jobs=1, exact=True)[source]¶
scRNA-seq recovery on a genes x cells DataFrame (
freadsemantics) and a cell annotation withID,CellTypeand optionallySample.subsamplecaps the number of cells per cell type (R’s-s; values below 50, e.g. the default-1, keep all cells). Returns(state_results, ecotype_result);ecotype_resultisNonewithout aSamplecolumn.
- ecotyper.workflows.recover_scrna(adata, model, *, discovery_root=None, layer=None, seed=42, subsample=-1, n_jobs=1, key='ecotyper', exact=True)[source]¶
Recover cell states in single cells (
adata: cells x genes, raw-scale expression;obsmust haveCellTypeand, for ecotypes,Sample).Ecotype abundances are per sample, returned (not stored in
adata).
- ecotyper.workflows.recover_scrna_files(matrix, annotation, model, out_dir, *, discovery_root=None, recovery_name=None, seed=42, subsample=-1, n_jobs=1, exact=True)[source]¶
File-based equivalent of
Rscript EcoTyper_recovery_scRNA.R.
- ecotyper.workflows.read_visium(matrix_dir)[source]¶
spatial_load_visium_data.R: 10x Visium folder → (genes x spots counts, spot annotation withID,X(array row),Y(array col)).
- ecotyper.workflows.recover_visium_frame(expr, spots, model, fractions, *, sample_name, malignant_cell='Epithelial.cells', seed=42, n_jobs=1, r_exact=True, exact=True)[source]¶
Returns
(state_results, state_abundances_long, state_abundances, ecotype_abundances).
- ecotyper.workflows.recover_visium_files(visium_dir, fractions_path, model, out_dir, *, recovery_name, discovery_root=None, malignant_cell='Epithelial.cells', seed=42, n_jobs=1, r_exact=True, exact=True)[source]¶
File-based equivalent of
Rscript EcoTyper_recovery_visium.R -c config.ymlwith precomputed fractions.
- ecotyper.workflows.ecotype_abundances_long(eco)[source]¶
melt(ecotype_data, id.vars = c("ID", "X", "Y", "Sample", "Malignant")).
- class ecotyper.workflows.DiscoveryResult[source]¶
Bases:
dictResults of a discovery run (attribute access to the dict keys).
- ecotyper.workflows.discover_from_profiles(profiles, annotation=None, *, scale_column=None, max_states=20, restarts=5, cophenetic_cutoff=0.95, min_states=3, n_jobs=1, r_exact=True, verbose=True, exact=True, nmf_method='brunet')[source]¶
Cell state + ecotype discovery from per-cell-type expression profiles (
EcoTyper_discovery_bulk.Rsteps 3–6 and 8 with CSx HiRes profiles as input, orEcoTyper_discovery_presorted.Rwith “no filter”).profiles: cell type → genes x samples DataFrame (values as read byread.delim(row.names = 1)), in the order ofclasses.txt.exact=False: fast mode;nmf_method="cd": alternative NMF solver (seeecotyper.nmf.nmf_cd()).
- ecotyper.workflows.read_profiles(input_dir, classes=None)[source]¶
Per-cell-type profiles
<input_dir>/<cell type>.txt(read.delim(row.names = 1)).classes: cell type order (default:list.filesorder).- Return type:
- ecotyper.workflows.write_discovery(res, out_dir, name, fractions)[source]¶
Write the R layout
<out_dir>/EcoTyper/<name>/<fractions>/....- Parameters:
res (DiscoveryResult)
name (str)
fractions (str)
- Return type:
- ecotyper.workflows.discover_files(input_dir, annotation_path, out_dir, *, name, fractions='All_genes', scale_column=None, max_states=20, restarts=5, cophenetic_cutoff=0.95, min_states=3, n_jobs=1, r_exact=True, exact=True, nmf_method='brunet')[source]¶
File-based discovery from a folder of per-cell-type profiles (CSx HiRes output or presorted profiles) and a sample annotation file.
- ecotyper.workflows.discover_scrna_frame(expr, annotation, *, filter_genes='cell type specific', scale_column=None, max_states=20, restarts=5, cophenetic_cutoff=0.975, p_value_cutoff=1.0, min_states=3, n_jobs=1, r_exact=True, verbose=True, exact=True, nmf_method='brunet')[source]¶
EcoTyper_discovery_scRNA.Ron a genes x cells matrix (fread semantics) and a cell annotation withID,CellTypeandSample.exact=False: fast mode.
- ecotyper.workflows.discover_scrna(adata, *, layer=None, **kwargs)[source]¶
scRNA-seq discovery on AnnData (cells x genes, raw-scale expression;
obswithCellTypeandSample). Results are stored inadata.obs["ecotyper_state_<cell type>"](per cell) and returned.