Skip to content

Commit

Permalink
Use allele info in VariantContext comparisons for stable sorts
Browse files Browse the repository at this point in the history
  • Loading branch information
clintval committed Feb 14, 2022
1 parent b5af659 commit a79b421
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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,11 +83,17 @@ 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.
final int contigCompare =
this.contigIndexLookup.get(firstVariantContext.getContig()) - this.contigIndexLookup.get(secondVariantContext.getContig());
return contigCompare != 0
? contigCompare
: firstVariantContext.getStart() - secondVariantContext.getStart();
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 (i > secondVariantContext.getAlleles().size()) { return 1; }
contigCompare = firstVariantContext.getAlleles().get(i).compareTo(secondVariantContext.getAlleles().get(i));
if (contigCompare != 0) return contigCompare;
}
}
return contigCompare;
}

/**
Expand Down

0 comments on commit a79b421

Please sign in to comment.