# ABOUTME: Drop-in API module for msastats (import as `msastats`).
# ABOUTME: Provides calculate_msa_stats, calculate_fasta_stats, and stats_names.
"""Pure-Python replacement for the `msastats` extension module.

This module implements the minimal public API used by MSACompare:
  - calculate_msa_stats(msa: list[str]) -> list[float]
  - calculate_fasta_stats(path: str) -> list[float]
  - stats_names() -> list[str]
"""

from __future__ import annotations

import os
from pathlib import Path
from typing import List, Sequence, Union

from msa_stats_calculator import MsaStatsCalculator, MsaStatsError, StatType

__all__ = [
    "MsaStatsCalculator",
    "MsaStatsError",
    "StatType",
    "calculate_fasta_stats",
    "calculate_msa_stats",
    "stats_names",
]


PathLike = Union[str, os.PathLike[str]]


def calculate_msa_stats(msa: Sequence[str]) -> List[float]:
    """Calculate stats from an in-memory MSA (list/tuple of aligned strings)."""
    calculator = MsaStatsCalculator(list(msa))
    calculator.recompute_stats()
    return calculator.get_stat_vec()


def calculate_fasta_stats(fasta_path: PathLike) -> List[float]:
    """Calculate stats from a FASTA file containing an aligned MSA."""
    calculator = MsaStatsCalculator.from_fasta(Path(fasta_path))
    calculator.recompute_stats()
    return calculator.get_stat_vec()


def stats_names() -> List[str]:
    """Return stat names in the same order as `calculate_*_stats`."""
    return [stat.name for stat in StatType]

