use of org.broadinstitute.barclay.argparser.CommandLineException in project gatk by broadinstitute.
the class VariantRecalibrator method onTraversalStart.
//---------------------------------------------------------------------------------------------------------------
//
// onTraversalStart
//
//---------------------------------------------------------------------------------------------------------------
@Override
public void onTraversalStart() {
if (gatk3Compatibility) {
// Temporary argument for validation of GATK4 implementation against GATK3 results:
// Reset the RNG and draw a single int to align the RNG initial state with that used
// by GATK3 to allow comparison of results with GATK3
Utils.resetRandomGenerator();
Utils.getRandomGenerator().nextInt();
}
dataManager = new VariantDataManager(new ArrayList<>(USE_ANNOTATIONS), VRAC);
if (RSCRIPT_FILE != null && !RScriptExecutor.RSCRIPT_EXISTS)
Utils.warnUser(logger, String.format("Rscript not found in environment path. %s will be generated but PDF plots will not.", RSCRIPT_FILE));
if (IGNORE_INPUT_FILTERS != null) {
ignoreInputFilterSet.addAll(IGNORE_INPUT_FILTERS);
}
try {
tranchesStream = new PrintStream(TRANCHES_FILE);
} catch (FileNotFoundException e) {
throw new UserException.CouldNotCreateOutputFile(TRANCHES_FILE, e);
}
for (FeatureInput<VariantContext> variantFeature : resource) {
dataManager.addTrainingSet(new TrainingSet(variantFeature));
}
if (!dataManager.checkHasTrainingSet()) {
throw new CommandLineException("No training set found! Please provide sets of known polymorphic loci marked with the training=true feature input tag. For example, -resource hapmap,VCF,known=false,training=true,truth=true,prior=12.0 hapmapFile.vcf");
}
if (!dataManager.checkHasTruthSet()) {
throw new CommandLineException("No truth set found! Please provide sets of known polymorphic loci marked with the truth=true feature input tag. For example, -resource hapmap,VCF,known=false,training=true,truth=true,prior=12.0 hapmapFile.vcf");
}
//TODO: this should be refactored/consolidated as part of
// https://github.com/broadinstitute/gatk/issues/2112
// https://github.com/broadinstitute/gatk/issues/121,
// https://github.com/broadinstitute/gatk/issues/1116 and
// Initialize VCF header lines
Set<VCFHeaderLine> hInfo = getDefaultToolVCFHeaderLines();
VariantRecalibrationUtils.addVQSRStandardHeaderLines(hInfo);
SAMSequenceDictionary sequenceDictionary = getBestAvailableSequenceDictionary();
if (hasReference()) {
hInfo = VcfUtils.updateHeaderContigLines(hInfo, referenceArguments.getReferenceFile(), sequenceDictionary, true);
} else if (null != sequenceDictionary) {
hInfo = VcfUtils.updateHeaderContigLines(hInfo, null, sequenceDictionary, true);
}
recalWriter = createVCFWriter(new File(output));
recalWriter.writeHeader(new VCFHeader(hInfo));
for (int iii = 0; iii < REPLICATE * 2; iii++) {
replicate.add(Utils.getRandomGenerator().nextDouble());
}
}
use of org.broadinstitute.barclay.argparser.CommandLineException in project gatk by broadinstitute.
the class GATKReadFilterPluginDescriptor method validateArguments.
/**
* Validate the list of arguments and reduce the list of read filters to those
* actually seen on the command line. This is called by the command line parser
* after all arguments have been parsed.
*/
@Override
public void validateArguments() {
// throw if a filter is *enabled* more than once by the user
final Set<String> duplicateUserEnabledFilterNames = Utils.getDuplicatedItems(userArgs.getUserEnabledReadFilterNames());
if (!duplicateUserEnabledFilterNames.isEmpty()) {
throw new CommandLineException.BadArgumentValue(String.format("The read filter(s) are enabled more than once: %s", Utils.join(", ", duplicateUserEnabledFilterNames)));
}
// throw if a filter is *disabled* more than once by the user
final Set<String> duplicateDisabledUserFilterNames = Utils.getDuplicatedItems(userArgs.getUserDisabledReadFilterNames());
if (!duplicateDisabledUserFilterNames.isEmpty()) {
throw new CommandLineException.BadArgumentValue(String.format("The read filter(s) are disabled more than once: %s", Utils.join(", ", duplicateDisabledUserFilterNames)));
}
// throw if a filter is both enabled *and* disabled by the user
final Set<String> enabledAndDisabled = new HashSet<>(userArgs.getUserEnabledReadFilterNames());
enabledAndDisabled.retainAll(userArgs.getUserDisabledReadFilterNames());
if (!enabledAndDisabled.isEmpty()) {
final String badFiltersList = Utils.join(", ", enabledAndDisabled);
throw new CommandLineException(String.format("The read filter(s): %s are both enabled and disabled", badFiltersList));
}
// throw if a disabled filter doesn't exist; warn if it wasn't enabled by the tool in the first place
userArgs.getUserDisabledReadFilterNames().forEach(s -> {
if (!allDiscoveredReadFilters.containsKey(s)) {
throw new CommandLineException.BadArgumentValue(String.format("Disabled filter (%s) does not exist", s));
} else if (!toolDefaultReadFilters.containsKey(s)) {
logger.warn(String.format("Disabled filter (%s) is not enabled by this tool", s));
}
});
// warn if a filter is both default and enabled by the user
final Set<String> redundant = new HashSet<>(toolDefaultReadFilters.keySet());
redundant.retainAll(userArgs.getUserEnabledReadFilterNames());
redundant.forEach(s -> {
logger.warn(String.format("Redundant enabled filter (%s) is enabled for this tool by default", s));
});
// Throw if args were specified for a filter that was also disabled, or that was not enabled by the
// tool by default.
//
// Note that this is also checked during command line argument parsing, but needs to be checked again
// here. Whenever the command line parser sees a dependent argument on the command line, it delegates
// back to the descriptor's isDependentArgumentAllowed method to allow it to validate that the predecessor
// for that dependent argument has been supplied, either by a default read filter, or by an explicitly
// enabled read filter. However, its possible for the user to subsequently try to disable that
// predecessor, which is what we want to catch here.
//
userArgs.getUserDisabledReadFilterNames().forEach(s -> {
if (requiredPredecessors.contains(s)) {
String message = String.format("Values were supplied for (%s) that is also disabled", s);
if (toolDefaultReadFilters.containsKey(s)) {
logger.warn(message);
} else {
throw new CommandLineException(message);
}
}
});
// throw if a filter name was specified that has no corresponding instance
final Map<String, ReadFilter> requestedReadFilters = new HashMap<>();
userArgs.getUserEnabledReadFilterNames().forEach(s -> {
ReadFilter trf = allDiscoveredReadFilters.get(s);
if (null == trf) {
if (!toolDefaultReadFilters.containsKey(s)) {
throw new CommandLineException("Unrecognized read filter name: " + s);
}
} else {
requestedReadFilters.put(s, trf);
}
});
}
use of org.broadinstitute.barclay.argparser.CommandLineException in project gatk by broadinstitute.
the class Main method mainEntry.
/**
* The entry point to the toolkit from commandline: it uses {@link #instanceMain(String[])} to run the command line
* program and handle the returned object with {@link #handleResult(Object)}, and exit with 0.
* If any error occurs, it handles the exception (if non-user exception, through {@link #handleNonUserException(Exception)})
* and exit with the concrete error exit value.
*
* Note: this is the only method that is allowed to call System.exit (because gatk tools may be run from test harness etc)
*/
protected final void mainEntry(final String[] args) {
final CommandLineProgram program = extractCommandLineProgram(args, getPackageList(), getClassList(), getCommandLineName());
try {
final Object result = runCommandLineProgram(program, args);
handleResult(result);
System.exit(0);
} catch (final CommandLineException e) {
System.err.println(program.getUsage());
handleUserException(e);
System.exit(COMMANDLINE_EXCEPTION_EXIT_VALUE);
} catch (final UserException e) {
handleUserException(e);
System.exit(USER_EXCEPTION_EXIT_VALUE);
} catch (final StorageException e) {
handleStorageException(e);
System.exit(ANY_OTHER_EXCEPTION_EXIT_VALUE);
} catch (final Exception e) {
handleNonUserException(e);
System.exit(ANY_OTHER_EXCEPTION_EXIT_VALUE);
}
}
Aggregations