initial check-in of an easy way to create command line tools based on the GATK
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@970 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
b0cc763eb5
commit
f304803811
|
|
@ -0,0 +1,192 @@
|
|||
package org.broadinstitute.sting.gatk;
|
||||
|
||||
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;
|
||||
import org.broadinstitute.sting.utils.cmdLine.ArgumentException;
|
||||
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;
|
||||
|
||||
|
||||
/*
|
||||
* 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 argument collection, the collection of command line args we accept
|
||||
protected GATKArgumentCollection argCollection = new GATKArgumentCollection();
|
||||
|
||||
/** the type of analysis to run - switch to the type of analysis */
|
||||
private String analysisName = "SomaticCoverageWalker";
|
||||
|
||||
// our walker manager
|
||||
private WalkerManager walkerManager = null;
|
||||
|
||||
// our genome analysis engine
|
||||
private GenomeAnalysisEngine GATKEngine = null;
|
||||
|
||||
public String pluginPathName = null;
|
||||
|
||||
// get the analysis name
|
||||
protected abstract String getAnalysisName();
|
||||
|
||||
// override select arguments
|
||||
protected abstract void overrideArguments();
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
// create the walker
|
||||
Walker<?, ?> mWalker = null;
|
||||
try {
|
||||
mWalker = walkerManager.createWalkerByName(analysisName);
|
||||
} catch (InstantiationException ex) {
|
||||
throw new RuntimeException("Unable to instantiate walker.", ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new RuntimeException("Unable to access walker", ex);
|
||||
}
|
||||
|
||||
// load the arguments into the walkers
|
||||
loadArgumentsIntoObject(argCollection);
|
||||
loadArgumentsIntoObject(mWalker);
|
||||
|
||||
// process any arguments that need a second pass
|
||||
processArguments(argCollection);
|
||||
|
||||
// set the analysis name in the argument collection
|
||||
this.argCollection.analysisName = this.analysisName;
|
||||
try {
|
||||
GATKEngine = new GenomeAnalysisEngine(argCollection, mWalker);
|
||||
}
|
||||
catch (ArgumentException ex) {
|
||||
// Rethrow argument exceptions. Let the command-line argument do what it's designed to do.
|
||||
throw ex;
|
||||
}
|
||||
catch (StingException exp) {
|
||||
System.err.println("Caught StingException. It's message is " + exp.getMessage());
|
||||
exp.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* GATK can add arguments dynamically based on analysis type.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
@Override
|
||||
protected boolean canAddArgumentsDynamically() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* GATK provides the walker as an argument source. As a side-effect, initializes the walker variable.
|
||||
*
|
||||
* @return List of walkers to load dynamically.
|
||||
*/
|
||||
@Override
|
||||
protected Class[] getArgumentSources() {
|
||||
// get the analysis name from the overriding class
|
||||
analysisName = this.getAnalysisName();
|
||||
|
||||
// get any argument overrides they want to present
|
||||
overrideArguments();
|
||||
// No walker info? No plugins.
|
||||
if (analysisName == null) return new Class[]{};
|
||||
|
||||
walkerManager = new WalkerManager(pluginPathName);
|
||||
|
||||
if (!walkerManager.doesWalkerExist(analysisName))
|
||||
throw new IllegalArgumentException("Invalid analysis name");
|
||||
|
||||
return new Class[]{walkerManager.getWalkerClassByName(analysisName)};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Preprocess the arguments before submitting them to the GATK engine.
|
||||
*
|
||||
* @param argCollection Collection of arguments to preprocess.
|
||||
*/
|
||||
private void processArguments( GATKArgumentCollection argCollection ) {
|
||||
argCollection.samFiles = unpackReads(argCollection.samFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>();
|
||||
for (File inputFile : inputFiles) {
|
||||
if (inputFile.getName().endsWith(".list")) {
|
||||
try {
|
||||
for (String fileName : new xReadLines(inputFile))
|
||||
unpackedReads.add(new File(fileName));
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
throw new StingException("Unable to find file while unpacking reads", ex);
|
||||
}
|
||||
} else
|
||||
unpackedReads.add(inputFile);
|
||||
}
|
||||
return unpackedReads;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgumentSourceName( Class argumentSource ) {
|
||||
return WalkerManager.getWalkerName((Class<Walker>) argumentSource);
|
||||
}
|
||||
|
||||
public GATKArgumentCollection getArgCollection() {
|
||||
return argCollection;
|
||||
}
|
||||
|
||||
public void setArgCollection( GATKArgumentCollection argCollection ) {
|
||||
this.argCollection = argCollection;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package org.broadinstitute.sting.playground.somaticcoverage;
|
||||
|
||||
import org.broadinstitute.sting.gatk.CommandLineExecutable;
|
||||
import org.broadinstitute.sting.gatk.GATKArgumentCollection;
|
||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* a executable command line for the Somatic Coverage Walker.
|
||||
*/
|
||||
public class SomaticCoverageTool extends CommandLineExecutable {
|
||||
|
||||
// the two sam/bam files, one for cancer, one for normal
|
||||
@Argument(fullName = "bam_files", shortName = "I", doc = "The bam files, one for the tumor one for the normal", required = true)
|
||||
public List<File> samFiles = new ArrayList<File>();
|
||||
|
||||
|
||||
/** Required main method implementation. */
|
||||
public static void main( String[] argv ) {
|
||||
try {
|
||||
SomaticCoverageTool instance = new SomaticCoverageTool();
|
||||
start(instance, argv);
|
||||
} catch (Exception e) {
|
||||
exitSystemWithError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* a required method, returns the analysis name. This is usually the walker
|
||||
* name with 'Walker' stripped off.
|
||||
*
|
||||
* @return the name of the analysis we're running
|
||||
*/
|
||||
protected String getAnalysisName() {
|
||||
return "SomaticCoverage";
|
||||
}
|
||||
|
||||
/** override any arguments we see fit. */
|
||||
protected void overrideArguments() {
|
||||
this.argCollection = GATKArgumentCollection.unmarshal("SomaticCoverage.xml");
|
||||
this.argCollection.intervals = "CancerIntervals.interval";
|
||||
this.argCollection.samFiles = samFiles;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue