spras.config package
Submodules
spras.config.config module
This config file is being used as a singleton. Because python creates a single instance of modules when they’re imported, we rely on the Snakefile instantiating the module. In particular, when the Snakefile calls init_config, it will reassign config to take the value of the actual config provided by Snakemake. After that point, any module that imports this module can access a config option by checking the object’s value. For example
import spras.config.config as config container_framework = config.config.container_settings.framework
will grab the top level registry configuration option as it appears in the config file
- class spras.config.config.Config(raw_config: dict[str, Any])
Bases:
object- classmethod from_file(filepath: str | PathLike[str])
- spras.config.config.attach_spras_revision(label: str) str
- spras.config.config.init_from_file(filepath)
- spras.config.config.init_global(config_dict)
- spras.config.config.spras_revision() str
Gets the revision of the current SPRAS repository. This function is meant to be user-friendly to warn for bad SPRAS installs. 1. If this file is inside the correct .git repository, we use the revision hash. This is for development in SPRAS as well as SPRAS installs via a cloned git repository. 2. If SPRAS was installed via a PyPA-compliant package manager, we use the hash of the RECORD file (https://packaging.python.org/en/latest/specifications/recording-installed-packages/#the-record-file).
which contains the hashes of all installed files to the package.
spras.config.schema module
Contains the raw pydantic schema for the configuration file.
Using Pydantic as our backing config parser allows us to declaratively type our config, giving us more robust user errors with guarantees that parts of the config exist after parsing it through Pydantic.
We declare models using two classes here: - BaseModel (docs: https://docs.pydantic.dev/latest/concepts/models/) - CaseInsensitiveEnum (see ./util.py)
- class spras.config.schema.Analysis(*, summary: ~spras.config.schema.SummaryAnalysis = SummaryAnalysis(include=False), cytoscape: ~spras.config.schema.CytoscapeAnalysis = CytoscapeAnalysis(include=False), ml: ~spras.config.schema.MlAnalysis = MlAnalysis(include=False, aggregate_per_algorithm=False, components=2, labels=True, kde=False, remove_empty_pathways=False, linkage=<MlLinkage.ward: 'ward'>, metric=<MlMetric.euclidean: 'euclidean'>), evaluation: ~spras.config.schema.EvaluationAnalysis = EvaluationAnalysis(include=False, aggregate_per_algorithm=False))
Bases:
BaseModel- cytoscape: CytoscapeAnalysis
- evaluation: EvaluationAnalysis
- ml: MlAnalysis
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- summary: SummaryAnalysis
- class spras.config.schema.CytoscapeAnalysis(*, include: bool)
Bases:
BaseModel- include: bool
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class spras.config.schema.EvaluationAnalysis(*, include: bool, aggregate_per_algorithm: bool = False)
Bases:
BaseModel- aggregate_per_algorithm: bool
- include: bool
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class spras.config.schema.GoldStandard(*, label: ~typing.Annotated[str, ~pydantic.functional_validators.AfterValidator(func=~spras.config.util.label_validator.<locals>.validate)], node_files: list[str] = [], edge_files: list[str] = [], data_dir: str, dataset_labels: list[str])
Bases:
BaseModel- data_dir: str
- dataset_labels: list[str]
- edge_files: list[str]
- label: validate)]
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- node_files: list[str]
- class spras.config.schema.Locations(*, reconstruction_dir: str)
Bases:
BaseModel- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- reconstruction_dir: str
- class spras.config.schema.MlAnalysis(*, include: bool, aggregate_per_algorithm: bool = False, components: int = 2, labels: bool = True, kde: bool = False, remove_empty_pathways: bool = False, linkage: MlLinkage = MlLinkage.ward, metric: MlMetric = MlMetric.euclidean)
Bases:
BaseModel- aggregate_per_algorithm: bool
- components: int
- include: bool
- kde: bool
- labels: bool
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- remove_empty_pathways: bool
- class spras.config.schema.MlLinkage(value)
Bases:
CaseInsensitiveEnum- average = 'average'
- complete = 'complete'
- single = 'single'
- ward = 'ward'
- class spras.config.schema.MlMetric(value)
Bases:
CaseInsensitiveEnum- cosine = 'cosine'
- euclidean = 'euclidean'
- manhattan = 'manhattan'
- class spras.config.schema.RawConfig(*, containers: ~spras.config.container_schema.ContainerSettings, hash_length: int = 7, algorithms: list[~typing.Annotated[~spras.config.algorithms.allpairsModel | ~spras.config.algorithms.bowtiebuilderModel | ~spras.config.algorithms.dominoModel | ~spras.config.algorithms.meoModel | ~spras.config.algorithms.mincostflowModel | ~spras.config.algorithms.omicsintegrator1Model | ~spras.config.algorithms.omicsintegrator2Model | ~spras.config.algorithms.pathlinkerModel | ~spras.config.algorithms.responsenetModel | ~spras.config.algorithms.rwrModel | ~spras.config.algorithms.strwrModel, FieldInfo(annotation=NoneType, required=True, discriminator='name')]], datasets: list[~spras.config.dataset.DatasetSchema], gold_standards: list[~spras.config.schema.GoldStandard] = [], analysis: ~spras.config.schema.Analysis = Analysis(summary=SummaryAnalysis(include=False), cytoscape=CytoscapeAnalysis(include=False), ml=MlAnalysis(include=False, aggregate_per_algorithm=False, components=2, labels=True, kde=False, remove_empty_pathways=False, linkage=<MlLinkage.ward: 'ward'>, metric=<MlMetric.euclidean: 'euclidean'>), evaluation=EvaluationAnalysis(include=False, aggregate_per_algorithm=False)), reconstruction_settings: ~spras.config.schema.ReconstructionSettings)
Bases:
BaseModel- algorithms: list[Annotated[allpairsModel | bowtiebuilderModel | dominoModel | meoModel | mincostflowModel | omicsintegrator1Model | omicsintegrator2Model | pathlinkerModel | responsenetModel | rwrModel | strwrModel, FieldInfo(annotation=NoneType, required=True, discriminator='name')]]
- containers: ContainerSettings
- datasets: list[DatasetSchema]
- gold_standards: list[GoldStandard]
- hash_length: int
The length of the hash used to identify a parameter combination
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_attribute_docstrings': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- reconstruction_settings: ReconstructionSettings
spras.config.util module
General config utilities. This is the only config file that should be imported by algorithms, and algorithms should only import this config file.
- class spras.config.util.CaseInsensitiveEnum(value)
Bases:
str,EnumWe prefer this over Enum to make sure the config parsing is more relaxed when it comes to string enum values.
- class spras.config.util.Empty
Bases:
BaseModelThe empty base model. Used for specifying that an algorithm takes no parameters, yet is deterministic.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- spras.config.util.label_validator(name: str)
A validator takes in a label and ensures that it contains only letters, numbers, or underscores.