2009-06-11 01:34:02 +08:00
|
|
|
package org.broadinstitute.sting.gatk;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;
|
2009-07-17 06:02:21 +08:00
|
|
|
import org.broadinstitute.sting.utils.cmdLine.ArgumentFactory;
|
|
|
|
|
import org.broadinstitute.sting.utils.cmdLine.ArgumentCollection;
|
2009-06-11 01:34:02 +08:00
|
|
|
import org.broadinstitute.sting.utils.StingException;
|
|
|
|
|
import org.broadinstitute.sting.utils.xReadLines;
|
|
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
2009-07-17 06:02:21 +08:00
|
|
|
import net.sf.samtools.SAMFileReader;
|
|
|
|
|
|
2009-06-11 01:34:02 +08:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2009 The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* 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:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* 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
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author aaron
|
|
|
|
|
* <p/>
|
|
|
|
|
* Generate a executable class for the SomaticCoverageWalker
|
|
|
|
|
*/
|
|
|
|
|
public abstract class CommandLineExecutable extends CommandLineProgram {
|
|
|
|
|
|
|
|
|
|
// our genome analysis engine
|
2009-07-10 07:59:53 +08:00
|
|
|
private GenomeAnalysisEngine GATKEngine = new GenomeAnalysisEngine();
|
2009-06-11 01:34:02 +08:00
|
|
|
|
|
|
|
|
// get the analysis name
|
|
|
|
|
protected abstract String getAnalysisName();
|
|
|
|
|
|
2009-07-17 06:02:21 +08:00
|
|
|
protected abstract GATKArgumentCollection getArgumentCollection();
|
|
|
|
|
|
2009-06-11 01:34:02 +08:00
|
|
|
// override select arguments
|
2009-07-17 06:02:21 +08:00
|
|
|
protected void overrideArguments() { }
|
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
|
|
|
|
|
*/
|
|
|
|
|
protected int execute() {
|
2009-07-17 06:02:21 +08:00
|
|
|
Walker<?,?> mWalker = GATKEngine.getWalkerByName(getAnalysisName());
|
|
|
|
|
|
|
|
|
|
GATKArgumentCollection arguments = getArgumentCollection();
|
2009-06-11 01:34:02 +08:00
|
|
|
|
|
|
|
|
// load the arguments into the walkers
|
2009-07-17 06:02:21 +08:00
|
|
|
loadArgumentsIntoObject(arguments);
|
2009-06-11 01:34:02 +08:00
|
|
|
loadArgumentsIntoObject(mWalker);
|
|
|
|
|
|
|
|
|
|
// process any arguments that need a second pass
|
2009-07-17 06:02:21 +08:00
|
|
|
processArguments(arguments);
|
2009-06-11 01:34:02 +08:00
|
|
|
|
|
|
|
|
// set the analysis name in the argument collection
|
2009-07-17 06:02:21 +08:00
|
|
|
arguments.analysisName = getAnalysisName();
|
|
|
|
|
GATKEngine.execute(arguments, mWalker);
|
2009-07-14 05:56:41 +08:00
|
|
|
|
2009-06-11 01:34:02 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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[] {};
|
|
|
|
|
return new Class[] { GATKEngine.getWalkerByName(getAnalysisName()).getClass() };
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
|
|
|
|
|
2009-07-17 06:02:21 +08:00
|
|
|
@Override
|
|
|
|
|
protected String getArgumentSourceName( Class argumentSource ) {
|
|
|
|
|
return WalkerManager.getWalkerName((Class<Walker>) argumentSource);
|
|
|
|
|
}
|
2009-06-11 01:34:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Preprocess the arguments before submitting them to the GATK engine.
|
|
|
|
|
*
|
|
|
|
|
* @param argCollection Collection of arguments to preprocess.
|
|
|
|
|
*/
|
|
|
|
|
private void processArguments( GATKArgumentCollection argCollection ) {
|
2009-07-17 06:02:21 +08:00
|
|
|
argCollection.samFiles = unpackReads( argCollection.samFiles );
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unpack the files to be processed, given a list of files. That list of files can
|
|
|
|
|
* itself contain lists of other files to be read.
|
|
|
|
|
*
|
|
|
|
|
* @param inputFiles
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<File> unpackReads( List<File> inputFiles ) {
|
|
|
|
|
List<File> unpackedReads = new ArrayList<File>();
|
2009-07-17 06:02:21 +08:00
|
|
|
for( File inputFile: inputFiles ) {
|
|
|
|
|
if (inputFile.getName().endsWith(".list") ) {
|
2009-06-11 01:34:02 +08:00
|
|
|
try {
|
2009-07-17 06:02:21 +08:00
|
|
|
for( String fileName : new xReadLines(inputFile) )
|
|
|
|
|
unpackedReads.add( new File(fileName) );
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
2009-07-17 06:02:21 +08:00
|
|
|
catch( FileNotFoundException ex ) {
|
2009-06-11 01:34:02 +08:00
|
|
|
throw new StingException("Unable to find file while unpacking reads", ex);
|
|
|
|
|
}
|
2009-07-17 06:02:21 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
unpackedReads.add( inputFile );
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
|
|
|
|
return unpackedReads;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-17 06:02:21 +08:00
|
|
|
/**
|
|
|
|
|
* Get a custom factory for instantiating specialty GATK arguments.
|
|
|
|
|
* @return An instance of the command-line argument of the specified type.
|
|
|
|
|
*/
|
2009-06-11 01:34:02 +08:00
|
|
|
@Override
|
2009-07-17 06:02:21 +08:00
|
|
|
protected ArgumentFactory getCustomArgumentFactory() {
|
|
|
|
|
return new ArgumentFactory() {
|
|
|
|
|
public Object createArgument( Class type, List<String> repr ) {
|
|
|
|
|
if (type == SAMFileReader.class && repr.size() == 1) {
|
|
|
|
|
SAMFileReader samFileReader = new SAMFileReader(new File(repr.get(0)),true);
|
|
|
|
|
samFileReader.setValidationStringency(getArgumentCollection().strictnessLevel);
|
|
|
|
|
return samFileReader;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-06-11 01:34:02 +08:00
|
|
|
}
|
|
|
|
|
}
|