Move filtering functionality into the PrintReadsWalker. More to come.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1010 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2009-06-15 16:38:08 +00:00
parent 161c74716c
commit 8f4bc8cb6e
2 changed files with 13 additions and 51 deletions

View File

@ -40,12 +40,25 @@ import java.util.Random;
* This walker prints out the reads from the BAM files provided to the traversal engines.
* It also supports the command line option '-outputBamFile filname', which outputs all the
* reads to a specified BAM file
* The walker now also optionally filters reads based on command line options.
*/
public class PrintReadsWalker extends ReadWalker<SAMRecord, SAMFileWriter> {
/** an optional argument to dump the reads out to a BAM file */
@Argument(fullName = "outputBamFile", shortName = "of", doc = "Write output to this BAM filename instead of STDOUT", required = false)
String outputBamFile = null;
@Argument(fullName = "maxReadLength", shortName = "maxRead", doc="Discard reads with length greater than the specified value", required = false)
Integer maxLength = null;
/**
* The reads filter function.
* @param ref the reference bases that correspond to our read, if a reference was provided
* @param read the read itself, as a SAMRecord
* @return true if the read passes the filter, false if it doesn't
*/
public boolean filter(char[] ref, SAMRecord read) {
return (maxLength == null || read.getReadLength() <= maxLength);
}
/**
* The reads map function.

View File

@ -1,51 +0,0 @@
package org.broadinstitute.sting.playground.gatk.walkers;
import java.io.File;
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.Utils;
public class ReadFilterWalker extends ReadWalker<Integer,Integer> {
@Argument(fullName="output_file", shortName="O",doc="SAM or BAM file to write filtered reads into (will be overwritten if exists)",required=true ) public String output;
@Argument(fullName="max_read_length",doc="Discard reads with length greater than the specified value",required=false) public Integer max_len;
private SAMFileWriter writer = null;
public void initialize() {
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
writer = Utils.createSAMFileWriterWithCompression(header, header.getSortOrder() != SAMFileHeader.SortOrder.unsorted, output, getToolkit().getBAMCompression());
}
@Override
public boolean filter(char[] ref, SAMRecord read) {
return read.getReadLength() <= max_len;
}
@Override
public Integer map(char[] ref, SAMRecord read) {
writer.addAlignment(read);
return 1;
}
@Override
public Integer reduce(Integer value, Integer sum) {
return sum+value;
}
@Override
public Integer reduceInit() {
return 0;
}
public void onTraversalDone(Integer nReads) {
writer.close();
out.println(nReads +" reads passed the filter and were written into output file "+output);
}
}