methylseg.MethylSegConfig
- class methylseg.MethylSegConfig(config_dict)[source]
Bases:
objectLightweight helper that knows how to build a serializable dictionary from a MethylSegPathway instance and how to write/read YAML.
- Parameters:
config_dict (dict)
- __init__(config_dict)[source]
Initialize a serializable MethylSeg configuration wrapper.
- Parameters:
config_dict (dict) – Configuration mapping to validate, serialize, or use when restoring a pathway.
Methods
__init__(config_dict)Initialize a serializable MethylSeg configuration wrapper.
build_pathway([load_learned])Reconstruct a
MethylSegPathwayfrom the serialized config.from_instance(inst[, out_dir, include_learned])Serialize a fitted pathway into a portable configuration bundle.
from_yaml(yaml_path)Load a serialized methylseg configuration from YAML.
Return the normalized rule-based cutoff configuration, if present.
rewrite_artifact_paths(source_dir, target_dir)Rewrite serialized artifact references from one base directory to another.
to_yaml(yaml_path)Write the serialized configuration dictionary to YAML.
- rewrite_artifact_paths(source_dir, target_dir)[source]
Rewrite serialized artifact references from one base directory to another.
- Parameters:
source_dir (str | Path) – Directory that relative artifact paths in
self.configcurrently resolve against.target_dir (str | Path) – Directory the rewritten paths should resolve against, typically the parent directory of the YAML file being written.
- Returns:
The same config wrapper with rewritten artifact references.
- Return type:
- classmethod from_instance(inst, out_dir=None, include_learned=True)[source]
Serialize a fitted pathway into a portable configuration bundle.
- Parameters:
inst (MethylSegPathway) – Fitted
MethylSegPathwayinstance to serialize.out_dir (str | None) – Directory where the YAML-adjacent artifacts should be written. When omitted, uses the pathway output directory.
include_learned (bool) – If
True, also write learned models and training artifacts such as PCA scores, labels, and feather tables.
- Returns:
Config wrapper whose
configdictionary references any artifacts written during serialization.- Return type:
- get_state_cutoffs()[source]
Return the normalized rule-based cutoff configuration, if present.
- Returns:
State-cutoff mapping compatible with
MethylStateAnalyzer.set_state_cutoffsorNonewhen the serialized config does not include rule thresholds.- Return type:
dict or None
- to_yaml(yaml_path)[source]
Write the serialized configuration dictionary to YAML.
- Parameters:
yaml_path (str) – Output path for the YAML configuration file. Parent directories are created automatically.
- classmethod from_yaml(yaml_path)[source]
Load a serialized methylseg configuration from YAML.
- Parameters:
yaml_path (str) – Path to a YAML file previously written by
to_yaml.- Returns:
Config wrapper with
source_pathset to the loaded YAML file.- Return type:
- build_pathway(load_learned=True)[source]
Reconstruct a
MethylSegPathwayfrom the serialized config.- Parameters:
load_learned (bool) – If
True, attempt to restore saved training artifacts, learned KMeans preprocessing components, and persisted tables referenced by the config.- Returns:
Rehydrated pathway configured from the serialized YAML bundle.
- Return type:
- Raises:
ValueError – If the loaded config is missing required sections or has invalid field shapes.
FileNotFoundError – If an expected serialized artifact referenced by the config is missing on disk.