secondOfPair.setReadUnmappedFlag(true);
secondOfPair.setReadPairedFlag(true);
secondOfPair.setSecondOfPairFlag(true);
SamPairUtil.setMateInfo(firstOfPair, secondOfPair, header);
final SAMFileWriter unmappedWriter = factory.makeSAMWriter(header, false, unmappedSam);
unmappedWriter.addAlignment(firstOfPair);
unmappedWriter.addAlignment(secondOfPair);
unmappedWriter.close();
final File alignedSam = File.createTempFile("aligned.", ".sam");
alignedSam.deleteOnExit();
// Populate the header with SAMSequenceRecords
header.getSequenceDictionary().addSequence(new SAMSequenceRecord("chr1", 1000000));
// Create 2 alignments for each end of pair
final SAMFileWriter alignedWriter = factory.makeSAMWriter(header, false, alignedSam);
for (int i = 1; i <= 2; ++i) {
final SAMRecord firstOfPairAligned = new SAMRecord(header);
firstOfPairAligned.setReadName(firstOfPair.getReadName());
firstOfPairAligned.setReadBases(firstOfPair.getReadBases());
firstOfPairAligned.setBaseQualities(firstOfPair.getBaseQualities());
firstOfPairAligned.setReferenceName("chr1");
firstOfPairAligned.setAlignmentStart(i);
firstOfPairAligned.setCigarString(cigar);
firstOfPairAligned.setMappingQuality(100);
firstOfPairAligned.setReadPairedFlag(true);
firstOfPairAligned.setFirstOfPairFlag(true);
firstOfPairAligned.setAttribute(SAMTag.HI.name(), i);
final SAMRecord secondOfPairAligned = new SAMRecord(header);
secondOfPairAligned.setReadName(secondOfPair.getReadName());
secondOfPairAligned.setReadBases(secondOfPair.getReadBases());
secondOfPairAligned.setBaseQualities(secondOfPair.getBaseQualities());
secondOfPairAligned.setReferenceName("chr1");
secondOfPairAligned.setAlignmentStart(i + 10);
secondOfPairAligned.setCigarString(cigar);
secondOfPairAligned.setMappingQuality(100);
secondOfPairAligned.setReadPairedFlag(true);
secondOfPairAligned.setSecondOfPairFlag(true);
secondOfPairAligned.setAttribute(SAMTag.HI.name(), i);
SamPairUtil.setMateInfo(firstOfPairAligned, secondOfPairAligned, header);
alignedWriter.addAlignment(firstOfPairAligned);
alignedWriter.addAlignment(secondOfPairAligned);
}
alignedWriter.close();
doMergeAlignment(unmappedSam, Collections.singletonList(alignedSam),
null, null, null, null,
false, true, false, 1,
"0", "1.0", "align!", "myAligner",