diff --git a/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java b/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java index 20fbeb59a..f3042a0dd 100755 --- a/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java +++ b/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java @@ -4,16 +4,15 @@ import org.broadinstitute.sting.gatk.walkers.Walker; import org.broadinstitute.sting.gatk.traversals.TraversalEngine; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.xReadLines; -import org.broadinstitute.sting.utils.cmdLine.Argument; -import org.broadinstitute.sting.utils.cmdLine.ArgumentCollection; -import org.broadinstitute.sting.utils.cmdLine.CommandLineProgram; -import org.broadinstitute.sting.utils.cmdLine.ArgumentException; +import org.broadinstitute.sting.utils.cmdLine.*; import java.io.FileNotFoundException; import java.io.File; import java.util.List; import java.util.ArrayList; +import net.sf.samtools.SAMFileReader; + /** * * User: aaron @@ -148,6 +147,24 @@ public class CommandLineGATK extends CommandLineProgram { 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, String repr ) { + if (type == SAMFileReader.class) { + SAMFileReader samFileReader = new SAMFileReader(new File(repr),true); + samFileReader.setValidationStringency(GenomeAnalysisEngine.getValidationStringency(argCollection)); + return samFileReader; + } + return null; + } + }; + } + /** * Preprocess the arguments before submitting them to the GATK engine. diff --git a/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java b/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java index 58381f317..91bf8f024 100755 --- a/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java +++ b/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java @@ -125,7 +125,7 @@ public class GenomeAnalysisEngine { } // Determine the validation stringency. Default to ValidationStringency.STRICT. - ValidationStringency strictness = getValidationStringency(); + ValidationStringency strictness = getValidationStringency(argCollection); logger.info("Strictness is " + strictness); @@ -219,7 +219,7 @@ public class GenomeAnalysisEngine { */ private Reads extractSourceInfoFromArguments( GATKArgumentCollection argCollection ) { return new Reads( argCollection.samFiles, - getValidationStringency(), + getValidationStringency(argCollection), argCollection.downsampleFraction, argCollection.downsampleCoverage, !argCollection.unsafe, @@ -264,10 +264,10 @@ public class GenomeAnalysisEngine { /** * Default to ValidationStringency.STRICT. - * + * TODO: Store ValidationStringency as pre-parsed enum in GATKArgumentCollection. * @return the validation stringency */ - private ValidationStringency getValidationStringency() { + public static ValidationStringency getValidationStringency( GATKArgumentCollection argCollection ) { ValidationStringency strictness = ValidationStringency.SILENT; try { strictness = Enum.valueOf(ValidationStringency.class, argCollection.strictnessLevel.toUpperCase().trim()); diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentFactory.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentFactory.java new file mode 100755 index 000000000..44c9901b4 --- /dev/null +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentFactory.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.broadinstitute.sting.utils.cmdLine; + +/** + * Provides a service whereby the application can provide a mechanism + * for creating specialty arguments. + * @version 0.1 + */ +public abstract class ArgumentFactory { + /** + * Create an instance of a specified type of argument. + * @param type The type of the argument to create. + * @param repr A String representation of the argument. + * @return + */ + public abstract Object createArgument(Class type, String repr); +} diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/CommandLineProgram.java b/java/src/org/broadinstitute/sting/utils/cmdLine/CommandLineProgram.java index 9d7ce1d7e..57f56a0f9 100644 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/CommandLineProgram.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/CommandLineProgram.java @@ -142,6 +142,14 @@ public abstract class CommandLineProgram { */ protected abstract int execute(); + /** + * Retrieves a factory for custom creation of command-line arguments, specified by the + * subclass. + * @return + */ + protected ArgumentFactory getCustomArgumentFactory() { + return null; + } /** * This function is called to start processing the command line, and kick @@ -160,7 +168,7 @@ public abstract class CommandLineProgram { PatternLayout layout = new PatternLayout(); // setup the parser - ParsingEngine parser = clp.parser = new ParsingEngine(); + ParsingEngine parser = clp.parser = new ParsingEngine( clp.getCustomArgumentFactory() ); parser.addArgumentSource( clp.getClass() ); // process the args diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java index 03db0d175..e61b1071e 100755 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java @@ -53,6 +53,13 @@ public class ParsingEngine { */ ArgumentMatches argumentMatches = null; + /** + * Stores a custom argument factory for building out arguments of which only + * subclasses of CommandLineProgram should be aware. + */ + ArgumentFactory customArgumentFactory = null; + + /** * Techniques for parsing and for argument lookup. */ @@ -63,7 +70,8 @@ public class ParsingEngine { */ protected static Logger logger = Logger.getLogger(ParsingEngine.class); - public ParsingEngine() { + public ParsingEngine( ArgumentFactory customArgumentFactory ) { + this.customArgumentFactory = customArgumentFactory; parsingMethods.add( ParsingMethod.FullNameParsingMethod ); parsingMethods.add( ParsingMethod.ShortNameParsingMethod ); } @@ -423,10 +431,13 @@ public class ParsingEngine { * @return parsed form of String. */ private Object constructSingleElement(Field f, Class type, String str) { - // lets go through the types we support - if (type == SAMFileReader.class) { - return new SAMFileReader(new File(str),true); + if( customArgumentFactory != null ) { + Object instance = customArgumentFactory.createArgument(type, str); + if( instance != null ) + return instance; } + + // lets go through the types we support if (type == Boolean.TYPE) { boolean b = false; if (str.toLowerCase().equals("true")) {