2010-04-20 07:00:08 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010 The Broad Institute
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2010-04-20 07:00:08 +08:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
2010-04-20 23:26:32 +08:00
|
|
|
* files (the "Software"), to deal in the Software without
|
2010-04-20 07:00:08 +08:00
|
|
|
* 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:
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2010-04-20 07:00:08 +08:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
2010-04-20 23:26:32 +08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
2010-04-20 07:00:08 +08:00
|
|
|
* 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.commandline;
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2011-07-18 08:29:58 +08:00
|
|
|
import org.apache.log4j.FileAppender;
|
|
|
|
|
import org.apache.log4j.Level;
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
import org.apache.log4j.PatternLayout;
|
2010-09-14 02:36:45 +08:00
|
|
|
import org.broadinstitute.sting.gatk.CommandLineGATK;
|
|
|
|
|
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
2009-12-08 03:23:12 +08:00
|
|
|
import org.broadinstitute.sting.utils.help.ApplicationDetails;
|
|
|
|
|
import org.broadinstitute.sting.utils.help.HelpFormatter;
|
2009-03-23 05:06:22 +08:00
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2011-10-15 00:06:41 +08:00
|
|
|
import java.util.*;
|
2009-03-23 05:06:22 +08:00
|
|
|
|
|
|
|
|
public abstract class CommandLineProgram {
|
|
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
/** The command-line program and the arguments it returned. */
|
2011-07-21 12:18:07 +08:00
|
|
|
public ParsingEngine parser = null;
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
/** the default log level */
|
2010-08-10 00:42:48 +08:00
|
|
|
@Argument(fullName = "logging_level",
|
2009-10-29 03:56:05 +08:00
|
|
|
shortName = "l",
|
2010-01-21 05:36:46 +08:00
|
|
|
doc = "Set the minimum level of logging, i.e. setting INFO get's you INFO up to FATAL, setting ERROR gets you ERROR and FATAL level logging.",
|
2009-10-29 03:56:05 +08:00
|
|
|
required = false)
|
2010-08-10 00:42:48 +08:00
|
|
|
protected String logging_level = "INFO";
|
2009-03-23 05:06:22 +08:00
|
|
|
|
|
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
/** where to send the output of our logger */
|
2010-06-26 04:51:13 +08:00
|
|
|
@Output(fullName = "log_to_file",
|
2009-10-29 03:56:05 +08:00
|
|
|
shortName = "log",
|
|
|
|
|
doc = "Set the logging location",
|
|
|
|
|
required = false)
|
2009-05-07 03:38:05 +08:00
|
|
|
protected String toFile = null;
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
/** this is used to indicate if they've asked for help */
|
2010-08-10 00:42:48 +08:00
|
|
|
@Argument(fullName = "help", shortName = "h", doc = "Generate this help message", required = false)
|
2009-09-05 03:13:37 +08:00
|
|
|
public Boolean help = false;
|
2009-05-08 03:08:19 +08:00
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
/** our logging output patterns */
|
2011-04-27 18:56:39 +08:00
|
|
|
private static final String patternString = "%-5p %d{HH:mm:ss,SSS} %C{1} - %m %n";
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2010-11-19 04:22:01 +08:00
|
|
|
static {
|
|
|
|
|
/**
|
|
|
|
|
* The very first thing that any Sting application does is forces the JVM locale into US English, so that we don't have
|
|
|
|
|
* to think about number formatting issues.
|
|
|
|
|
*/
|
2010-09-30 05:55:21 +08:00
|
|
|
forceJVMLocaleToUSEnglish();
|
2010-11-19 04:22:01 +08:00
|
|
|
// setup a basic log configuration
|
|
|
|
|
CommandLineUtils.configureConsoleLogging();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-30 05:55:21 +08:00
|
|
|
|
2009-05-08 03:08:19 +08:00
|
|
|
/**
|
2009-07-22 06:23:28 +08:00
|
|
|
* Allows a given application to return a brief description of itself.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
|
|
|
|
* @return An ApplicationDetails object describing the current application. Should not be null.
|
2009-05-08 03:08:19 +08:00
|
|
|
*/
|
2009-07-22 06:23:28 +08:00
|
|
|
protected ApplicationDetails getApplicationDetails() {
|
2009-10-29 03:56:05 +08:00
|
|
|
return new ApplicationDetails(ApplicationDetails.createDefaultHeader(getClass()),
|
2010-10-02 02:31:19 +08:00
|
|
|
Collections.<String>emptyList(),
|
|
|
|
|
ApplicationDetails.createDefaultRunningInstructions(getClass()),
|
|
|
|
|
null);
|
2009-07-14 05:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
2009-08-23 08:56:02 +08:00
|
|
|
/**
|
2009-10-29 03:56:05 +08:00
|
|
|
* Subclasses of CommandLinePrograms can provide their own types of command-line arguments.
|
2009-08-23 08:56:02 +08:00
|
|
|
* @return A collection of type descriptors generating implementation-dependent placeholders.
|
|
|
|
|
*/
|
|
|
|
|
protected Collection<ArgumentTypeDescriptor> getArgumentTypeDescriptors() {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-25 08:12:00 +08:00
|
|
|
/**
|
|
|
|
|
* Will this application want to vary its argument list dynamically?
|
|
|
|
|
* If so, parse the command-line options and then prompt the subclass to return
|
|
|
|
|
* a list of argument providers.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-03-25 08:12:00 +08:00
|
|
|
* @return Whether the application should vary command-line arguments dynamically.
|
|
|
|
|
*/
|
|
|
|
|
protected boolean canAddArgumentsDynamically() { return false; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provide a list of object to inspect, looking for additional command-line arguments.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-03-25 08:12:00 +08:00
|
|
|
* @return A list of objects to inspect.
|
|
|
|
|
*/
|
2009-10-29 03:56:05 +08:00
|
|
|
protected Class[] getArgumentSources() {
|
|
|
|
|
return new Class[]{};
|
|
|
|
|
}
|
2009-03-27 04:45:27 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Name this argument source. Provides the (full) class name as a default.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-03-27 04:45:27 +08:00
|
|
|
* @param source The argument source.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-03-27 04:45:27 +08:00
|
|
|
* @return a name for the argument source.
|
|
|
|
|
*/
|
|
|
|
|
protected String getArgumentSourceName( Class source ) { return source.toString(); }
|
2009-03-25 08:12:00 +08:00
|
|
|
|
2011-04-01 23:04:35 +08:00
|
|
|
/**
|
|
|
|
|
* Sets the command-line parsing engine. Necessary for unit testing purposes.
|
|
|
|
|
* @param parser the new command-line parsing engine
|
|
|
|
|
*/
|
|
|
|
|
public void setParser( ParsingEngine parser ) {
|
|
|
|
|
this.parser = parser;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-23 05:06:22 +08:00
|
|
|
/**
|
|
|
|
|
* this is the function that the inheriting class can expect to have called
|
|
|
|
|
* when all the argument processing is done
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-03-23 05:06:22 +08:00
|
|
|
* @return the return code to exit the program with
|
2010-11-19 04:22:01 +08:00
|
|
|
* @throws Exception when an exception occurs
|
2009-03-23 05:06:22 +08:00
|
|
|
*/
|
2010-08-29 06:53:32 +08:00
|
|
|
protected abstract int execute() throws Exception;
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2009-09-05 06:26:57 +08:00
|
|
|
public static int result = -1;
|
2009-09-05 03:13:37 +08:00
|
|
|
|
2011-07-21 12:18:07 +08:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public static void start(CommandLineProgram clp, String[] args) throws Exception {
|
|
|
|
|
start(clp, args, false);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-23 05:06:22 +08:00
|
|
|
/**
|
|
|
|
|
* This function is called to start processing the command line, and kick
|
|
|
|
|
* off the execute message of the program.
|
|
|
|
|
*
|
2009-10-29 03:56:05 +08:00
|
|
|
* @param clp the command line program to execute
|
2009-03-23 05:06:22 +08:00
|
|
|
* @param args the command line arguments passed in
|
2011-10-15 00:06:41 +08:00
|
|
|
* @param dryRun dry run
|
2010-11-19 04:22:01 +08:00
|
|
|
* @throws Exception when an exception occurs
|
2009-03-23 05:06:22 +08:00
|
|
|
*/
|
2010-08-10 00:42:48 +08:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-07-21 12:18:07 +08:00
|
|
|
public static void start(CommandLineProgram clp, String[] args, boolean dryRun) throws Exception {
|
2009-03-23 05:06:22 +08:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// setup our log layout
|
|
|
|
|
PatternLayout layout = new PatternLayout();
|
|
|
|
|
|
2010-11-19 04:22:01 +08:00
|
|
|
Logger logger = CommandLineUtils.getStingLogger();
|
|
|
|
|
|
2010-08-13 23:54:08 +08:00
|
|
|
// now set the layout of all the loggers to our layout
|
2010-11-19 04:22:01 +08:00
|
|
|
CommandLineUtils.setLayout(logger, layout);
|
2010-08-13 23:54:08 +08:00
|
|
|
|
|
|
|
|
// Initialize the logger using the defaults.
|
|
|
|
|
clp.setupLoggerLevel(layout);
|
|
|
|
|
|
2009-03-23 05:06:22 +08:00
|
|
|
// setup the parser
|
2009-07-30 00:11:45 +08:00
|
|
|
ParsingEngine parser = clp.parser = new ParsingEngine(clp);
|
2009-10-29 03:56:05 +08:00
|
|
|
parser.addArgumentSource(clp.getClass());
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2011-10-15 00:06:41 +08:00
|
|
|
Map<ArgumentMatchSource, List<String>> parsedArgs;
|
|
|
|
|
|
2009-03-23 05:06:22 +08:00
|
|
|
// process the args
|
2009-10-29 03:56:05 +08:00
|
|
|
if (clp.canAddArgumentsDynamically()) {
|
2009-03-25 08:12:00 +08:00
|
|
|
// if the command-line program can toss in extra args, fetch them and reparse the arguments.
|
2009-05-07 03:38:05 +08:00
|
|
|
parser.parse(args);
|
2009-05-18 08:42:00 +08:00
|
|
|
|
|
|
|
|
// Allow invalid and missing required arguments to pass this validation step.
|
|
|
|
|
// - InvalidArgument in case these arguments are specified by plugins.
|
|
|
|
|
// - MissingRequiredArgument in case the user requested help. Handle that later, once we've
|
|
|
|
|
// determined the full complement of arguments.
|
2011-07-21 12:18:07 +08:00
|
|
|
if ( ! dryRun )
|
|
|
|
|
parser.validate(EnumSet.of(ParsingEngine.ValidationType.MissingRequiredArgument,
|
|
|
|
|
ParsingEngine.ValidationType.InvalidArgument));
|
2009-10-29 03:56:05 +08:00
|
|
|
parser.loadArgumentsIntoObject(clp);
|
2009-03-27 04:45:27 +08:00
|
|
|
|
2010-08-13 23:54:08 +08:00
|
|
|
// Initialize the logger using the loaded command line.
|
|
|
|
|
clp.setupLoggerLevel(layout);
|
|
|
|
|
|
2009-03-27 04:45:27 +08:00
|
|
|
Class[] argumentSources = clp.getArgumentSources();
|
2009-10-29 03:56:05 +08:00
|
|
|
for (Class argumentSource : argumentSources)
|
|
|
|
|
parser.addArgumentSource(clp.getArgumentSourceName(argumentSource), argumentSource);
|
2011-10-15 00:06:41 +08:00
|
|
|
parsedArgs = parser.parse(args);
|
2009-05-18 08:42:00 +08:00
|
|
|
|
2010-08-10 00:42:48 +08:00
|
|
|
if (isHelpPresent(parser))
|
2009-10-29 03:56:05 +08:00
|
|
|
printHelpAndExit(clp, parser);
|
2009-05-18 08:42:00 +08:00
|
|
|
|
2011-07-21 12:18:07 +08:00
|
|
|
if ( ! dryRun ) parser.validate();
|
2009-10-29 03:56:05 +08:00
|
|
|
} else {
|
2011-10-15 00:06:41 +08:00
|
|
|
parsedArgs = parser.parse(args);
|
2009-05-18 08:42:00 +08:00
|
|
|
|
2011-07-21 12:18:07 +08:00
|
|
|
if ( ! dryRun ) {
|
|
|
|
|
if (isHelpPresent(parser))
|
|
|
|
|
printHelpAndExit(clp, parser);
|
2009-05-18 08:42:00 +08:00
|
|
|
|
2011-07-21 12:18:07 +08:00
|
|
|
parser.validate();
|
|
|
|
|
}
|
2009-10-29 03:56:05 +08:00
|
|
|
parser.loadArgumentsIntoObject(clp);
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2010-08-13 23:54:08 +08:00
|
|
|
// Initialize the logger using the loaded command line.
|
|
|
|
|
clp.setupLoggerLevel(layout);
|
2009-06-26 03:47:29 +08:00
|
|
|
}
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2011-07-21 12:18:07 +08:00
|
|
|
if ( ! dryRun ) {
|
|
|
|
|
// if they specify a log location, output our data there
|
|
|
|
|
if (clp.toFile != null) {
|
|
|
|
|
FileAppender appender;
|
|
|
|
|
try {
|
|
|
|
|
appender = new FileAppender(layout, clp.toFile, false);
|
|
|
|
|
logger.addAppender(appender);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("Unable to re-route log output to " + clp.toFile + " make sure the destination exists");
|
|
|
|
|
}
|
2009-03-23 05:06:22 +08:00
|
|
|
}
|
|
|
|
|
|
2011-07-21 12:18:07 +08:00
|
|
|
// regardless of what happens next, generate the header information
|
2011-10-15 00:06:41 +08:00
|
|
|
HelpFormatter.generateHeaderInformation(clp.getApplicationDetails(), parsedArgs);
|
2009-10-15 20:07:44 +08:00
|
|
|
|
2011-07-21 12:18:07 +08:00
|
|
|
// call the execute
|
|
|
|
|
CommandLineProgram.result = clp.execute();
|
|
|
|
|
}
|
2009-03-23 05:06:22 +08:00
|
|
|
}
|
2009-05-20 07:26:17 +08:00
|
|
|
catch (ArgumentException e) {
|
2009-10-29 03:56:05 +08:00
|
|
|
clp.parser.printHelp(clp.getApplicationDetails());
|
2009-05-08 03:31:32 +08:00
|
|
|
// Rethrow the exception to exit with an error.
|
|
|
|
|
throw e;
|
2009-03-25 08:12:00 +08:00
|
|
|
}
|
2009-10-29 03:56:05 +08:00
|
|
|
}
|
|
|
|
|
|
2009-03-27 04:45:27 +08:00
|
|
|
/**
|
|
|
|
|
* Find fields in the object obj that look like command-line arguments, and put command-line
|
|
|
|
|
* arguments into them.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-03-27 04:45:27 +08:00
|
|
|
* @param obj Object to inspect for command line arguments.
|
|
|
|
|
*/
|
2009-10-29 03:56:05 +08:00
|
|
|
public void loadArgumentsIntoObject(Object obj) {
|
|
|
|
|
parser.loadArgumentsIntoObject(obj);
|
2009-03-27 04:45:27 +08:00
|
|
|
}
|
|
|
|
|
|
2009-03-23 05:06:22 +08:00
|
|
|
/**
|
|
|
|
|
* this function checks the logger level passed in on the command line, taking the lowest
|
|
|
|
|
* level that was provided.
|
2010-08-13 23:54:08 +08:00
|
|
|
* @param layout Pattern layout to format based on the logger level.
|
2009-03-23 05:06:22 +08:00
|
|
|
*/
|
2010-08-13 23:54:08 +08:00
|
|
|
private void setupLoggerLevel(PatternLayout layout) {
|
2011-04-27 18:56:39 +08:00
|
|
|
layout.setConversionPattern(patternString);
|
2010-08-13 23:54:08 +08:00
|
|
|
|
|
|
|
|
// set the default logger level
|
2010-08-10 00:42:48 +08:00
|
|
|
Level par;
|
2009-09-01 12:21:58 +08:00
|
|
|
if (logging_level.toUpperCase().equals("DEBUG")) {
|
2009-03-23 05:06:22 +08:00
|
|
|
par = Level.DEBUG;
|
2009-10-29 03:56:05 +08:00
|
|
|
} else if (logging_level.toUpperCase().equals("ERROR")) {
|
2009-03-23 05:06:22 +08:00
|
|
|
par = Level.ERROR;
|
2009-10-29 03:56:05 +08:00
|
|
|
} else if (logging_level.toUpperCase().equals("FATAL")) {
|
2009-03-23 05:06:22 +08:00
|
|
|
par = Level.FATAL;
|
2009-10-29 03:56:05 +08:00
|
|
|
} else if (logging_level.toUpperCase().equals("INFO")) {
|
2009-03-23 05:06:22 +08:00
|
|
|
par = Level.INFO;
|
2009-10-29 03:56:05 +08:00
|
|
|
} else if (logging_level.toUpperCase().equals("WARN")) {
|
2009-03-23 05:06:22 +08:00
|
|
|
par = Level.WARN;
|
2009-10-29 03:56:05 +08:00
|
|
|
} else if (logging_level.toUpperCase().equals("OFF")) {
|
2009-03-23 05:06:22 +08:00
|
|
|
par = Level.OFF;
|
2009-10-29 03:56:05 +08:00
|
|
|
} else {
|
2009-03-27 12:29:27 +08:00
|
|
|
// we don't understand the logging level, let's get out of here
|
2009-05-20 07:26:17 +08:00
|
|
|
throw new ArgumentException("Unable to match: " + logging_level + " to a logging level, make sure it's a valid level (INFO, DEBUG, ERROR, FATAL, OFF)");
|
2009-03-27 12:29:27 +08:00
|
|
|
}
|
2009-03-23 05:06:22 +08:00
|
|
|
|
2010-11-23 06:59:42 +08:00
|
|
|
Logger.getRootLogger().setLevel(par);
|
2009-03-23 05:06:22 +08:00
|
|
|
}
|
2009-05-11 10:07:20 +08:00
|
|
|
|
|
|
|
|
/**
|
2010-08-10 00:42:48 +08:00
|
|
|
* a function used to indicate an error occurred in the command line tool
|
2009-05-11 10:07:20 +08:00
|
|
|
*/
|
2010-09-09 19:32:20 +08:00
|
|
|
private static void printDocumentationReference() {
|
2012-07-21 05:16:24 +08:00
|
|
|
errorPrintf("Visit our website and forum for extensive documentation and answers to %n");
|
|
|
|
|
errorPrintf("commonly asked questions http://www.broadinstitute.org/gatk%n");
|
2009-05-11 10:07:20 +08:00
|
|
|
}
|
|
|
|
|
|
2010-09-09 19:32:20 +08:00
|
|
|
|
2009-05-18 08:42:00 +08:00
|
|
|
/**
|
|
|
|
|
* Do a cursory search for the given argument.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-05-18 08:42:00 +08:00
|
|
|
* @param parser Parser
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-05-18 08:42:00 +08:00
|
|
|
* @return True if help is present; false otherwise.
|
|
|
|
|
*/
|
2010-08-10 00:42:48 +08:00
|
|
|
private static boolean isHelpPresent(ParsingEngine parser) {
|
2009-05-18 08:42:00 +08:00
|
|
|
return parser.isArgumentPresent("help");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print help and exit.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
|
|
|
|
* @param clp Instance of the command-line program.
|
2009-05-18 08:42:00 +08:00
|
|
|
* @param parser True if help is present; false otherwise.
|
|
|
|
|
*/
|
2009-10-29 03:56:05 +08:00
|
|
|
private static void printHelpAndExit(CommandLineProgram clp, ParsingEngine parser) {
|
|
|
|
|
parser.printHelp(clp.getApplicationDetails());
|
2009-05-18 08:42:00 +08:00
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-09 19:32:20 +08:00
|
|
|
private static void errorPrintf(String format, Object... s) {
|
|
|
|
|
String formatted = String.format(format, s);
|
|
|
|
|
|
|
|
|
|
if ( formatted.trim().equals("") )
|
2010-09-14 20:35:57 +08:00
|
|
|
System.err.println("##### ERROR");
|
2010-09-09 19:32:20 +08:00
|
|
|
else {
|
|
|
|
|
for ( String part : formatted.split("\n") ) {
|
2010-09-14 20:35:57 +08:00
|
|
|
System.err.println("##### ERROR " + part);
|
2010-09-09 19:32:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
2009-05-11 10:07:20 +08:00
|
|
|
}
|
|
|
|
|
|
2010-09-09 19:32:20 +08:00
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
/**
|
|
|
|
|
* used to indicate an error occured
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-05-11 10:07:20 +08:00
|
|
|
* @param msg the message
|
2011-09-13 22:49:16 +08:00
|
|
|
* @param t the error
|
2009-05-11 10:07:20 +08:00
|
|
|
*/
|
2011-09-13 22:49:16 +08:00
|
|
|
public static void exitSystemWithError(String msg, final Throwable t) {
|
2010-09-09 19:32:20 +08:00
|
|
|
errorPrintf("------------------------------------------------------------------------------------------%n");
|
|
|
|
|
errorPrintf("stack trace %n");
|
2011-09-13 22:49:16 +08:00
|
|
|
t.printStackTrace();
|
2010-09-09 19:32:20 +08:00
|
|
|
|
|
|
|
|
errorPrintf("------------------------------------------------------------------------------------------%n");
|
2010-09-14 02:36:45 +08:00
|
|
|
errorPrintf("A GATK RUNTIME ERROR has occurred (version %s):%n", CommandLineGATK.getVersionNumber());
|
2010-09-09 19:32:20 +08:00
|
|
|
errorPrintf("%n");
|
2011-03-22 11:57:11 +08:00
|
|
|
errorPrintf("Please visit the wiki to see if this is a known problem%n");
|
2010-09-09 19:32:20 +08:00
|
|
|
errorPrintf("If not, please post the error, with stack trace, to the GATK forum%n");
|
|
|
|
|
printDocumentationReference();
|
2010-09-14 02:36:45 +08:00
|
|
|
if ( msg == null ) // some exceptions don't have detailed messages
|
|
|
|
|
msg = "Code exception (see stack trace for error itself)";
|
2010-09-09 19:32:20 +08:00
|
|
|
errorPrintf("%n");
|
|
|
|
|
errorPrintf("MESSAGE: %s%n", msg.trim());
|
|
|
|
|
errorPrintf("------------------------------------------------------------------------------------------%n");
|
2009-05-11 10:07:20 +08:00
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-22 23:22:17 +08:00
|
|
|
public static void exitSystemWithUserError(final Exception e) {
|
2010-09-14 02:36:45 +08:00
|
|
|
if ( e.getMessage() == null )
|
|
|
|
|
throw new ReviewedStingException("UserException found with no message!", e);
|
|
|
|
|
|
2010-09-09 19:32:20 +08:00
|
|
|
errorPrintf("------------------------------------------------------------------------------------------%n");
|
2010-09-14 02:36:45 +08:00
|
|
|
errorPrintf("A USER ERROR has occurred (version %s): %n", CommandLineGATK.getVersionNumber());
|
|
|
|
|
errorPrintf("The invalid arguments or inputs must be corrected before the GATK can proceed%n");
|
2010-10-04 02:58:03 +08:00
|
|
|
errorPrintf("Please do not post this error to the GATK forum%n");
|
2010-09-09 19:32:20 +08:00
|
|
|
errorPrintf("%n");
|
2010-10-04 02:58:03 +08:00
|
|
|
errorPrintf("See the documentation (rerun with -h) for this tool to view allowable command-line arguments.%n");
|
2010-09-09 19:32:20 +08:00
|
|
|
printDocumentationReference();
|
|
|
|
|
errorPrintf("%n");
|
|
|
|
|
errorPrintf("MESSAGE: %s%n", e.getMessage().trim());
|
|
|
|
|
errorPrintf("------------------------------------------------------------------------------------------%n");
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-19 01:56:35 +08:00
|
|
|
public static void exitSystemWithSamError(final Throwable t) {
|
|
|
|
|
if ( t.getMessage() == null )
|
|
|
|
|
throw new ReviewedStingException("SamException found with no message!", t);
|
2011-04-18 11:52:43 +08:00
|
|
|
|
|
|
|
|
errorPrintf("------------------------------------------------------------------------------------------%n");
|
|
|
|
|
errorPrintf("A BAM ERROR has occurred (version %s): %n", CommandLineGATK.getVersionNumber());
|
|
|
|
|
errorPrintf("The invalid inputs must be corrected before the GATK can proceed%n");
|
|
|
|
|
errorPrintf("Please do not post this error to the GATK forum until you have followed the instructions below%n");
|
|
|
|
|
errorPrintf("%n");
|
|
|
|
|
errorPrintf("Please make sure that your BAM file is well-formed by running Picard's validator on it%n");
|
|
|
|
|
errorPrintf("(see http://picard.sourceforge.net/command-line-overview.shtml#ValidateSamFile for details)%n");
|
|
|
|
|
errorPrintf("Also, please ensure that your BAM index is not corrupted: delete the current one and regenerate it with 'samtools index'%n");
|
|
|
|
|
printDocumentationReference();
|
|
|
|
|
errorPrintf("%n");
|
2012-07-19 01:56:35 +08:00
|
|
|
errorPrintf("MESSAGE: %s%n", t.getMessage().trim());
|
2011-04-18 11:52:43 +08:00
|
|
|
errorPrintf("------------------------------------------------------------------------------------------%n");
|
|
|
|
|
System.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-09 19:32:20 +08:00
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
/**
|
|
|
|
|
* used to indicate an error occured
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2011-11-22 23:50:22 +08:00
|
|
|
* @param t the exception that occurred
|
2009-05-11 10:07:20 +08:00
|
|
|
*/
|
2011-09-13 22:49:16 +08:00
|
|
|
public static void exitSystemWithError(Throwable t) {
|
|
|
|
|
exitSystemWithError(t.getMessage(), t);
|
2009-05-11 10:07:20 +08:00
|
|
|
}
|
2009-10-29 03:56:05 +08:00
|
|
|
|
2010-08-03 11:48:26 +08:00
|
|
|
/**
|
|
|
|
|
* A hack to ensure that numbers are always formatted in the US style.
|
|
|
|
|
*/
|
|
|
|
|
protected static void forceJVMLocaleToUSEnglish() {
|
|
|
|
|
Locale.setDefault(Locale.US);
|
|
|
|
|
}
|
2009-03-23 05:06:22 +08:00
|
|
|
}
|