Validates that the tribble binding provides the right object types at startup

Tests to ensure this remains working
This commit is contained in:
Mark DePristo 2011-08-02 20:11:24 -04:00
parent e4a67f3df1
commit 3a27a25cfc
5 changed files with 106 additions and 16 deletions

View File

@ -39,10 +39,15 @@ import java.util.List;
* There is no constraint on the type of the ROD bound. * There is no constraint on the type of the ROD bound.
*/ */
public class RodBinding<T extends Feature> { public class RodBinding<T extends Feature> {
final String variableName; final private String variableName;
final String source; final private String source;
final Tags tags; final private Tags tags;
final Class<T> type; final private Class<T> type;
public boolean isBound() {
// todo : implement me
return source != null;
}
public RodBinding(Class<T> type, final String variableName, final String source, final Tags tags) { public RodBinding(Class<T> type, final String variableName, final String source, final Tags tags) {
this.type = type; this.type = type;

View File

@ -38,10 +38,7 @@ import org.broadinstitute.sting.gatk.walkers.Walker;
import org.broadinstitute.sting.utils.classloader.JVMUtils; import org.broadinstitute.sting.utils.classloader.JVMUtils;
import org.broadinstitute.sting.utils.text.ListFileUtils; import org.broadinstitute.sting.utils.text.ListFileUtils;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/** /**
* @author aaron * @author aaron
@ -134,6 +131,7 @@ public abstract class CommandLineExecutable extends CommandLineProgram {
return 0; return 0;
} }
/** /**
* Generate the GATK run report for this walker using the current GATKEngine, if -et is enabled. * Generate the GATK run report for this walker using the current GATKEngine, if -et is enabled.
* This report will be written to either STDOUT or to the run repository, depending on the options * This report will be written to either STDOUT or to the run repository, depending on the options

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010 The Broad Institute * Copyright (c) 2011, The Broad Institute
* *
* Permission is hereby granted, free of charge, to any person * Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation * obtaining a copy of this software and associated documentation
@ -12,15 +12,14 @@
* *
* The above copyright notice and this permission notice shall be * The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software. * included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
package org.broadinstitute.sting.gatk.refdata.tracks; package org.broadinstitute.sting.gatk.refdata.tracks;
@ -100,7 +99,7 @@ public class RMDTrackBuilder extends PluginManager<FeatureCodec> {
public RMDTrackBuilder(SAMSequenceDictionary dict, public RMDTrackBuilder(SAMSequenceDictionary dict,
GenomeLocParser genomeLocParser, GenomeLocParser genomeLocParser,
ValidationExclusion.TYPE validationExclusionType) { ValidationExclusion.TYPE validationExclusionType) {
super(FeatureCodec.class, "Codecs", "Codec"); this();
this.dict = dict; this.dict = dict;
this.genomeLocParser = genomeLocParser; this.genomeLocParser = genomeLocParser;
this.validationExclusionType = validationExclusionType; this.validationExclusionType = validationExclusionType;
@ -108,7 +107,21 @@ public class RMDTrackBuilder extends PluginManager<FeatureCodec> {
classes = new HashMap<String, Class>(); classes = new HashMap<String, Class>();
for (String name: this.getPluginsByName().keySet()) { for (String name: this.getPluginsByName().keySet()) {
classes.put(name.toUpperCase(), getPluginsByName().get(name)); classes.put(name.toUpperCase(), getPluginsByName().get(name));
} } }
}
/**
* Limited constructor that produces a builder capable for validating types, but not building tracks
*/
public RMDTrackBuilder() {
super(FeatureCodec.class, "Codecs", "Codec");
classes = new HashMap<String, Class>();
for (String name: this.getPluginsByName().keySet()) {
classes.put(name.toUpperCase(), getPluginsByName().get(name));
}
}
/** @return a list of all available track types we currently have access to create */ /** @return a list of all available track types we currently have access to create */
public Map<String, Class> getAvailableTrackNamesAndTypes() { public Map<String, Class> getAvailableTrackNamesAndTypes() {
@ -125,6 +138,10 @@ public class RMDTrackBuilder extends PluginManager<FeatureCodec> {
return classToRecord; return classToRecord;
} }
public Class getFeatureCodecClass(RMDTriplet fileDescriptor) {
return getAvailableTrackNamesAndTypes().get(fileDescriptor.getType().toUpperCase());
}
/** /**
* create a RMDTrack of the specified type * create a RMDTrack of the specified type
* *
@ -136,7 +153,7 @@ public class RMDTrackBuilder extends PluginManager<FeatureCodec> {
String name = fileDescriptor.getName(); String name = fileDescriptor.getName();
File inputFile = new File(fileDescriptor.getFile()); File inputFile = new File(fileDescriptor.getFile());
Class featureCodecClass = getAvailableTrackNamesAndTypes().get(fileDescriptor.getType().toUpperCase()); Class featureCodecClass = getFeatureCodecClass(fileDescriptor);
if (featureCodecClass == null) if (featureCodecClass == null)
throw new UserException.BadArgumentValue("-B",fileDescriptor.getType()); throw new UserException.BadArgumentValue("-B",fileDescriptor.getType());

View File

@ -29,6 +29,7 @@ import org.broadinstitute.sting.commandline.RodBinding;
import org.broadinstitute.sting.commandline.Tags; import org.broadinstitute.sting.commandline.Tags;
import org.broadinstitute.sting.gatk.datasources.reads.SAMReaderID; import org.broadinstitute.sting.gatk.datasources.reads.SAMReaderID;
import org.broadinstitute.sting.gatk.refdata.features.DbSNPHelper; import org.broadinstitute.sting.gatk.refdata.features.DbSNPHelper;
import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrackBuilder;
import org.broadinstitute.sting.gatk.refdata.utils.RMDTriplet; import org.broadinstitute.sting.gatk.refdata.utils.RMDTriplet;
import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.exceptions.UserException;
@ -134,6 +135,7 @@ public class ListFileUtils {
public static Collection<RMDTriplet> unpackRODBindings(final Collection<RodBinding> RODBindings, final ParsingEngine parser) { public static Collection<RMDTriplet> unpackRODBindings(final Collection<RodBinding> RODBindings, final ParsingEngine parser) {
// todo -- this is a strange home for this code. Move into ROD system // todo -- this is a strange home for this code. Move into ROD system
Collection<RMDTriplet> rodBindings = new ArrayList<RMDTriplet>(); Collection<RMDTriplet> rodBindings = new ArrayList<RMDTriplet>();
RMDTrackBuilder builderForValidation = new RMDTrackBuilder();
for (RodBinding rodBinding: RODBindings) { for (RodBinding rodBinding: RODBindings) {
String argValue = rodBinding.getSource(); String argValue = rodBinding.getSource();
@ -158,7 +160,17 @@ public class ListFileUtils {
else else
storageType = RMDTriplet.RMDStorageType.FILE; storageType = RMDTriplet.RMDStorageType.FILE;
rodBindings.add(new RMDTriplet(name,type,fileName,storageType,tags)); RMDTriplet triplet = new RMDTriplet(name,type,fileName,storageType,tags);
// validate triplet type
Class typeFromTribble = builderForValidation.getFeatureCodecClass(triplet);
if ( typeFromTribble != null && ! rodBinding.getType().isAssignableFrom(typeFromTribble) )
throw new UserException.BadArgumentValue(rodBinding.getVariableName(),
String.format("Field %s expected type %s, but the type of the input file provided on the command line was %s",
rodBinding.getVariableName(), rodBinding.getType(), typeFromTribble));
rodBindings.add(triplet);
} }
return rodBindings; return rodBindings;

View File

@ -0,0 +1,58 @@
/*
* 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.gatk;
import org.broadinstitute.sting.WalkerTest;
import org.broadinstitute.sting.utils.exceptions.UserException;
import org.testng.annotations.Test;
/**
*
*/
public class EngineFeaturesIntegrationTest extends WalkerTest {
private void testBadRODBindingInput(String type, String name) {
WalkerTestSpec spec = new WalkerTestSpec("-T SelectVariants -L 1:1 --variants:" + type + " "
+ b37dbSNP132 + " -R " + b37KGReference + " -o %s",
1, UserException.class);
executeTest(name, spec);
}
@Test() private void testBadRODBindingInputType1() {
testBadRODBindingInput("beagle", "BEAGLE input to VCF expecting walker");
}
@Test() private void testBadRODBindingInputType2() {
testBadRODBindingInput("vcf3", "VCF3 input to VCF expecting walker");
}
@Test() private void testBadRODBindingInputType3() {
testBadRODBindingInput("bed", "Bed input to VCF expecting walker");
}
@Test() private void testBadRODBindingInputTypeUnknownType() {
testBadRODBindingInput("bedXXX", "Unknown input to VCF expecting walker");
}
}