Source:
public void testHardClipRoundTrip() throws Exception { final File outputMBA = File.createTempFile("test-output-hard-clipped-round-trip-mba", ".sam"); final String mergeBamAlignmentsArgs = new String[] { "UNMAPPED_BAM=" + hardClippedUnmappedSam.getAbsolutePath(), "ALIGNED_BAM=" + hardClippedAlignedSam.getAbsolutePath(), "OUTPUT=" + outputMBA.getAbsolutePath(), "REFERENCE_SEQUENCE=" + hardClipFasta.getAbsolutePath(), "HARD_CLIP_OVERLAPPING_READS=true" }; Assert.assertEquals(runPicardCommandLine("MergeBamAlignment", mergeBamAlignmentsArgs), 0); final File outputRevert = File.createTempFile("test-output-hard-clipped-round-trip-reverted", ".sam"); final String revertSamArgs = new String[] { "I=" + outputMBA.getAbsolutePath(), "RESTORE_HARDCLIPS=true", "O=" + outputRevert.getAbsolutePath() }; Assert.assertEquals(runPicardCommandLine("RevertSam", revertSamArgs), 0); final SamReader revertedReader = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).open(outputRevert); final SamReader unmappedReader = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).open(hardClippedUnmappedSam); final SAMRecordIterator revertedIterator = revertedReader.iterator(); final SAMRecordIterator unmappedIterator = unmappedReader.iterator(); while (revertedIterator.hasNext() && unmappedIterator.hasNext()) { SAMRecord reverted = revertedIterator.next(); SAMRecord unmapped = unmappedIterator.next(); Assert.assertEquals(reverted.getReadString(), unmapped.getReadString()); Assert.assertEquals(SAMUtils.phredToFastq(reverted.getBaseQualities()), SAMUtils.phredToFastq(unmapped.getBaseQualities())); } if (revertedIterator.hasNext() || unmappedIterator.hasNext()) { Assert.fail("Reverted sam file should be identical in length to unmapped sam file in test, but was not."); } revertedReader.close(); unmappedReader.close(); }

Target:
public void testHardClipRoundTrip() throws Exception { final File outputMBA = File.createTempFile("test-output-hard-clipped-round-trip-mba", ".sam"); outputMBA.deleteOnExit(); final String mergeBamAlignmentsArgs = new String[] { "UNMAPPED_BAM=" + hardClippedUnmappedSam.getAbsolutePath(), "ALIGNED_BAM=" + hardClippedAlignedSam.getAbsolutePath(), "OUTPUT=" + outputMBA.getAbsolutePath(), "REFERENCE_SEQUENCE=" + hardClipFasta.getAbsolutePath(), "HARD_CLIP_OVERLAPPING_READS=true" }; Assert.assertEquals(runPicardCommandLine("MergeBamAlignment", mergeBamAlignmentsArgs), 0); final File outputRevert = File.createTempFile("test-output-hard-clipped-round-trip-reverted", ".sam"); outputRevert.deleteOnExit(); final String revertSamArgs = new String[] { "I=" + outputMBA.getAbsolutePath(), "RESTORE_HARDCLIPS=true", "O=" + outputRevert.getAbsolutePath() }; Assert.assertEquals(runPicardCommandLine("RevertSam", revertSamArgs), 0); try(SamReader revertedReader = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).open(outputRevert); SamReader unmappedReader = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).open(hardClippedUnmappedSam)) { final SAMRecordIterator revertedIterator = revertedReader.iterator(); final SAMRecordIterator unmappedIterator = unmappedReader.iterator(); while (revertedIterator.hasNext() && unmappedIterator.hasNext()) { final SAMRecord reverted = revertedIterator.next(); final SAMRecord unmapped = unmappedIterator.next(); Assert.assertEquals(reverted.getReadString(), unmapped.getReadString()); Assert.assertEquals(SAMUtils.phredToFastq(reverted.getBaseQualities()), SAMUtils.phredToFastq(unmapped.getBaseQualities())); } if (revertedIterator.hasNext() || unmappedIterator.hasNext()) { Assert.fail("Reverted sam file should be identical in length to unmapped sam file in test, but was not."); } } }