Skip to content

Commit

Permalink
Revert "Use allele info in VariantContext comparisons for stable sorts (
Browse files Browse the repository at this point in the history
#1593)"

This reverts commit 14a8cc0.

This introduced a serious issue that causes existing valid VCFs to fail as unsorted.
  • Loading branch information
lbergelson committed Nov 23, 2022
1 parent 7346f5b commit e2943b7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 90 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
htsjdk.iws
.command_tmp
.DS_Store
atlassian-ide-plugin.xml
/htsjdk.version.properties
/test-output/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,11 @@ public int compare(final VariantContext firstVariantContext, final VariantContex
// Will throw NullPointerException -- happily -- if either of the chromosomes/contigs aren't
// present. This error checking should already have been done in the constructor but it's left
// in as defence anyway.
int contigCompare = this.contigIndexLookup.get(firstVariantContext.getContig()).compareTo(this.contigIndexLookup.get(secondVariantContext.getContig()));
contigCompare = contigCompare == 0 ? firstVariantContext.getStart() - secondVariantContext.getStart() : contigCompare;
if (contigCompare == 0) {
// Compare variants that have the same genomic span (chr:start-end) lexicographically by all alleles (ref and alts).
for (int i = 0; i < firstVariantContext.getAlleles().size(); i++) {
// If all previous alleles are identical and the first variant has additional alleles, make the first variant greater.
if (i >= secondVariantContext.getAlleles().size()) { return 1; }
contigCompare = firstVariantContext.getAlleles().get(i).compareTo(secondVariantContext.getAlleles().get(i));
if (contigCompare != 0) return contigCompare;
}
}
// If all previous alleles are identical and the second variant has additional alleles, make the second variant greater.
if (firstVariantContext.getAlleles().size() < secondVariantContext.getAlleles().size()) { return -1; }
return contigCompare;
final int contigCompare =
this.contigIndexLookup.get(firstVariantContext.getContig()) - this.contigIndexLookup.get(secondVariantContext.getContig());
return contigCompare != 0
? contigCompare
: firstVariantContext.getStart() - secondVariantContext.getStart();
}

/**
Expand Down

This file was deleted.

0 comments on commit e2943b7

Please sign in to comment.