From 697d7e02c8302d7463b9609f9025a5b4f5a73057 Mon Sep 17 00:00:00 2001 From: ebanks Date: Thu, 12 Nov 2009 02:14:50 +0000 Subject: [PATCH] Remove the lazy initialize functionality. When no calls are made by the genotyper, we still want a vcf file to be output with valid header. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2024 348d0f76-0448-11de-a6fe-93d51630548a --- .../vcf/VCFGenotypeWriterAdapter.java | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeWriterAdapter.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeWriterAdapter.java index a388adc40..baeb2b89f 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeWriterAdapter.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeWriterAdapter.java @@ -21,10 +21,7 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter { private VCFHeader mHeader = null; private String mSource; private String mReferenceName; - private boolean mInitialized = false; private final Set mSampleNames = new HashSet(); - private final File mFile; - private final OutputStream mStream; /** our log, which we want to capture anything from this class */ protected static Logger logger = Logger.getLogger(VCFGenotypeWriterAdapter.class); @@ -33,29 +30,29 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter { public VCFGenotypeWriterAdapter(String source, String referenceName, File writeTo, Set sampleNames) { mReferenceName = referenceName; mSource = source; - mFile = writeTo; - if (mFile == null) throw new RuntimeException("VCF output file must not be null"); - mStream = null; mSampleNames.addAll(sampleNames); + + initializeHeader(); + + if (writeTo == null) throw new RuntimeException("VCF output file must not be null"); + mWriter = new VCFWriter(mHeader, writeTo); } public VCFGenotypeWriterAdapter(String source, String referenceName, OutputStream writeTo, Set sampleNames) { mReferenceName = referenceName; mSource = source; - mFile = null; - mStream = writeTo; - if (mStream == null) throw new RuntimeException("VCF output stream must not be null"); mSampleNames.addAll(sampleNames); + initializeHeader(); + + if (writeTo == null) throw new RuntimeException("VCF output stream must not be null"); + mWriter = new VCFWriter(mHeader, writeTo); } /** - * initialize this VCF writer - * - * @param file the file location to write to - * @param stream the output stream + * initialize this VCF header */ - private void lazyInitialize(File file, OutputStream stream) { + private void initializeHeader() { Map hInfo = new HashMap(); // setup the header fields @@ -65,11 +62,6 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter { // setup the sample names mHeader = new VCFHeader(hInfo, mSampleNames); - if (mFile == null) - mWriter = new VCFWriter(mHeader, stream); - else - mWriter = new VCFWriter(mHeader, file); - mInitialized = true; } /** @@ -109,8 +101,7 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter { /** finish writing, closing any open files. */ public void close() { - if (mInitialized) - mWriter.close(); + mWriter.close(); } /** @@ -119,9 +110,6 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter { * @param genotypes the list of genotypes */ public void addMultiSampleCall(List genotypes, GenotypeLocusData locusdata) { - if (!mInitialized) - lazyInitialize(mFile, mStream); - if ( locusdata != null && !(locusdata instanceof VCFGenotypeLocusData) ) throw new IllegalArgumentException("Only VCFGenotypeLocusData objects should be passed in to the VCF writers");