Repository navigation
Build KEEP co-occurrence from OMOP and MIMIC histories - #6
Merged
lee-leonardo merged 10 commits intoNov 21, 2026
Merged
Conversation
Reads Athena OMOP vocabularies and builds the SNOMED "Disease" hierarchy used by KEEP (depth-limited, all parents kept, orphans re-attached) plus an ICD-9-CM/ICD-10-CM to standard concept mapper that accepts MIMIC's dot-free codes. Adds synthetic-data tests, docs, and an example script that reports the depth ablation and MIMIC-IV coverage as counts only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrebVyPi1jFyjkAiLbLSC1
- Split omop.py into pyhealth/medcode/omop/ (vocabulary, condition_hierarchy, icd_mapper); public imports unchanged. Tests split to match, sharing tests/core/omop_test_utils.py. - Rename ConditionHierarchy to OMOPConditionHierarchy. - to_triples(direction=...) and new to_knowledge_graph(); rescue edges get their own relation; knowledge graph defaults to parent -> child so GraphProcessor reaches ancestors from a child seed. - Add OMOPVocabularyFormat for non-Athena vocabulary files. - map_frame() and coverage() accept polars LazyFrames. - Docs: KnowledgeGraph/GraphProcessor example; rescue described as an adapter policy. Example script documents task and processor entry points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrebVyPi1jFyjkAiLbLSC1
lee-leonardo
force-pushed
the
task/llee_keep_cooccurrence
branch
from
November 16, 2026 20:41
44ac3b6 to
3ee408a
Compare
Maps observed concept codes to retained SNOMED ancestors within a depth limit of the "Disease" root (KEEP, Elhussein et al., CHIL 2025) and projects the successful paths into one PyG Data graph per sample with edge_index, edge_type, node_ids, x, seed_mask, target_mask and an edge-aligned closure_only mask. Two entry points build the same internal index: a generic constructor over pyhealth.graph.KnowledgeGraph (hierarchy relation supplied parent -> child, optional authoritative root depths and closure pairs) and from_omop, which derives the uncut condition subtree, closure-derived root depths and the all-domain classification universe from the OMOPVocabulary reader. pyhealth/medcode/omop.py is unchanged. The depth cutoff is target eligibility over the uncut subtree, so deep sources and intermediates stay traversable; the target policy (first_retained / all_retained) is an explicit caller choice; rollup_codes returns one typed result per input occurrence so tasks keep their event IDs and count converging targets once; and path_source="closure" adds separation-one CONCEPT_ANCESTOR pairs, flagged closure_only where no direct "Is a" row supports them. Orphan-rescue shortcuts are deferred and stay available through the reader's hierarchy export. Tests port the standalone behavioural reference fixtures to the generic path (exact edges and masks, both policies, root inclusion, supplied depths that disagree with graph distances, invalid DAGs, PyG batching and disk round-trip) and add a synthetic Athena-discrepancy suite reproducing the recorded 1075201/140708 signature: direct mode reports no_target where closure mode returns the target and flags the stitched edge, with parity checks against ConditionHierarchy.retained_ancestors and ICD one-to-many event mapping. Adds an RST page with runnable examples, cross-linked from the medcode OMOP section and the processors toctree.
The OMOP factory now builds a pyhealth.graph.KnowledgeGraph over the uncut Disease subtree with explicit entity ids, so isolated concepts (concepts whose incoming edges were filtered out) stay addressable and even an edge-free, root-only subtree supports identity mappings; KnowledgeGraph accordingly accepts an empty triple list when explicit entity and relation mappings are provided. Both entry points emit Data.node_ids as integer graph entity ids decoded through id2entity. process() now projects node features: the generic path uses KnowledgeGraph.node_features, and from_omop accepts node_features_by_code keyed by string OMOP concept id, aligns the vectors to the graph, and zero-fills entities without vectors (untrained deep sources and traversal intermediates included). Empty samples keep the feature width so empty and nonempty samples batch together. The cache fingerprint (schema v2) covers the entity-id mapping and the feature contents. Adds tests for feature projection and alignment, zero filling, empty/nonempty batching, pickle round-tripping, identity projection on an edge-free ontology, and the ICD-to-embedding path, and documents a pretrained-embedding section with a runnable example. Line lengths on the new code are held to the 88-character contributor limit.
lee-leonardo
force-pushed
the
task/llee_keep_cooccurrence
branch
from
November 17, 2026 19:43
8fa97df to
46261db
Compare
rishabshah
marked this pull request as ready for review
November 18, 2026 01:34
rishabshah
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This draft targets
keepand depends on the OMOP vocabulary work in #2 and the ancestor roll-up work in #4.Validation
44ac3b6.Clinical-data validation and runtime benchmarks are pending.