-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use allele info in VariantContext comparisons for stable sorts (#1593)
* Use allele info in VariantContext comparisons for more stable sorts * Ensure a more stable sort for varying length alleles, add unit tests
- Loading branch information
Showing
3 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/test/java/htsjdk/variant/variantcontext/VariantContextComparatorUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package htsjdk.variant.variantcontext; | ||
|
||
import htsjdk.HtsjdkTest; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Unit tests for VariantContextComparator. | ||
*/ | ||
public class VariantContextComparatorUnitTest extends HtsjdkTest { | ||
private Allele refA, altG, altT; | ||
|
||
@BeforeSuite | ||
public void before() { | ||
refA = Allele.create("A", true); | ||
altG = Allele.create("G", false); | ||
altT = Allele.create("T", false); | ||
} | ||
|
||
@Test | ||
public void testVariantContextsWithSameSiteSortLexicographicallyByAlleleIdentical() { | ||
final String contig = "chr1"; | ||
final VariantContextComparator comparator = new VariantContextComparator(Collections.singletonList(contig)); | ||
final VariantContextBuilder builder = new VariantContextBuilder("test", contig, 1, 1, Collections.emptyList()); | ||
|
||
final VariantContext variant1 = builder.alleles(Arrays.asList(refA, altG)).make(); | ||
final VariantContext variant2 = builder.alleles(Arrays.asList(refA, altG)).make(); | ||
|
||
final int compare = comparator.compare(variant1, variant2); | ||
Assert.assertEquals(compare, 0); // TODO: What other criteria might we sort by to break this tie? | ||
} | ||
|
||
@Test | ||
public void testVariantContextsWithSameSiteSortLexicographicallyByAllele() { | ||
final String contig = "chr1"; | ||
final VariantContextComparator comparator = new VariantContextComparator(Collections.singletonList(contig)); | ||
final VariantContextBuilder builder = new VariantContextBuilder("test", contig, 1, 1, Collections.emptyList()); | ||
|
||
final VariantContext variant1 = builder.alleles(Arrays.asList(refA, altG)).make(); | ||
final VariantContext variant2 = builder.alleles(Arrays.asList(refA, altT)).make(); | ||
|
||
final int compare = comparator.compare(variant1, variant2); | ||
Assert.assertEquals(compare, -1); | ||
} | ||
|
||
@Test | ||
public void testVariantContextsWithSameSiteSortLexicographicallyByAlleleThenExtraAllelesForFirstVariant() { | ||
final String contig = "chr1"; | ||
final VariantContextComparator comparator = new VariantContextComparator(Collections.singletonList(contig)); | ||
final VariantContextBuilder builder = new VariantContextBuilder("test", contig, 1, 1, Collections.emptyList()); | ||
|
||
final VariantContext variant1 = builder.alleles(Arrays.asList(refA, altG, altT)).make(); | ||
final VariantContext variant2 = builder.alleles(Arrays.asList(refA, altG)).make(); | ||
|
||
final int compare = comparator.compare(variant1, variant2); | ||
Assert.assertEquals(compare, 1); | ||
} | ||
|
||
@Test | ||
public void testVariantContextsWithSameSiteSortLexicographicallyByAlleleThenExtraAllelesForSecondVariant() { | ||
final String contig = "chr1"; | ||
final VariantContextComparator comparator = new VariantContextComparator(Collections.singletonList(contig)); | ||
final VariantContextBuilder builder = new VariantContextBuilder("test", contig, 1, 1, Collections.emptyList()); | ||
|
||
final VariantContext variant1 = builder.alleles(Arrays.asList(refA, altG)).make(); | ||
final VariantContext variant2 = builder.alleles(Arrays.asList(refA, altG, altT)).make(); | ||
|
||
final int compare = comparator.compare(variant1, variant2); | ||
Assert.assertEquals(compare, -1); | ||
} | ||
} |