Skip to content

fix: expand() preserves non-standard rowRanges columns (#85)#95

Open
jmg421 wants to merge 3 commits into
Bioconductor:develfrom
jmg421:fix/85-expand-preserve-mcols
Open

fix: expand() preserves non-standard rowRanges columns (#85)#95
jmg421 wants to merge 3 commits into
Bioconductor:develfrom
jmg421:fix/85-expand-preserve-mcols

Conversation

@jmg421

@jmg421 jmg421 commented Jun 30, 2026

Copy link
Copy Markdown

Summary

expand() on a CollapsedVCF with multi-allelic sites was dropping all user-added mcols from rowRanges. For example, a column like SNP_name added via mcols(rowRanges(vcf))$SNP_name <- ... would disappear after expand().

Root Cause

In methods-expand.R, the multi-allelic expansion path had:

rdexp <- rd[idx, ]
mcols(rdexp) <- NULL

This wiped ALL metadata columns. The rd[idx, ] subsetting already correctly repeats rows for multi-allelic sites — the mcols <- NULL was unnecessary and destructive.

Note: the fast path (all(elt == 1L), no multi-allelic sites) already preserved user columns correctly by passing rd directly to VCF().

Fix

Remove the mcols(rdexp) <- NULL line. Simply use rd[idx, ] which preserves all columns. The VCF() constructor stores these in the rowRanges slot separately from the fixed fields (REF/ALT/QUAL/FILTER are in the fixed slot).

Testing

Added test_expand_preserves_nonstandard_mcols to existing test file using the exact reproducer from the issue.

Reproducer (from issue)

vcf <- VCF(rowRanges = GRanges("chr1", IRanges(1:4*3, width=c(1, 2, 1, 1))))
alt(vcf) <- DNAStringSetList("A", c("TT"), c("G", "A"), c("TT", "C"))
ref(vcf) <- DNAStringSet(c("G", "AA", "T", "G"))
mcols(rowRanges(vcf))$SNP_name <- paste0("SNP_", 1:4)

vcfLong <- expand(vcf)
# Before fix: SNP_name is gone
# After fix: SNP_name is preserved and correctly expanded
mcols(rowRanges(vcfLong, fixed=FALSE))$SNP_name
# [1] "SNP_1" "SNP_2" "SNP_3" "SNP_3" "SNP_4" "SNP_4"

Fixes #85

vjcitn and others added 3 commits July 17, 2026 21:15
Convert \itemize blocks that used \item{label}{desc} syntax to \describe,
and replace empty \item{}{} labels in \describe blocks with the function
signature from the body, resolving all checkRd warnings in isSNV-methods,
PolyPhenDb-class, readVcf-methods, SIFTDb-class, summarizeVariants-methods,
VariantType-class, VCF-class, VcfFile-class, VCFHeader-class, VRanges-class,
and VRangesList-class Rd files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
expand() on a CollapsedVCF was calling mcols(rdexp) <- NULL after
expanding rowRanges, which wiped all user-added metadata columns
(e.g. SNP_name, num_alts). The fast path (no multi-allelic sites)
already preserved these columns correctly.

Fix: simply expand rd[idx, ] without wiping mcols. The VCF()
constructor accepts rowRanges with extra mcols — they are stored
in the rowRanges slot alongside paramRangeID, separate from the
fixed fields (REF/ALT/QUAL/FILTER).

Fixes Bioconductor#85
@jmg421
jmg421 force-pushed the fix/85-expand-preserve-mcols branch from c525658 to f4bf45c Compare July 18, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expand() and non-standard rowRanges columns

2 participants