From 47bbddb7244c71ade9198e3f52126e20a9dff1d1 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Thu, 18 Aug 2011 10:47:16 -0400 Subject: [PATCH] Now provides type-specific user feedback For RodBinding error messages now list only the Tribble types that produce VariantContexts --- .../commandline/ArgumentTypeDescriptor.java | 7 +++-- .../gatk/refdata/tracks/FeatureManager.java | 28 ++++++++++++++----- .../sting/utils/text/ListFileUtils.java | 9 +++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java b/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java index 9f3eae610..dc32fcc16 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java +++ b/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java @@ -338,6 +338,8 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor { public Object parse(ParsingEngine parsingEngine, ArgumentSource source, Type type, ArgumentMatches matches) { ArgumentDefinition defaultDefinition = createDefaultArgumentDefinition(source); String value = getArgumentValue( defaultDefinition, matches ); + Class parameterType = getParameterizedTypeClass(type); + try { String name = defaultDefinition.fullName; String tribbleType = null; @@ -376,15 +378,14 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor { } else { throw new UserException.CommandLineException( String.format("No tribble type was provided on the command line and the type of the file could not be determined dynamically. " + - "Please add an explicit type tag :TYPE listing the correct type from among the supported types:%n%s", - manager.userFriendlyListOfAvailableFeatures())); + "Please add an explicit type tag :NAME listing the correct type from among the supported types:%n%s", + manager.userFriendlyListOfAvailableFeatures(parameterType))); } } } } Constructor ctor = (makeRawTypeIfNecessary(type)).getConstructor(Class.class, String.class, String.class, String.class, Tags.class); - Class parameterType = getParameterizedTypeClass(type); RodBinding result = (RodBinding)ctor.newInstance(parameterType, name, value, tribbleType, tags); parsingEngine.addTags(result,tags); parsingEngine.addRodBinding(result); diff --git a/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/FeatureManager.java b/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/FeatureManager.java index 7237f8bb5..9a565f1cb 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/FeatureManager.java +++ b/public/java/src/org/broadinstitute/sting/gatk/refdata/tracks/FeatureManager.java @@ -197,23 +197,37 @@ public class FeatureManager { */ @Ensures("result != null") public String userFriendlyListOfAvailableFeatures() { + return userFriendlyListOfAvailableFeatures(Feature.class); + } + + /** + * Returns a list of the available tribble track names (vcf,dbsnp,etc) that we can load + * restricted to only Codecs producting Features consistent with the requiredFeatureType + * @return + */ + @Ensures("result != null") + public String userFriendlyListOfAvailableFeatures(Class requiredFeatureType) { final String nameHeader="Name", featureHeader = "FeatureType", docHeader="Documentation"; int maxNameLen = nameHeader.length(), maxFeatureNameLen = featureHeader.length(); for ( final FeatureDescriptor descriptor : featureDescriptors ) { - maxNameLen = Math.max(maxNameLen, descriptor.getName().length()); - maxFeatureNameLen = Math.max(maxFeatureNameLen, descriptor.getSimpleFeatureName().length()); + if ( requiredFeatureType.isAssignableFrom(descriptor.getFeatureClass()) ) { + maxNameLen = Math.max(maxNameLen, descriptor.getName().length()); + maxFeatureNameLen = Math.max(maxFeatureNameLen, descriptor.getSimpleFeatureName().length()); + } } StringBuilder docs = new StringBuilder(); String format = "%" + maxNameLen + "s %" + maxFeatureNameLen + "s %s%n"; docs.append(String.format(format, nameHeader, featureHeader, docHeader)); for ( final FeatureDescriptor descriptor : featureDescriptors ) { - String oneDoc = String.format(format, - descriptor.getName(), - descriptor.getSimpleFeatureName(), - HelpUtils.helpLinksToGATKDocs(descriptor.getCodecClass())); - docs.append(oneDoc); + if ( requiredFeatureType.isAssignableFrom(descriptor.getFeatureClass()) ) { + String oneDoc = String.format(format, + descriptor.getName(), + descriptor.getSimpleFeatureName(), + HelpUtils.helpLinksToGATKDocs(descriptor.getCodecClass())); + docs.append(oneDoc); + } } return docs.toString(); 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 8584ce3bb..9d4b23a8b 100644 --- a/public/java/src/org/broadinstitute/sting/utils/text/ListFileUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/text/ListFileUtils.java @@ -156,12 +156,13 @@ public class ListFileUtils { FeatureManager.FeatureDescriptor descriptor = builderForValidation.getByTriplet(triplet); if ( descriptor == null ) throw new UserException.UnknownTribbleType(rodBinding.getTribbleType(), - String.format("Field %s had provided type %s but there's no such Tribble type. Available types are %s", - rodBinding.getName(), rodBinding.getTribbleType(), builderForValidation.userFriendlyListOfAvailableFeatures())); + String.format("Field %s had provided type %s but there's no such Tribble type. The compatible types are: %n%s", + rodBinding.getName(), rodBinding.getTribbleType(), builderForValidation.userFriendlyListOfAvailableFeatures(rodBinding.getType()))); if ( ! rodBinding.getType().isAssignableFrom(descriptor.getFeatureClass()) ) throw new UserException.BadArgumentValue(rodBinding.getName(), - String.format("Field %s expected type %s, but the type of the input file provided on the command line was %s producing %s. Please make sure that you have provided the correct file type and/or that you are not binding your rod to a name matching one of the available types.", - rodBinding.getName(), rodBinding.getType(), descriptor.getName(), descriptor.getSimpleFeatureName())); + String.format("Field %s expects Features of type %s, but the input file produces Features of type %s. The compatible types are: %n%s", + rodBinding.getName(), rodBinding.getType().getSimpleName(), descriptor.getSimpleFeatureName(), + builderForValidation.userFriendlyListOfAvailableFeatures(rodBinding.getType()))); rodBindings.add(triplet);