a first, simplest version of a walker that filters out reads based on user-specified criteria and writes remaining reads into a new bam file
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@467 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
1660379753
commit
03ec3452f2
|
|
@ -0,0 +1,48 @@
|
|||
package org.broadinstitute.sting.playground.gatk.walkers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.sf.samtools.SAMFileWriter;
|
||||
import net.sf.samtools.SAMFileWriterFactory;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
@Override
|
||||
public boolean filter(LocusContext context, SAMRecord read) {
|
||||
if ( read.getReadLength() > max_len ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer map(LocusContext context, SAMRecord read) {
|
||||
if ( writer == null ) writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(read.getHeader(), true, new File(output));
|
||||
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) {
|
||||
super.onTraversalDone(nReads);
|
||||
out.println(nReads +" reads passed the filter and were written into output file "+output);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue