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",
|
"UnifiedGenotyper",
|
||||||
this.getToolkit().getArguments().referenceFile.getName());
|
this.getToolkit().getArguments().referenceFile.getName());
|
||||||
else
|
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);
|
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) {
|
switch (format) {
|
||||||
case GELI:
|
case GELI:
|
||||||
return new GeliTextWriter(destination);
|
return new GeliTextWriter(destination);
|
||||||
|
case GLF:
|
||||||
|
return new GLFWriter(header.toString(), destination);
|
||||||
|
case VCF:
|
||||||
|
return new VCFGenotypeWriterAdapter(source, referenceName, destination);
|
||||||
default:
|
default:
|
||||||
throw new StingException("Genotype writer to " + format.toString() + " to standard output is not implemented");
|
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.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
/*
|
/*
|
||||||
|
|
@ -73,6 +74,20 @@ public class GLFWriter implements GenotypeWriter {
|
||||||
this.writeHeader();
|
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
|
* 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 org.broadinstitute.sting.utils.genotype.SampleBacked;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -31,13 +28,21 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
||||||
private final Map<String, String> mSampleNames = new HashMap<String, String>();
|
private final Map<String, String> mSampleNames = new HashMap<String, String>();
|
||||||
private boolean mInitialized = false;
|
private boolean mInitialized = false;
|
||||||
private final File mFile;
|
private final File mFile;
|
||||||
|
private final OutputStream mStream;
|
||||||
|
|
||||||
public VCFGenotypeWriterAdapter(String source, String referenceName, File writeTo) {
|
public VCFGenotypeWriterAdapter(String source, String referenceName, File writeTo) {
|
||||||
mReferenceName = referenceName;
|
mReferenceName = referenceName;
|
||||||
mSource = source;
|
mSource = source;
|
||||||
mFile = writeTo;
|
mFile = writeTo;
|
||||||
|
mStream = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VCFGenotypeWriterAdapter(String source, String referenceName, OutputStream writeTo) {
|
||||||
|
mReferenceName = referenceName;
|
||||||
|
mSource = source;
|
||||||
|
mFile = null;
|
||||||
|
mStream = writeTo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize this VCF writer
|
* initialize this VCF writer
|
||||||
|
|
@ -45,7 +50,7 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
||||||
* @param genotypes the genotypes
|
* @param genotypes the genotypes
|
||||||
* @param file the file location to write to
|
* @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>();
|
Map<String, String> hInfo = new HashMap<String, String>();
|
||||||
List<String> sampleNames = getSampleNames(genotypes);
|
List<String> sampleNames = getSampleNames(genotypes);
|
||||||
|
|
||||||
|
|
@ -55,6 +60,9 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
||||||
|
|
||||||
// setup the sample names
|
// setup the sample names
|
||||||
mHeader = new VCFHeader(hInfo, sampleNames);
|
mHeader = new VCFHeader(hInfo, sampleNames);
|
||||||
|
if (mFile == null)
|
||||||
|
mWriter = new VCFWriter(mHeader, stream);
|
||||||
|
else
|
||||||
mWriter = new VCFWriter(mHeader, file);
|
mWriter = new VCFWriter(mHeader, file);
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +119,7 @@ public class VCFGenotypeWriterAdapter implements GenotypeWriter {
|
||||||
@Override
|
@Override
|
||||||
public void addMultiSampleCall(List<Genotype> genotypes) {
|
public void addMultiSampleCall(List<Genotype> genotypes) {
|
||||||
if (!mInitialized)
|
if (!mInitialized)
|
||||||
lazyInitialize(genotypes, mFile);
|
lazyInitialize(genotypes, mFile, mStream);
|
||||||
|
|
||||||
|
|
||||||
VCFParamters params = new VCFParamters();
|
VCFParamters params = new VCFParamters();
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
package org.broadinstitute.sting.utils.genotype.vcf;
|
package org.broadinstitute.sting.utils.genotype.vcf;
|
||||||
|
|
||||||
|
|
||||||
|
import org.broadinstitute.sting.utils.StingException;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/** this class writers VCF files */
|
/**
|
||||||
|
* this class writers VCF files
|
||||||
|
*/
|
||||||
public class VCFWriter {
|
public class VCFWriter {
|
||||||
|
|
||||||
// the VCF header we're storing
|
// the VCF header we're storing
|
||||||
|
|
@ -21,16 +25,30 @@ public class VCFWriter {
|
||||||
* @param location the file location to write to
|
* @param location the file location to write to
|
||||||
*/
|
*/
|
||||||
public VCFWriter(VCFHeader header, File location) {
|
public VCFWriter(VCFHeader header, File location) {
|
||||||
this.mHeader = header;
|
FileOutputStream output;
|
||||||
Charset utf8 = Charset.forName("UTF-8");
|
|
||||||
try {
|
try {
|
||||||
mWriter = new BufferedWriter(
|
output = new FileOutputStream(location);
|
||||||
new OutputStreamWriter(
|
|
||||||
new FileOutputStream(location),
|
|
||||||
utf8));
|
|
||||||
} catch (FileNotFoundException e) {
|
} 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 {
|
try {
|
||||||
// write the header meta-data out
|
// write the header meta-data out
|
||||||
for (String metadata : header.getMetaData().keySet()) {
|
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() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
mWriter.flush();
|
mWriter.flush();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue