Search in sources :

Example 51 with SAMSequenceRecord

use of htsjdk.samtools.SAMSequenceRecord 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 52 with SAMSequenceRecord

use of htsjdk.samtools.SAMSequenceRecord 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 53 with SAMSequenceRecord

use of htsjdk.samtools.SAMSequenceRecord 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 54 with SAMSequenceRecord

use of htsjdk.samtools.SAMSequenceRecord in project gatk by broadinstitute.

the class IndexUtilsUnitTest method testIsSequenceDictionaryFromIndexNegative.

@Test
public void testIsSequenceDictionaryFromIndexNegative() throws Exception {
    SAMSequenceDictionary dict = new SAMSequenceDictionary();
    dict.addSequence(new SAMSequenceRecord("1", 99));
    dict.addSequence(new SAMSequenceRecord("2", 99));
    Assert.assertFalse(IndexUtils.isSequenceDictionaryFromIndex(dict));
}
Also used : SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 55 with SAMSequenceRecord

use of htsjdk.samtools.SAMSequenceRecord in project gatk by broadinstitute.

the class IntervalUtilsUnitTest method testLoadIntervalsInvalidPicardIntervalHandling.

@Test(expectedExceptions = UserException.MalformedFile.class, dataProvider = "invalidIntervalTestData")
public void testLoadIntervalsInvalidPicardIntervalHandling(GenomeLocParser genomeLocParser, String contig, int intervalStart, int intervalEnd) throws Exception {
    SAMFileHeader picardFileHeader = new SAMFileHeader();
    picardFileHeader.addSequence(genomeLocParser.getContigInfo("1"));
    // Intentionally add an extra contig not in our genomeLocParser's sequence dictionary
    // so that we can add intervals to the Picard interval file for contigs not in our dictionary
    picardFileHeader.addSequence(new SAMSequenceRecord("2", 100000));
    IntervalList picardIntervals = new IntervalList(picardFileHeader);
    picardIntervals.add(new Interval(contig, intervalStart, intervalEnd, true, "dummyname"));
    File picardIntervalFile = createTempFile("testLoadIntervalsInvalidPicardIntervalHandling", ".intervals");
    picardIntervals.write(picardIntervalFile);
    List<String> intervalArgs = new ArrayList<>(1);
    intervalArgs.add(picardIntervalFile.getAbsolutePath());
    // loadIntervals() will validate all intervals against the sequence dictionary in our genomeLocParser,
    // and should throw for all intervals in our invalidIntervalTestData set
    IntervalUtils.loadIntervals(intervalArgs, IntervalSetRule.UNION, IntervalMergingRule.ALL, 0, genomeLocParser);
}
Also used : IntervalList(htsjdk.samtools.util.IntervalList) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Interval(htsjdk.samtools.util.Interval) QueryInterval(htsjdk.samtools.QueryInterval) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)72 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)35 Test (org.testng.annotations.Test)26 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)24 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)13 File (java.io.File)10 SAMFileHeader (htsjdk.samtools.SAMFileHeader)9 UserException (org.broadinstitute.hellbender.exceptions.UserException)8 DataProvider (org.testng.annotations.DataProvider)8 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)7 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 QueryInterval (htsjdk.samtools.QueryInterval)5 Allele (htsjdk.variant.variantcontext.Allele)4 VariantContext (htsjdk.variant.variantcontext.VariantContext)4 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)4