ecotyper.model

EcoTyper discovery results (“models”) in the R directory layout.

A model is the folder EcoTyper/<discovery>/<fractions>/ written by the R discovery wrappers (the prebuilt Carcinoma and Lymphoma models ship in this layout) or by ecotyper.workflows. Only the files used by recovery are loaded; numbers are parsed with R’s own read.delim number parser so that recovery starts from exactly the values R sees.

Functions

ecotype_levels(values)

Levels of ecotype_to_factor(values) (lib/misc.R).

load_cell_type(d, cell_type, n_states)

model_ecotypes_table(result)

ecotypes.txt as written by the discovery workflow (the scRNA variant has R's extra Cell type column, ecotypes_scRNA.R:152).

read_W(path)

read.delim("W.txt") with R's number parser.

write_model_files(result, base, *[, heatmap])

Write the files recovery reads from a discovery result into base (<discovery>/<fractions>), byte-identical to the corresponding files of ecotyper.workflows.write_discovery() / write_discovery_scrna.

Classes

CellTypeModel(cell_type, n_states, W, ...[, ...])

Cell states of one cell type (Cell_States/discovery/<ct>/<rank>).

EcoTyperModel(name, fractions, rank_data[, ...])

A discovery result: chosen ranks, per-cell-type states and ecotypes.

class ecotyper.model.CellTypeModel(cell_type, n_states, W, mapping, initial_gene_info, gene_info=None, heatmap_genes=None, path=None)[source]

Bases: object

Cell states of one cell type (Cell_States/discovery/<ct>/<rank>).

Parameters:
cell_type: str
n_states: int
W: DataFrame
mapping: DataFrame
initial_gene_info: DataFrame
gene_info: DataFrame | None = None
heatmap_genes: list | None = None
path: Path | None = None
class ecotyper.model.EcoTyperModel(name, fractions, rank_data, cell_types=<factory>, ecotypes=None, path=None, discovery_result=None)[source]

Bases: object

A discovery result: chosen ranks, per-cell-type states and ecotypes.

Get one from ecotyper.discovery(), load() (a saved model, an R discovery folder, or a built-in model by name: "Carcinoma", "Lymphoma") and pass it to ecotyper.recovery(). save() writes the files recovery needs in the R layout, so a saved model can be used by both this package and the R scripts.

Parameters:
name: str
fractions: str
rank_data: DataFrame
cell_types: dict
ecotypes: DataFrame | None = None
path: Path | None = None
discovery_result: object | None = None

full in-memory discovery result (ecotyper.workflows.DiscoveryResult) when the model comes from ecotyper.discovery(); not saved

property cell_type_order: list[str]
property n_states: dict

Cell type → number of cell states.

property ecotype_names: list[str]
classmethod from_discovery(result, name='custom', fractions=None)[source]

Model from an in-memory discovery result (discover_from_profiles / discover_scrna_frame).

The R pipeline hands discovery results to recovery through text files (15 significant digits). To stay exact, the model tables take the same text round trip here (through a temporary folder that is removed again), so recovery with this model equals recovery with the model written by the file-based workflow.

Parameters:
  • name (str)

  • fractions (str | None)

Return type:

EcoTyperModel

save(path, *, heatmap=True)[source]

Write the model to path (the R <discovery>/<fractions> folder layout).

Load it back with EcoTyperModel.load(path). With heatmap the (large) heatmap_data.txt/heatmap_top_ann.txt files that the R recovery scripts use for their heatmap plots are written too, when available.

Parameters:

heatmap (bool)

Return type:

Path

classmethod load(root, discovery=None, fractions=None)[source]

Load a model.

  • load("Carcinoma") / load("Lymphoma"): a built-in model (see ecotyper.builtin; downloaded and cached on first use);

  • load(path): a folder written by save() or an R EcoTyper/<discovery>/<fractions> folder (contains Analysis/);

  • load(root, discovery, fractions): <root>/<discovery>/<fractions> (fractions defaults to <discovery>_Fractions).

Parameters:
  • discovery (str | None)

  • fractions (str | None)

Return type:

EcoTyperModel

ecotyper.model.read_W(path)[source]

read.delim("W.txt") with R’s number parser.

Return type:

DataFrame

ecotyper.model.load_cell_type(d, cell_type, n_states)[source]
Parameters:
Return type:

CellTypeModel

ecotyper.model.ecotype_levels(values)[source]

Levels of ecotype_to_factor(values) (lib/misc.R).

Return type:

list[str]

ecotyper.model.model_ecotypes_table(result)[source]

ecotypes.txt as written by the discovery workflow (the scRNA variant has R’s extra Cell type column, ecotypes_scRNA.R:152).

Return type:

DataFrame

ecotyper.model.write_model_files(result, base, *, heatmap=True)[source]

Write the files recovery reads from a discovery result into base (<discovery>/<fractions>), byte-identical to the corresponding files of ecotyper.workflows.write_discovery() / write_discovery_scrna.

Parameters:

heatmap (bool)

Return type:

Path