Skip to content

Preset Management

Load and list YAML-configured presets for CRISPR nucleases, transposons, and chromatin state definitions. All presets live in recipes/presets/ and must have an explicit type field.

CRISPR presets

load_preset

load_preset(name: str) -> CRISPRPreset

Load a CRISPR nuclease preset by name.

Searches the built-in presets directory for a YAML file matching name (case-insensitive, without extension).

Parameters:

Name Type Description Default
name str

Preset name (e.g. "spcas9", "cas12a").

required

Returns:

Type Description
CRISPRPreset

A CRISPRPreset with the loaded configuration.

Raises:

Type Description
FileNotFoundError

If no preset file matches name.

Examples:

>>> preset = load_preset("spcas9")
>>> preset.pam
'NGG'
Source code in src/seqchain/recipes/__init__.py
def load_preset(name: str) -> CRISPRPreset:
    """Load a CRISPR nuclease preset by name.

    Searches the built-in presets directory for a YAML file matching
    *name* (case-insensitive, without extension).

    Args:
        name: Preset name (e.g. ``"spcas9"``, ``"cas12a"``).

    Returns:
        A `CRISPRPreset` with the loaded configuration.

    Raises:
        FileNotFoundError: If no preset file matches *name*.

    Examples:
        >>> preset = load_preset("spcas9")
        >>> preset.pam
        'NGG'
    """
    import yaml

    path = _PRESETS_DIR / f"{name.lower()}.yaml"
    if not path.exists():
        available = ", ".join(p.stem for p in _PRESETS_DIR.glob("*.yaml"))
        raise FileNotFoundError(
            f"No preset named {name!r}. Available: {available}"
        )

    with open(path) as f:
        data = yaml.safe_load(f)

    return _preset_from_dict(data)

load_preset_from_file

load_preset_from_file(path: str | Path) -> CRISPRPreset

Load a CRISPR nuclease preset from an arbitrary YAML file.

Parameters:

Name Type Description Default
path str | Path

Path to a YAML preset file.

required

Returns:

Type Description
CRISPRPreset

A CRISPRPreset with the loaded configuration.

Examples:

>>> preset = load_preset_from_file("my_nuclease.yaml")
Source code in src/seqchain/recipes/__init__.py
def load_preset_from_file(path: str | Path) -> CRISPRPreset:
    """Load a CRISPR nuclease preset from an arbitrary YAML file.

    Args:
        path: Path to a YAML preset file.

    Returns:
        A `CRISPRPreset` with the loaded configuration.

    Examples:
        >>> preset = load_preset_from_file("my_nuclease.yaml")
    """
    import yaml

    with open(path) as f:
        data = yaml.safe_load(f)

    return _preset_from_dict(data)

list_presets

list_presets() -> list[str]

List available built-in CRISPR nuclease preset names.

Returns:

Type Description
list[str]

Sorted list of preset names (without .yaml extension).

Examples:

>>> list_presets()
['cas12a', 'spcas9']
Source code in src/seqchain/recipes/__init__.py
def list_presets() -> list[str]:
    """List available built-in CRISPR nuclease preset names.

    Returns:
        Sorted list of preset names (without ``.yaml`` extension).

    Examples:
        >>> list_presets()
        ['cas12a', 'spcas9']
    """
    names: list[str] = []
    for p in _PRESETS_DIR.glob("*.yaml"):
        if _yaml_type(p) == "crispr":
            names.append(p.stem)
    names.sort()
    return names

Transposon presets

load_transposon_preset

load_transposon_preset(name: str) -> TransposonPreset

Load a transposon preset by name.

Searches the built-in presets directory for a YAML file matching name (case-insensitive, without extension) whose type field is "transposon".

Parameters:

Name Type Description Default
name str

Preset name (e.g. "himar1", "tn5").

required

Returns:

Type Description
TransposonPreset

A TransposonPreset with the loaded configuration.

Raises:

Type Description
FileNotFoundError

If no transposon preset file matches name.

Examples:

>>> preset = load_transposon_preset("himar1")
>>> preset.insertion_motif
'TA'
Source code in src/seqchain/recipes/__init__.py
def load_transposon_preset(name: str) -> TransposonPreset:
    """Load a transposon preset by name.

    Searches the built-in presets directory for a YAML file matching
    *name* (case-insensitive, without extension) whose ``type`` field
    is ``"transposon"``.

    Args:
        name: Preset name (e.g. ``"himar1"``, ``"tn5"``).

    Returns:
        A `TransposonPreset` with the loaded configuration.

    Raises:
        FileNotFoundError: If no transposon preset file matches *name*.

    Examples:
        >>> preset = load_transposon_preset("himar1")
        >>> preset.insertion_motif
        'TA'
    """
    import yaml

    path = _PRESETS_DIR / f"{name.lower()}.yaml"
    if not path.exists():
        raise FileNotFoundError(
            f"No transposon preset named {name!r}. "
            f"Available: {', '.join(list_transposon_presets())}"
        )

    with open(path) as f:
        data = yaml.safe_load(f)

    if data.get("type") != "transposon":
        raise FileNotFoundError(
            f"{name!r} is not a transposon preset (type={data.get('type')!r}). "
            f"Available: {', '.join(list_transposon_presets())}"
        )

    return _transposon_preset_from_dict(data)

list_transposon_presets

list_transposon_presets() -> list[str]

List available built-in transposon preset names.

Returns:

Type Description
list[str]

Sorted list of transposon preset names.

Examples:

>>> list_transposon_presets()
['himar1', 'tn5']
Source code in src/seqchain/recipes/__init__.py
def list_transposon_presets() -> list[str]:
    """List available built-in transposon preset names.

    Returns:
        Sorted list of transposon preset names.

    Examples:
        >>> list_transposon_presets()
        ['himar1', 'tn5']
    """
    names: list[str] = []
    for p in _PRESETS_DIR.glob("*.yaml"):
        if _yaml_type(p) == "transposon":
            names.append(p.stem)
    names.sort()
    return names

Chromatin configs

load_chromatin_config

load_chromatin_config(name: str) -> ChromatinConfig

Load a chromatin state configuration by name.

Searches the built-in presets directory for a YAML file matching name (case-insensitive, without extension) whose type field is "chromatin".

Parameters:

Name Type Description Default
name str

Config name (e.g. "yeast_chromatin").

required

Returns:

Type Description
ChromatinConfig

A ChromatinConfig with the loaded configuration.

Raises:

Type Description
FileNotFoundError

If no chromatin config file matches name.

Examples:

>>> config = load_chromatin_config("yeast_chromatin")
>>> config.organism
'S. cerevisiae'
Source code in src/seqchain/recipes/__init__.py
def load_chromatin_config(name: str) -> ChromatinConfig:
    """Load a chromatin state configuration by name.

    Searches the built-in presets directory for a YAML file matching
    *name* (case-insensitive, without extension) whose ``type`` field
    is ``"chromatin"``.

    Args:
        name: Config name (e.g. ``"yeast_chromatin"``).

    Returns:
        A `ChromatinConfig` with the loaded configuration.

    Raises:
        FileNotFoundError: If no chromatin config file matches *name*.

    Examples:
        >>> config = load_chromatin_config("yeast_chromatin")
        >>> config.organism
        'S. cerevisiae'
    """
    import yaml

    path = _PRESETS_DIR / f"{name.lower()}.yaml"
    if not path.exists():
        raise FileNotFoundError(
            f"No chromatin config named {name!r}. "
            f"Available: {', '.join(list_chromatin_configs())}"
        )

    with open(path) as f:
        data = yaml.safe_load(f)

    if data.get("type") != "chromatin":
        raise FileNotFoundError(
            f"{name!r} is not a chromatin config (type={data.get('type')!r}). "
            f"Available: {', '.join(list_chromatin_configs())}"
        )

    return chromatin_config_from_dict(data)

load_chromatin_config_from_file

load_chromatin_config_from_file(path: str | Path) -> ChromatinConfig

Load a chromatin state configuration from an arbitrary YAML file.

Parameters:

Name Type Description Default
path str | Path

Path to a YAML config file.

required

Returns:

Type Description
ChromatinConfig

A ChromatinConfig with the loaded configuration.

Examples:

>>> config = load_chromatin_config_from_file("my_states.yaml")
Source code in src/seqchain/recipes/__init__.py
def load_chromatin_config_from_file(path: str | Path) -> ChromatinConfig:
    """Load a chromatin state configuration from an arbitrary YAML file.

    Args:
        path: Path to a YAML config file.

    Returns:
        A `ChromatinConfig` with the loaded configuration.

    Examples:
        >>> config = load_chromatin_config_from_file("my_states.yaml")  # doctest: +SKIP
    """
    import yaml

    with open(path) as f:
        data = yaml.safe_load(f)

    return chromatin_config_from_dict(data)

list_chromatin_configs

list_chromatin_configs() -> list[str]

List available built-in chromatin state config names.

Returns:

Type Description
list[str]

Sorted list of chromatin config names.

Examples:

>>> list_chromatin_configs()
['yeast_chromatin']
Source code in src/seqchain/recipes/__init__.py
def list_chromatin_configs() -> list[str]:
    """List available built-in chromatin state config names.

    Returns:
        Sorted list of chromatin config names.

    Examples:
        >>> list_chromatin_configs()
        ['yeast_chromatin']
    """
    names: list[str] = []
    for p in _PRESETS_DIR.glob("*.yaml"):
        if _yaml_type(p) == "chromatin":
            names.append(p.stem)
    names.sort()
    return names