Now provides type-specific user feedback

For RodBinding<VariantContext> error messages now list only the Tribble types that produce VariantContexts
This commit is contained in:
Mark DePristo 2011-08-18 10:47:16 -04:00
parent 2d41ba15a4
commit 47bbddb724
3 changed files with 30 additions and 14 deletions

View File

@ -338,6 +338,8 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor {
public Object parse(ParsingEngine parsingEngine, ArgumentSource source, Type type, ArgumentMatches matches) { public Object parse(ParsingEngine parsingEngine, ArgumentSource source, Type type, ArgumentMatches matches) {
ArgumentDefinition defaultDefinition = createDefaultArgumentDefinition(source); ArgumentDefinition defaultDefinition = createDefaultArgumentDefinition(source);
String value = getArgumentValue( defaultDefinition, matches ); String value = getArgumentValue( defaultDefinition, matches );
Class<? extends Feature> parameterType = getParameterizedTypeClass(type);
try { try {
String name = defaultDefinition.fullName; String name = defaultDefinition.fullName;
String tribbleType = null; String tribbleType = null;
@ -376,15 +378,14 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor {
} else { } else {
throw new UserException.CommandLineException( 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. " + 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", "Please add an explicit type tag :NAME listing the correct type from among the supported types:%n%s",
manager.userFriendlyListOfAvailableFeatures())); manager.userFriendlyListOfAvailableFeatures(parameterType)));
} }
} }
} }
} }
Constructor ctor = (makeRawTypeIfNecessary(type)).getConstructor(Class.class, String.class, String.class, String.class, Tags.class); 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); RodBinding result = (RodBinding)ctor.newInstance(parameterType, name, value, tribbleType, tags);
parsingEngine.addTags(result,tags); parsingEngine.addTags(result,tags);
parsingEngine.addRodBinding(result); parsingEngine.addRodBinding(result);

View File

@ -197,23 +197,37 @@ public class FeatureManager {
*/ */
@Ensures("result != null") @Ensures("result != null")
public String userFriendlyListOfAvailableFeatures() { 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<? extends Feature> requiredFeatureType) {
final String nameHeader="Name", featureHeader = "FeatureType", docHeader="Documentation"; final String nameHeader="Name", featureHeader = "FeatureType", docHeader="Documentation";
int maxNameLen = nameHeader.length(), maxFeatureNameLen = featureHeader.length(); int maxNameLen = nameHeader.length(), maxFeatureNameLen = featureHeader.length();
for ( final FeatureDescriptor descriptor : featureDescriptors ) { for ( final FeatureDescriptor descriptor : featureDescriptors ) {
maxNameLen = Math.max(maxNameLen, descriptor.getName().length()); if ( requiredFeatureType.isAssignableFrom(descriptor.getFeatureClass()) ) {
maxFeatureNameLen = Math.max(maxFeatureNameLen, descriptor.getSimpleFeatureName().length()); maxNameLen = Math.max(maxNameLen, descriptor.getName().length());
maxFeatureNameLen = Math.max(maxFeatureNameLen, descriptor.getSimpleFeatureName().length());
}
} }
StringBuilder docs = new StringBuilder(); StringBuilder docs = new StringBuilder();
String format = "%" + maxNameLen + "s %" + maxFeatureNameLen + "s %s%n"; String format = "%" + maxNameLen + "s %" + maxFeatureNameLen + "s %s%n";
docs.append(String.format(format, nameHeader, featureHeader, docHeader)); docs.append(String.format(format, nameHeader, featureHeader, docHeader));
for ( final FeatureDescriptor descriptor : featureDescriptors ) { for ( final FeatureDescriptor descriptor : featureDescriptors ) {
String oneDoc = String.format(format, if ( requiredFeatureType.isAssignableFrom(descriptor.getFeatureClass()) ) {
descriptor.getName(), String oneDoc = String.format(format,
descriptor.getSimpleFeatureName(), descriptor.getName(),
HelpUtils.helpLinksToGATKDocs(descriptor.getCodecClass())); descriptor.getSimpleFeatureName(),
docs.append(oneDoc); HelpUtils.helpLinksToGATKDocs(descriptor.getCodecClass()));
docs.append(oneDoc);
}
} }
return docs.toString(); return docs.toString();

View File

@ -156,12 +156,13 @@ public class ListFileUtils {
FeatureManager.FeatureDescriptor descriptor = builderForValidation.getByTriplet(triplet); FeatureManager.FeatureDescriptor descriptor = builderForValidation.getByTriplet(triplet);
if ( descriptor == null ) if ( descriptor == null )
throw new UserException.UnknownTribbleType(rodBinding.getTribbleType(), 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", 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.getName(), rodBinding.getTribbleType(), builderForValidation.userFriendlyListOfAvailableFeatures(rodBinding.getType())));
if ( ! rodBinding.getType().isAssignableFrom(descriptor.getFeatureClass()) ) if ( ! rodBinding.getType().isAssignableFrom(descriptor.getFeatureClass()) )
throw new UserException.BadArgumentValue(rodBinding.getName(), 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.", 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(), descriptor.getName(), descriptor.getSimpleFeatureName())); rodBinding.getName(), rodBinding.getType().getSimpleName(), descriptor.getSimpleFeatureName(),
builderForValidation.userFriendlyListOfAvailableFeatures(rodBinding.getType())));
rodBindings.add(triplet); rodBindings.add(triplet);