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
This commit is contained in:
ebanks 2009-11-12 02:14:50 +00:00
parent 2ea85fb62b
commit 697d7e02c8
1 changed files with 12 additions and 24 deletions

View File

@ -21,10 +21,7 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
private VCFHeader mHeader = null; private VCFHeader mHeader = null;
private String mSource; private String mSource;
private String mReferenceName; private String mReferenceName;
private boolean mInitialized = false;
private final Set<String> mSampleNames = new HashSet<String>(); private final Set<String> mSampleNames = new HashSet<String>();
private final File mFile;
private final OutputStream mStream;
/** our log, which we want to capture anything from this class */ /** our log, which we want to capture anything from this class */
protected static Logger logger = Logger.getLogger(VCFGenotypeWriterAdapter.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<String> sampleNames) { public VCFGenotypeWriterAdapter(String source, String referenceName, File writeTo, Set<String> sampleNames) {
mReferenceName = referenceName; mReferenceName = referenceName;
mSource = source; mSource = source;
mFile = writeTo;
if (mFile == null) throw new RuntimeException("VCF output file must not be null");
mStream = null;
mSampleNames.addAll(sampleNames); 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<String> sampleNames) { public VCFGenotypeWriterAdapter(String source, String referenceName, OutputStream writeTo, Set<String> sampleNames) {
mReferenceName = referenceName; mReferenceName = referenceName;
mSource = source; mSource = source;
mFile = null;
mStream = writeTo;
if (mStream == null) throw new RuntimeException("VCF output stream must not be null");
mSampleNames.addAll(sampleNames); 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 * initialize this VCF header
*
* @param file the file location to write to
* @param stream the output stream
*/ */
private void lazyInitialize(File file, OutputStream stream) { private void initializeHeader() {
Map<String, String> hInfo = new HashMap<String, String>(); Map<String, String> hInfo = new HashMap<String, String>();
// setup the header fields // setup the header fields
@ -65,11 +62,6 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
// setup the sample names // setup the sample names
mHeader = new VCFHeader(hInfo, mSampleNames); 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. */ /** finish writing, closing any open files. */
public void close() { public void close() {
if (mInitialized) mWriter.close();
mWriter.close();
} }
/** /**
@ -119,9 +110,6 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
* @param genotypes the list of genotypes * @param genotypes the list of genotypes
*/ */
public void addMultiSampleCall(List<Genotype> genotypes, GenotypeLocusData locusdata) { public void addMultiSampleCall(List<Genotype> genotypes, GenotypeLocusData locusdata) {
if (!mInitialized)
lazyInitialize(mFile, mStream);
if ( locusdata != null && !(locusdata instanceof VCFGenotypeLocusData) ) if ( locusdata != null && !(locusdata instanceof VCFGenotypeLocusData) )
throw new IllegalArgumentException("Only VCFGenotypeLocusData objects should be passed in to the VCF writers"); throw new IllegalArgumentException("Only VCFGenotypeLocusData objects should be passed in to the VCF writers");