diff --git a/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java b/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java index 2e5cb4d62..5106dccb7 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java +++ b/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java @@ -26,6 +26,7 @@ package org.broadinstitute.sting.commandline; import org.apache.log4j.Logger; +import org.broad.tribble.Feature; import org.broadinstitute.sting.gatk.walkers.Multiplex; import org.broadinstitute.sting.gatk.walkers.Multiplexer; import org.broadinstitute.sting.utils.classloader.JVMUtils; @@ -299,10 +300,10 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor { ArgumentDefinition defaultDefinition = createDefaultArgumentDefinition(source); String value = getArgumentValue( defaultDefinition, matches ); try { - // TODO: determine type of internal value via Parameter - Constructor ctor = type.getConstructor(Class.class, String.class, String.class, ParsingEngine.class); - RodBinding result = (RodBinding)ctor.newInstance(null, source.field.getName(), value, parsingEngine); Tags tags = getArgumentTags(matches); + Constructor ctor = type.getConstructor(Class.class, String.class, String.class, Tags.class); + Class parameterType = getParameterizedTypeClass(source.field.getGenericType()); + RodBinding result = (RodBinding)ctor.newInstance(parameterType, source.field.getName(), value, tags); parsingEngine.addTags(result,tags); return result; } catch (InvocationTargetException e) { @@ -315,6 +316,16 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor { value, source.field.getName())); } } + + private Class getParameterizedTypeClass(Type t) { + if ( t instanceof ParameterizedType ) { + ParameterizedType parameterizedType = (ParameterizedType)t; + if ( parameterizedType.getActualTypeArguments().length != 1 ) + throw new ReviewedStingException("BUG: more than 1 generic type found on class" + t); + return (Class)parameterizedType.getActualTypeArguments()[0]; + } else + throw new ReviewedStingException("BUG: could not find generic type on class " + t); + } } /** diff --git a/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java b/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java index d7d086824..b39e0d7ba 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java +++ b/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java @@ -27,7 +27,10 @@ package org.broadinstitute.sting.commandline; import org.broad.tribble.Feature; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; +import org.broadinstitute.sting.utils.GenomeLoc; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -38,14 +41,14 @@ import java.util.List; public class RodBinding { final String variableName; final String source; - final ParsingEngine parser; + final Tags tags; final Class type; - protected RodBinding(Class type, final String variableName, final String source, final ParsingEngine parser) { + public RodBinding(Class type, final String variableName, final String source, final Tags tags) { this.type = type; this.variableName = variableName; this.source = source; - this.parser = parser; + this.tags = tags; } public String getVariableName() { @@ -56,16 +59,26 @@ public class RodBinding { return source; } + // ------------------------------------------------------------------------------------------ + // + // + // Accessors should be kept in sync with RefMetaDataTracker + // + // + // ------------------------------------------------------------------------------------------ + public List getValues(final RefMetaDataTracker tracker) { - return tracker.getValues(variableName, type); + return tracker.getValues(type, getVariableName()); + } + public List getValues(final RefMetaDataTracker tracker, final GenomeLoc onlyAtThisLoc) { + return tracker.getValues(type, getVariableName(), onlyAtThisLoc); } -// public List getValues(final RefMetaDataTracker tracker, final Class clazz) { -// return tracker.getValues(variableName, clazz); -// } - public T getFirstValue(final RefMetaDataTracker tracker) { - return tracker.getFirstValue(variableName, type); + return tracker.getFirstValue(type, getVariableName()); + } + public T getFirstValue(final RefMetaDataTracker tracker, final GenomeLoc onlyAtThisLoc) { + return tracker.getFirstValue(type, getVariableName(), onlyAtThisLoc); } public boolean hasValues(final RefMetaDataTracker tracker) { @@ -77,7 +90,7 @@ public class RodBinding { } public Tags getTags() { - return parser.getTags(this); + return tags; } public String toString() { diff --git a/public/java/src/org/broadinstitute/sting/commandline/VariantContextRodBinding.java b/public/java/src/org/broadinstitute/sting/commandline/VariantContextRodBinding.java deleted file mode 100644 index a1bc05ef6..000000000 --- a/public/java/src/org/broadinstitute/sting/commandline/VariantContextRodBinding.java +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright (c) 2011, 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.commandline; - -import org.broadinstitute.sting.gatk.contexts.ReferenceContext; -import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.variantcontext.VariantContext; - -import java.util.Collection; - -/** -* A RodBinding representing a walker argument that gets bound to a ROD track containing VariantContexts -*/ -public class VariantContextRodBinding extends RodBinding { - /** - * Create a new RodBinding specialized to provide VariantContexts. - * @param variableName the name of the field in the walker that we will bind the ROD track too - * @param sourceFile the data source from which we will read the VCs - * @param parser the Engine parser used to obtain information about this argument, such as its underlying file type - */ - protected VariantContextRodBinding(final String variableName, final String sourceFile, final ParsingEngine parser) { - super(VariantContext.class, variableName, sourceFile, parser); - } - - /** - * Forwarding method to identical tracker method - */ - public Collection getVariantContexts(final RefMetaDataTracker tracker, - final GenomeLoc curLocation, - final boolean requireStartHere, - final boolean takeFirstOnly ) { - return tracker.getVariantContexts(variableName, curLocation, requireStartHere, takeFirstOnly); - } - - /** - * Forwarding method to identical tracker method - * @param tracker - * @param curLocation - * @param requireStartHere - * @return - */ - public VariantContext getVariantContext(final RefMetaDataTracker tracker, - final GenomeLoc curLocation, - final boolean requireStartHere ) { - return tracker.getVariantContext(variableName, curLocation, requireStartHere); - } - - /** - * Forwarding method to identical tracker method - */ - public VariantContext getVariantContext(final RefMetaDataTracker tracker, - final GenomeLoc curLocation) { - return tracker.getVariantContext(variableName, curLocation); - } -} diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java index f5db48f0d..a7955f1fb 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java @@ -24,6 +24,7 @@ package org.broadinstitute.sting.gatk.walkers.variantutils; +import org.broad.tribble.Feature; import org.broadinstitute.sting.commandline.*; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; @@ -62,10 +63,10 @@ public class VariantsToTableNewRodStyle extends RodWalker { public boolean ALLOW_MISSING_DATA = false; @Input(fullName="variants", shortName="V", doc="The variant file we will convert to a table", required=true) - public VariantContextRodBinding variants; + public RodBinding variants; - @Input(fullName="rodList", shortName="RL", doc="A list of ROD types that we will convert to a table", required=true) - public List variantsList; +// @Input(fullName="rodList", shortName="RL", doc="A list of ROD types that we will convert to a table", required=true) +// public List> variantsList; public void initialize() { out.println(Utils.join("\t", fieldsToTake)); @@ -134,11 +135,11 @@ public class VariantsToTableNewRodStyle extends RodWalker { if ( tracker == null ) // RodWalkers can make funky map calls return 0; - for ( RodBinding binding : variantsList ) - System.out.printf("VariantList binding %s tags=%s%n", binding, getToolkit().getTags(binding).getPositionalTags()); +// for ( RodBinding binding : variantsList ) +// System.out.printf("VariantList binding %s tags=%s%n", binding, getToolkit().getTags(binding).getPositionalTags()); if ( ++nRecords < MAX_RECORDS || MAX_RECORDS == -1 ) { - VariantContext vc = variants.getVariantContext(tracker, context.getLocation()); + VariantContext vc = variants.getFirstValue(tracker, context.getLocation()); if ( (keepMultiAllelic || vc.isBiallelic()) && ( showFiltered || vc.isNotFiltered() ) ) { List vals = extractFields(vc, fieldsToTake, ALLOW_MISSING_DATA); out.println(Utils.join("\t", vals));