From e32174fbc4c7e01f26a4ad282f9f9eeca96dfcf3 Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 29 Dec 2009 16:46:24 +0000 Subject: [PATCH] UnifiedGenotyper now works without -varout or -vf set. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2464 348d0f76-0448-11de-a6fe-93d51630548a --- .../GenotypeWriterArgumentTypeDescriptor.java | 20 ++++++++++++++ .../sting/utils/cmdLine/ArgumentSource.java | 27 ++++++++++++++++--- .../utils/cmdLine/ArgumentTypeDescriptor.java | 27 +++++++++++++++++++ .../sting/utils/cmdLine/ParsingEngine.java | 10 +++---- 4 files changed, 75 insertions(+), 9 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/GenotypeWriterArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/GenotypeWriterArgumentTypeDescriptor.java index ed32e793b..4b03394e8 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/GenotypeWriterArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/GenotypeWriterArgumentTypeDescriptor.java @@ -58,6 +58,26 @@ public class GenotypeWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor createGenotypeFormatArgumentDefinition(source) ); } + /** + * This command-line argument descriptor does want to override the provided default value. + * @return true always. + */ + @Override + public boolean overridesDefault() { + return true; + } + + /** + * Provide the default value for this argument. + * @return A VCFGenotypeWriter which writes to the default output stream. + */ + @Override + public Object getDefault() { + GenotypeWriterStub defaultGenotypeWriter = new VCFGenotypeWriterStub(engine,System.out); + engine.addOutput(defaultGenotypeWriter); + return defaultGenotypeWriter; + } + /** * Convert the given argument matches into a single object suitable for feeding into the ArgumentSource. * @param source Source for this argument. diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java index e766130b9..acf69d7e1 100644 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentSource.java @@ -48,6 +48,11 @@ public class ArgumentSource { */ public final Field field; + /** + * Type descriptor to use when parsing new argument types. + */ + private final ArgumentTypeDescriptor typeDescriptor; + /** * Create a new command-line argument target. * @param clazz Class containing the argument. @@ -56,6 +61,7 @@ public class ArgumentSource { public ArgumentSource( Class clazz, Field field ) { this.clazz = clazz; this.field = field; + this.typeDescriptor = ArgumentTypeDescriptor.create( field.getType() ); } /** @@ -89,10 +95,25 @@ public class ArgumentSource { * @return A non-null, non-empty list of argument definitions. */ public List createArgumentDefinitions() { - ArgumentTypeDescriptor typeDescriptor = ArgumentTypeDescriptor.create( field.getType() ); return typeDescriptor.createArgumentDefinitions( this ); } + /** + * This argument type descriptor wants to override any default value the user might have specified. + * @return True if this descriptor wants to override any default the user specified. False otherwise. + */ + public boolean overridesDefault() { + return typeDescriptor.overridesDefault(); + } + + /** + * Provides the default value for the command-line argument. + * @return Default value to load into the object. + */ + public Object getDefault() { + return typeDescriptor.getDefault(); + } + /** * Parses the specified value based on the specified type. * @param source The type of value to be parsed. @@ -101,10 +122,8 @@ public class ArgumentSource { */ public Object parse( ArgumentSource source, ArgumentMatches values ) { Object value = null; - if( !isFlag() ) { - ArgumentTypeDescriptor typeDescriptor = ArgumentTypeDescriptor.create( field.getType() ); + if( !isFlag() ) value = typeDescriptor.parse( source, values ); - } else value = true; diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentTypeDescriptor.java index 6bf6b3288..e0597d513 100644 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentTypeDescriptor.java @@ -65,6 +65,11 @@ public abstract class ArgumentTypeDescriptor { descriptors = allDescriptors; } + /** + * Fetch the given descriptor from the descriptor repository. + * @param type Class for which to specify a descriptor. + * @return descriptor for the given type. + */ public static ArgumentTypeDescriptor create( Class type ) { for( ArgumentTypeDescriptor descriptor: descriptors ) { if( descriptor.supports(type) ) @@ -80,6 +85,22 @@ public abstract class ArgumentTypeDescriptor { */ public abstract boolean supports( Class type ); + /** + * This argument type descriptor wants to override any default value the user might have specified. + * @return True if this descriptor wants to override any default the user specified. False otherwise. + */ + public boolean overridesDefault() { + return false; + } + + /** + * Provides the default value for the command-line argument. + * @return Default value to load into the object. + */ + public Object getDefault() { + throw new UnsupportedOperationException(String.format("Type descriptor %s cannot override default value of command-line argument",this.getClass())); + } + /** * Given the given argument source and attributes, synthesize argument definitions for command-line arguments. * @param source Source class and field for the given argument. @@ -115,6 +136,7 @@ public abstract class ArgumentTypeDescriptor { /** * Retrieves the full name of the argument, specifiable with the '--' prefix. The full name can be * either specified explicitly with the fullName annotation parameter or implied by the field name. + * @param source Original field specifying command-line arguments. * @return full name of the argument. Never null. */ protected String getFullName( ArgumentSource source ) { @@ -125,6 +147,7 @@ public abstract class ArgumentTypeDescriptor { /** * Retrieves the short name of the argument, specifiable with the '-' prefix. The short name can * be specified or not; if left unspecified, no short name will be present. + * @param source Original field specifying command-line arguments. * @return short name of the argument. Null if no short name exists. */ protected String getShortName( ArgumentSource source ) { @@ -134,6 +157,7 @@ public abstract class ArgumentTypeDescriptor { /** * Documentation for this argument. Mandatory field. + * @param source Original field specifying command-line arguments. * @return Documentation for this argument. */ protected String getDoc( ArgumentSource source ) { @@ -143,6 +167,7 @@ public abstract class ArgumentTypeDescriptor { /** * Returns whether this field is required. Note that flag fields are always forced to 'not required'. + * @param source Original field specifying command-line arguments. * @return True if the field is mandatory and not a boolean flag. False otherwise. */ protected boolean isRequired( ArgumentSource source ) { @@ -152,6 +177,7 @@ public abstract class ArgumentTypeDescriptor { /** * Specifies other arguments which cannot be used in conjunction with tihs argument. Comma-separated list. + * @param source Original field specifying command-line arguments. * @return A comma-separated list of exclusive arguments, or null if none are present. */ protected String getExclusiveOf( ArgumentSource source ) { @@ -161,6 +187,7 @@ public abstract class ArgumentTypeDescriptor { /** * A regular expression which can be used for validation. + * @param source Original field specifying command-line arguments. * @return a JVM regex-compatible regular expression, or null to permit any possible value. */ protected String getValidationRegex( ArgumentSource source ) { diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java index 485cb500e..bfd86f8e9 100755 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ParsingEngine.java @@ -250,7 +250,7 @@ public class ParsingEngine { public void loadArgumentsIntoObject( Object object ) { List argumentSources = extractArgumentSources(object.getClass()); for( ArgumentSource argumentSource: argumentSources ) - loadMatchesIntoObject( argumentSource, object, argumentMatches.findMatches(argumentSource) ); + loadValueIntoObject( argumentSource, object, argumentMatches.findMatches(argumentSource) ); } /** @@ -259,9 +259,9 @@ public class ParsingEngine { * @param source Argument source to load into the object. * @param instance Object into which to inject the value. The target might be in a container within the instance. */ - private void loadMatchesIntoObject( ArgumentSource source, Object instance, ArgumentMatches argumentMatches ) { + private void loadValueIntoObject( ArgumentSource source, Object instance, ArgumentMatches argumentMatches ) { // Nothing to load - if( argumentMatches.size() == 0 ) + if( argumentMatches.size() == 0 && !source.overridesDefault()) return; // Target instance into which to inject the value. @@ -280,8 +280,8 @@ public class ParsingEngine { throw new StingException("Internal command-line parser error: unable to find a home for argument matches " + argumentMatches); for( Object target: targets ) { - Object value = source.parse( source, argumentMatches ); - JVMUtils.setFieldValue( source.field, target, value ); + Object value = (argumentMatches.size() != 0) ? source.parse(source,argumentMatches) : source.getDefault(); + JVMUtils.setFieldValue(source.field,target,value); } }