Search in sources :

Example 51 with SAMFileHeader

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

the class IntervalUtilsUnitTest method genomeLocsFromLocatablesData.

@DataProvider(name = "genomeLocsFromLocatablesData")
public Object[][] genomeLocsFromLocatablesData() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, 10);
    final GenomeLocParser genomeLocParser = new GenomeLocParser(header.getSequenceDictionary());
    return new Object[][] { { genomeLocParser, Collections.emptyList() }, { genomeLocParser, Collections.singletonList(new SimpleInterval("1", 1, 2)) }, { genomeLocParser, Arrays.asList(new SimpleInterval("1", 1, 2), new SimpleInterval("1", 1, 1), new SimpleInterval("1", 5, 9)) }, { genomeLocParser, Arrays.asList(new SimpleInterval("1", 9, 10), new SimpleInterval("1", 5, 9), new SimpleInterval("1", 1, 9)) } };
}
Also used : SAMFileHeader(htsjdk.samtools.SAMFileHeader) DataProvider(org.testng.annotations.DataProvider)

Example 52 with SAMFileHeader

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

the class ContextCovariateUnitTest method testSimpleContexts.

@Test
public void testSimpleContexts() {
    final Random rnd = Utils.getRandomGenerator();
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    for (int i = 0; i < 10; i++) {
        final GATKRead read = ArtificialReadUtils.createRandomRead(header, 1000);
        read.setIsReverseStrand(rnd.nextBoolean());
        final GATKRead clippedRead = ReadClipper.clipLowQualEnds(read, RAC.LOW_QUAL_TAIL, ClippingRepresentation.WRITE_NS);
        final ReadCovariates readCovariates = new ReadCovariates(read.getLength(), 1, new CovariateKeyCache());
        covariate.recordValues(read, header, readCovariates, true);
        verifyCovariateArray(readCovariates.getMismatchesKeySet(), RAC.MISMATCHES_CONTEXT_SIZE, clippedRead, covariate, RAC.LOW_QUAL_TAIL);
        verifyCovariateArray(readCovariates.getInsertionsKeySet(), RAC.INDELS_CONTEXT_SIZE, clippedRead, covariate, RAC.LOW_QUAL_TAIL);
        verifyCovariateArray(readCovariates.getDeletionsKeySet(), RAC.INDELS_CONTEXT_SIZE, clippedRead, covariate, RAC.LOW_QUAL_TAIL);
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Random(java.util.Random) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 53 with SAMFileHeader

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

the class CycleCovariateUnitTest method testMaxCyclePasses.

@Test
public void testMaxCyclePasses() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithReadGroup(illuminaReadGroup);
    int readLength = RAC.MAXIMUM_CYCLE_VALUE;
    GATKRead read = ArtificialReadUtils.createRandomRead(readLength);
    read.setIsPaired(true);
    read.setReadGroup(illuminaReadGroup.getReadGroupId());
    ReadCovariates readCovariates = new ReadCovariates(read.getLength(), 1, new CovariateKeyCache());
    covariate.recordValues(read, header, readCovariates, true);
}
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 54 with SAMFileHeader

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

the class CycleCovariateUnitTest method testSimpleCycles.

@Test
public void testSimpleCycles() {
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithReadGroup(illuminaReadGroup);
    short readLength = 10;
    GATKRead read = ArtificialReadUtils.createRandomRead(header, readLength);
    read.setIsPaired(true);
    read.setReadGroup(illuminaReadGroup.getReadGroupId());
    ReadCovariates readCovariates = new ReadCovariates(read.getLength(), 1, new CovariateKeyCache());
    covariate.recordValues(read, header, readCovariates, true);
    verifyCovariateArray(readCovariates.getMismatchesKeySet(), 1, (short) 1);
    read.setIsReverseStrand(true);
    covariate.recordValues(read, header, readCovariates, true);
    verifyCovariateArray(readCovariates.getMismatchesKeySet(), readLength, -1);
    read.setIsSecondOfPair();
    covariate.recordValues(read, header, readCovariates, true);
    verifyCovariateArray(readCovariates.getMismatchesKeySet(), -readLength, 1);
    read.setIsReverseStrand(false);
    covariate.recordValues(read, header, readCovariates, true);
    verifyCovariateArray(readCovariates.getMismatchesKeySet(), -1, -1);
}
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 55 with SAMFileHeader

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

the class ReadThreadingGraphUnitTest method testDanglingTails.

@Test(dataProvider = "DanglingTails")
public void testDanglingTails(final String refEnd, final String altEnd, final String cigar, final boolean cigarIsGood, final int mergePointDistanceFromSink) {
    final int kmerSize = 15;
    // construct the haplotypes
    final String commonPrefix = "AAAAAAAAAACCCCCCCCCCGGGGGGGGGGTTTTTTTTTT";
    final String ref = commonPrefix + refEnd;
    final String alt = commonPrefix + altEnd;
    // create the graph and populate it
    final ReadThreadingGraph rtgraph = new ReadThreadingGraph(kmerSize);
    rtgraph.addSequence("ref", ref.getBytes(), true);
    final GATKRead read = ArtificialReadUtils.createArtificialRead(alt.getBytes(), Utils.dupBytes((byte) 30, alt.length()), alt.length() + "M");
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader();
    rtgraph.addRead(read, header);
    rtgraph.buildGraphIfNecessary();
    // confirm that we have just a single dangling tail
    MultiDeBruijnVertex altSink = null;
    for (final MultiDeBruijnVertex v : rtgraph.vertexSet()) {
        if (rtgraph.isSink(v) && !rtgraph.isReferenceNode(v)) {
            Assert.assertTrue(altSink == null, "We found more than one non-reference sink");
            altSink = v;
        }
    }
    Assert.assertTrue(altSink != null, "We did not find a non-reference sink");
    // confirm that the SW alignment agrees with our expectations
    final ReadThreadingGraph.DanglingChainMergeHelper result = rtgraph.generateCigarAgainstDownwardsReferencePath(altSink, 0, 4);
    if (result == null) {
        Assert.assertFalse(cigarIsGood);
        return;
    }
    Assert.assertTrue(cigar.equals(result.cigar.toString()), "SW generated cigar = " + result.cigar.toString());
    // confirm that the goodness of the cigar agrees with our expectations
    Assert.assertEquals(ReadThreadingGraph.cigarIsOkayToMerge(result.cigar, false, true), cigarIsGood);
    // confirm that the tail merging works as expected
    if (cigarIsGood) {
        final int mergeResult = rtgraph.mergeDanglingTail(result);
        Assert.assertTrue(mergeResult == 1 || mergePointDistanceFromSink == -1);
        // confirm that we created the appropriate edge
        if (mergePointDistanceFromSink >= 0) {
            MultiDeBruijnVertex v = altSink;
            for (int i = 0; i < mergePointDistanceFromSink; i++) {
                if (rtgraph.inDegreeOf(v) != 1)
                    Assert.fail("Encountered vertex with multiple edges");
                v = rtgraph.getEdgeSource(rtgraph.incomingEdgeOf(v));
            }
            Assert.assertTrue(rtgraph.outDegreeOf(v) > 1);
        }
    }
}
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)

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