OpenIslet

scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py

OpenIslet Wave-6 Round-14 Prospective Candidate W6-C2 (Staged Slot IIP-0047 -> Provisional

script Release v0.8.0 gen-eb955f8266035aba 466 KB · 37 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py · SHA-256: 25e12d578ba80b55…

        "bank_origin": bank_origin,
        "canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
        "construct_manifest_sha256": c_sha,
        "evidence_tier": ev_tier,
        "decision": decision,
        "authority_scope": authority_scope,
        "bank_qualified": bank_qualified,
        "promotion_authorized": promotion_authorized,
    }

    all_candidate_fields: Tuple[str, ...] = (
        CURRENT_ASSAY_ALWAYS_BOUND_FIELDS
        + CURRENT_ASSAY_STAGE1_OMENTUM_BOUND_FIELDS
        + CURRENT_ASSAY_STAGE1_COMMON_BOUND_FIELDS
        + CURRENT_ASSAY_EXVIVO_REST_STAGE0_BOUND_FIELDS
        + CURRENT_ASSAY_EXVIVO_REST_STAGE1_BOUND_FIELDS
        + ("measured_bed_po2_mmhg",)
    )
    for fname in all_candidate_fields:
        if fname in payload and payload[fname] is not None:
            body[fname] = payload[fname]

    load_v = payload.get("areal_loading_ieq_per_cm2")
    if load_v is None:
        load_v = payload.get("areal_loading_ieq_cm2")
    if load_v is not None:
        body["areal_loading_ieq_per_cm2"] = load_v

    return seal_upstream_evidence_record(body)


seal_gate35_current_assay_record = seal_gate33_current_assay_record


def sync_gate33_fixture_current_assay_and_store(
    payload: Dict[str, Any],
    store: Optional[Dict[str, Dict[str, Any]]] = None,
    *,
    arm_manifest: Optional[Dict[str, Any]] = None,
    index_by_sha: bool = False,
) -> Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]:
    """Return a copy of payload with re-sealed GATE-35 current_assay_evidence_record and an updated trusted store."""
    out_payload = dict(payload)
    cur_rec = seal_gate33_current_assay_record(out_payload, arm_manifest=arm_manifest)
    out_payload["current_assay_evidence_record"] = cur_rec
    out_store: Dict[str, Dict[str, Any]] = dict(store) if store is not None else {}
    if index_by_sha:
        out_store[cur_rec["archive_sha256"]] = dict(cur_rec)
    else:
        out_store[cur_rec["record_id"]] = dict(cur_rec)
    return out_payload, out_store


def _make_per_leaf_records(
    *,
    loading_ieq_cm2: float,
    total_ieq: float,
    bed_bot: float,
    bed_top: float,
    face_o2: float,
    core_o2: float,
    thickness_um: float = 120.0,
    d_o2_matrix_m2_s: float = 1.50e-9,
    n_leaves: int = 2,
) -> Tuple[float, List[Dict[str, Any]]]:
    """Build physically reconciled separated-leaf records with implied loading <= loading_ieq_cm2."""
    total_area_cm2 = math.ceil((total_ieq / loading_ieq_cm2) * 10000.0) / 10000.0
    leaf_ieq = total_ieq / float(n_leaves)
    leaf_area = total_area_cm2 / float(n_leaves)
    leaves = [
        {
            "leaf_id": f"LEAF-{i:02d}",
            "loaded_ieq": leaf_ieq,
            "measured_area_cm2": leaf_area,
            "measured_thickness_um": thickness_um,
            "measured_d_o2_matrix_m2_s": d_o2_matrix_m2_s,
            "measured_face_o2_mmhg": face_o2,
            "measured_core_o2_mmhg": core_o2,
            "bed_face_bot_po2_mmhg": bed_bot,
            "bed_face_top_po2_mmhg": bed_top,
            "direct_o2_sensor_coverage_verified": True,
        }
        for i in range(1, n_leaves + 1)
    ]
    return total_area_cm2, leaves


def _make_subject_cohorts(lot_id: str, *, capsule_um: float = 8.8, retrieval_pct: float = 99.94) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
    porcine = [
        {
            "subject_id": f"PIG-{i:02d}",
            "species": "PORCINE",
            "lot_id": lot_id,
            "followup_duration_days": 90.0,
            "capsule_sampling_day": 90.0,
            "retrieval_assessment_day": 90.0,
            "survival_to_endpoint": True,
            "major_hemorrhage_or_dehiscence": False,
            "bowel_obstruction_event": False,
            "omental_torsion_event": False,
            "grade3_adhesion_event": False,
            "monitored_complications": [],
            "surgical_safety_pass": True,
            "month3_capsule_um": capsule_um,
            "retrieval_mass_pct": retrieval_pct,
            "total_implanted_cells": 450_000_000,
            "residual_viable_cells_measured": 135_000,
            "residual_sampling_fraction": 0.50,
            "localization_verified": True,
        }
        for i in range(1, 7)
    ]
    nhp = [
        {
            "subject_id": f"NHP-{i:02d}",
            "species": "NHP",
            "lot_id": lot_id,
            "preimplant_diabetic_verified": True,
            "baseline_exogenous_insulin_u_kg_d": 0.85,
            "baseline_fasting_c_peptide_ng_ml": 0.05,
            "dose_ieq_per_kg": 9200.0,
            "achieved_insulin_independence": True if i <= 3 else False,
            "followup_duration_days": 91.0 if i <= 3 else 90.0,
            "capsule_sampling_day": 90.0,
            "omentectomy_performed": True if i <= 3 else None,
            "omentectomy_procedure_id": f"OMENT-NHP-{i:02d}" if i <= 3 else None,
            "omentectomy_day": 90.0 if i <= 3 else None,
            "cpeptide_extinction_subject_id": f"NHP-{i:02d}" if i <= 3 else None,
            "cpeptide_extinction_procedure_id": f"OMENT-NHP-{i:02d}" if i <= 3 else None,
            "cpeptide_extinction_assessment_day": 91.0 if i <= 3 else None,
            "post_omentectomy_cpeptide_extinguished": True if i <= 3 else None,
            "lloq_c_peptide_ng_ml": 0.05 if i <= 3 else None,
            "pre_explant_stimulated_c_peptide_ng_ml": 1.85 if i <= 3 else None,
            "post_explant_stimulated_c_peptide_ng_ml": 0.02 if i <= 3 else None,
            "portal_gradient_assessment_day": 90.0 if i <= 3 else None,
            "insulin_indep_day": (28.0 + 4.0 * i) if i <= 3 else None,
            "bowel_obstruction_event": False,
            "omental_torsion_event": False,
            "grade3_adhesion_event": False,
            "monitored_complications": [],
            "month3_capsule_um": capsule_um,
            "residual_exogenous_insulin_u_kg_d": 0.0 if i <= 3 else 0.15,
            "paired_dynamic_gsis_pass": True if i <= 3 else False,
            "retrieval_mass_pct": retrieval_pct,
            "total_implanted_cells": 140_000_000,
            "residual_viable_cells_measured": 42_000,
            "residual_sampling_fraction": 0.50,
            "localization_verified": True,
        }
        for i in range(1, 5)
    ]
    return porcine, nhp


def make_synthetic_valid_gate33_payload(
    arm_manifest: Dict[str, Any],
    *,
    arm_key: str = "D",
    site: str = "R4_OMENTUM_LEAD",
    scope: str = "CLINICAL_PROMOTION",
    exvivo_rest_applied: bool = True,
    evidence_tier: str = "SYNTHETIC_FIXTURE",
    lot_id: Optional[str] = None,
    bank_id: Optional[str] = None,
    construct_manifest_sha256: Optional[str] = None,
    upstream_records: Optional[Dict[str, Dict[str, Any]]] = None,
    dec009_primate_free: bool = False,
) -> Dict[str, Any]:
    """Build a complete Round-14 Gate-35 fixture with sealed current_assay_evidence_record (default SYNTHETIC_FIXTURE)."""
    spec = arm_manifest["arms"][arm_key]
    eff_lot = lot_id if lot_id is not None else (
        f"SYNTH-LOT-{arm_key}-001" if evidence_tier == "SYNTHETIC_FIXTURE" else f"MOCK-WETLAB-LOT-{arm_key}-001"
    )
    eff_bank = bank_id if bank_id is not None else f"BANK-{arm_key}-001"
    eff_csha = construct_manifest_sha256 if construct_manifest_sha256 is not None else _fixture_construct_manifest_sha256(arm_key, spec["product_id"])
    if upstream_records is not None:
        upstream_recs = {k: dict(v) for k, v in upstream_records.items()}
        up_src_rec = upstream_recs.get("upstream_gate34_record") or upstream_recs.get("upstream_gate32_record")
        if isinstance(up_src_rec, dict) and "construct_manifest_sha256" in up_src_rec:
            eff_csha = str(up_src_rec["construct_manifest_sha256"])
    else:
        upstream_recs, _ = _make_upstream_fixture_bundle(
            arm_manifest, arm_key=arm_key, lot_id=eff_lot, evidence_tier=evidence_tier,
            bank_id=eff_bank, construct_manifest_sha256=eff_csha,
        )
    porcine_subjs, nhp_subjs = _make_subject_cohorts(eff_lot, capsule_um=8.8, retrieval_pct=99.94)
    total_ieq = 500_000.0 if site == "R4_OMENTUM_LEAD" else 300_000.0
    total_area_cm2, leaf_recs = _make_per_leaf_records(
        loading_ieq_cm2=1200.0,
        total_ieq=total_ieq,
        bed_bot=36.0,
        bed_top=37.0,
        face_o2=16.12,
        core_o2=14.16,
        thickness_um=120.0,
        d_o2_matrix_m2_s=1.50e-9,
        n_leaves=2,
    )

    stage1_pathway_fields: Dict[str, Any] = {}
    if dec009_primate_free:
        stage1_pathway_fields.update({
            "dec009_primate_free_pathway": True,
            "dec009_pillar1_humanized_mouse_efficacy_pass": True,
            "dec009_pillar2_chandler_loop_50donor_pass": True,
            "dec009_pillar1_glp_biodistribution_erasure_pass": True,
            "dec009_post_explant_cpeptide_extinction_verified": True,
            "porcine_portal_peripheral_insulin_gradient": 1.85,
        })
    else:
        stage1_pathway_fields.update({
            "dec009_primate_free_pathway": False,
            "dec009_fda_cber_nhp_exception_authorized": True,
            "nhp_subjects": nhp_subjs,
            "nhp_r4o05_portal_peripheral_insulin_gradient": 1.85,
            "nhp_r4o05_post_omentectomy_cpeptide_extinction": True,
        })

    base: Dict[str, Any] = {
        "evaluation_scope": scope,
        "evidence_tier": evidence_tier,
        "lot_id": eff_lot,
        "bank_id": eff_bank,
        "canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
        "construct_manifest_sha256": eff_csha,
        "deployment_site": site,
        "arm_key": arm_key,
        "product_id": spec["product_id"],
        "safety_switch_id": spec["safety_switch"],
        "dual_switch_lot_qualified": bool(spec["dual_switch_required_for_release"]),
        **upstream_recs,
        "clinical_matrix_id": (
            "GMP_AUTOLOGOUS_PLASMA_THROMBIN" if site == "R4_OMENTUM_LEAD" else "BIODEGRADABLE_THIN_PLANAR_CARRIER_SHEET"
        ),
        "needle_microtracks_used": False,
        "coformulated_immune_cuff_agents": ["sCR1_v2", "THBD-M406L", "CD200-ECD"],
        "polyglactin_sutures_used": False,
        "ductal_cytokeratin_impurity_pct": 1.1,
        "endotoxin_eu_per_ml": 0.12,
        "sterility_pass": True,
        "mycoplasma_negative": True,
        "analytical_fasl_ug": 0.0,
        "hepatocyte_72h_caspase37_u95_fold": 1.04,
        "hepatocyte_72h_alt_ldh_u95_fold": 1.06,
        "cuff_leachate_assay_passed": True,
        "construct_layout": "STAGGERED_BILAYER",
        "construct_thickness_um": 120.0,
        "cluster_min_diam_um": 54.0,
        "cluster_d_rms3_um": 59.5,
        "cluster_d_p95_um": 62.5,