diff --git a/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java b/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java index 23acc2a78..f5621a780 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java +++ b/public/java/src/org/broadinstitute/sting/commandline/RodBinding.java @@ -39,10 +39,15 @@ import java.util.List; * There is no constraint on the type of the ROD bound. */ public class RodBinding { - final String variableName; - final String source; - final Tags tags; - final Class type; + final private String variableName; + final private String source; + final private Tags tags; + final private Class type; + + public boolean isBound() { + // todo : implement me + return source != null; + } public RodBinding(Class type, final String variableName, final String source, final Tags tags) { this.type = type; diff --git a/public/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java b/public/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java index efdc64066..32132c7ca 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java +++ b/public/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java @@ -38,10 +38,7 @@ import org.broadinstitute.sting.gatk.walkers.Walker; import org.broadinstitute.sting.utils.classloader.JVMUtils; import org.broadinstitute.sting.utils.text.ListFileUtils; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; +import java.util.*; /** * @author aaron @@ -134,6 +131,7 @@ public abstract class CommandLineExecutable extends CommandLineProgram { return 0; } + /** * 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 diff --git a/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackBuilder.java b/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackBuilder.java index 41e8cf15b..a775a82d2 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackBuilder.java +++ b/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackBuilder.java @@ -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 * obtaining a copy of this software and associated documentation @@ -12,15 +12,14 @@ * * 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. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ package org.broadinstitute.sting.gatk.refdata.tracks; @@ -100,7 +99,7 @@ public class RMDTrackBuilder extends PluginManager { public RMDTrackBuilder(SAMSequenceDictionary dict, GenomeLocParser genomeLocParser, ValidationExclusion.TYPE validationExclusionType) { - super(FeatureCodec.class, "Codecs", "Codec"); + this(); this.dict = dict; this.genomeLocParser = genomeLocParser; this.validationExclusionType = validationExclusionType; @@ -108,7 +107,21 @@ public class RMDTrackBuilder extends PluginManager { classes = new HashMap(); for (String name: this.getPluginsByName().keySet()) { 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(); + 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 */ public Map getAvailableTrackNamesAndTypes() { @@ -125,6 +138,10 @@ public class RMDTrackBuilder extends PluginManager { return classToRecord; } + public Class getFeatureCodecClass(RMDTriplet fileDescriptor) { + return getAvailableTrackNamesAndTypes().get(fileDescriptor.getType().toUpperCase()); + } + /** * create a RMDTrack of the specified type * @@ -136,7 +153,7 @@ public class RMDTrackBuilder extends PluginManager { String name = fileDescriptor.getName(); File inputFile = new File(fileDescriptor.getFile()); - Class featureCodecClass = getAvailableTrackNamesAndTypes().get(fileDescriptor.getType().toUpperCase()); + Class featureCodecClass = getFeatureCodecClass(fileDescriptor); if (featureCodecClass == null) throw new UserException.BadArgumentValue("-B",fileDescriptor.getType()); diff --git a/public/java/src/org/broadinstitute/sting/utils/text/ListFileUtils.java b/public/java/src/org/broadinstitute/sting/utils/text/ListFileUtils.java index d758b4e5c..3175037f6 100644 --- a/public/java/src/org/broadinstitute/sting/utils/text/ListFileUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/text/ListFileUtils.java @@ -29,6 +29,7 @@ import org.broadinstitute.sting.commandline.RodBinding; import org.broadinstitute.sting.commandline.Tags; import org.broadinstitute.sting.gatk.datasources.reads.SAMReaderID; 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.utils.exceptions.UserException; @@ -134,6 +135,7 @@ public class ListFileUtils { public static Collection unpackRODBindings(final Collection RODBindings, final ParsingEngine parser) { // todo -- this is a strange home for this code. Move into ROD system Collection rodBindings = new ArrayList(); + RMDTrackBuilder builderForValidation = new RMDTrackBuilder(); for (RodBinding rodBinding: RODBindings) { String argValue = rodBinding.getSource(); @@ -158,7 +160,17 @@ public class ListFileUtils { else 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; diff --git a/public/java/test/org/broadinstitute/sting/gatk/EngineFeaturesIntegrationTest.java b/public/java/test/org/broadinstitute/sting/gatk/EngineFeaturesIntegrationTest.java new file mode 100644 index 000000000..2bdddafe3 --- /dev/null +++ b/public/java/test/org/broadinstitute/sting/gatk/EngineFeaturesIntegrationTest.java @@ -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"); + } +}