Intermediate check in: transfer responsibility of wrapping the GenotypeWriter around the output stream to the output
management code. Currently, will not work when neither -varout nor -vf are specified, but should work in all other cases. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2463 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
aeb34758e6
commit
b125571a98
|
|
@ -34,6 +34,7 @@ import org.broadinstitute.sting.gatk.io.stubs.GenotypeWriterStub;
|
|||
import org.broadinstitute.sting.utils.genotype.*;
|
||||
import org.broadinstitute.sting.utils.genotype.vcf.*;
|
||||
import org.broadinstitute.sting.utils.SampleUtils;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
/**
|
||||
* Provides temporary storage for GenotypeWriters.
|
||||
|
|
@ -43,6 +44,7 @@ import org.broadinstitute.sting.utils.SampleUtils;
|
|||
*/
|
||||
public abstract class GenotypeWriterStorage<T extends GenotypeWriter> implements GenotypeWriter, Storage<T> {
|
||||
protected final File file;
|
||||
protected final PrintStream stream;
|
||||
protected final GenotypeWriter writer;
|
||||
|
||||
/**
|
||||
|
|
@ -52,7 +54,13 @@ public abstract class GenotypeWriterStorage<T extends GenotypeWriter> implements
|
|||
*/
|
||||
public GenotypeWriterStorage( GenotypeWriterStub stub ) {
|
||||
this.file = stub.getFile();
|
||||
writer = GenotypeWriterFactory.create(stub.getFormat(), file);
|
||||
this.stream = stub.getOutputStream();
|
||||
if(file != null)
|
||||
writer = GenotypeWriterFactory.create(stub.getFormat(), file);
|
||||
else if(stream != null)
|
||||
writer = GenotypeWriterFactory.create(stub.getFormat(), stream);
|
||||
else
|
||||
throw new StingException("Unable to create target to which to write; storage was provided with neither a file nor a stream.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,6 +70,7 @@ public abstract class GenotypeWriterStorage<T extends GenotypeWriter> implements
|
|||
*/
|
||||
public GenotypeWriterStorage( GenotypeWriterStub stub, File file ) {
|
||||
this.file = file;
|
||||
this.stream = null;
|
||||
writer = GenotypeWriterFactory.create(stub.getFormat(), file);
|
||||
Set<String> samples = SampleUtils.getSAMFileSamples(stub.getSAMFileHeader());
|
||||
GenotypeWriterFactory.writeHeader(writer, stub.getSAMFileHeader(), samples, new HashSet<VCFHeaderLine>());
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import org.broadinstitute.sting.utils.genotype.glf.GLFRecord;
|
|||
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* Stub providing a passthrough for GLF files.
|
||||
|
|
@ -23,6 +24,15 @@ public class GLFGenotypeWriterStub extends GenotypeWriterStub<GLFGenotypeWriter>
|
|||
super(engine,genotypeFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new stub with the given engine and target stream.
|
||||
* @param engine The engine, for extracting command-line arguments, etc.
|
||||
* @param genotypeStream Target stream into which to write genotyping data.
|
||||
*/
|
||||
public GLFGenotypeWriterStub(GenomeAnalysisEngine engine, PrintStream genotypeStream) {
|
||||
super(engine,genotypeStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the format of this stub. We may want to discontinue use of this method and rely on instanceof comparisons.
|
||||
* @return GLF always.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.broadinstitute.sting.utils.genotype.GenotypeWriterFactory;
|
|||
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
import edu.mit.broad.picard.genotype.geli.GenotypeLikelihoods;
|
||||
|
|
@ -25,6 +26,15 @@ public class GeliTextGenotypeWriterStub extends GenotypeWriterStub<GeliGenotypeW
|
|||
super(engine,genotypeFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new stub with the given engine and target stream.
|
||||
* @param engine The engine, for extracting command-line arguments, etc.
|
||||
* @param genotypeStream Target stream into which to write genotyping data.
|
||||
*/
|
||||
public GeliTextGenotypeWriterStub(GenomeAnalysisEngine engine, PrintStream genotypeStream) {
|
||||
super(engine,genotypeStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the format of this stub. We may want to discontinue use of this method and rely on instanceof comparisons.
|
||||
* @return GELI always.
|
||||
|
|
|
|||
|
|
@ -67,10 +67,11 @@ public class GenotypeWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
|
|||
*/
|
||||
@Override
|
||||
public Object parse( ArgumentSource source, Class type, ArgumentMatches matches ) {
|
||||
// Get the filename for the genotype file, if it exists. If not, we'll need to send output to out.
|
||||
String writerFileName = getArgumentValue(createGenotypeFileArgumentDefinition(source),matches);
|
||||
if(writerFileName == null)
|
||||
throw new StingException("Genotype format was supplied, but no file was supplied to contain the genotype info..");
|
||||
File writerFile = writerFileName != null ? new File(writerFileName) : null;
|
||||
|
||||
// Get the format of the genotype object, if it exists.
|
||||
String genotypeFormatText = getArgumentValue(createGenotypeFormatArgumentDefinition(source),matches);
|
||||
GenotypeWriterFactory.GENOTYPE_FORMAT genotypeFormat = GenotypeWriterFactory.GENOTYPE_FORMAT.VCF;
|
||||
if(genotypeFormatText != null) {
|
||||
|
|
@ -82,19 +83,22 @@ public class GenotypeWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
|
|||
}
|
||||
}
|
||||
|
||||
// Create a stub for the given object.
|
||||
GenotypeWriterStub stub = null;
|
||||
switch(genotypeFormat) {
|
||||
case GELI:
|
||||
stub = new GeliTextGenotypeWriterStub(engine, new File(writerFileName));
|
||||
stub = (writerFile != null) ? new GeliTextGenotypeWriterStub(engine, writerFile) : new GeliTextGenotypeWriterStub(engine,System.out);
|
||||
break;
|
||||
case GELI_BINARY:
|
||||
stub = new GeliBinaryGenotypeWriterStub(engine, new File(writerFileName));
|
||||
if(writerFile == null)
|
||||
throw new StingException("Geli binary files cannot be output to the console.");
|
||||
stub = new GeliBinaryGenotypeWriterStub(engine, writerFile);
|
||||
break;
|
||||
case GLF:
|
||||
stub = new GLFGenotypeWriterStub(engine, new File(writerFileName));
|
||||
stub = (writerFile != null) ? new GLFGenotypeWriterStub(engine, writerFile) : new GLFGenotypeWriterStub(engine,System.out);
|
||||
break;
|
||||
case VCF:
|
||||
stub = new VCFGenotypeWriterStub(engine, new File(writerFileName));
|
||||
stub = (writerFile != null) ? new VCFGenotypeWriterStub(engine, writerFile) : new VCFGenotypeWriterStub(engine,System.out);
|
||||
break;
|
||||
default:
|
||||
throw new StingException("Unable to create stub for file format " + genotypeFormat);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
package org.broadinstitute.sting.gatk.io.stubs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.broadinstitute.sting.gatk.io.OutputTracker;
|
||||
|
|
@ -50,11 +51,17 @@ public abstract class GenotypeWriterStub<T extends GenotypeWriter> implements St
|
|||
private final GenomeAnalysisEngine engine;
|
||||
|
||||
/**
|
||||
* The file that this stub should write to. Should be passed along to
|
||||
* whatever happens to create the StreamConnector.
|
||||
* The file that this stub should write to. Should be mutually
|
||||
* exclusive with genotypeStream.
|
||||
*/
|
||||
private final File genotypeFile;
|
||||
|
||||
/**
|
||||
* The output stream to which stub data should be written. Will be
|
||||
* mutually exclusive with genotypeFile.
|
||||
*/
|
||||
private final PrintStream genotypeStream;
|
||||
|
||||
/**
|
||||
* Connects this stub with an external stream capable of serving the
|
||||
* requests of the consumer of this stub.
|
||||
|
|
@ -69,16 +76,36 @@ public abstract class GenotypeWriterStub<T extends GenotypeWriter> implements St
|
|||
public GenotypeWriterStub(GenomeAnalysisEngine engine,File genotypeFile) {
|
||||
this.engine = engine;
|
||||
this.genotypeFile = genotypeFile;
|
||||
this.genotypeStream = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new stub given the requested file.
|
||||
* @param engine GATK engine.
|
||||
* @param genotypeStream stream to (ultimately) write.
|
||||
*/
|
||||
public GenotypeWriterStub(GenomeAnalysisEngine engine,PrintStream genotypeStream) {
|
||||
this.engine = engine;
|
||||
this.genotypeFile = null;
|
||||
this.genotypeStream = genotypeStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the file to (ultimately) be created.
|
||||
* @return The file. Must not be null.
|
||||
* @return The file. Can be null if genotypeStream is not.
|
||||
*/
|
||||
public File getFile() {
|
||||
return genotypeFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the output stearm to which to (ultimately) write.
|
||||
* @return The file. Can be null if genotypeFile is not.
|
||||
*/
|
||||
public PrintStream getOutputStream() {
|
||||
return genotypeStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the header to use when creating the new file.
|
||||
* @return header to use when creating the new file.
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import org.broadinstitute.sting.utils.genotype.vcf.VCFRecord;
|
|||
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
|
@ -25,6 +26,15 @@ public class VCFGenotypeWriterStub extends GenotypeWriterStub<VCFGenotypeWriter>
|
|||
super(engine,genotypeFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new stub with the given engine and target stream.
|
||||
* @param engine The engine, for extracting command-line arguments, etc.
|
||||
* @param genotypeStream Target stream into which to write genotyping data.
|
||||
*/
|
||||
public VCFGenotypeWriterStub(GenomeAnalysisEngine engine, PrintStream genotypeStream) {
|
||||
super(engine,genotypeStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the format of this stub. We may want to discontinue use of this method and rely on instanceof comparisons.
|
||||
* @return VCF always.
|
||||
|
|
|
|||
|
|
@ -118,13 +118,6 @@ public class UnifiedGenotyper extends LocusWalker<Pair<VariationCall, List<Genot
|
|||
throw new IllegalArgumentException("For technical reasons, the VERBOSE argument cannot be used with multiple threads");
|
||||
}
|
||||
|
||||
// set up the writer manually if it needs to use the output stream
|
||||
if ( writer == null && out != null ) {
|
||||
logger.warn("For technical reasons, VCF format must be used when writing to standard out.");
|
||||
logger.warn("Specify an output file if you would like to use a different output format.");
|
||||
writer = GenotypeWriterFactory.create(GenotypeWriterFactory.GENOTYPE_FORMAT.VCF, out);
|
||||
}
|
||||
|
||||
// get all of the unique sample names - unless we're in POOLED mode, in which case we ignore the sample names
|
||||
if ( UAC.genotypeModel != GenotypeCalculationModel.Model.POOLED ) {
|
||||
// if we're supposed to assume a single sample, do so
|
||||
|
|
|
|||
Loading…
Reference in New Issue