Search in sources :

Example 1 with Allele

use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.

the class AlleleSpecificAnnotationDataUnitTest method testTwoRef.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testTwoRef() throws Exception {
    final Allele Aref = Allele.create("A", true);
    final Allele Tref = Allele.create("T", true);
    final List<Allele> alleles = Arrays.asList(Aref, Tref);
    String rawData = "1|2";
    new AlleleSpecificAnnotationData<>(alleles, rawData);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 2 with Allele

use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.

the class AlleleSpecificAnnotationDataUnitTest method testCreate.

@Test
public void testCreate() throws Exception {
    final Allele Aref = Allele.create("A", true);
    final Allele T = Allele.create("T", false);
    final List<Allele> alleles = Arrays.asList(Aref, T);
    String rawData = "1|2";
    final AlleleSpecificAnnotationData<Integer> asad = new AlleleSpecificAnnotationData<>(alleles, rawData);
    Assert.assertEquals(asad.getAlleles(), alleles);
    Assert.assertEquals(asad.getRefAllele(), Aref);
    Assert.assertNull(asad.getAttribute(Aref));
    Assert.assertNull(asad.getAttribute(T));
    Assert.assertEquals(asad.getRawData(), rawData);
    final Map<Allele, Integer> map = new HashMap<>();
    map.put(Aref, 10);
    map.put(T, 11);
    asad.setAttributeMap(map);
    Assert.assertEquals(asad.getAttribute(Aref), (Integer) 10);
    Assert.assertEquals(asad.getAttribute(T), (Integer) 11);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) HashMap(java.util.HashMap) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with Allele

use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.

the class AlleleListUnitTest method testShufflePermutation.

@Test(dataProvider = "singleAlleleListData", dependsOnMethods = { "testAsList", "testEquals" })
public void testShufflePermutation(final List<Allele> alleles1) {
    final AlleleList<Allele> originalAlleleList = new IndexedAlleleList<>(alleles1);
    if (originalAlleleList.numberOfAlleles() <= 1) {
        //return because this input is invalid for this test
        return;
    }
    final Allele[] targetAlleleArray = originalAlleleList.asListOfAlleles().toArray(new Allele[originalAlleleList.numberOfAlleles()]);
    final int[] fromIndex = new int[targetAlleleArray.length];
    for (int i = 0; i < fromIndex.length; i++) fromIndex[i] = i;
    for (int i = 0; i < targetAlleleArray.length - 1; i++) {
        final int swapIndex = rnd.nextInt(targetAlleleArray.length - i - 1);
        final int otherIndex = fromIndex[swapIndex + i + 1];
        final Allele other = targetAlleleArray[swapIndex + i + 1];
        fromIndex[swapIndex + i + 1] = fromIndex[i];
        fromIndex[i] = otherIndex;
        targetAlleleArray[swapIndex + i + 1] = targetAlleleArray[i];
        targetAlleleArray[i] = other;
    }
    final AlleleList<Allele> targetAlleleList = new IndexedAlleleList<>(targetAlleleArray);
    final AlleleListPermutation<Allele> permutation = originalAlleleList.permutation(targetAlleleList);
    Assert.assertFalse(permutation.isNonPermuted());
    AlleleListUnitTester.assertAlleleList(originalAlleleList, permutation.fromList());
    AlleleListUnitTester.assertAlleleList(targetAlleleList, permutation.toList());
    Assert.assertFalse(permutation.isPartial());
    Assert.assertEquals(permutation.fromSize(), originalAlleleList.numberOfAlleles());
    Assert.assertEquals(permutation.toSize(), targetAlleleList.numberOfAlleles());
    for (int i = 0; i < permutation.fromSize(); i++) {
        Assert.assertEquals(permutation.toIndex(i), targetAlleleList.indexOfAllele(originalAlleleList.getAllele(i)));
        Assert.assertEquals(permutation.fromIndex(i), originalAlleleList.indexOfAllele(targetAlleleList.getAllele(i)));
        Assert.assertEquals(permutation.fromIndex(i), fromIndex[i]);
    }
    Assert.assertTrue(AlleleList.equals(permutation, targetAlleleList));
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) Test(org.testng.annotations.Test)

Example 4 with Allele

use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.

the class ReadLikelihoodsUnitTest method testAlleleQueries.

private void testAlleleQueries(final AlleleList<Allele> alleles, ReadLikelihoods<Allele> result) {
    final Set<Integer> alleleIndices = new LinkedHashSet<>();
    for (final Allele allele : alleles.asListOfAlleles()) {
        final int indexOfAllele = result.indexOfAllele(allele);
        Assert.assertTrue(indexOfAllele >= 0);
        Assert.assertFalse(alleleIndices.contains(indexOfAllele));
        alleleIndices.add(indexOfAllele);
        Assert.assertSame(allele, alleles.getAllele(indexOfAllele));
    }
}
Also used : Allele(htsjdk.variant.variantcontext.Allele)

Example 5 with Allele

use of htsjdk.variant.variantcontext.Allele in project gatk by broadinstitute.

the class ReadLikelihoodsUnitTest method testAlleleQueries.

private void testAlleleQueries(Allele[] alleles, ReadLikelihoods<Allele> result) {
    final Set<Integer> alleleIndices = new LinkedHashSet<>();
    for (final Allele allele : alleles) {
        final int indexOfAllele = result.indexOfAllele(allele);
        Assert.assertTrue(indexOfAllele >= 0);
        Assert.assertFalse(alleleIndices.contains(indexOfAllele));
        alleleIndices.add(indexOfAllele);
        Assert.assertSame(allele, alleles[indexOfAllele]);
    }
}
Also used : Allele(htsjdk.variant.variantcontext.Allele)

Aggregations

Allele (htsjdk.variant.variantcontext.Allele)157 VariantContext (htsjdk.variant.variantcontext.VariantContext)82 Genotype (htsjdk.variant.variantcontext.Genotype)72 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)66 ArrayList (java.util.ArrayList)50 Test (org.testng.annotations.Test)48 VCFHeader (htsjdk.variant.vcf.VCFHeader)42 GenotypeBuilder (htsjdk.variant.variantcontext.GenotypeBuilder)37 File (java.io.File)31 Collectors (java.util.stream.Collectors)31 HashSet (java.util.HashSet)30 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)29 IOException (java.io.IOException)28 VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)26 VCFInfoHeaderLine (htsjdk.variant.vcf.VCFInfoHeaderLine)25 VCFConstants (htsjdk.variant.vcf.VCFConstants)22 VCFFormatHeaderLine (htsjdk.variant.vcf.VCFFormatHeaderLine)22 List (java.util.List)22 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)21 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)20