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);
}
}
}
}
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");
}
}
}
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");
}
}
}
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;
}
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");
}
}
}
Aggregations