Search in sources :

Example 6 with SAMFileHeader

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

the class GATKProtectedVariantContextUtilsUnitTest method testGetPileup.

@Test
public void testGetPileup() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 1000);
    final Locatable loc = new SimpleInterval("chr1", 10, 10);
    final int readLength = 3;
    //this read doesn't overlap {@code loc}
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "read1", 0, 1, readLength);
    read1.setBases(Utils.dupBytes((byte) 'A', readLength));
    read1.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
    read1.setCigar("3M");
    //this read overlaps {@code loc} with a Q30 'A'
    final GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "read2", 0, 10, readLength);
    read2.setBases(Utils.dupBytes((byte) 'A', readLength));
    read2.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
    read2.setCigar("3M");
    //this read overlaps {@code loc} with a Q20 'C' (due to the deletion)
    final GATKRead read3 = ArtificialReadUtils.createArtificialRead(header, "read3", 0, 7, readLength);
    read3.setBases(Utils.dupBytes((byte) 'C', readLength));
    read3.setBaseQualities(Utils.dupBytes((byte) 20, readLength));
    read3.setCigar("1M1D2M");
    //this read doesn't overlap {@code loc} due to the deletion
    final GATKRead read4 = ArtificialReadUtils.createArtificialRead(header, "read4", 0, 7, readLength);
    read4.setBases(Utils.dupBytes((byte) 'C', readLength));
    read4.setBaseQualities(Utils.dupBytes((byte) 20, readLength));
    read4.setCigar("1M5D2M");
    final ReadPileup pileup = GATKProtectedVariantContextUtils.getPileup(loc, Arrays.asList(read1, read2, read3, read4));
    // the pileup should contain a Q30 'A' and a Q20 'C'
    final int[] counts = pileup.getBaseCounts();
    Assert.assertEquals(counts, new int[] { 1, 1, 0, 0 });
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ReadPileup(org.broadinstitute.hellbender.utils.pileup.ReadPileup) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Locatable(htsjdk.samtools.util.Locatable) Test(org.testng.annotations.Test)

Example 7 with SAMFileHeader

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

the class GenomeLocParserUnitTest method getFlankingGenomeLocs.

@DataProvider(name = "flankingGenomeLocs")
public Object[][] getFlankingGenomeLocs() {
    int contigLength = 10000;
    SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, contigLength);
    GenomeLocParser parser = new GenomeLocParser(header.getSequenceDictionary());
    new FlankingGenomeLocTestData("atStartBase1", parser, 1, "1:1", null, "1:2");
    new FlankingGenomeLocTestData("atStartBase50", parser, 50, "1:1", null, "1:2-51");
    new FlankingGenomeLocTestData("atStartRange50", parser, 50, "1:1-10", null, "1:11-60");
    new FlankingGenomeLocTestData("atEndBase1", parser, 1, "1:" + contigLength, "1:" + (contigLength - 1), null);
    new FlankingGenomeLocTestData("atEndBase50", parser, 50, "1:" + contigLength, String.format("1:%d-%d", contigLength - 50, contigLength - 1), null);
    new FlankingGenomeLocTestData("atEndRange50", parser, 50, String.format("1:%d-%d", contigLength - 10, contigLength), String.format("1:%d-%d", contigLength - 60, contigLength - 11), null);
    new FlankingGenomeLocTestData("nearStartBase1", parser, 1, "1:2", "1:1", "1:3");
    new FlankingGenomeLocTestData("nearStartRange50", parser, 50, "1:21-30", "1:1-20", "1:31-80");
    new FlankingGenomeLocTestData("nearEndBase1", parser, 1, "1:" + (contigLength - 1), "1:" + (contigLength - 2), "1:" + contigLength);
    new FlankingGenomeLocTestData("nearEndRange50", parser, 50, String.format("1:%d-%d", contigLength - 30, contigLength - 21), String.format("1:%d-%d", contigLength - 80, contigLength - 31), String.format("1:%d-%d", contigLength - 20, contigLength));
    new FlankingGenomeLocTestData("beyondStartBase1", parser, 1, "1:3", "1:2", "1:4");
    new FlankingGenomeLocTestData("beyondStartRange50", parser, 50, "1:101-200", "1:51-100", "1:201-250");
    new FlankingGenomeLocTestData("beyondEndBase1", parser, 1, "1:" + (contigLength - 3), "1:" + (contigLength - 4), "1:" + (contigLength - 2));
    new FlankingGenomeLocTestData("beyondEndRange50", parser, 50, String.format("1:%d-%d", contigLength - 200, contigLength - 101), String.format("1:%d-%d", contigLength - 250, contigLength - 201), String.format("1:%d-%d", contigLength - 100, contigLength - 51));
    new FlankingGenomeLocTestData("unmapped", parser, 50, "unmapped", null, null);
    new FlankingGenomeLocTestData("fullContig", parser, 50, "1", null, null);
    return FlankingGenomeLocTestData.getTests(FlankingGenomeLocTestData.class);
}
Also used : SAMFileHeader(htsjdk.samtools.SAMFileHeader) DataProvider(org.testng.annotations.DataProvider)

Example 8 with SAMFileHeader

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

the class GenomeLocParserUnitTest method testContigHasColon.

@Test
public void testContigHasColon() {
    SAMFileHeader header = new SAMFileHeader();
    header.setSortOrder(htsjdk.samtools.SAMFileHeader.SortOrder.coordinate);
    SAMSequenceDictionary dict = new SAMSequenceDictionary();
    SAMSequenceRecord rec = new SAMSequenceRecord("c:h:r1", 10);
    rec.setSequenceLength(10);
    dict.addSequence(rec);
    header.setSequenceDictionary(dict);
    final GenomeLocParser myGenomeLocParser = new GenomeLocParser(header.getSequenceDictionary());
    GenomeLoc loc = myGenomeLocParser.parseGenomeLoc("c:h:r1:4-5");
    assertEquals(0, loc.getContigIndex());
    assertEquals(loc.getStart(), 4);
    assertEquals(loc.getStop(), 5);
}
Also used : SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 9 with SAMFileHeader

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

the class GenomeLocParserUnitTest method testParsingPositions.

@Test(dataProvider = "parseGenomeLoc")
public void testParsingPositions(final String string, final String contig, final int start) {
    SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 10000000);
    GenomeLocParser genomeLocParser = new GenomeLocParser(header.getSequenceDictionary());
    final GenomeLoc loc = genomeLocParser.parseGenomeLoc(string);
    Assert.assertEquals(loc.getContig(), contig);
    Assert.assertEquals(loc.getStart(), start);
    Assert.assertEquals(loc.getStop(), start);
}
Also used : SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 10 with SAMFileHeader

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

the class ReadPileupUnitTest method testNullConstructorParametersReads.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullConstructorParametersReads() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 1000);
    ArtificialReadUtils.createArtificialRead(header, "read1", 0, 1, 10);
    new ReadPileup(loc, null, Arrays.asList(1));
}
Also used : SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

SAMFileHeader (htsjdk.samtools.SAMFileHeader)148 Test (org.testng.annotations.Test)89 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)85 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)71 File (java.io.File)23 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)22 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)17 DataProvider (org.testng.annotations.DataProvider)17 java.util (java.util)15 UserException (org.broadinstitute.hellbender.exceptions.UserException)15 ArrayList (java.util.ArrayList)14 List (java.util.List)12 Collectors (java.util.stream.Collectors)12 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)12 SAMRecord (htsjdk.samtools.SAMRecord)11 Locatable (htsjdk.samtools.util.Locatable)11 BeforeClass (org.testng.annotations.BeforeClass)11 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)10 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)10 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)10