CaMa recurrence trains on the loaded METABRIC and SCAN-B patients in the total cohort, not on bundled files; the second survival scenario is retired

This commit is contained in:
Roberto Treviño Cervantes
2026-11-22 19:51:20 -06:00
parent 5a10be44d0
commit b3e02f0980
14 changed files with 182 additions and 17113 deletions
+18 -12
View File
@@ -1,7 +1,8 @@
"""CaMa's recurrence analysis as a scenario: the dataflow from the two external cohorts to the registered model, its results and
its routines. Each node is one stage of Luis's scripts (`prep`, `modeling`, `factors`, `calculator`); the training machinery
(`models.dags.training.train`) saves what the nodes `fitted_model`, `metrics`, `routines` and `population` give. The figures the
dashboard shows are in `population["recurrencia"]`.
"""CaMa's recurrence analysis as a scenario: the dataflow from the cohort's patients loaded from METABRIC and SCAN-B (the
`fuente` of each, indexed at her first invasive biopsy) to the registered model, its results and its routines. Each node is one
stage of Luis's scripts (`prep`, `modeling`, `factors`, `calculator`); the training machinery (`models.dags.training.train`)
saves what the nodes `fitted_model`, `metrics`, `routines` and `population` give. The figures the dashboard shows are in
`population["recurrencia"]`.
"""
import numpy as np
@@ -11,17 +12,22 @@ import statsmodels.api as sm
from models.cama.recurrence import calculator as calc
from models.cama.recurrence import factors as fac
from models.cama.recurrence import modeling
from models.cama.recurrence.prep import FILES, PREPARE, Prepared
from models.cama.recurrence.source import data_folder
from models.cama.recurrence.steps import run_steps # noqa: F401 (the CLI's own steps: not a node)
from models.cama.recurrence import cohort as timeline
from models.cama.recurrence.prep import Prepared, finish
COHORTS = ("metabric", "scanb")
def prepared(recurrence: dict) -> dict[str, Prepared]:
"""Each cohort as one table of categories with its covariates (`prep`)."""
folder = data_folder(recurrence["data_dir"])
return {name: PREPARE[name](str(folder / FILES[name]), recurrence["v_max"]) for name in COHORTS}
def dictionary() -> dict:
"""The variables, cohorts and scenarios of `cohorts.toml`."""
return timeline.load()
def prepared(cohort: pd.DataFrame, dictionary: dict, recurrence: dict) -> dict[str, Prepared]:
"""Each cohort's patients as one table of categories with its covariates (`cohort.recode`, then `prep`)."""
fixed = ["paciente", "tiempo_meses", "evento"]
return {name: finish(timeline.recode(cohort, dictionary, name), fixed, dictionary["cohorts"][name]["treatment"],
recurrence["v_max"]) for name in COHORTS}
def fits(prepared: dict[str, Prepared], recurrence: dict) -> dict[str, modeling.CohortModels]:
@@ -122,7 +128,7 @@ def routines(prepared: dict[str, Prepared], fits: dict[str, modeling.CohortModel
return {
"MUESTREO": {"cohortes": {n: {"pacientes": len(p.cohort), "recaidas": int(p.cohort["evento"].sum()), "covariables": len(p.covariates),
"eliminadas_por_colinealidad": p.eliminated} for n, p in prepared.items()},
"criterio": "pacientes con tiempo y estado de recaída; SCAN-B solo mujeres", "origen": "METABRIC y SCAN-B (externas)"},
"criterio": "pacientes con tiempo y estado de recaída; SCAN-B solo mujeres", "origen": "pacientes cargadas de METABRIC y SCAN-B (`fuente`)"},
"DATOS_FALTANTES": {"criterio": "el dato faltante es una categoría más («Desconocido»); no se imputa ni se descarta",
"desconocidos_por_covariable": {n: {c: float((p.cohort[c] == "Desconocido").mean()) for c in p.covariates} for n, p in prepared.items()}},
"METODO_ANALITICO": {"modelos": "regresión logística con selección stepwise y red bayesiana con padres del desenlace por BDeu, uno por horizonte",