Skip to content

Fix madc2vcf_all() "invalid substring arguments" error on off-target alleles#65

Open
shbrainard wants to merge 6 commits into
Breeding-Insight:developmentfrom
shbrainard:fix-madc2vcf-others-empty-substring
Open

Fix madc2vcf_all() "invalid substring arguments" error on off-target alleles#65
shbrainard wants to merge 6 commits into
Breeding-Insight:developmentfrom
shbrainard:fix-madc2vcf-others-empty-substring

Conversation

@shbrainard

Copy link
Copy Markdown

Summary

madc2vcf_all(..., add_others = TRUE) aborts with Error: ... invalid substring arguments on some DArTag datasets.

Root cause

In compare() (R/madc2vcf_all.R), the off-target ("Other") branch computes other_ref_base / other_alt_base with substring() before the existing if (length(pos_ref_idx) > 0) check. When an "Other" allele aligns to the reference with its only mismatch at the target SNP position, that index is removed, leaving pos_ref_idx / pos_alt_idx as integer(0). substring(x, integer(0), integer(0)) errors with "invalid substring arguments", and aborts the run.

The off-target Match branch already protects its substring() calls with the same length(pos_ref_idx) > 0 check; the Other branch applies this check too late.

Fix

Move the two substring() calls inside the existing if (length(pos_ref_idx) > 0) block, mirroring the Match branch. No behavior change when mismatch positions remain.

Verification

  • Reproduced on a real DArTag order: 2 of ~5,400 loci triggered it.
  • After the fix, all loci process and the full add_others = TRUE pipeline completes.
  • The existing tests/testthat/test-madc2vcf_all.R suite passes.

alex-sandercock and others added 6 commits May 19, 2025 09:13
Updated funding source and note about BIGr development.
…atches

When add_others = TRUE, compare() computed other_ref_base/other_alt_base with
substring() before checking that any mismatch positions remained. If an off-target
("Other") allele aligns to the reference with its only mismatch at the target SNP
position, that position is removed and pos_ref_idx/pos_alt_idx become integer(0),
so substring() errors with "invalid substring arguments" and the whole run aborts.

Move the two substring() calls inside the existing 'if (length(pos_ref_idx) > 0)'
guard, mirroring how the off-target Match alleles are already handled. Behavior is
unchanged when mismatch positions remain; existing madc2vcf_all tests still pass.
@Cristianetaniguti Cristianetaniguti changed the base branch from main to development June 19, 2026 14:16
@Cristianetaniguti Cristianetaniguti self-requested a review June 19, 2026 14:16
@Cristianetaniguti

Copy link
Copy Markdown
Collaborator

Hi @shbrainard! Good to have codes from you. Thank you for your contribution, we will take a look and let you know :)

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.

3 participants