feat(l2g): add EGL and training set generation steps#1272
Draft
addramir wants to merge 1 commit into
Draft
Conversation
Introduce two new pipeline steps that generate the L2G gold standard inside gentropy, replacing the out-of-band notebook workflow. - EffectorGeneListStep: assembles the Effector Gene List (EGL) from up to three optional platform-ETL sources (rare-variant evidence, ChEMBL clinical precedence, legacy OTG gold standard). Each source and its filter (score / clinical phase / confidence) is a parameter. - TrainingSetStep: labels the L2G feature matrix against the EGL and applies parametrised, toggleable cleaning filters (replication, max positives per locus, PPI/STRING, distance leakage, protein-coding, deduplication), writing the training set as JSON. Register both step configs and add docs + unit tests. Refs: opentargets/issues#3783 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 task
addramir
marked this pull request as draft
July 23, 2026 16:55
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces two new pipeline steps to generate the L2G gold standard inside gentropy (replacing the prior notebook-based process): an Effector Gene List (EGL) builder and a Training Set generator that labels and filters the L2G feature matrix.
Changes:
- Added
EffectorGeneListStepto assemble a deduplicated(diseaseId, targetId)EGL from optional platform/legacy sources with configurable filters. - Added
TrainingSetStepto label the L2G feature matrix against the EGL and apply a configurable chain of cleaning/leakage-reduction filters, writing the final JSON output. - Registered both steps in Hydra config, added API docs pages, and added unit tests for EGL and training-set filters/validation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/gentropy/effector_gene_list.py |
New EGL step implementation combining optional evidence sources into a distinct parquet output. |
src/gentropy/training_set.py |
New training set step implementation: annotate + label + optional filters + JSON output. |
src/gentropy/config.py |
Adds EffectorGeneListConfig and TrainingSetConfig and registers both steps. |
tests/gentropy/step/test_effector_gene_list_step.py |
End-to-end tests validating EGL source combination and filtering. |
tests/gentropy/step/test_training_set_step.py |
Unit tests for training-set labeling and filter logic + constructor validation. |
docs/python_api/steps/effector_gene_list.md |
API docs stub for the EGL step. |
docs/python_api/steps/training_set.md |
API docs stub for the training set step. |
Comments suppressed due to low confidence (2)
src/gentropy/effector_gene_list.py:101
- Calling
.count()just to log source sizes triggers a full Spark action (and will likely be repeated again during the union/write), which can be very expensive at pipeline scale. Prefer logging that the source was included (or compute counts only under an explicit debug flag with caching if really needed).
logger.info("Clinical source contributes %d pairs", clinical.count())
src/gentropy/effector_gene_list.py:108
- Calling
.count()just to log source sizes triggers a full Spark action (and will likely be repeated again during the union/write), which can be very expensive at pipeline scale. Prefer logging that the source was included (or compute counts only under an explicit debug flag with caching if really needed).
logger.info("Gold standard source contributes %d pairs", gold.count())
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| apply_replication_filter: bool = True, | ||
| min_replication_studies: int = 2, | ||
| max_gsp_per_locus: int = 2, | ||
| apply_interaction_filter: bool = True, |
| apply_replication_filter: bool = True | ||
| min_replication_studies: int = 2 | ||
| max_gsp_per_locus: int = 2 | ||
| apply_interaction_filter: bool = True |
Comment on lines
+333
to
+344
| interactions = session.load_data( | ||
| interaction_path, "parquet", recursiveFileLookup=True | ||
| ) | ||
| return ( | ||
| interactions.filter( | ||
| (f.col("sourceDatabase") == interaction_source) | ||
| & (f.col("scoring") >= interaction_score_threshold) | ||
| & (f.col("targetA") != f.col("targetB")) | ||
| ) | ||
| .select("targetA", "targetB") | ||
| .distinct() | ||
| ) |
Comment on lines
+153
to
+156
| if apply_distance_filter: | ||
| labelled = labelled.filter( | ||
| ~((f.col("GSP") == 1) & (f.col("distanceSentinelFootprint") == 0)) | ||
| ) |
Comment on lines
+79
to
+91
| def test_filter(self, spark: SparkSession) -> None: | ||
| """A negative that is a STRING partner of a positive in the same locus is removed.""" | ||
| labelled = spark.createDataFrame( | ||
| [ | ||
| ("sl1", "ENSG_POS", 1), | ||
| ("sl1", "ENSG_PARTNER", 0), # interacts with ENSG_POS -> removed | ||
| ("sl1", "ENSG_OTHER", 0), # no interaction -> kept | ||
| ], | ||
| ["studyLocusId", "geneId", "GSP"], | ||
| ) | ||
| interactions = spark.createDataFrame( | ||
| [("ENSG_POS", "ENSG_PARTNER")], ["targetA", "targetB"] | ||
| ) |
| rare = self._rare_variant_pairs( | ||
| session, rare_variant_evidence_paths, rare_variant_score_threshold | ||
| ) | ||
| logger.info("Rare-variant source contributes %d pairs", rare.count()) |
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.
Context
Closes the automation gap described in opentargets/issues#3783 — the L2G gold standard was being generated outside gentropy from ad-hoc notebooks (
EGL_and_training_set/2606/01_EGL_preparation.ipynband02_training_set.ipynb). This PR brings that logic into the pipeline as two parametrised steps.What's added
EffectorGeneListStep(gentropy.effector_gene_list)Builds the Effector Gene List (EGL): a deduplicated set of
(diseaseId, targetId)pairs. It combines up to three optional platform-ETL sources, each with its own parametrised filter:rare_variant_evidence_paths(list, unioned)rare_variant_score_threshold(0.75)clinical_evidence_pathapproved_clinical_phases(PHASE_4/APPROVAL/PHASE_3/PREAPPROVAL)gold_standard_path(JSON)gold_standard_confidence(High/Medium)Output: one clean parquet with distinct
diseaseId,targetId.TrainingSetStep(gentropy.training_set)Labels the L2G feature matrix against the EGL (
positive/negative) and applies a chain of toggleable, parametrised cleaning filters mirroring notebook 02:apply_replication_filter, default on;min_replication_studies=2)max_gsp_per_locus=2)apply_interaction_filter,interaction_source,interaction_score_threshold)apply_distance_filter)protein_coding_only)apply_deduplication)Output: clean JSON matching the notebook example (
studyLocusId,geneId,diseaseIds,variantId,studyId,goldStandardSet).Also
EffectorGeneListConfig/TrainingSetConfigregistered aseffector_gene_listandtraining_setsteps.docs/python_api/steps/.Notes for review
L2GGoldStandardschema (keptdiseaseIdsarray), per request. It does not yet plug directly intoLocusToGeneTrainTestSplitStep; happy to add a schema-conformant variant if wanted._no_replpath — it's a single flag to flip).🤖 Generated with Claude Code