Refactored to clean it up a bit
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@495 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
1bf4d040d8
commit
d99d67d51c
|
|
@ -15,18 +15,20 @@ 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="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;
|
@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;
|
private SAMFileWriter writer = null;
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
SAMFileHeader header = getToolkit().getSamReader().getFileHeader();
|
||||||
|
writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, header.getSortOrder() != SAMFileHeader.SortOrder.unsorted, new File(output));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean filter(LocusContext context, SAMRecord read) {
|
public boolean filter(LocusContext context, SAMRecord read) {
|
||||||
if ( read.getReadLength() > max_len ) return false;
|
return read.getReadLength() <= max_len;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer map(LocusContext context, SAMRecord read) {
|
public Integer map(LocusContext context, SAMRecord read) {
|
||||||
if ( writer == null ) writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(read.getHeader(), read.getHeader().getSortOrder() != SAMFileHeader.SortOrder.unsorted, new File(output));
|
|
||||||
writer.addAlignment(read);
|
writer.addAlignment(read);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -42,8 +44,8 @@ public class ReadFilterWalker extends ReadWalker<Integer,Integer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTraversalDone(Integer nReads) {
|
public void onTraversalDone(Integer nReads) {
|
||||||
super.onTraversalDone(nReads);
|
writer.close();
|
||||||
out.println(nReads +" reads passed the filter and were written into output file "+output);
|
out.println(nReads +" reads passed the filter and were written into output file "+output);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue