Kt varient context change #733

Merged
merged 5 commits into from Nov 21, 2016
@@ -37,18 +37,7 @@
import htsjdk.variant.vcf.VCFHeaderLineType;
import java.io.Serializable;
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -1699,10 +1688,8 @@ public Allele getAltAlleleWithHighestAlleleCount() {
return getAlternateAllele(0);
return getAlternateAlleles().stream()
- .map(allele -> new Tuple<>(allele, getCalledChrCount(allele)))
- .max((alleleAndCount1, alleleAndCount2) -> Integer.compare(alleleAndCount1.b, alleleAndCount2.b))
- .get()
- .a;
+ .max(Comparator.comparing(this::getCalledChrCount))
+ .orElse(null);
}
/**
@@ -464,6 +464,8 @@ public void testAccessingCompleteGenotypes() {
Assert.assertEquals(4, vc.getCalledChrCount(T));
Assert.assertEquals(3, vc.getCalledChrCount(ATC));
Assert.assertEquals(2, vc.getCalledChrCount(Allele.NO_CALL));
+
+ Assert.assertEquals(T, vc.getAltAlleleWithHighestAlleleCount());
}
@Test
@@ -487,6 +489,16 @@ public void testAccessingRefGenotypes() {
Assert.assertEquals(4, vc.getCalledChrCount(Aref));
Assert.assertEquals(0, vc.getCalledChrCount(T));
Assert.assertEquals(2, vc.getCalledChrCount(Allele.NO_CALL));
+
+ //bi allelic, only one alt allele
+ Allele expected;
+ if (alleles.size()>1) {
+ expected = alleles.get(1);
+ } else {
+ expected = null;
+ }
+
+ Assert.assertEquals( vc.getAltAlleleWithHighestAlleleCount(), expected);
}
}
@@ -600,6 +612,21 @@ public void testVCFfromGenotypes() {
Assert.assertEquals(4, vc125.getCalledChrCount(Aref));
}
+ @Test
+ public void testMonomorphicVariant() {
+ Genotype g1 = GenotypeBuilder.create("AA", Arrays.asList(Aref, Aref));
+ Genotype g2 = GenotypeBuilder.create("BB", Arrays.asList(Aref, Allele.NO_CALL));
+ Genotype g3 = GenotypeBuilder.create("CC", Arrays.asList(Allele.NO_CALL,Allele.NO_CALL));
+ GenotypesContext gc = GenotypesContext.create(g1, g2, g3);
+ VariantContext vc = new VariantContextBuilder("genotypes", snpLoc, snpLocStart, snpLocStop, Collections.singletonList(Aref)).genotypes(gc).make();
+
+ Assert.assertEquals(vc.getType(), VariantContext.Type.NO_VARIATION);
+ Assert.assertNull(vc.getAltAlleleWithHighestAlleleCount());
+ Assert.assertEquals(vc.getCalledChrCount(Aref), 3);
+
+ }
+
+
public void testGetGenotypeMethods() {
Genotype g1 = GenotypeBuilder.create("AA", Arrays.asList(Aref, Aref));
Genotype g2 = GenotypeBuilder.create("AT", Arrays.asList(Aref, T));