);
SAMFileReader result = new SAMFileReader(output);
Assert.assertEquals(result.getFileHeader().getSequenceDictionary().getSequences().size(), 8,
"Number of sequences did not match");
SAMProgramRecord pg = result.getFileHeader().getProgramRecords().get(0);
Assert.assertEquals(pg.getProgramGroupId(), "0");
Assert.assertEquals(pg.getProgramVersion(), "1.0");
Assert.assertEquals(pg.getCommandLine(), "align!");
Assert.assertEquals(pg.getProgramName(), "myAligner");
final SAMReadGroupRecord rg = result.getFileHeader().getReadGroups().get(0);
Assert.assertEquals(rg.getReadGroupId(), "0");
Assert.assertEquals(rg.getSample(), "Hi,Mom!");
Assert.assertEquals(result.getFileHeader().getSortOrder(), SAMFileHeader.SortOrder.coordinate);
for (final SAMRecord sam : result) {
// This tests that we clip both (a) when the adapter is marked in the unmapped BAM file and
// (b) when the insert size is less than the read length
if (sam.getReadName().equals("both_reads_align_clip_adapter") ||
sam.getReadName().equals("both_reads_align_clip_marked")) {
Assert.assertEquals(sam.getReferenceName(), "chr7");
if (sam.getReadNegativeStrandFlag()) {
Assert.assertEquals(sam.getCigarString(), "5S96M", "Incorrect CIGAR string for " +
sam.getReadName());
} else {
Assert.assertEquals(sam.getCigarString(), "96M5S", "Incorrect CIGAR string for " +
sam.getReadName());
}
}
// This tests that we DON'T clip when we run off the end if there are equal to or more than
// MIN_ADAPTER_BASES hanging off the end
else if (sam.getReadName().equals("both_reads_align_min_adapter_bases_exceeded")) {
Assert.assertEquals(sam.getReferenceName(), "chr7");
Assert.assertTrue(sam.getCigarString().indexOf("S") == -1,
"Read was clipped when it should not be.");
} else if (sam.getReadName().equals("neither_read_aligns_or_present")) {
Assert.assertTrue(sam.getReadUnmappedFlag(), "Read should be unmapped but isn't");
}
// Two pairs in which only the first read should align
else if (sam.getReadName().equals("both_reads_present_only_first_aligns") ||
sam.getReadName().equals("read_2_too_many_gaps")) {
if (sam.getFirstOfPairFlag()) {
Assert.assertEquals(sam.getReferenceName(), "chr7", "Read should be mapped but isn't");
} else {
Assert.assertTrue(sam.getReadUnmappedFlag(), "Read should not be mapped but is");
}
} else {
throw new Exception("Unexpected read name: " + sam.getReadName());
}
}
// Quick test to make sure the program record gets picked up from the file if not specified
// on the command line.
doMergeAlignment(unmappedBam, Collections.singletonList(alignedBam),
null, null, null, null,
false, true, false, 1,
null, null, null, null,
true, fasta, output,
SamPairUtil.PairOrientation.FR, null, null, null
);
result = new SAMFileReader(output);
pg = result.getFileHeader().getProgramRecords().get(0);
Assert.assertEquals(pg.getProgramGroupId(), "1",
"Program group ID not picked up correctly from aligned BAM");
Assert.assertEquals(pg.getProgramVersion(), "2.0",
"Program version not picked up correctly from aligned BAM");
Assert.assertNull(pg.getCommandLine(),
"Program command line not picked up correctly from aligned BAM");
Assert.assertEquals(pg.getProgramName(), "Hey!",
"Program name not picked up correctly from aligned BAM");
}