protected int doPaired() {
IOUtil.assertFileIsReadable(FASTQ);
IOUtil.assertFileIsReadable(FASTQ2);
IOUtil.assertFileIsWritable(OUTPUT);
final FastqReader freader1 = new FastqReader(FASTQ,ALLOW_AND_IGNORE_EMPTY_LINES);
final FastqReader freader2 = new FastqReader(FASTQ2,ALLOW_AND_IGNORE_EMPTY_LINES);
final SAMFileHeader header = createFileHeader() ;
final SAMFileWriter writer = (new SAMFileWriterFactory()).makeSAMOrBAMWriter(header, false, OUTPUT);
int readCount = 0;
final ProgressLogger progress = new ProgressLogger(LOG);
for ( ; freader1.hasNext() && freader2.hasNext() ; readCount++) {
final FastqRecord frec1 = freader1.next();
final FastqRecord frec2 = freader2.next();
final String frec1Name = getReadName(frec1.getReadHeader(), true);
final String frec2Name = getReadName(frec2.getReadHeader(), true);
final String baseName = getBaseName(frec1Name, frec2Name, freader1, freader2);
final SAMRecord srec1 = createSamRecord(header, baseName, frec1, true) ;
srec1.setFirstOfPairFlag(true);
srec1.setSecondOfPairFlag(false);
writer.addAlignment(srec1);
progress.record(srec1);
final SAMRecord srec2 = createSamRecord(header, baseName, frec2, true) ;
srec2.setFirstOfPairFlag(false);
srec2.setSecondOfPairFlag(true);
writer.addAlignment(srec2);
progress.record(srec2);
}
writer.close();
if (freader1.hasNext() || freader2.hasNext()) {
throw new PicardException("Input paired fastq files must be the same length");
}
return readCount;
}