Skip to content

Fix non-deterministic field ordering in AnnotationSourceTSV annotation extraction#403

Draft
Copilot wants to merge 2 commits intonanno_multi_genefrom
copilot/sub-pr-400-another-one
Draft

Fix non-deterministic field ordering in AnnotationSourceTSV annotation extraction#403
Copilot wants to merge 2 commits intonanno_multi_genefrom
copilot/sub-pr-400-another-one

Conversation

Copy link

Copilot AI commented Feb 27, 2026

AnnotationSourceTSV was iterating over HashMap.keySet() to build the precomputed fieldNames/fieldPositions arrays, producing annotation output in arbitrary order rather than the user-requested field order.

Changes

  • AnnotationSourceTSV.java: Replace keyset iteration with fieldNames.split(",") when building precomputed arrays. The HashMap is retained for O(1) position lookups; only the iteration source changes.
// Before — non-deterministic HashMap keyset order
this.fieldNames = headerNameAndPosition.keySet().toArray(new String[0]);
this.fieldPositions = new int[this.fieldNames.length];
for (int i = 0; i < this.fieldNames.length; i++) {
    this.fieldPositions[i] = headerNameAndPosition.get(this.fieldNames[i]);
}

// After — preserves user-requested field order
String[] requestedFields = fieldNames.split(",");
this.fieldNames = requestedFields;
this.fieldPositions = new int[requestedFields.length];
for (int i = 0; i < requestedFields.length; i++) {
    this.fieldPositions[i] = headerNameAndPosition.get(requestedFields[i]);
}

Since getHeaderNameAndPositions also splits on "," to build the map, the keys are guaranteed to match — no risk of NullPointerException at lookup time.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Existing AnnotationSourceTSVTest unit tests cover extractFieldsFromRecord and getHeaderNameAndPositions

Are WDL Updates Required?

No WDL changes required.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…erating over fieldNames.split() instead of HashMap keyset

Co-authored-by: holmeso <7066552+holmeso@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback on handling multiple genes in snpeff variant reporting Fix non-deterministic field ordering in AnnotationSourceTSV annotation extraction Feb 27, 2026
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.

2 participants