Search in sources :

Example 41 with SAMFileHeader

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

the class ReadFilterPluginUnitTest method testToolHasDefaultRequiredArgsPositive.

@Test(dataProvider = "testDefaultFilters")
public void testToolHasDefaultRequiredArgsPositive(final String[] args) {
    CommandLineParser clp = new CommandLineArgumentParser(new Object(), Collections.singletonList(new GATKReadFilterPluginDescriptor(Collections.singletonList(new ReadGroupReadFilter()))));
    clp.parseArguments(nullMessageStream, args);
    SAMFileHeader samHeader = createHeaderWithReadGroups();
    ReadFilter rf = instantiateFilter(clp, samHeader);
    final GATKRead read = simpleGoodRead(samHeader);
    // make sure the test read actually has this read group
    Assert.assertEquals(read.getReadGroup(), readgroupName);
    Assert.assertTrue(rf.test(read));
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) GATKReadFilterPluginDescriptor(org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor) CommandLineArgumentParser(org.broadinstitute.barclay.argparser.CommandLineArgumentParser) CommandLineParser(org.broadinstitute.barclay.argparser.CommandLineParser) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Test(org.testng.annotations.Test)

Example 42 with SAMFileHeader

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

the class BreakpointClustererUnitTest method simpleEvidence.

@DataProvider(name = "simpleEvidenceClusters")
public Object[][] simpleEvidence() {
    final SAMFileHeader artificialSamHeader = ArtificialReadUtils.createArtificialSamHeaderWithGroups(2, 1, 1000000, 1);
    final List<BreakpointEvidence> evidenceList = new ArrayList<>(5);
    final ReadMetadata readMetadata = new ReadMetadata(new HashSet<Integer>(), artificialSamHeader, new ReadMetadata.ReadGroupFragmentStatistics(350, 40, 40), 1, 100, 10, 30);
    final BreakpointEvidence splitEvidence1 = new BreakpointEvidence.SplitRead(ArtificialReadUtils.createArtificialRead(artificialSamHeader, "1", "1", 1000, ArtificialReadUtils.createRandomReadBases(151, false), ArtificialReadUtils.createRandomReadQuals(151), "100M50S"), readMetadata, false);
    evidenceList.add(splitEvidence1);
    final BreakpointEvidence splitEvidence2 = new BreakpointEvidence.SplitRead(ArtificialReadUtils.createArtificialRead(artificialSamHeader, "1", "1", 1010, ArtificialReadUtils.createRandomReadBases(151, false), ArtificialReadUtils.createRandomReadQuals(151), "90M60S"), readMetadata, false);
    evidenceList.add(splitEvidence2);
    final List<GATKRead> pair1 = ArtificialReadUtils.createPair(artificialSamHeader, "pair1", 151, 1250, 500000, true, false);
    evidenceList.add(new BreakpointEvidence.WeirdTemplateSize(pair1.get(0), readMetadata));
    final List<GATKRead> pair2 = ArtificialReadUtils.createPair(artificialSamHeader, "pair1", 151, 1255, 500000, true, false);
    evidenceList.add(new BreakpointEvidence.WeirdTemplateSize(pair2.get(0), readMetadata));
    final List<GATKRead> pair3 = ArtificialReadUtils.createPair(artificialSamHeader, "pair1", 151, 1350, 500000, true, false);
    evidenceList.add(new BreakpointEvidence.WeirdTemplateSize(pair3.get(0), readMetadata));
    return new Object[][] { { readMetadata, evidenceList } };
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ArrayList(java.util.ArrayList) SAMFileHeader(htsjdk.samtools.SAMFileHeader) DataProvider(org.testng.annotations.DataProvider)

Example 43 with SAMFileHeader

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

the class BreakpointEvidenceTest method restOfFragmentSizeTest.

@Test(groups = "spark")
void restOfFragmentSizeTest() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithGroups(1, 1, 10000000, 1);
    final String groupName = header.getReadGroups().get(0).getReadGroupId();
    final int readSize = 151;
    final ReadMetadata.ReadGroupFragmentStatistics groupStats = new ReadMetadata.ReadGroupFragmentStatistics(401, 175, 20);
    final ReadMetadata readMetadata = new ReadMetadata(Collections.emptySet(), header, groupStats, 1, 1L, 1L, 1);
    final String templateName = "xyzzy";
    final int readStart = 1010101;
    final GATKRead read = ArtificialReadUtils.createArtificialRead(header, templateName, 0, readStart, readSize);
    read.setIsPaired(false);
    read.setIsReverseStrand(true);
    read.setReadGroup(groupName);
    final BreakpointEvidence evidence1 = new BreakpointEvidence(read, readMetadata);
    final int uncertainty = (readMetadata.getStatistics(groupName).getMedianFragmentSize() - readSize) / 2;
    final int evidenceLocus = readStart - uncertainty;
    final BreakpointEvidence evidence2 = new BreakpointEvidence(read, readMetadata, evidenceLocus, uncertainty);
    Assert.assertEquals(evidence1.getLocation().getContig(), 0);
    Assert.assertEquals(evidence1.getLocation().getStart(), evidenceLocus - uncertainty);
    Assert.assertEquals(evidence1.getLocation().getEnd(), evidenceLocus + uncertainty);
    Assert.assertEquals(evidence1.getLocation().getLength(), 2 * uncertainty);
    Assert.assertEquals(evidence1.getTemplateName(), templateName);
    Assert.assertEquals(evidence1.getTemplateEnd(), BreakpointEvidence.TemplateEnd.UNPAIRED);
    Assert.assertEquals(evidence1.toString(), evidence2.toString());
    read.setIsReverseStrand(false);
    final BreakpointEvidence evidence3 = new BreakpointEvidence(read, readMetadata);
    final BreakpointEvidence evidence4 = new BreakpointEvidence(read, readMetadata, readStart + readSize + uncertainty, uncertainty);
    Assert.assertEquals(evidence3.toString(), evidence4.toString());
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 44 with SAMFileHeader

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

the class SATagBuilderUnitTests method testAddTag.

@Test
public void testAddTag() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    GATKRead read = ArtificialReadUtils.createArtificialRead("40M");
    read.setAttribute("SA", "2,500,+,3S2=1X2=2S,60,1;");
    SATagBuilder builder = new SATagBuilder(read);
    GATKRead read1 = ArtificialReadUtils.createArtificialRead(header, "read1", 1, 10000, new byte[] {}, new byte[] {}, "4M");
    read1.setIsSupplementaryAlignment(true);
    GATKRead read2 = ArtificialReadUtils.createArtificialRead(header, "read2", 2, 10001, new byte[] {}, new byte[] {}, "4S");
    read2.setIsSupplementaryAlignment(true);
    SATagBuilder read2builder = new SATagBuilder(read2);
    GATKRead read3 = ArtificialReadUtils.createArtificialRead(header, "read3", 3, 10003, new byte[] {}, new byte[] {}, "4D");
    read3.setIsSupplementaryAlignment(false);
    builder.addTag(read1).addTag(read3).addTag(read2builder).setSATag();
    Assert.assertEquals(read.getAttributeAsString("SA"), "4,10003,+,4D,0,*;2,500,+,3S2=1X2=2S,60,1;2,10000,+,4M,0,*;3,10001,+,4S,0,*;");
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Test(org.testng.annotations.Test)

Example 45 with SAMFileHeader

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

the class SATagBuilderUnitTests method testGetArtificalReadsBasedOnSATag.

@Test
public void testGetArtificalReadsBasedOnSATag() {
    // setup the record
    final SAMFileHeader header = new SAMFileHeader();
    header.addSequence(new SAMSequenceRecord("1", 1000));
    header.addSequence(new SAMSequenceRecord("2", 1000));
    GATKRead read = ArtificialReadUtils.createArtificialRead(header, "name", "2", 1, "AAAAAAAAAA".getBytes(), "##########".getBytes());
    read.setIsFirstOfPair();
    read.setCigar(TextCigarCodec.decode("10M"));
    read.setMatePosition("2", 1);
    //spec says first 'SA' record will be the primary record
    read.setIsSupplementaryAlignment(true);
    SATagBuilder builder = new SATagBuilder(read);
    // check no alignments if no SA tag */
    Assert.assertEquals(builder.getArtificialReadsBasedOnSATag(header).size(), 0);
    // Tests that parsing existing tags works properly
    read.setAttribute("SA", "2,500,+,3S2=1X2=2S,60,1;" + "1,191,-,8M2S,60,0;");
    builder = new SATagBuilder(read);
    List<GATKRead> suppl = builder.getArtificialReadsBasedOnSATag(header);
    Assert.assertNotNull(suppl);
    Assert.assertEquals(suppl.size(), 2);
    for (final GATKRead other : suppl) {
        Assert.assertFalse(other.isUnmapped());
        Assert.assertTrue(other.isPaired());
        Assert.assertFalse(other.mateIsUnmapped());
        Assert.assertEquals(other.getMateContig(), read.getMateContig());
        Assert.assertEquals(other.getName(), read.getName());
    }
    GATKRead other = suppl.get(0);
    //1st of suppl and 'record' is supplementary
    Assert.assertFalse(other.isSupplementaryAlignment());
    Assert.assertEquals(other.getContig(), "2");
    Assert.assertEquals(other.getStart(), 500);
    Assert.assertEquals(other.getMappingQuality(), 60);
    Assert.assertEquals((int) other.getAttributeAsInteger("NM"), 1);
    Assert.assertEquals(other.getCigar().toString(), "3S2=1X2=2S");
    other = suppl.get(1);
    Assert.assertTrue(other.isSupplementaryAlignment());
    Assert.assertEquals(other.getContig(), "1");
    Assert.assertEquals(other.getStart(), 191);
    Assert.assertTrue(other.isReverseStrand());
    Assert.assertEquals(other.getMappingQuality(), 60);
    Assert.assertEquals((int) other.getAttributeAsInteger("NM"), 0);
    Assert.assertEquals(other.getCigar().toString(), "8M2S");
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) SAMFileHeader(htsjdk.samtools.SAMFileHeader) 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