"""Feature engineering shared by training and serving. Keep this identical to api/app/services/scoring.py.""" import pandas as pd IMPACT_ORDER = {"MODIFIER": 0, "LOW": 1, "MODERATE": 2, "HIGH": 3} CATEGORICAL = ["consequence"] NUMERIC = ["impact_rank", "gnomad_af", "cadd_phred", "am_pathogenicity"] def build(df: pd.DataFrame) -> pd.DataFrame: out = pd.DataFrame() out["impact_rank"] = df["impact"].map(IMPACT_ORDER).fillna(0) out["gnomad_af"] = pd.to_numeric(df["gnomad_af"], errors="coerce").fillna(0.0) out["cadd_phred"] = pd.to_numeric(df["cadd_phred"], errors="coerce") out["am_pathogenicity"] = pd.to_numeric(df["am_pathogenicity"], errors="coerce") out["consequence"] = df["consequence"].astype("category") return out