OpenIslet

scripts/build_cross_study_graph.py

Step 4: Full Recursive Schema Validator & Cross-Study Causal / Effect-Modifier Graph Builder

script Release v0.8.0 gen-eb955f8266035aba 62 KB · 5 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/build_cross_study_graph.py · SHA-256: 94a7b2be6571d9e1…

            "effects_by_direction": dict(sorted(direction_counts.items())),
            "effects_by_polarity_orientation_sign": dict(sorted(orientation_sign_counts.items())),
            "matched_context_multi_hop_chains_count": matched_ctx_chains,
            "cross_context_hypothesis_chains_count": len(multi_hop_chains) - matched_ctx_chains,
        },
        "multi_hop_hypothesis_paths_enumeration_policy": {
            "estimand_role": "Heuristic cross-study hypothesis-generation paths (NOT used as quantitative input weights in stack ranking)",
            "per_bridge_node_incoming_cap": 25,
            "per_bridge_node_outgoing_cap": 25,
            "global_exported_chain_cap": 500,
            "chains_total_before_cap": chains_total_before_cap,
            "active_non_terminal_bridge_concepts_represented_in_export": len(exported_bridge_counts),
            "ordering_basis": "Balanced round-robin selection across all non-terminal bridge concepts (prioritizing matched cell-source/stage context and total supporting study count within each bridge concept)",
            "untruncated_per_bridge_node_chain_counts": untruncated_bridge_counts,
            "exported_per_bridge_node_chain_counts": dict(sorted(exported_bridge_counts.items())),
        },
        "target_gene_atlas": target_gene_atlas,
        "shared_cross_study_bridge_nodes": shared_bridge_nodes,
        "multi_hop_cross_study_causal_chains": multi_hop_chains,
        "effect_modifiers_by_canonical_class": dict(modifiers_by_class),
        "cross_gate_pleiotropic_discoveries": pleiotropic_bonuses,
        "residual_failure_and_complementary_lever_pairs": residual_escapes,
        "regime_thresholds": regime_thresholds,
        "all_causal_edges": edges_all,
    }

    out_file = EXTRACTED_DIR / "cross_study_discovery_graph.json"
    with open(out_file, "w", encoding="utf-8") as f:
        json.dump(graph_out, f, indent=2, ensure_ascii=False)
        f.write("\n")

    print(
        f"[GRAPH VALIDATED] {len(studies)} studies | {total_arms} arms | "
        f"{total_atomic_effects} atomic effects | {total_modifier_interactions} effect modifiers | "
        f"{total_causal_edges} causal edges | {len(shared_bridge_nodes)} shared cross-study bridge nodes"
    )


if __name__ == "__main__":
    main()