fixes for GSA-199: Need easier way to write binary outputs to standard output. GLF and VCF now have stream constructors, and can get dumped to standard out.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1818 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
f37564e63a
commit
77499e35ac
|
|
@ -101,7 +101,8 @@ public class UnifiedGenotyper extends LocusWalker<List<GenotypeCall>, Integer> {
|
|||
"UnifiedGenotyper",
|
||||
this.getToolkit().getArguments().referenceFile.getName());
|
||||
else
|
||||
writer = GenotypeWriterFactory.create(VAR_FORMAT, GenomeAnalysisEngine.instance.getSAMFileHeader(), out);
|
||||
writer = GenotypeWriterFactory.create(VAR_FORMAT, GenomeAnalysisEngine.instance.getSAMFileHeader(), out, "UnifiedGenotyper",
|
||||
this.getToolkit().getArguments().referenceFile.getName());
|
||||
|
||||
gcm = GenotypeCalculationModelFactory.makeGenotypeCalculation(UAC, samples, writer, logger);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,10 +46,14 @@ public class GenotypeWriterFactory {
|
|||
}
|
||||
}
|
||||
|
||||
public static GenotypeWriter create(GENOTYPE_FORMAT format, SAMFileHeader header, PrintStream destination) {
|
||||
public static GenotypeWriter create(GENOTYPE_FORMAT format, SAMFileHeader header, PrintStream destination, String source, String referenceName ) {
|
||||
switch (format) {
|
||||
case GELI:
|
||||
return new GeliTextWriter(destination);
|
||||
case GLF:
|
||||
return new GLFWriter(header.toString(), destination);
|
||||
case VCF:
|
||||
return new VCFGenotypeWriterAdapter(source, referenceName, destination);
|
||||
default:
|
||||
throw new StingException("Genotype writer to " + format.toString() + " to standard output is not implemented");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.broadinstitute.sting.utils.genotype.*;
|
|||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
/*
|
||||
|
|
@ -73,6 +74,20 @@ public class GLFWriter implements GenotypeWriter {
|
|||
this.writeHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* The public constructor for creating a GLF object
|
||||
*
|
||||
* @param headerText the header text (currently unclear what the contents are)
|
||||
* @param writeTo the location to write to
|
||||
*/
|
||||
public GLFWriter(String headerText, OutputStream writeTo) {
|
||||
this.headerText = headerText;
|
||||
outputBinaryCodec = new BinaryCodec(writeTo);
|
||||
outputBinaryCodec.setOutputFileName(writeTo.toString());
|
||||
this.writeHeader();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add a point genotype to the GLF writer
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,11 +8,8 @@ import org.broadinstitute.sting.utils.genotype.ReadBacked;
|
|||
import org.broadinstitute.sting.utils.genotype.SampleBacked;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -31,13 +28,21 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
|||
private final Map<String, String> mSampleNames = new HashMap<String, String>();
|
||||
private boolean mInitialized = false;
|
||||
private final File mFile;
|
||||
private final OutputStream mStream;
|
||||
|
||||
public VCFGenotypeWriterAdapter(String source, String referenceName, File writeTo) {
|
||||
mReferenceName = referenceName;
|
||||
mSource = source;
|
||||
mFile = writeTo;
|
||||
mStream = null;
|
||||
}
|
||||
|
||||
public VCFGenotypeWriterAdapter(String source, String referenceName, OutputStream writeTo) {
|
||||
mReferenceName = referenceName;
|
||||
mSource = source;
|
||||
mFile = null;
|
||||
mStream = writeTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize this VCF writer
|
||||
|
|
@ -45,7 +50,7 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
|||
* @param genotypes the genotypes
|
||||
* @param file the file location to write to
|
||||
*/
|
||||
private void lazyInitialize(List<Genotype> genotypes, File file) {
|
||||
private void lazyInitialize(List<Genotype> genotypes, File file, OutputStream stream) {
|
||||
Map<String, String> hInfo = new HashMap<String, String>();
|
||||
List<String> sampleNames = getSampleNames(genotypes);
|
||||
|
||||
|
|
@ -55,7 +60,10 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
|||
|
||||
// setup the sample names
|
||||
mHeader = new VCFHeader(hInfo, sampleNames);
|
||||
mWriter = new VCFWriter(mHeader, file);
|
||||
if (mFile == null)
|
||||
mWriter = new VCFWriter(mHeader, stream);
|
||||
else
|
||||
mWriter = new VCFWriter(mHeader, file);
|
||||
mInitialized = true;
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +119,7 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
|||
@Override
|
||||
public void addMultiSampleCall(List<Genotype> genotypes) {
|
||||
if (!mInitialized)
|
||||
lazyInitialize(genotypes, mFile);
|
||||
lazyInitialize(genotypes, mFile, mStream);
|
||||
|
||||
|
||||
VCFParamters params = new VCFParamters();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
package org.broadinstitute.sting.utils.genotype.vcf;
|
||||
|
||||
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/** this class writers VCF files */
|
||||
/**
|
||||
* this class writers VCF files
|
||||
*/
|
||||
public class VCFWriter {
|
||||
|
||||
// the VCF header we're storing
|
||||
|
|
@ -21,16 +25,30 @@ public class VCFWriter {
|
|||
* @param location the file location to write to
|
||||
*/
|
||||
public VCFWriter(VCFHeader header, File location) {
|
||||
this.mHeader = header;
|
||||
Charset utf8 = Charset.forName("UTF-8");
|
||||
FileOutputStream output;
|
||||
try {
|
||||
mWriter = new BufferedWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(location),
|
||||
utf8));
|
||||
output = new FileOutputStream(location);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException("Unable to create VCF file: " + location, e);
|
||||
throw new RuntimeException("Unable to create VCF file at location: " + location);
|
||||
}
|
||||
initialize(header, output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create a VCF writer, given a VCF header and a file to write to
|
||||
*
|
||||
* @param header the VCF header
|
||||
* @param location the file location to write to
|
||||
*/
|
||||
public VCFWriter(VCFHeader header, OutputStream location) {
|
||||
initialize(header, location);
|
||||
}
|
||||
|
||||
private void initialize(VCFHeader header, OutputStream location) {
|
||||
this.mHeader = header;
|
||||
mWriter = new BufferedWriter(
|
||||
new OutputStreamWriter(location));
|
||||
try {
|
||||
// write the header meta-data out
|
||||
for (String metadata : header.getMetaData().keySet()) {
|
||||
|
|
@ -71,8 +89,9 @@ public class VCFWriter {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/** attempt to close the VCF file */
|
||||
/**
|
||||
* attempt to close the VCF file
|
||||
*/
|
||||
public void close() {
|
||||
try {
|
||||
mWriter.flush();
|
||||
|
|
|
|||
Loading…
Reference in New Issue