Cleaned up some duplicate code in preparation for making plugin dir configurable.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1270 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
31f3f466ca
commit
7c30c30d26
|
|
@ -1,7 +1,8 @@
|
|||
package org.broadinstitute.sting.gatk;
|
||||
|
||||
import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram;
|
||||
import org.broadinstitute.sting.utils.cmdLine.ArgumentException;
|
||||
import org.broadinstitute.sting.utils.cmdLine.ArgumentFactory;
|
||||
import org.broadinstitute.sting.utils.cmdLine.ArgumentCollection;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
import org.broadinstitute.sting.utils.xReadLines;
|
||||
import org.broadinstitute.sting.gatk.walkers.Walker;
|
||||
|
|
@ -11,6 +12,8 @@ import java.io.FileNotFoundException;
|
|||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.sf.samtools.SAMFileReader;
|
||||
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The Broad Institute
|
||||
|
|
@ -44,20 +47,16 @@ import java.util.ArrayList;
|
|||
*/
|
||||
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 genome analysis engine
|
||||
private GenomeAnalysisEngine GATKEngine = new GenomeAnalysisEngine();
|
||||
|
||||
// get the analysis name
|
||||
protected abstract String getAnalysisName();
|
||||
|
||||
protected abstract GATKArgumentCollection getArgumentCollection();
|
||||
|
||||
// override select arguments
|
||||
protected abstract void overrideArguments();
|
||||
protected void overrideArguments() { }
|
||||
|
||||
/**
|
||||
* this is the function that the inheriting class can expect to have called
|
||||
|
|
@ -66,18 +65,20 @@ public abstract class CommandLineExecutable extends CommandLineProgram {
|
|||
* @return the return code to exit the program with
|
||||
*/
|
||||
protected int execute() {
|
||||
Walker<?,?> mWalker = GATKEngine.getWalkerByName(analysisName);
|
||||
Walker<?,?> mWalker = GATKEngine.getWalkerByName(getAnalysisName());
|
||||
|
||||
GATKArgumentCollection arguments = getArgumentCollection();
|
||||
|
||||
// load the arguments into the walkers
|
||||
loadArgumentsIntoObject(argCollection);
|
||||
loadArgumentsIntoObject(arguments);
|
||||
loadArgumentsIntoObject(mWalker);
|
||||
|
||||
// process any arguments that need a second pass
|
||||
processArguments(argCollection);
|
||||
processArguments(arguments);
|
||||
|
||||
// set the analysis name in the argument collection
|
||||
this.argCollection.analysisName = this.analysisName;
|
||||
GATKEngine.execute(argCollection, mWalker);
|
||||
arguments.analysisName = getAnalysisName();
|
||||
GATKEngine.execute(arguments, mWalker);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -93,17 +94,20 @@ public abstract class CommandLineExecutable extends CommandLineProgram {
|
|||
}
|
||||
|
||||
/**
|
||||
* GATK provides the walker as an argument source. As a side-effect, initializes the walker variable.
|
||||
*
|
||||
* GATK provides the walker as an argument source.
|
||||
* @return List of walkers to load dynamically.
|
||||
*/
|
||||
@Override
|
||||
protected Class[] getArgumentSources() {
|
||||
// No walker info? No plugins.
|
||||
if (analysisName == null) return new Class[] {};
|
||||
return new Class[] { GATKEngine.getWalkerByName(analysisName).getClass() };
|
||||
if (getAnalysisName() == null) return new Class[] {};
|
||||
return new Class[] { GATKEngine.getWalkerByName(getAnalysisName()).getClass() };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgumentSourceName( Class argumentSource ) {
|
||||
return WalkerManager.getWalkerName((Class<Walker>) argumentSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess the arguments before submitting them to the GATK engine.
|
||||
|
|
@ -111,7 +115,7 @@ public abstract class CommandLineExecutable extends CommandLineProgram {
|
|||
* @param argCollection Collection of arguments to preprocess.
|
||||
*/
|
||||
private void processArguments( GATKArgumentCollection argCollection ) {
|
||||
argCollection.samFiles = unpackReads(argCollection.samFiles);
|
||||
argCollection.samFiles = unpackReads( argCollection.samFiles );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,33 +128,37 @@ public abstract class CommandLineExecutable extends CommandLineProgram {
|
|||
*/
|
||||
private List<File> unpackReads( List<File> inputFiles ) {
|
||||
List<File> unpackedReads = new ArrayList<File>();
|
||||
for (File inputFile : inputFiles) {
|
||||
if (inputFile.getName().endsWith(".list")) {
|
||||
for( File inputFile: inputFiles ) {
|
||||
if (inputFile.getName().endsWith(".list") ) {
|
||||
try {
|
||||
for (String fileName : new xReadLines(inputFile))
|
||||
unpackedReads.add(new File(fileName));
|
||||
for( String fileName : new xReadLines(inputFile) )
|
||||
unpackedReads.add( new File(fileName) );
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
catch( FileNotFoundException ex ) {
|
||||
throw new StingException("Unable to find file while unpacking reads", ex);
|
||||
}
|
||||
} else
|
||||
unpackedReads.add(inputFile);
|
||||
}
|
||||
else
|
||||
unpackedReads.add( inputFile );
|
||||
}
|
||||
return unpackedReads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a custom factory for instantiating specialty GATK arguments.
|
||||
* @return An instance of the command-line argument of the specified type.
|
||||
*/
|
||||
@Override
|
||||
protected String getArgumentSourceName( Class argumentSource ) {
|
||||
return WalkerManager.getWalkerName((Class<Walker>) argumentSource);
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public GATKArgumentCollection getArgCollection() {
|
||||
return argCollection;
|
||||
}
|
||||
|
||||
public void setArgCollection( GATKArgumentCollection argCollection ) {
|
||||
this.argCollection = argCollection;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
package org.broadinstitute.sting.gatk;
|
||||
|
||||
import org.broadinstitute.sting.gatk.walkers.Walker;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
import org.broadinstitute.sting.utils.xReadLines;
|
||||
import org.broadinstitute.sting.utils.cmdLine.*;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -40,49 +35,18 @@ import net.sf.samtools.SAMFileReader;
|
|||
* gatk all the parsed out information. Pretty much anything dealing with the underlying system should go here,
|
||||
* the gatk engine should deal with any data related information.
|
||||
*/
|
||||
public class CommandLineGATK extends CommandLineProgram {
|
||||
public class CommandLineGATK extends CommandLineExecutable {
|
||||
|
||||
@Argument(fullName = "analysis_type", shortName = "T", doc = "Type of analysis to run")
|
||||
public String analysisName = null;
|
||||
|
||||
@ArgumentCollection // our argument collection, the collection of command line args we accept
|
||||
public GATKArgumentCollection argCollection = new GATKArgumentCollection();
|
||||
|
||||
/** our genome analysis engine */
|
||||
GenomeAnalysisEngine GATKEngine = new GenomeAnalysisEngine();
|
||||
|
||||
/** Required main method implementation. */
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
CommandLineGATK instance = new CommandLineGATK();
|
||||
start(instance, argv);
|
||||
} catch (Exception e) {
|
||||
exitSystemWithError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
Walker<?,?> mWalker = GATKEngine.getWalkerByName(analysisName);
|
||||
|
||||
loadArgumentsIntoObject(argCollection);
|
||||
loadArgumentsIntoObject(mWalker);
|
||||
|
||||
processArguments(argCollection);
|
||||
|
||||
this.argCollection.analysisName = this.analysisName;
|
||||
GATKEngine.execute(argCollection, mWalker);
|
||||
return 0;
|
||||
}
|
||||
// our argument collection, the collection of command line args we accept
|
||||
@ArgumentCollection
|
||||
protected GATKArgumentCollection argCollection = new GATKArgumentCollection();
|
||||
|
||||
/**
|
||||
* Get pleasing info about the GATK.
|
||||
* @return
|
||||
* @return A list of Strings that contain pleasant info about the GATK.
|
||||
*/
|
||||
@Override
|
||||
protected List<String> getApplicationHeader() {
|
||||
|
|
@ -95,90 +59,23 @@ public class CommandLineGATK extends CommandLineProgram {
|
|||
return header;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
// No walker info? No plugins.
|
||||
if (analysisName == null) return new Class[] {};
|
||||
return new Class[] { GATKEngine.getWalkerByName(analysisName).getClass() };
|
||||
protected String getAnalysisName() {
|
||||
return analysisName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgumentSourceName(Class argumentSource) {
|
||||
return WalkerManager.getWalkerName((Class<Walker>) argumentSource);
|
||||
}
|
||||
|
||||
public GATKArgumentCollection getArgCollection() {
|
||||
protected GATKArgumentCollection getArgumentCollection() {
|
||||
return argCollection;
|
||||
}
|
||||
|
||||
public void setArgCollection(GATKArgumentCollection argCollection) {
|
||||
this.argCollection = argCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a custom factory for instantiating specialty GATK arguments.
|
||||
* @return An instance of the command-line argument of the specified type.
|
||||
*/
|
||||
@Override
|
||||
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(argCollection.strictnessLevel);
|
||||
return samFileReader;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
/** Required main method implementation. */
|
||||
public static void main(String[] argv) {
|
||||
try {
|
||||
CommandLineGATK instance = new CommandLineGATK();
|
||||
start(instance, argv);
|
||||
} catch (Exception e) {
|
||||
exitSystemWithError(e);
|
||||
}
|
||||
return unpackedReads;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ public class WalkerManager {
|
|||
public Walker createWalkerByName(String walkerName)
|
||||
throws InstantiationException, IllegalAccessException {
|
||||
Class<? extends Walker> walker = walkersByName.get(walkerName);
|
||||
if( walker == null )
|
||||
throw new StingException(String.format("Could not find walker with name: %s", walkerName));
|
||||
return walker.newInstance();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ public class SomaticCoverageTool extends CommandLineExecutable {
|
|||
@Argument(fullName = "bam_file", 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 {
|
||||
|
|
@ -69,8 +68,9 @@ public class SomaticCoverageTool extends CommandLineExecutable {
|
|||
}
|
||||
|
||||
/** override any arguments we see fit. */
|
||||
protected void overrideArguments() {
|
||||
this.argCollection = GATKArgumentCollection.unmarshal(getClass().getClassLoader().getResourceAsStream("SomaticCoverage.xml"));
|
||||
this.argCollection.samFiles = samFiles;
|
||||
protected GATKArgumentCollection getArgumentCollection() {
|
||||
GATKArgumentCollection argCollection = GATKArgumentCollection.unmarshal(getClass().getClassLoader().getResourceAsStream("SomaticCoverage.xml"));
|
||||
argCollection.samFiles = samFiles;
|
||||
return argCollection;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue