use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.
the class SAMRecordSerializerUnitTest method testChangingContigsOnHeaderlessSAMRecord.
@Test
public void testChangingContigsOnHeaderlessSAMRecord() {
final SparkConf conf = new SparkConf().set("spark.kryo.registrator", "org.broadinstitute.hellbender.engine.spark.SAMRecordSerializerUnitTest$TestGATKRegistrator");
final SAMRecord read = ((SAMRecordToGATKReadAdapter) ArtificialReadUtils.createHeaderlessSamBackedRead("read1", "1", 100, 50)).getEncapsulatedSamRecord();
final SAMRecord roundTrippedRead = SparkTestUtils.roundTripInKryo(read, SAMRecord.class, conf);
Assert.assertEquals(roundTrippedRead, read, "\nActual read: " + roundTrippedRead.getSAMString() + "\nExpected read: " + read.getSAMString());
read.setReferenceName("2");
read.setAlignmentStart(1);
final SAMRecord roundTrippedRead2 = SparkTestUtils.roundTripInKryo(read, SAMRecord.class, conf);
Assert.assertEquals(roundTrippedRead2, read, "\nActual read: " + roundTrippedRead2.getSAMString() + "\nExpected read: " + read.getSAMString());
}
use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.
the class SAMRecordSerializerUnitTest method testSerializerRoundTripHeaderlessSAMRecord.
@Test
public void testSerializerRoundTripHeaderlessSAMRecord() {
SparkConf conf = new SparkConf().set("spark.kryo.registrator", "org.broadinstitute.hellbender.engine.spark.SAMRecordSerializerUnitTest$TestGATKRegistrator");
// check round trip with no header
final SAMRecord read = ((SAMRecordToGATKReadAdapter) ArtificialReadUtils.createHeaderlessSamBackedRead("read1", "1", 100, 50)).getEncapsulatedSamRecord();
final SAMRecord roundTrippedRead = SparkTestUtils.roundTripInKryo(read, SAMRecord.class, conf);
Assert.assertEquals(roundTrippedRead, read, "\nActual read: " + roundTrippedRead.getSAMString() + "\nExpected read: " + read.getSAMString());
}
use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter 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.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.
the class SATagBuilder method getArtificialReadsBasedOnSATag.
/**
* Returns a list of artificial GATKReads corresponding to the reads described by the SA tag in read.
* Fills as much information as can be inferred from the original read onto the artificial read copies
* This function is only used for testing (e.g. testGetArtificialReadsBasedOnSATag, testEmptyNMTagSupport)
*
* @param header the header to be used in constructing artificial reads
*/
public List<GATKRead> getArtificialReadsBasedOnSATag(SAMFileHeader header) {
List<GATKRead> output = new ArrayList<>(supplementaryReads.size());
GATKRead readCopy = read.copy();
readCopy.setAttribute("SA", getTag());
SAMRecord record = readCopy.convertToSAMRecord(header);
List<SAMRecord> readRecords = SAMUtils.getOtherCanonicalAlignments(record);
for (SAMRecord artificialRead : readRecords) {
output.add(new SAMRecordToGATKReadAdapter(artificialRead));
}
return output;
}
use of org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter in project gatk by broadinstitute.
the class CollectQualityYieldMetrics method doWork.
/**
* Main method for the program. Checks that all input files are present and
* readable and that the output file can be written to. Then iterates through
* all the records accumulating metrics. Finally writes metrics file
*/
@Override
protected Object doWork() {
final ProgressLogger progress = new ProgressLogger(logger);
File output = new File(qualityYieldMetricsArgs.output);
// Some quick parameter checking
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(output);
logger.info("Reading input file and calculating metrics.");
final SamReader sam = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT);
final MetricsFile<QualityYieldMetrics, Integer> metricsFile = getMetricsFile();
final QualityYieldMetrics metrics = new QualityYieldMetrics();
metrics.setUseOriginalQualities(qualityYieldMetricsArgs.useOriginalQualities);
for (final SAMRecord rec : sam) {
metrics.addRead(new SAMRecordToGATKReadAdapter(rec));
progress.record(rec);
}
metrics.finish();
metricsFile.addMetric(metrics);
metricsFile.write(output);
return null;
}
Aggregations