Tolerate flip-twin collapse in .ldFromSketch instead of erroring - #572
Open
Yining97 wants to merge 1 commit into
Open
Tolerate flip-twin collapse in .ldFromSketch instead of erroring#572Yining97 wants to merge 1 commit into
Yining97 wants to merge 1 commit into
Conversation
When the requested set carries a variant and its ref/alt-swapped twin (e.g. a panel that stores both orientations, imputed by RAISS as two), matchVariants merges the pair and .ldFromSketch mislabeled the drop as a panel absence and stopped. Count only genuine absences (position not on the panel) toward that error; build LD on the deduplicated set and realign z/N at the fine-mapping, kriging, and zMismatch callers. Genuine absences still error; distinct multi-allelic ALTs are unaffected.
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.
Problem
On an LD panel that stores a variant in both ref/alt orientations (e.g. ADSP R5: 6,365 such records on chr19; R4 has none), RAISS imputes both orientations — each is a distinct panel
variant_idabsent from the observed GWAS — so a region's variant set ends up carrying a variant and its own ref/alt-swapped twin..ldFromSketchcallsmatchVariants(allowFlip = TRUE), which treats a variant and its swap as the same variant and merges the pair to one match. The old code then computednMissing = length(requested) - length(matched) > 0and stopped with "N variant id(s) not present in the LD sketch panel" — but nothing is absent; the pair merged. Two real regions died this way (APOE in the kriging prefilter; chr11 in the fine-mapping LD build), making R5 unusable end to end.Fix
.ldFromSketchnow distinguishes a collapsed flip-twin (a requested id whose(chrom, pos)IS on the panel but merged onto its sibling) from a genuine absence (position not on the panel at all). Only genuine absences count toward theonMissing = "error"stop; the LD matrix is built on the deduplicated set and the survivors are exposed viakeptVariantIds(now always, not just under"drop"). The callers that use the matrix alongsidez/Nrealign to the survivors: a new.fmAlignToKeptLdhelper at both fine-mapping sites, and adfrow-drop at the kriging prefilter and zMismatch QC. No panel/data change — this makes pecotmr tolerant of a panel that carries both orientations.Preserved: the genuine-absence safety check still errors, and distinct multi-allelic ALT alleles at one position are never merged (verified) so they still enter the credible set. The dropped twin is the same variant (its z is the sign-flip of the kept one), so results are unchanged.
Scope: covers the GWAS RSS path (fine-mapping both methods, kriging, zMismatch).
jointEngine/causalInference/twasWeightsare out of that path with different vector shapes; theirz/Nrealignment is deferred (the central fix already removes the misleading error there).Validation
onMissing="error"→ no stop, deduplicated LD matrix withkeptVariantIds; genuine absence still errors; distinct ALTs don't collapse..fmAlignToKeptLdrealignsz/n/afcorrectly (no-op otherwise); end-to-endfineMappingPipeline(GwasSumStats)on a flip-twin region fits on the deduplicated set (z len 3, R 3x3 from 4 requested)..ldFromSketchconsumer (test_ld 217, sumstatsQc 325, fineMapping 185, colocboost 42, cip 69, twas 166, jointEngine 57, coloc 36, variantId 100). The 6test_ctwasPipeline.Rerrors are pre-existing onmain(confirmed by stash comparison), unrelated.Tests added: test_ld.R +3, test_fineMappingPipeline.R +2.
🤖 Generated with Claude Code