Search in sources :

Example 81 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadLikelihoods method changeReads.

public void changeReads(final Map<GATKRead, GATKRead> readRealignments) {
    final int sampleCount = samples.numberOfSamples();
    for (int s = 0; s < sampleCount; s++) {
        final GATKRead[] sampleReads = readsBySampleIndex[s];
        final Object2IntMap<GATKRead> readIndex = readIndexBySampleIndex[s];
        final int sampleReadCount = sampleReads.length;
        for (int r = 0; r < sampleReadCount; r++) {
            final GATKRead read = sampleReads[r];
            final GATKRead replacement = readRealignments.get(read);
            if (replacement == null) {
                continue;
            }
            sampleReads[r] = replacement;
            if (readIndex != null) {
                readIndex.remove(read);
                readIndex.put(replacement, r);
            }
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead)

Example 82 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadsDataSourceUnitTest method testSingleFileTraversalWithIntervals.

@Test(dataProvider = "SingleFileTraversalWithIntervalsData")
public void testSingleFileTraversalWithIntervals(final Path samFile, final List<SimpleInterval> intervals, final List<String> expectedReadNames) {
    try (ReadsDataSource readsSource = new ReadsDataSource(samFile)) {
        Assert.assertTrue(readsSource.indicesAvailable(), "Indices should be reported as available for this reads source");
        readsSource.setTraversalBounds(intervals);
        List<GATKRead> reads = new ArrayList<>();
        for (GATKRead read : readsSource) {
            reads.add(read);
        }
        // Make sure we got the right number of reads
        Assert.assertEquals(reads.size(), expectedReadNames.size(), "Wrong number of reads returned in traversal by intervals of " + samFile.toAbsolutePath());
        // Make sure we got the reads we expected in the right order
        for (int readIndex = 0; readIndex < reads.size(); ++readIndex) {
            Assert.assertEquals(reads.get(readIndex).getName(), expectedReadNames.get(readIndex), "Read #" + (readIndex + 1) + " in traversal by intervals of " + samFile.toAbsolutePath() + " not equal to expected read");
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 83 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadsDataSourceUnitTest method testMultipleFilesTraversalWithIntervals.

@Test(dataProvider = "MultipleFilesTraversalWithIntervalsData")
public void testMultipleFilesTraversalWithIntervals(final List<Path> samFiles, final List<SimpleInterval> intervals, final List<String> expectedReadNames) {
    try (ReadsDataSource readsSource = new ReadsDataSource(samFiles)) {
        Assert.assertTrue(readsSource.indicesAvailable(), "Indices should be reported as available for this reads source");
        readsSource.setTraversalBounds(intervals);
        List<GATKRead> reads = new ArrayList<>();
        for (GATKRead read : readsSource) {
            reads.add(read);
        }
        // Make sure we got the right number of reads
        Assert.assertEquals(reads.size(), expectedReadNames.size(), "Wrong number of reads returned in traversal by intervals of " + samFiles);
        // Make sure we got the reads we expected in the right order
        for (int readIndex = 0; readIndex < reads.size(); ++readIndex) {
            Assert.assertEquals(reads.get(readIndex).getName(), expectedReadNames.get(readIndex), "Read #" + (readIndex + 1) + " in traversal by intervals of " + samFiles + " not equal to expected read");
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 84 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadsDataSourceUnitTest method getFileWithAddedContig.

// Copy the reads in the inputFile to the output file, adding an extra contig to the sequence dictionary
// and a read referencing that contig
private File getFileWithAddedContig(final Path inputPath, final String extraContig, final String outputName, final String extension) {
    final File outputFile = BaseTest.createTempFile(outputName, extension);
    try (ReadsDataSource readsSource = new ReadsDataSource(inputPath)) {
        SAMFileHeader header = readsSource.getHeader();
        SAMSequenceRecord fakeSequenceRec = new SAMSequenceRecord(extraContig, 100);
        header.addSequence(fakeSequenceRec);
        try (final SAMFileGATKReadWriter gatkReadWriter = new SAMFileGATKReadWriter(ReadUtils.createCommonSAMWriter(outputFile, null, header, true, true, false))) {
            for (final GATKRead read : readsSource) {
                gatkReadWriter.addRead(read);
            }
            // use the contig name in the read name to make it easy to see where this read came from
            SAMRecord samRec = new SAMRecord(header);
            samRec.setReadName(extraContig + "_READ");
            samRec.setReferenceName(extraContig);
            samRec.setAlignmentStart(5);
            samRec.setReadBases(new byte[] { 'a', 'c', 'g', 't' });
            gatkReadWriter.addRead(new SAMRecordToGATKReadAdapter(samRec));
        }
    }
    return outputFile;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMFileGATKReadWriter(org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter) File(java.io.File)

Example 85 with GATKRead

use of org.broadinstitute.hellbender.utils.read.GATKRead in project gatk by broadinstitute.

the class ReadsDataSourceUnitTest method testSingleFileCompleteTraversal.

@Test(dataProvider = "SingleFileCompleteTraversalData")
public void testSingleFileCompleteTraversal(final Path samFile, final List<String> expectedReadNames) {
    try (ReadsDataSource readsSource = new ReadsDataSource(samFile)) {
        List<GATKRead> reads = new ArrayList<>();
        for (GATKRead read : readsSource) {
            reads.add(read);
        }
        // Make sure we got the right number of reads
        Assert.assertEquals(reads.size(), expectedReadNames.size(), "Wrong number of reads returned in complete traversal of " + samFile.toAbsolutePath());
        // Make sure we got the reads we expected in the right order
        for (int readIndex = 0; readIndex < reads.size(); ++readIndex) {
            Assert.assertEquals(reads.get(readIndex).getName(), expectedReadNames.get(readIndex), "Read #" + (readIndex + 1) + " in complete traversal of " + samFile.toAbsolutePath() + " not equal to expected read");
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)457 Test (org.testng.annotations.Test)286 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)163 SAMFileHeader (htsjdk.samtools.SAMFileHeader)87 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)59 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)40 ArrayList (java.util.ArrayList)34 Collectors (java.util.stream.Collectors)34 List (java.util.List)30 Cigar (htsjdk.samtools.Cigar)29 File (java.io.File)28 java.util (java.util)28 DataProvider (org.testng.annotations.DataProvider)28 JavaRDD (org.apache.spark.api.java.JavaRDD)26 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)26 Assert (org.testng.Assert)25 ReadPileup (org.broadinstitute.hellbender.utils.pileup.ReadPileup)24 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)22 Argument (org.broadinstitute.barclay.argparser.Argument)18 UserException (org.broadinstitute.hellbender.exceptions.UserException)18