Search in sources :

Example 91 with Allele

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

the class TandemRepeatUnitTest method testUsingVC.

@Test
public void testUsingVC() {
    // - [ref] / ATC from 20-20
    final String insLoc = "chr1";
    final int insLocStart = 2;
    final int insLocStop = 2;
    final byte[] refBytes = "GTATCATCATCGGA".getBytes();
    final Allele nullR = Allele.create("A", true);
    final Allele atc = Allele.create("AATC", false);
    // A*,ATC, context = ATC ATC ATC : (ATC)3 -> (ATC)4
    final VariantContext vc = new VariantContextBuilder("foo", insLoc, insLocStart, insLocStop, Arrays.asList(nullR, atc)).make();
    // we test that the interval from which the ReferenceContext is constructed does not need to exactly overlap
    // the VariantContext.  The annotation should be able to handle this.
    final SimpleInterval interval = new SimpleInterval(insLoc, insLocStart + 3, insLocStop + 4);
    final SimpleInterval interval1 = new SimpleInterval(insLoc, 1, refBytes.length);
    final ReferenceBases ref1 = new ReferenceBases(refBytes, interval1);
    final SAMSequenceDictionary dict = new SAMSequenceDictionary(Arrays.asList(new SAMSequenceRecord(insLoc, refBytes.length)));
    final ReferenceContext ref = new ReferenceContext(ReferenceDataSource.of(ref1, dict), interval, 20, 20);
    final InfoFieldAnnotation ann = new TandemRepeat();
    final Map<String, Object> a = ann.annotate(ref, vc, null);
    Assert.assertEquals(a.size(), 3);
    Assert.assertEquals(a.get(GATKVCFConstants.STR_PRESENT_KEY), true);
    Assert.assertEquals(a.get(GATKVCFConstants.REPEAT_UNIT_KEY), "ATC");
    //3 repeats in the reference, 4 in the variant
    Assert.assertEquals(a.get(GATKVCFConstants.REPEATS_PER_ALLELE_KEY), Arrays.asList(3, 4));
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases) Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 92 with Allele

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

the class TandemRepeatUnitTest method testUsingVCNoRepeat.

@Test
public void testUsingVCNoRepeat() {
    // - [ref] / ATC from 20-20
    final String insLoc = "chr1";
    final int insLocStart = 6;
    final int insLocStop = 6;
    final byte[] refBytes = "GTATCATCATCGGA".getBytes();
    final Allele nullR = Allele.create("A", true);
    final Allele atc = Allele.create("AATC", false);
    // A*,ATC, context = ATC ATC ATC : (ATC)3 -> (ATC)4
    final VariantContext vc = new VariantContextBuilder("foo", insLoc, insLocStart, insLocStop, Arrays.asList(nullR, atc)).make();
    final SimpleInterval interval = new SimpleInterval(insLoc, insLocStart, insLocStop);
    final SimpleInterval interval1 = new SimpleInterval(insLoc, 1, refBytes.length);
    final ReferenceBases ref1 = new ReferenceBases(refBytes, interval1);
    final SAMSequenceDictionary dict = new SAMSequenceDictionary(Arrays.asList(new SAMSequenceRecord(insLoc, refBytes.length)));
    final ReferenceContext ref = new ReferenceContext(ReferenceDataSource.of(ref1, dict), interval, 0, 20);
    final InfoFieldAnnotation ann = new TandemRepeat();
    final Map<String, Object> a = ann.annotate(ref, vc, null);
    Assert.assertTrue(a.isEmpty());
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases) Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 93 with Allele

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

the class TandemRepeatUnitTest method testUsingVCNotIndel.

@Test
public void testUsingVCNotIndel() {
    // - [ref] / ATC from 20-20
    String insLoc = "chr1";
    int insLocStart = 2;
    int insLocStop = 2;
    byte[] refBytes = "GTATCATCATCGGA".getBytes();
    Allele nullR = Allele.create("A", true);
    Allele atc = Allele.create("C", false);
    // A*,ATC, context = ATC ATC ATC : (ATC)3 -> (ATC)4
    VariantContext vc = new VariantContextBuilder("foo", insLoc, insLocStart, insLocStop, Arrays.asList(nullR, atc)).make();
    final SimpleInterval interval = new SimpleInterval("chr1", insLocStart, insLocStop);
    final String contigName = "chr1";
    final SimpleInterval interval1 = new SimpleInterval(contigName, 1, refBytes.length);
    final ReferenceBases ref1 = new ReferenceBases(refBytes, interval1);
    final SAMSequenceDictionary dict = new SAMSequenceDictionary(Arrays.asList(new SAMSequenceRecord(contigName, refBytes.length)));
    final ReferenceContext ref = new ReferenceContext(ReferenceDataSource.of(ref1, dict), interval, 0, 20);
    final InfoFieldAnnotation ann = new TandemRepeat();
    final Map<String, Object> a = ann.annotate(ref, vc, null);
    Assert.assertTrue(a.isEmpty());
}
Also used : VariantContext(htsjdk.variant.variantcontext.VariantContext) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ReferenceBases(org.broadinstitute.hellbender.utils.reference.ReferenceBases) Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 94 with Allele

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

the class AlleleSpecificAnnotationDataUnitTest method testNoRef.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testNoRef() throws Exception {
    final Allele A = Allele.create("A", false);
    final Allele T = Allele.create("T", false);
    final List<Allele> alleles = Arrays.asList(A, T);
    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 95 with Allele

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

the class ReducibleAnnotationDataUnitTest method testCreate.

@Test
public void testCreate() throws Exception {
    final Allele Aref = Allele.create("A", true);
    final Allele T = Allele.create("T", false);
    String rawData = "1|2";
    final ReducibleAnnotationData<Integer> asad = new ReducibleAnnotationData<>(rawData);
    Assert.assertEquals(asad.getAlleles(), Arrays.asList(Allele.NO_CALL));
    Assert.assertNull(asad.getAttribute(Aref));
    Assert.assertNull(asad.getAttribute(T));
    Assert.assertFalse(asad.hasAttribute(Aref));
    Assert.assertFalse(asad.hasAttribute(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);
    Assert.assertEquals(asad.getAttributeMap(), map);
    asad.putAttribute(T, 19);
    Assert.assertEquals(asad.getAttribute(T), (Integer) 19);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) HashMap(java.util.HashMap) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

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