2009-03-16 06:42:24 +08:00
|
|
|
package org.broadinstitute.sting.gatk.walkers;
|
|
|
|
|
|
|
|
|
|
import net.sf.samtools.SAMRecord;
|
2009-05-22 02:30:45 +08:00
|
|
|
import net.sf.samtools.SAMFileWriter;
|
|
|
|
|
import net.sf.samtools.SAMFileHeader;
|
|
|
|
|
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
2009-06-05 16:48:34 +08:00
|
|
|
import org.broadinstitute.sting.utils.Utils;
|
2009-03-16 06:42:24 +08:00
|
|
|
|
2009-05-22 02:30:45 +08:00
|
|
|
import java.io.PrintStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class PrintReadsWalker extends ReadWalker<SAMRecord, SAMFileWriter> {
|
|
|
|
|
|
|
|
|
|
@Argument(fullName="outputBamFile", shortName="of", doc="Write output to this BAM filename instead of STDOUT", required=false)
|
|
|
|
|
String outputBamFile = null;
|
|
|
|
|
|
|
|
|
|
public SAMRecord map(char[] ref, SAMRecord read) {
|
|
|
|
|
return read;
|
2009-03-16 06:42:24 +08:00
|
|
|
}
|
|
|
|
|
|
2009-05-22 02:30:45 +08:00
|
|
|
public SAMFileWriter reduceInit() {
|
|
|
|
|
if ( outputBamFile != null ) { // ! outputBamFile.equals("") ) {
|
|
|
|
|
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
|
2009-06-05 16:48:34 +08:00
|
|
|
return Utils.createSAMFileWriterWithCompression(header, true, outputBamFile, getToolkit().getBAMCompression());
|
2009-05-22 02:30:45 +08:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SAMFileWriter reduce(SAMRecord read, SAMFileWriter output) {
|
|
|
|
|
if ( output != null ) {
|
|
|
|
|
output.addAlignment(read);
|
|
|
|
|
} else {
|
|
|
|
|
out.println(read.format());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
2009-03-16 06:42:24 +08:00
|
|
|
|
2009-05-22 02:30:45 +08:00
|
|
|
public void onTraversalDone(SAMFileWriter output) {
|
|
|
|
|
if ( output != null ) {
|
|
|
|
|
output.close();
|
|
|
|
|
}
|
2009-03-16 06:42:24 +08:00
|
|
|
}
|
|
|
|
|
}
|