use of htsjdk.samtools.SAMTextWriter in project gatk by broadinstitute.
the class AlignedAssemblyOrExcuse method writeSAMFile.
/**
* write a SAM file containing records for each aligned contig
*/
static void writeSAMFile(final String samFile, final SAMFileHeader header, final List<AlignedAssemblyOrExcuse> alignedAssemblyOrExcuseList) {
try (final OutputStream os = BucketUtils.createFile(samFile)) {
final SAMTextWriter writer = new SAMTextWriter(os);
writer.setSortOrder(SAMFileHeader.SortOrder.queryname, true);
writer.setHeader(header);
final List<String> refNames = getRefNames(header);
alignedAssemblyOrExcuseList.stream().filter(AlignedAssemblyOrExcuse::isNotFailure).flatMap(aa -> aa.toSAMStreamForAlignmentsOfThisAssembly(header, refNames)).forEach(writer::addAlignment);
writer.finish();
} catch (final IOException ioe) {
throw new GATKException("Can't write SAM file of aligned contigs.", ioe);
}
}
Aggregations