From 67c07d1a6a4055202b663360799094148a698949 Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 14 Dec 2010 19:35:15 +0000 Subject: [PATCH] Fixed recently introduced multiplexer issue where DoC couldn't be written directly to command-line. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4839 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/commandline/ArgumentSource.java | 17 +++++++++++++++++ .../commandline/ArgumentTypeDescriptor.java | 7 ++++--- .../sting/commandline/ParsingEngine.java | 6 ++---- .../OutputStreamArgumentTypeDescriptor.java | 4 ++-- .../SAMFileWriterArgumentTypeDescriptor.java | 2 +- .../stubs/VCFWriterArgumentTypeDescriptor.java | 2 +- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java b/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java index 6b8653093..f48ca864a 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java @@ -167,6 +167,23 @@ public class ArgumentSource { return field.isAnnotationPresent(Deprecated.class); } + /** + * Returns false if a type-specific default can be employed. + * @return True to throw in a type specific default. False otherwise. + */ + public boolean createsTypeDefault() { + return typeDescriptor.createsTypeDefault(this); + } + + /** + * Generates a default for the given type. + * @param parsingEngine the parsing engine used to validate this argument type descriptor. + * @return A default value for the given type. + */ + public Object createTypeDefault(ParsingEngine parsingEngine) { + return typeDescriptor.createTypeDefault(parsingEngine,this,field.getType()); + } + /** * Builds out a new type descriptor for the given dependent argument as a function * of the containing object. diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java index b0de17591..7847f4575 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java @@ -84,9 +84,10 @@ public abstract class ArgumentTypeDescriptor { * Generates a default for the given type. * @param parsingEngine the parsing engine used to validate this argument type descriptor. * @param source Source of the command-line argument. + * @param type Type of value to create, in case the command-line argument system wants influence. * @return A default value for the given type. */ - public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source) { throw new UnsupportedOperationException("Unable to create default for type " + getClass()); } + public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class type) { throw new UnsupportedOperationException("Unable to create default for type " + getClass()); } /** * Given the given argument source and attributes, synthesize argument definitions for command-line arguments. @@ -503,7 +504,7 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { } @Override - public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source) { + public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class type) { if(multiplexer == null || multiplexedIds == null) throw new ReviewedStingException("No multiplexed ids available"); @@ -514,7 +515,7 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { for(Object id: multiplexedIds) { Object value = null; if(componentTypeDescriptor.createsTypeDefault(source)) - value = componentTypeDescriptor.createTypeDefault(parsingEngine,source); + value = componentTypeDescriptor.createTypeDefault(parsingEngine,source,componentType); multiplexedMapping.put(id,value); } return multiplexedMapping; diff --git a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java index 57fd2b998..863b344ee 100755 --- a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java +++ b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java @@ -326,10 +326,8 @@ public class ParsingEngine { * @param instance Object into which to inject the value. The target might be in a container within the instance. */ private void loadValueIntoObject( ArgumentSource source, Object instance, ArgumentMatches argumentMatches ) { - ArgumentTypeDescriptor typeDescriptor = selectBestTypeDescriptor(source.field.getType()); - // Nothing to load - if( argumentMatches.size() == 0 && !(typeDescriptor.createsTypeDefault(source) && source.isRequired())) + if( argumentMatches.size() == 0 && !(source.createsTypeDefault() && source.isRequired())) return; // Target instance into which to inject the value. @@ -340,7 +338,7 @@ public class ParsingEngine { throw new ReviewedStingException("Internal command-line parser error: unable to find a home for argument matches " + argumentMatches); for( Object target: targets ) { - Object value = (argumentMatches.size() != 0) ? source.parse(this,argumentMatches) : typeDescriptor.createTypeDefault(this,source); + Object value = (argumentMatches.size() != 0) ? source.parse(this,argumentMatches) : source.createTypeDefault(this); JVMUtils.setFieldValue(source.field,target,value); } diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java index c550a7608..00e78f391 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java @@ -69,12 +69,12 @@ public class OutputStreamArgumentTypeDescriptor extends ArgumentTypeDescriptor { } @Override - public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source) { + public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class type) { if(!source.isRequired()) throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default."); OutputStreamStub stub = new OutputStreamStub(defaultOutputStream); engine.addOutput(stub); - return createInstanceOfClass(source.field.getType(),stub); + return createInstanceOfClass(type,stub); } @Override diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java index ffe33fe2b..5b5270a70 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java @@ -88,7 +88,7 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor } @Override - public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source) { + public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class type) { if(!source.isRequired()) throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default."); SAMFileWriterStub stub = new SAMFileWriterStub(engine,defaultOutputStream); diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java index 906de1276..e80ca8949 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/VCFWriterArgumentTypeDescriptor.java @@ -108,7 +108,7 @@ public class VCFWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor { } @Override - public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source) { + public Object createTypeDefault(ParsingEngine parsingEngine,ArgumentSource source,Class type) { if(!source.isRequired()) throw new ReviewedStingException("BUG: tried to create type default for argument type descriptor that can't support a type default."); VCFWriterStub stub = new VCFWriterStub(engine, defaultOutputStream, false, argumentSources, false);