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) {
ArgumentDefinition defaultDefinition = createDefaultArgumentDefinition(source);
String value = getArgumentValue( defaultDefinition, matches );
Class<? extends Feature> 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);

View File

@ -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<? extends Feature> 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();

View File

@ -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);