Given that all classes implementing output stubs already have getters for the underlying OutputStream and File, it makes sense to unify that functionality into the Stub interface. Now it is possible to have an Engine utility method that iterates over all registered stubs to find the one representing a given OutputStream and return the File associated with it.
This commit is contained in:
parent
994a4ff387
commit
4bb7a99f08
|
|
@ -63,6 +63,7 @@ import org.broadinstitute.sting.utils.recalibration.BaseRecalibration;
|
|||
import org.broadinstitute.sting.utils.threading.ThreadEfficiencyMonitor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
|
@ -731,6 +732,21 @@ public class GenomeAnalysisEngine {
|
|||
outputs.add(stub);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over all registered output stubs and tries to find the one representing the given OutputStream.
|
||||
*
|
||||
* @param output the stream to check for
|
||||
* @return the file associated with the given stream/stub if available, null otherwise
|
||||
*/
|
||||
public File getFilenameFromAssociatedOutputStream(final OutputStream output) {
|
||||
for ( final Stub<?> stub : outputs ) {
|
||||
if ( stub.getOutputStream() == output )
|
||||
return stub.getOutputFile();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tag associated with a given command-line argument.
|
||||
* @param key Object for which to inspect the tag.
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage<SAMFileWrite
|
|||
private static Logger logger = Logger.getLogger(SAMFileWriterStorage.class);
|
||||
|
||||
public SAMFileWriterStorage( SAMFileWriterStub stub ) {
|
||||
this(stub,stub.getSAMFile());
|
||||
this(stub,stub.getOutputFile());
|
||||
}
|
||||
|
||||
public SAMFileWriterStorage( SAMFileWriterStub stub, File file ) {
|
||||
|
|
@ -66,7 +66,7 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage<SAMFileWrite
|
|||
if(stub.getMaxRecordsInRam() != null)
|
||||
factory.setMaxRecordsInRam(stub.getMaxRecordsInRam());
|
||||
|
||||
if(stub.getSAMFile() != null) {
|
||||
if(stub.getOutputFile() != null) {
|
||||
try {
|
||||
this.writer = createBAMWriter(factory,stub.getFileHeader(),stub.isPresorted(),file,stub.getCompressionLevel());
|
||||
}
|
||||
|
|
@ -74,8 +74,8 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage<SAMFileWrite
|
|||
throw new UserException.CouldNotCreateOutputFile(file,"file could not be created",ex);
|
||||
}
|
||||
}
|
||||
else if(stub.getSAMOutputStream() != null){
|
||||
this.writer = factory.makeSAMWriter( stub.getFileHeader(), stub.isPresorted(), stub.getSAMOutputStream());
|
||||
else if(stub.getOutputStream() != null){
|
||||
this.writer = factory.makeSAMWriter( stub.getFileHeader(), stub.isPresorted(), stub.getOutputStream());
|
||||
}
|
||||
else
|
||||
throw new UserException("Unable to write to SAM file; neither a target file nor a stream has been specified");
|
||||
|
|
|
|||
|
|
@ -69,9 +69,9 @@ public class VariantContextWriterStorage implements Storage<VariantContextWriter
|
|||
* @param stub Stub to use when constructing the output file.
|
||||
*/
|
||||
public VariantContextWriterStorage(VariantContextWriterStub stub) {
|
||||
if ( stub.getFile() != null ) {
|
||||
this.file = stub.getFile();
|
||||
writer = vcfWriterToFile(stub,stub.getFile(),true);
|
||||
if ( stub.getOutputFile() != null ) {
|
||||
this.file = stub.getOutputFile();
|
||||
writer = vcfWriterToFile(stub,stub.getOutputFile(),true);
|
||||
}
|
||||
else if ( stub.getOutputStream() != null ) {
|
||||
this.file = null;
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public class SAMFileWriterStub implements Stub<SAMFileWriter>, StingSAMFileWrite
|
|||
* Retrieves the SAM file to (ultimately) be created.
|
||||
* @return The SAM file. Must not be null.
|
||||
*/
|
||||
public File getSAMFile() {
|
||||
public File getOutputFile() {
|
||||
return samFile;
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ public class SAMFileWriterStub implements Stub<SAMFileWriter>, StingSAMFileWrite
|
|||
simplifyBAM = v;
|
||||
}
|
||||
|
||||
public OutputStream getSAMOutputStream() {
|
||||
public OutputStream getOutputStream() {
|
||||
return samOutputStream;
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ public class SAMFileWriterStub implements Stub<SAMFileWriter>, StingSAMFileWrite
|
|||
|
||||
/**
|
||||
* Gets whether to generate an md5 on-the-fly for this BAM.
|
||||
* @return True generates the md5. False means skip writing the file.
|
||||
* @param generateMD5 True generates the md5. False means skip writing the file.
|
||||
*/
|
||||
public void setGenerateMD5(boolean generateMD5) {
|
||||
if(writeStarted)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ package org.broadinstitute.sting.gatk.io.stubs;
|
|||
|
||||
import org.broadinstitute.sting.gatk.io.OutputTracker;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* A stub used for managing IO. Acts as a proxy for IO streams
|
||||
* not yet created or streams that need significant external
|
||||
|
|
@ -43,4 +46,14 @@ public interface Stub<StreamType> {
|
|||
* @param outputTracker The connector used to provide an appropriate stream.
|
||||
*/
|
||||
public void register( OutputTracker outputTracker );
|
||||
|
||||
/**
|
||||
* Returns the OutputStream represented by this stub or null if not available.
|
||||
*/
|
||||
public OutputStream getOutputStream();
|
||||
|
||||
/**
|
||||
* Returns the File represented by this stub or null if not available.
|
||||
*/
|
||||
public File getOutputFile();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public class VariantContextWriterStub implements Stub<VariantContextWriter>, Var
|
|||
* Retrieves the file to (ultimately) be created.
|
||||
* @return The file. Can be null if genotypeStream is not.
|
||||
*/
|
||||
public File getFile() {
|
||||
public File getOutputFile() {
|
||||
return genotypeFile;
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ public class VariantContextWriterStub implements Stub<VariantContextWriter>, Var
|
|||
* Retrieves the output stearm to which to (ultimately) write.
|
||||
* @return The file. Can be null if genotypeFile is not.
|
||||
*/
|
||||
public PrintStream getOutputStream() {
|
||||
public OutputStream getOutputStream() {
|
||||
return genotypeStream;
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ public class VariantContextWriterStub implements Stub<VariantContextWriter>, Var
|
|||
if ( engine.lenientVCFProcessing() ) options.add(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
|
||||
if ( indexOnTheFly && ! isCompressed() ) options.add(Options.INDEX_ON_THE_FLY);
|
||||
|
||||
if ( forceBCF || (getFile() != null && VariantContextWriterFactory.isBCFOutput(getFile())) )
|
||||
if ( forceBCF || (getOutputFile() != null && VariantContextWriterFactory.isBCFOutput(getOutputFile())) )
|
||||
options.add(Options.FORCE_BCF);
|
||||
|
||||
return options.isEmpty() ? EnumSet.noneOf(Options.class) : EnumSet.copyOf(options);
|
||||
|
|
@ -271,7 +271,7 @@ public class VariantContextWriterStub implements Stub<VariantContextWriter>, Var
|
|||
public boolean alsoWriteBCFForTest() {
|
||||
return engine.getArguments().numberOfDataThreads == 1 && // only works single threaded
|
||||
! isCompressed() && // for non-compressed outputs
|
||||
getFile() != null && // that are going to disk
|
||||
getOutputFile() != null && // that are going to disk
|
||||
engine.getArguments().generateShadowBCF; // and we actually want to do it
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue