From b125571a98d5a1961d3b3eca0b45ec04d291cd13 Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 29 Dec 2009 16:11:11 +0000 Subject: [PATCH] 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 --- .../io/storage/GenotypeWriterStorage.java | 11 ++++++- .../gatk/io/stubs/GLFGenotypeWriterStub.java | 10 ++++++ .../io/stubs/GeliTextGenotypeWriterStub.java | 10 ++++++ .../GenotypeWriterArgumentTypeDescriptor.java | 16 +++++---- .../gatk/io/stubs/GenotypeWriterStub.java | 33 +++++++++++++++++-- .../gatk/io/stubs/VCFGenotypeWriterStub.java | 10 ++++++ .../walkers/genotyper/UnifiedGenotyper.java | 7 ---- 7 files changed, 80 insertions(+), 17 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/io/storage/GenotypeWriterStorage.java b/java/src/org/broadinstitute/sting/gatk/io/storage/GenotypeWriterStorage.java index 54fd534e9..62418b183 100755 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/GenotypeWriterStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/GenotypeWriterStorage.java @@ -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 implements GenotypeWriter, Storage { protected final File file; + protected final PrintStream stream; protected final GenotypeWriter writer; /** @@ -52,7 +54,13 @@ public abstract class GenotypeWriterStorage 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 implements */ public GenotypeWriterStorage( GenotypeWriterStub stub, File file ) { this.file = file; + this.stream = null; writer = GenotypeWriterFactory.create(stub.getFormat(), file); Set samples = SampleUtils.getSAMFileSamples(stub.getSAMFileHeader()); GenotypeWriterFactory.writeHeader(writer, stub.getSAMFileHeader(), samples, new HashSet()); diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/GLFGenotypeWriterStub.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/GLFGenotypeWriterStub.java index a898553e7..1f540bf19 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/GLFGenotypeWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/GLFGenotypeWriterStub.java @@ -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 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. diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/GeliTextGenotypeWriterStub.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/GeliTextGenotypeWriterStub.java index 915901bee..1af3c7651 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/GeliTextGenotypeWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/GeliTextGenotypeWriterStub.java @@ -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 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 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. diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFGenotypeWriterStub.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFGenotypeWriterStub.java index 75ca245e8..fa03cc340 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFGenotypeWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFGenotypeWriterStub.java @@ -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 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. diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java index 2e70fe6da..5525f50db 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java @@ -118,13 +118,6 @@ public class UnifiedGenotyper extends LocusWalker