*/
int writeSamText(PrintStream printStream) {
try {
IOUtil.assertFileIsReadable(INPUT);
final SAMFileReader in = new SAMFileReader(INPUT);
final AsciiWriter writer = new AsciiWriter(printStream);
final SAMFileHeader header = in.getFileHeader();
if (header.getTextHeader() != null) {
writer.write(header.getTextHeader());
} else {
// Headers that are too large are not retained as text, so need to regenerate text
new SAMTextHeaderCodec().encode(writer, header, true);
}
for (final SAMRecord rec : in) {
if (printStream.checkError()) {
return 1;
}
if (this.ALIGNMENT_STATUS == AlignmentStatus.Aligned && rec.getReadUnmappedFlag()) continue;
if (this.ALIGNMENT_STATUS == AlignmentStatus.Unaligned && !rec.getReadUnmappedFlag()) continue;
if (this.PF_STATUS == PfStatus.PF && rec.getReadFailsVendorQualityCheckFlag()) continue;
if (this.PF_STATUS == PfStatus.NonPF && !rec.getReadFailsVendorQualityCheckFlag()) continue;
writer.write(rec.getSAMString());
}
writer.flush();
if (printStream.checkError()) {
return 1;
}
return 0;
} catch (IOException e) {