2009-06-11 01:34:02 +08:00
|
|
|
/*
|
2010-04-20 07:00:08 +08:00
|
|
|
* Copyright (c) 2010 The Broad Institute
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2009-06-11 01:34:02 +08:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
2010-04-20 23:26:32 +08:00
|
|
|
* files (the "Software"), to deal in the Software without
|
2009-06-11 01:34:02 +08:00
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2009-06-11 01:34:02 +08:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
2010-04-20 23:26:32 +08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
2009-06-11 01:34:02 +08:00
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
2010-04-20 07:00:08 +08:00
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-06-11 01:34:02 +08:00
|
|
|
*/
|
|
|
|
|
|
2010-04-20 07:00:08 +08:00
|
|
|
package org.broadinstitute.sting.gatk;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection;
|
|
|
|
|
import org.broadinstitute.sting.commandline.CommandLineProgram;
|
|
|
|
|
import org.broadinstitute.sting.commandline.ArgumentTypeDescriptor;
|
2010-09-22 23:27:58 +08:00
|
|
|
import org.broadinstitute.sting.gatk.io.stubs.OutputStreamArgumentTypeDescriptor;
|
|
|
|
|
import org.broadinstitute.sting.gatk.io.stubs.SAMFileReaderArgumentTypeDescriptor;
|
|
|
|
|
import org.broadinstitute.sting.gatk.io.stubs.SAMFileWriterArgumentTypeDescriptor;
|
|
|
|
|
import org.broadinstitute.sting.gatk.io.stubs.VCFWriterArgumentTypeDescriptor;
|
2010-08-29 06:53:32 +08:00
|
|
|
import org.broadinstitute.sting.gatk.phonehome.GATKRunReport;
|
2010-04-20 07:00:08 +08:00
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import net.sf.picard.filter.SamRecordFilter;
|
|
|
|
|
|
2009-06-11 01:34:02 +08:00
|
|
|
/**
|
|
|
|
|
* @author aaron
|
|
|
|
|
*/
|
|
|
|
|
public abstract class CommandLineExecutable extends CommandLineProgram {
|
2009-07-17 06:48:44 +08:00
|
|
|
/**
|
2009-07-22 02:50:51 +08:00
|
|
|
* The actual engine which performs the analysis.
|
2009-07-17 06:48:44 +08:00
|
|
|
*/
|
2010-09-22 23:27:58 +08:00
|
|
|
protected GenomeAnalysisEngine engine = new GenomeAnalysisEngine();
|
2009-06-11 01:34:02 +08:00
|
|
|
|
|
|
|
|
// get the analysis name
|
2010-09-22 23:27:58 +08:00
|
|
|
public abstract String getAnalysisName();
|
2009-06-11 01:34:02 +08:00
|
|
|
|
2009-07-17 06:48:44 +08:00
|
|
|
/**
|
|
|
|
|
* Gets the GATK argument bundle.
|
|
|
|
|
* @return A structure consisting of whatever arguments should be used to initialize the GATK engine.
|
|
|
|
|
*/
|
2009-07-17 06:02:21 +08:00
|
|
|
protected abstract GATKArgumentCollection getArgumentCollection();
|
|
|
|
|
|
2010-09-22 23:27:58 +08:00
|
|
|
/**
|
|
|
|
|
* A list of all the arguments initially used as sources.
|
|
|
|
|
*/
|
|
|
|
|
private final Collection<Object> argumentSources = new ArrayList<Object>();
|
2009-06-11 01:34:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* this is the function that the inheriting class can expect to have called
|
|
|
|
|
* when the command line system has initialized.
|
|
|
|
|
*
|
|
|
|
|
* @return the return code to exit the program with
|
|
|
|
|
*/
|
2010-08-29 06:53:32 +08:00
|
|
|
protected int execute() throws Exception {
|
2010-10-28 03:44:55 +08:00
|
|
|
engine.setParser(parser);
|
2010-09-22 23:27:58 +08:00
|
|
|
argumentSources.add(this);
|
|
|
|
|
|
|
|
|
|
Walker<?,?> walker = engine.getWalkerByName(getAnalysisName());
|
2009-07-17 06:48:44 +08:00
|
|
|
|
2010-08-29 06:53:32 +08:00
|
|
|
try {
|
2010-09-24 07:28:55 +08:00
|
|
|
engine.setArguments(getArgumentCollection());
|
|
|
|
|
engine.setWalker(walker);
|
2010-09-25 10:49:30 +08:00
|
|
|
walker.setToolkit(engine);
|
2010-09-24 07:28:55 +08:00
|
|
|
|
|
|
|
|
Collection<SamRecordFilter> filters = engine.createFilters();
|
|
|
|
|
engine.setFilters(filters);
|
2010-09-12 22:02:43 +08:00
|
|
|
|
|
|
|
|
// load the arguments into the walker / filters.
|
2010-09-22 23:27:58 +08:00
|
|
|
// TODO: The fact that this extra load call exists here when all the parsing happens at the engine
|
|
|
|
|
// TODO: level indicates that we're doing something wrong. Turn this around so that the GATK can drive
|
|
|
|
|
// TODO: argument processing.
|
|
|
|
|
loadArgumentsIntoObject(walker);
|
|
|
|
|
argumentSources.add(walker);
|
|
|
|
|
|
|
|
|
|
for (SamRecordFilter filter: filters) {
|
2010-09-12 22:02:43 +08:00
|
|
|
loadArgumentsIntoObject(filter);
|
2010-09-22 23:27:58 +08:00
|
|
|
argumentSources.add(filter);
|
|
|
|
|
}
|
2010-09-12 22:02:43 +08:00
|
|
|
|
2010-09-24 07:28:55 +08:00
|
|
|
engine.execute();
|
2010-09-22 23:27:58 +08:00
|
|
|
generateGATKRunReport(walker);
|
2010-08-29 06:53:32 +08:00
|
|
|
} catch ( Exception e ) {
|
2010-09-22 23:27:58 +08:00
|
|
|
generateGATKRunReport(walker, e);
|
2010-08-29 06:53:32 +08:00
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// always return 0
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-08-29 23:59:25 +08:00
|
|
|
* Generate the GATK run report for this walker using the current GATKEngine, if -et is enabled.
|
|
|
|
|
* This report will be written to either STDOUT or to the run repository, depending on the options
|
|
|
|
|
* for -et.
|
|
|
|
|
*
|
2010-08-29 06:53:32 +08:00
|
|
|
* @param e the exception, can be null if no exception occurred
|
|
|
|
|
*/
|
2010-09-22 23:27:58 +08:00
|
|
|
private void generateGATKRunReport(Walker<?,?> walker, Exception e) {
|
2010-08-29 06:53:32 +08:00
|
|
|
if ( getArgumentCollection().phoneHomeType != GATKRunReport.PhoneHomeOption.NO_ET ) {
|
2010-09-22 23:27:58 +08:00
|
|
|
GATKRunReport report = new GATKRunReport(walker, e, engine, getArgumentCollection().phoneHomeType );
|
2010-08-29 06:53:32 +08:00
|
|
|
if ( getArgumentCollection().phoneHomeType == GATKRunReport.PhoneHomeOption.STDOUT )
|
|
|
|
|
report.postReport(System.out);
|
|
|
|
|
else
|
|
|
|
|
report.postReport();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-29 23:59:25 +08:00
|
|
|
/**
|
|
|
|
|
* Convenience method for fully parameterized generateGATKRunReport when an exception has
|
|
|
|
|
* not occurred
|
2010-09-24 07:28:55 +08:00
|
|
|
*
|
2010-09-22 23:27:58 +08:00
|
|
|
* @param walker
|
2010-08-29 23:59:25 +08:00
|
|
|
*/
|
2010-09-22 23:27:58 +08:00
|
|
|
private void generateGATKRunReport(Walker<?,?> walker) {
|
|
|
|
|
generateGATKRunReport(walker, null);
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
|
|
|
|
|
2009-08-23 08:56:02 +08:00
|
|
|
/**
|
|
|
|
|
* Subclasses of CommandLinePrograms can provide their own types of command-line arguments.
|
|
|
|
|
* @return A collection of type descriptors generating implementation-dependent placeholders.
|
|
|
|
|
*/
|
|
|
|
|
protected Collection<ArgumentTypeDescriptor> getArgumentTypeDescriptors() {
|
2010-09-22 23:27:58 +08:00
|
|
|
return Arrays.asList( new VCFWriterArgumentTypeDescriptor(engine,System.out,argumentSources),
|
|
|
|
|
new SAMFileReaderArgumentTypeDescriptor(engine),
|
|
|
|
|
new SAMFileWriterArgumentTypeDescriptor(engine,System.out),
|
|
|
|
|
new OutputStreamArgumentTypeDescriptor(engine,System.out) );
|
2009-08-23 08:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
2009-06-11 01:34:02 +08:00
|
|
|
/**
|
|
|
|
|
* GATK can add arguments dynamically based on analysis type.
|
|
|
|
|
*
|
|
|
|
|
* @return true
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean canAddArgumentsDynamically() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-07-17 06:02:21 +08:00
|
|
|
* GATK provides the walker as an argument source.
|
2009-06-11 01:34:02 +08:00
|
|
|
* @return List of walkers to load dynamically.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected Class[] getArgumentSources() {
|
|
|
|
|
// No walker info? No plugins.
|
2009-07-17 06:02:21 +08:00
|
|
|
if (getAnalysisName() == null) return new Class[] {};
|
2009-11-11 07:36:17 +08:00
|
|
|
|
|
|
|
|
Collection<Class> argumentSources = new ArrayList<Class>();
|
|
|
|
|
|
2010-09-22 23:27:58 +08:00
|
|
|
Walker walker = engine.getWalkerByName(getAnalysisName());
|
2010-09-24 07:28:55 +08:00
|
|
|
engine.setArguments(getArgumentCollection());
|
|
|
|
|
engine.setWalker(walker);
|
2010-09-25 10:49:30 +08:00
|
|
|
walker.setToolkit(engine);
|
2009-11-11 07:36:17 +08:00
|
|
|
argumentSources.add(walker.getClass());
|
|
|
|
|
|
2010-09-24 07:28:55 +08:00
|
|
|
Collection<SamRecordFilter> filters = engine.createFilters();
|
2009-11-11 07:36:17 +08:00
|
|
|
for(SamRecordFilter filter: filters)
|
|
|
|
|
argumentSources.add(filter.getClass());
|
|
|
|
|
|
|
|
|
|
Class[] argumentSourcesAsArray = new Class[argumentSources.size()];
|
|
|
|
|
return argumentSources.toArray(argumentSourcesAsArray);
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
|
|
|
|
|
2009-07-17 06:02:21 +08:00
|
|
|
@Override
|
|
|
|
|
protected String getArgumentSourceName( Class argumentSource ) {
|
2010-09-22 23:27:58 +08:00
|
|
|
return engine.getWalkerName((Class<Walker>)argumentSource);
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
2010-10-29 02:37:42 +08:00
|
|
|
}
|