Skip to content

Weights

Load mismatch weight matrices from CSV files. The weight matrix maps position + substitution type to an activity penalty.

weights

Weight I/O for mismatch scoring models.

Loads mismatch model parameters from CSV files matching the format used by legacy/crispr_experiment/assets/mismatch_parameters.csv.

load_mismatch_weights

load_mismatch_weights(path: str) -> dict[str, float]

Load mismatch model weights from a CSV file.

Expected CSV format: columns feature and weight. Features include intercept, 0-19 (position weights), AC/AG/... (substitution weights), and GC_content.

Parameters:

Name Type Description Default
path str

Path to CSV file.

required

Returns:

Type Description
dict[str, float]

Dict mapping feature names to float weights.

Examples:

>>> w = load_mismatch_weights("tests/fixtures/mismatch_parameters.csv")
>>> "intercept" in w
True
Source code in src/seqchain/operations/score/weights.py
def load_mismatch_weights(path: str) -> dict[str, float]:
    """Load mismatch model weights from a CSV file.

    Expected CSV format: columns ``feature`` and ``weight``.
    Features include ``intercept``, ``0``-``19`` (position weights),
    ``AC``/``AG``/... (substitution weights), and ``GC_content``.

    Args:
        path: Path to CSV file.

    Returns:
        Dict mapping feature names to float weights.

    Examples:
        >>> w = load_mismatch_weights("tests/fixtures/mismatch_parameters.csv")
        >>> "intercept" in w
        True
    """
    weights: dict[str, float] = {}
    with open(path) as f:
        reader = csv.DictReader(f)
        for row in reader:
            weights[row["feature"]] = float(row["weight"])
    return weights