RodBinding subclassed to VariantContextRodBinding for easy access to VariantContext providing RODs
This commit is contained in:
parent
7ab8b53339
commit
d0badd5bd6
|
|
@ -291,17 +291,28 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor {
|
|||
}
|
||||
|
||||
public static boolean isRodBinding( Class type ) {
|
||||
return type.isAssignableFrom(RodBinding.class);
|
||||
return RodBinding.class.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object parse(ParsingEngine parsingEngine, ArgumentSource source, Class type, ArgumentMatches matches) {
|
||||
ArgumentDefinition defaultDefinition = createDefaultArgumentDefinition(source);
|
||||
String value = getArgumentValue( defaultDefinition, matches );
|
||||
RodBinding<Object> result = new RodBinding<Object>(source.field.getName(), new File(value));
|
||||
Tags tags = getArgumentTags(matches);
|
||||
parsingEngine.addTags(result,tags);
|
||||
return result;
|
||||
try {
|
||||
Constructor ctor = type.getConstructor(String.class, String.class);
|
||||
RodBinding result = (RodBinding)ctor.newInstance(source.field.getName(), value);
|
||||
Tags tags = getArgumentTags(matches);
|
||||
parsingEngine.addTags(result,tags);
|
||||
return result;
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new UserException.CommandLineException(
|
||||
String.format("Failed to parse value %s for argument %s.",
|
||||
value, source.field.getName()));
|
||||
} catch (Exception e) {
|
||||
throw new UserException.CommandLineException(
|
||||
String.format("Failed to parse value %s for argument %s.",
|
||||
value, source.field.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,23 +24,18 @@
|
|||
|
||||
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.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
// TODO -- should have a derived class called VariantContentRodBinding with simple accessors
|
||||
public class RodBinding {
|
||||
final String variableName;
|
||||
final File sourceFile;
|
||||
final String sourceFile;
|
||||
|
||||
public RodBinding(final String variableName, final File sourceFile) {
|
||||
public RodBinding(final String variableName, final String sourceFile) {
|
||||
this.variableName = variableName;
|
||||
this.sourceFile = sourceFile;
|
||||
}
|
||||
|
|
@ -49,7 +44,7 @@ public class RodBinding {
|
|||
return variableName;
|
||||
}
|
||||
|
||||
public File getSourceFile() {
|
||||
public String getSourceFile() {
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
|
|
@ -57,10 +52,6 @@ public class RodBinding {
|
|||
return tracker.getReferenceMetaData(variableName);
|
||||
}
|
||||
|
||||
public VariantContext getVariantContext(RefMetaDataTracker tracker, ReferenceContext ref, GenomeLoc loc) {
|
||||
return tracker.getVariantContext(ref, variableName, loc);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("(RodBinding name=%s source=%s)", variableName, sourceFile);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class VariantContextRodBinding extends RodBinding {
|
||||
public VariantContextRodBinding(final String variableName, final String sourceFile) {
|
||||
super(variableName, sourceFile);
|
||||
}
|
||||
|
||||
public VariantContext getVariantContext(RefMetaDataTracker tracker, ReferenceContext ref, GenomeLoc loc) {
|
||||
return tracker.getVariantContext(ref, variableName, loc);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,14 +24,10 @@
|
|||
|
||||
package org.broadinstitute.sting.gatk.walkers.variantutils;
|
||||
|
||||
import org.broadinstitute.sting.commandline.Argument;
|
||||
import org.broadinstitute.sting.commandline.Input;
|
||||
import org.broadinstitute.sting.commandline.Output;
|
||||
import org.broadinstitute.sting.commandline.RodBinding;
|
||||
import org.broadinstitute.sting.commandline.*;
|
||||
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
|
||||
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
||||
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
||||
import org.broadinstitute.sting.gatk.walkers.Requires;
|
||||
import org.broadinstitute.sting.gatk.walkers.RodWalker;
|
||||
import org.broadinstitute.sting.utils.MathUtils;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
|
|
@ -66,9 +62,9 @@ public class VariantsToTableNewRodStyle extends RodWalker<Integer, Integer> {
|
|||
public boolean ALLOW_MISSING_DATA = false;
|
||||
|
||||
@Input(fullName="variants", shortName="V", doc="The variant file we will convert to a table", required=true)
|
||||
public RodBinding variants;
|
||||
public VariantContextRodBinding variants;
|
||||
|
||||
@Input(fullName="variantsList", shortName="VL", doc="The variant file we will convert to a table", required=true)
|
||||
@Input(fullName="rodList", shortName="RL", doc="A list of ROD types that we will convert to a table", required=true)
|
||||
public List<RodBinding> variantsList;
|
||||
|
||||
public void initialize() {
|
||||
|
|
@ -139,7 +135,7 @@ public class VariantsToTableNewRodStyle extends RodWalker<Integer, Integer> {
|
|||
return 0;
|
||||
|
||||
for ( RodBinding binding : variantsList )
|
||||
System.out.printf("VariantList binding %s%n", binding);
|
||||
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, ref, context.getLocation());
|
||||
|
|
|
|||
Loading…
Reference in New Issue