use of htsjdk.samtools.SAMRecord in project gatk by broadinstitute.
the class AlignedAssemblyUnitTest method testConstructionFromSAMRecord.
@Test(dataProvider = "AlignmentIntervalCtorTestForSimpleInversion", groups = "sv")
public void testConstructionFromSAMRecord(final BwaMemAlignment bwaMemAlignment, final SimpleInterval expectedReferenceInterval, final Cigar expectedCigar, final boolean expectedIsPositiveStrand, final int expectedStartOnContig_1BasedInclusive, final int expectedEndOnContig_1BasedInclusive, final int expectedContigLength, final int expectedMapQualInBwaMemAlignment, final AlignedAssembly.AlignmentInterval expectedAlignmentInterval) {
final SAMRecord samRecord = BwaMemAlignmentUtils.applyAlignment("whatever", SVDiscoveryTestDataProvider.makeDummySequence(expectedContigLength, (byte) 'A'), null, null, bwaMemAlignment, refNames, hg19Header, false, false);
final AlignedAssembly.AlignmentInterval alignmentInterval = new AlignedAssembly.AlignmentInterval(samRecord);
Assert.assertEquals(alignmentInterval.referenceInterval, expectedReferenceInterval);
Assert.assertEquals(alignmentInterval.cigarAlong5to3DirectionOfContig, expectedCigar);
Assert.assertEquals(alignmentInterval.forwardStrand, expectedIsPositiveStrand);
Assert.assertEquals(alignmentInterval.startInAssembledContig, expectedStartOnContig_1BasedInclusive);
Assert.assertEquals(alignmentInterval.endInAssembledContig, expectedEndOnContig_1BasedInclusive);
Assert.assertEquals(alignmentInterval.mapQual, Math.max(SAMRecord.NO_MAPPING_QUALITY, expectedMapQualInBwaMemAlignment));
Assert.assertEquals(alignmentInterval, expectedAlignmentInterval);
}
use of htsjdk.samtools.SAMRecord in project gatk by broadinstitute.
the class SamReaderQueryingIterator method next.
@Override
public SAMRecord next() {
if (nextRecord == null) {
throw new NoSuchElementException("Iterator is exhausted");
}
final SAMRecord toReturn = nextRecord;
nextRecord = loadNextRecord();
return toReturn;
}
use of htsjdk.samtools.SAMRecord in project gatk by broadinstitute.
the class RevertBaseQualityScoresIntegrationTest method hasOriginalQualScores.
private static boolean hasOriginalQualScores(final File bam) throws IOException {
try (final SamReader reader = SamReaderFactory.makeDefault().open(bam)) {
for (SAMRecord read : reader) {
final byte[] originalBaseQualities = read.getOriginalBaseQualities();
Assert.assertNotNull(originalBaseQualities);
final byte[] baseQualities = read.getBaseQualities();
Assert.assertEquals(originalBaseQualities.length, baseQualities.length);
for (int i = 0; i < originalBaseQualities.length; ++i) {
if (originalBaseQualities[i] != baseQualities[i]) {
return false;
}
}
}
}
return true;
}
use of htsjdk.samtools.SAMRecord in project gatk by broadinstitute.
the class UnmarkDuplicatesIntegrationTest method getDuplicateCountForBam.
private static int getDuplicateCountForBam(final File bam, final File referenceFile) throws IOException {
int duplicateCount = 0;
final SamReaderFactory factory = SamReaderFactory.makeDefault();
if (referenceFile != null) {
factory.referenceSequence(referenceFile);
}
try (final SamReader reader = factory.open(bam)) {
for (SAMRecord read : reader) {
if (read.getDuplicateReadFlag()) {
++duplicateCount;
}
}
}
return duplicateCount;
}
use of htsjdk.samtools.SAMRecord in project gatk by broadinstitute.
the class ReadsSparkSink method writeReadsADAM.
private static void writeReadsADAM(final JavaSparkContext ctx, final String outputFile, final JavaRDD<SAMRecord> reads, final SAMFileHeader header) throws IOException {
final SequenceDictionary seqDict = SequenceDictionary.fromSAMSequenceDictionary(header.getSequenceDictionary());
final RecordGroupDictionary readGroups = RecordGroupDictionary.fromSAMHeader(header);
final JavaPairRDD<Void, AlignmentRecord> rddAlignmentRecords = reads.map(read -> {
read.setHeaderStrict(header);
AlignmentRecord alignmentRecord = GATKReadToBDGAlignmentRecordConverter.convert(read, seqDict, readGroups);
read.setHeaderStrict(null);
return alignmentRecord;
}).mapToPair(alignmentRecord -> new Tuple2<>(null, alignmentRecord));
// instantiating a Job is necessary here in order to set the Hadoop Configuration...
final Job job = Job.getInstance(ctx.hadoopConfiguration());
// ...here, which sets a config property that the AvroParquetOutputFormat needs when writing data. Specifically,
// we are writing the Avro schema to the Configuration as a JSON string. The AvroParquetOutputFormat class knows
// how to translate objects in the Avro data model to the Parquet primitives that get written.
AvroParquetOutputFormat.setSchema(job, AlignmentRecord.getClassSchema());
deleteHadoopFile(outputFile, ctx.hadoopConfiguration());
rddAlignmentRecords.saveAsNewAPIHadoopFile(outputFile, Void.class, AlignmentRecord.class, AvroParquetOutputFormat.class, job.getConfiguration());
}
Aggregations