Fixed bugs in CleanedReadInjector arising from integration testing.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@999 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2009-06-12 17:37:33 +00:00
parent fb7ba47fff
commit 5859948e80
2 changed files with 32 additions and 2 deletions

View File

@ -4,16 +4,17 @@ import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.Utils;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.SAMFileReader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.util.CloseableIterator;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.Queue;
import java.util.LinkedList;
import java.io.File;
/**
* User: hanna
* Date: Jun 10, 2009
@ -49,7 +50,7 @@ public class CleanedReadInjector extends ReadWalker<Integer,Integer> {
* Target file for BAM output.
*/
@Argument(fullName="output_bam",shortName="ob",doc="Output BAM file",required=true)
SAMFileWriter outputBAM = null;
String outputBAMFileName = null;
/**
* A stream of processed intervals. The current head of the queue represents the next interval.
@ -66,11 +67,25 @@ public class CleanedReadInjector extends ReadWalker<Integer,Integer> {
*/
private Map<String,SAMRecord> cleanedReads = new HashMap<String,SAMRecord>();
/**
* The writer that handles writing of SAM files.
*/
SAMFileWriter outputBAM = null;
@Override
public void initialize() {
intervals = new LinkedList<GenomeLoc>( GenomeAnalysisEngine.parseIntervalRegion(intervalsSource,false) );
interval = intervals.remove();
loadCleanedReadsOverlappingInterval( interval );
// HACK: The unit tests create their own output files. Make sure this walker doesn't step
// on any toes.
if( outputBAM == null ) {
outputBAM = Utils.createSAMFileWriterWithCompression(getToolkit().getEngine().getSAMHeader(),
false,
outputBAMFileName,
getToolkit().getBAMCompression());
}
}
/**
@ -124,6 +139,11 @@ public class CleanedReadInjector extends ReadWalker<Integer,Integer> {
return accum + value;
}
@Override
public void onTraversalDone( Integer value ) {
outputBAM.close();
}
/**
* Load a list of all the reads overlapping the given interval into memory.
* @param interval
@ -135,6 +155,7 @@ public class CleanedReadInjector extends ReadWalker<Integer,Integer> {
SAMRecord read = overlappingReads.next();
cleanedReads.put( read.getReadName(), read );
}
overlappingReads.close();
}
/**

View File

@ -15,6 +15,12 @@ import java.util.List;
import java.util.Collection;
import java.util.Arrays;
import java.util.EnumSet;
import java.io.File;
import net.sf.samtools.SAMFileReader;
import net.sf.samtools.SAMFileWriter;
import net.sf.samtools.SAMFileWriterFactory;
import net.sf.samtools.SAMFileHeader;
/**
* Created by IntelliJ IDEA.
@ -418,6 +424,9 @@ public class ParsingEngine {
*/
private Object constructSingleElement(Field f, Class type, String str) {
// lets go through the types we support
if (type == SAMFileReader.class) {
return new SAMFileReader(new File(str),true);
}
if (type == Boolean.TYPE) {
boolean b = false;
if (str.toLowerCase().equals("true")) {