2009-05-11 10:07:20 +08:00
|
|
|
package org.broadinstitute.sting.gatk;
|
|
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
import org.broadinstitute.sting.utils.GATKErrorReport;
|
2009-12-05 07:24:29 +08:00
|
|
|
import org.broadinstitute.sting.utils.TextFormattingUtils;
|
2009-12-08 03:23:12 +08:00
|
|
|
import org.broadinstitute.sting.utils.help.ApplicationDetails;
|
2009-07-07 23:18:05 +08:00
|
|
|
import org.broadinstitute.sting.utils.cmdLine.*;
|
2009-12-05 07:24:29 +08:00
|
|
|
import org.broadinstitute.sting.gatk.walkers.Walker;
|
2009-05-11 10:07:20 +08:00
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
import java.io.PrintStream;
|
2009-07-22 06:23:28 +08:00
|
|
|
import java.util.*;
|
2009-05-16 05:02:12 +08:00
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* User: aaron
|
|
|
|
|
* Date: May 8, 2009
|
|
|
|
|
* Time: 10:50:58 AM
|
|
|
|
|
*
|
|
|
|
|
* The Broad Institute
|
|
|
|
|
* SOFTWARE COPYRIGHT NOTICE AGREEMENT
|
|
|
|
|
* This software and its documentation are copyright 2009 by the
|
|
|
|
|
* Broad Institute/Massachusetts Institute of Technology. All rights are reserved.
|
|
|
|
|
*
|
|
|
|
|
* This software is supplied without any warranty or guaranteed support whatsoever. Neither
|
|
|
|
|
* the Broad Institute nor MIT can be responsible for its use, misuse, or functionality.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author aaron
|
|
|
|
|
* @version 1.0
|
|
|
|
|
* @date May 8, 2009
|
|
|
|
|
* <p/>
|
|
|
|
|
* Class CommandLineGATK
|
|
|
|
|
* <p/>
|
|
|
|
|
* We run command line GATK programs using this class. It gets the command line args, parses them, and hands the
|
|
|
|
|
* gatk all the parsed out information. Pretty much anything dealing with the underlying system should go here,
|
|
|
|
|
* the gatk engine should deal with any data related information.
|
|
|
|
|
*/
|
2009-07-17 06:02:21 +08:00
|
|
|
public class CommandLineGATK extends CommandLineExecutable {
|
2009-05-12 23:33:55 +08:00
|
|
|
@Argument(fullName = "analysis_type", shortName = "T", doc = "Type of analysis to run")
|
2009-07-17 06:48:44 +08:00
|
|
|
private String analysisName = null;
|
|
|
|
|
|
2009-07-17 06:02:21 +08:00
|
|
|
// our argument collection, the collection of command line args we accept
|
|
|
|
|
@ArgumentCollection
|
2009-10-29 03:56:05 +08:00
|
|
|
private GATKArgumentCollection argCollection = new GATKArgumentCollection();
|
2009-05-11 10:07:20 +08:00
|
|
|
|
2009-07-14 05:56:41 +08:00
|
|
|
/**
|
|
|
|
|
* Get pleasing info about the GATK.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-07-17 06:02:21 +08:00
|
|
|
* @return A list of Strings that contain pleasant info about the GATK.
|
2009-07-14 05:56:41 +08:00
|
|
|
*/
|
|
|
|
|
@Override
|
2009-07-22 06:23:28 +08:00
|
|
|
protected ApplicationDetails getApplicationDetails() {
|
2009-10-29 03:56:05 +08:00
|
|
|
return new ApplicationDetails(createApplicationHeader(),
|
|
|
|
|
ApplicationDetails.createDefaultRunningInstructions(getClass()),
|
|
|
|
|
getAdditionalHelp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* generate an error log, given the stream to write to and the exception that was thrown
|
|
|
|
|
*
|
|
|
|
|
* @param stream the output stream
|
|
|
|
|
* @param e the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void generateErrorLog(PrintStream stream, Exception e) {
|
|
|
|
|
GATKErrorReport report = new GATKErrorReport(e, this.argCollection);
|
|
|
|
|
report.reportToStream(stream);
|
2009-07-14 05:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
@Override
|
2009-07-17 06:02:21 +08:00
|
|
|
protected String getAnalysisName() {
|
|
|
|
|
return analysisName;
|
2009-05-11 10:07:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2009-07-17 06:02:21 +08:00
|
|
|
protected GATKArgumentCollection getArgumentCollection() {
|
2009-05-11 10:07:20 +08:00
|
|
|
return argCollection;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
/**
|
|
|
|
|
* Required main method implementation.
|
|
|
|
|
*/
|
2009-07-17 06:02:21 +08:00
|
|
|
public static void main(String[] argv) {
|
|
|
|
|
try {
|
|
|
|
|
CommandLineGATK instance = new CommandLineGATK();
|
|
|
|
|
start(instance, argv);
|
2009-09-05 03:13:37 +08:00
|
|
|
System.exit(CommandLineProgram.result); // todo -- this is a painful hack
|
2009-07-17 06:02:21 +08:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
exitSystemWithError(e);
|
2009-05-16 05:02:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
2009-07-22 06:23:28 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates the a short blurb about the GATK, copyright info, and where to get documentation.
|
2009-10-29 03:56:05 +08:00
|
|
|
*
|
2009-07-22 06:23:28 +08:00
|
|
|
* @return The application header.
|
|
|
|
|
*/
|
2009-10-29 03:56:05 +08:00
|
|
|
public static List<String> createApplicationHeader() {
|
2009-07-22 06:23:28 +08:00
|
|
|
List<String> header = new ArrayList<String>();
|
|
|
|
|
header.add("The Genome Analysis Toolkit (GATK)");
|
|
|
|
|
header.add("Copyright (c) 2009 The Broad Institute");
|
|
|
|
|
header.add("Please view our documentation at http://www.broadinstitute.org/gsa/wiki");
|
2009-09-21 07:36:54 +08:00
|
|
|
header.add("For support, email gsahelp@broadinstitute.org");
|
2009-07-22 06:23:28 +08:00
|
|
|
header.add("");
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves additional information about GATK walkers.
|
2009-10-29 03:56:05 +08:00
|
|
|
* the code in HelpFormatter and supply it as a helper to this method.
|
|
|
|
|
*
|
2009-07-22 06:23:28 +08:00
|
|
|
* @return A string summarizing the walkers available in this distribution.
|
|
|
|
|
*/
|
|
|
|
|
private String getAdditionalHelp() {
|
2009-12-11 00:43:06 +08:00
|
|
|
String additionalHelp = "";
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2009-12-11 00:43:06 +08:00
|
|
|
// If no analysis name is present, fill in extra help on the walkers.
|
2009-12-12 12:04:37 +08:00
|
|
|
WalkerManager walkerManager = GATKEngine.getWalkerManager();
|
2009-12-11 00:43:06 +08:00
|
|
|
String analysisName = getAnalysisName();
|
2009-12-12 12:04:37 +08:00
|
|
|
if(analysisName != null && walkerManager.exists(getAnalysisName()))
|
|
|
|
|
additionalHelp = getWalkerHelp(walkerManager.getWalkerClassByName(getAnalysisName()));
|
|
|
|
|
else
|
|
|
|
|
additionalHelp = getAllWalkerHelp();
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2009-12-11 00:43:06 +08:00
|
|
|
return additionalHelp;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-12 12:04:37 +08:00
|
|
|
private static final int PACKAGE_INDENT = 1;
|
|
|
|
|
private static final int WALKER_INDENT = 3;
|
|
|
|
|
private static final String FIELD_SEPARATOR = " ";
|
|
|
|
|
|
|
|
|
|
private String getWalkerHelp(Class<Walker> walkerType) {
|
|
|
|
|
// Construct a help string to output details on this walker.
|
|
|
|
|
StringBuilder additionalHelp = new StringBuilder();
|
|
|
|
|
Formatter formatter = new Formatter(additionalHelp);
|
|
|
|
|
|
|
|
|
|
formatter.format("Description:%n");
|
|
|
|
|
|
|
|
|
|
WalkerManager walkerManager = GATKEngine.getWalkerManager();
|
|
|
|
|
String walkerHelpText = walkerManager.getWalkerDescriptionText(walkerType);
|
|
|
|
|
|
|
|
|
|
printDescriptorLine(formatter,WALKER_INDENT,"",WALKER_INDENT,FIELD_SEPARATOR,walkerHelpText,TextFormattingUtils.DEFAULT_LINE_WIDTH);
|
|
|
|
|
|
|
|
|
|
return additionalHelp.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-11 00:43:06 +08:00
|
|
|
/**
|
|
|
|
|
* Load in additional help information about all available walkers.
|
|
|
|
|
* @return A string representation of the additional help.
|
|
|
|
|
*/
|
2009-12-12 12:04:37 +08:00
|
|
|
private String getAllWalkerHelp() {
|
2009-12-05 07:24:29 +08:00
|
|
|
// Construct a help string to output available walkers.
|
2009-07-22 06:23:28 +08:00
|
|
|
StringBuilder additionalHelp = new StringBuilder();
|
2009-10-29 03:56:05 +08:00
|
|
|
Formatter formatter = new Formatter(additionalHelp);
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2009-12-11 00:43:06 +08:00
|
|
|
formatter.format("Available analyses:%n");
|
2009-07-22 06:23:28 +08:00
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
// Get the list of walker names from the walker manager.
|
|
|
|
|
WalkerManager walkerManager = GATKEngine.getWalkerManager();
|
|
|
|
|
|
2009-12-08 05:33:11 +08:00
|
|
|
// Build a list sorted by walker display name. As this information is collected, keep track of the longest
|
|
|
|
|
// package / walker name for later formatting.
|
|
|
|
|
SortedSet<HelpEntry> helpText = new TreeSet<HelpEntry>(new HelpEntryComparator());
|
|
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
int longestPackageName = 0;
|
|
|
|
|
int longestWalkerName = 0;
|
2009-12-08 05:33:11 +08:00
|
|
|
for(Map.Entry<String,Collection<Class<? extends Walker>>> walkersByPackage: walkerManager.getWalkerNamesByPackage().entrySet()) {
|
|
|
|
|
// Get the display name.
|
|
|
|
|
String packageName = walkersByPackage.getKey();
|
|
|
|
|
String packageDisplayName = walkerManager.getPackageDisplayName(walkersByPackage.getKey());
|
2009-12-12 12:04:37 +08:00
|
|
|
String packageHelpText = walkerManager.getPackageSummaryText(packageName);
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
// Compute statistics about which names is longest.
|
|
|
|
|
longestPackageName = Math.max(longestPackageName,packageDisplayName.length());
|
|
|
|
|
|
|
|
|
|
SortedSet<HelpEntry> walkersInPackage = new TreeSet<HelpEntry>(new HelpEntryComparator());
|
|
|
|
|
for(Class<? extends Walker> walkerType: walkersByPackage.getValue()) {
|
|
|
|
|
String walkerName = walkerType.getName();
|
|
|
|
|
String walkerDisplayName = walkerManager.getName(walkerType);
|
2009-12-12 12:04:37 +08:00
|
|
|
String walkerHelpText = walkerManager.getWalkerSummaryText(walkerType);
|
2009-12-08 05:33:11 +08:00
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
longestWalkerName = Math.max(longestWalkerName,walkerManager.getName(walkerType).length());
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
walkersInPackage.add(new HelpEntry(walkerName,walkerDisplayName,walkerHelpText));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dump the walkers into the sorted set.
|
2009-12-10 03:34:56 +08:00
|
|
|
helpText.add(new HelpEntry(packageName,packageDisplayName,packageHelpText,Collections.unmodifiableSortedSet(walkersInPackage)));
|
2009-07-22 06:23:28 +08:00
|
|
|
}
|
2009-10-29 03:56:05 +08:00
|
|
|
|
2009-12-05 07:24:29 +08:00
|
|
|
final int headerWidth = Math.max(longestPackageName+PACKAGE_INDENT,longestWalkerName+WALKER_INDENT);
|
|
|
|
|
|
|
|
|
|
|
2009-12-08 05:33:11 +08:00
|
|
|
for(HelpEntry packageHelp: helpText) {
|
2009-12-12 12:04:37 +08:00
|
|
|
printDescriptorLine(formatter,PACKAGE_INDENT,packageHelp.displayName,headerWidth,FIELD_SEPARATOR,packageHelp.summary,TextFormattingUtils.DEFAULT_LINE_WIDTH);
|
2009-12-05 07:24:29 +08:00
|
|
|
|
2009-12-08 05:33:11 +08:00
|
|
|
for(HelpEntry walkerHelp: packageHelp.children)
|
2009-12-12 12:04:37 +08:00
|
|
|
printDescriptorLine(formatter,WALKER_INDENT,walkerHelp.displayName,headerWidth,FIELD_SEPARATOR,walkerHelp.summary,TextFormattingUtils.DEFAULT_LINE_WIDTH);
|
2009-12-05 07:24:29 +08:00
|
|
|
|
|
|
|
|
// Print a blank line between sets of walkers.
|
|
|
|
|
printDescriptorLine(formatter,0,"",headerWidth,FIELD_SEPARATOR,"", TextFormattingUtils.DEFAULT_LINE_WIDTH);
|
2009-07-22 06:23:28 +08:00
|
|
|
}
|
|
|
|
|
|
2009-10-29 03:56:05 +08:00
|
|
|
return additionalHelp.toString();
|
2009-07-22 06:23:28 +08:00
|
|
|
}
|
2009-12-05 07:24:29 +08:00
|
|
|
|
|
|
|
|
private void printDescriptorLine(Formatter formatter,
|
|
|
|
|
int headerIndentWidth,
|
|
|
|
|
String header,
|
|
|
|
|
int headerWidth,
|
|
|
|
|
String fieldSeparator,
|
|
|
|
|
String description,
|
|
|
|
|
int lineWidth) {
|
|
|
|
|
final int headerPaddingWidth = headerWidth - header.length() - headerIndentWidth;
|
|
|
|
|
final int descriptionWidth = lineWidth - fieldSeparator.length() - headerWidth;
|
|
|
|
|
List<String> wordWrappedText = TextFormattingUtils.wordWrap(description,descriptionWidth);
|
|
|
|
|
|
|
|
|
|
String headerIndentFormatString = headerIndentWidth > 0 ? "%" + headerIndentWidth + "s" : "%s";
|
|
|
|
|
String headerPaddingFormatString = headerPaddingWidth > 0 ? "%" + headerPaddingWidth + "s" : "%s";
|
|
|
|
|
String headerWidthFormatString = headerWidth > 0 ? "%" + headerWidth + "s" : "%s";
|
|
|
|
|
|
|
|
|
|
// Output description line.
|
|
|
|
|
formatter.format(headerIndentFormatString + "%s" + headerPaddingFormatString + "%s%s%n",
|
|
|
|
|
"", header, "", fieldSeparator, wordWrappedText.size()>0?wordWrappedText.get(0):"");
|
|
|
|
|
for(int i = 1; i < wordWrappedText.size(); i++)
|
|
|
|
|
formatter.format(headerWidthFormatString + "%s%s%n", "", fieldSeparator, wordWrappedText.get(i));
|
|
|
|
|
}
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-12 12:04:37 +08:00
|
|
|
* Represents a given help entry; contains a display name, a summary and optionally some children.
|
2009-12-08 05:33:11 +08:00
|
|
|
*/
|
|
|
|
|
class HelpEntry {
|
|
|
|
|
public final String uid;
|
|
|
|
|
public final String displayName;
|
2009-12-12 12:04:37 +08:00
|
|
|
public final String summary;
|
2009-12-08 05:33:11 +08:00
|
|
|
public final SortedSet<HelpEntry> children;
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-12 12:04:37 +08:00
|
|
|
* Create a new help entry with the given display name, summary and children.
|
2009-12-08 05:33:11 +08:00
|
|
|
* @param uid a unique identifier. Usually, the java package.
|
|
|
|
|
* @param displayName display name for this help entry.
|
2009-12-12 12:04:37 +08:00
|
|
|
* @param summary summary for this help entry.
|
2009-12-08 05:33:11 +08:00
|
|
|
* @param children children for this help entry.
|
|
|
|
|
*/
|
2009-12-12 12:04:37 +08:00
|
|
|
public HelpEntry(String uid, String displayName, String summary, SortedSet<HelpEntry> children) {
|
2009-12-08 05:33:11 +08:00
|
|
|
this.uid = uid;
|
|
|
|
|
this.displayName = displayName;
|
2009-12-12 12:04:37 +08:00
|
|
|
this.summary = summary;
|
2009-12-08 05:33:11 +08:00
|
|
|
this.children = children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-12-12 12:04:37 +08:00
|
|
|
* Create a new help entry with the given display name, summary and children.
|
2009-12-08 05:33:11 +08:00
|
|
|
* @param uid a unique identifier. Usually, the java package.
|
|
|
|
|
* @param displayName display name for this help entry.
|
2009-12-12 12:04:37 +08:00
|
|
|
* @param summary summary for this help entry.
|
2009-12-08 05:33:11 +08:00
|
|
|
*/
|
2009-12-12 12:04:37 +08:00
|
|
|
public HelpEntry(String uid, String displayName, String summary) {
|
|
|
|
|
this(uid,displayName,summary,null);
|
2009-12-08 05:33:11 +08:00
|
|
|
}
|
|
|
|
|
|
2009-05-11 10:07:20 +08:00
|
|
|
}
|
2009-12-08 05:33:11 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compare two help entries by display name.
|
|
|
|
|
*/
|
|
|
|
|
class HelpEntryComparator implements Comparator<HelpEntry> {
|
|
|
|
|
private static TextFormattingUtils.CaseInsensitiveComparator textComparator = new TextFormattingUtils.CaseInsensitiveComparator();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compares the order of lhs to rhs, not taking case into account.
|
|
|
|
|
* @param lhs First object to compare.
|
|
|
|
|
* @param rhs Second object to compare.
|
|
|
|
|
* @return 0 if objects are identical; -1 if lhs is before rhs, 1 if rhs is before lhs. Nulls are treated as after everything else.
|
|
|
|
|
*/
|
|
|
|
|
public int compare(HelpEntry lhs, HelpEntry rhs) {
|
|
|
|
|
if(lhs == null && rhs == null) return 0;
|
2009-12-10 03:34:56 +08:00
|
|
|
if(lhs == null || lhs.displayName.equals("")) return 1;
|
|
|
|
|
if(rhs == null || rhs.displayName.equals("")) return -1;
|
|
|
|
|
return lhs.displayName.equals(rhs.displayName) ? textComparator.compare(lhs.uid,rhs.uid) : textComparator.compare(lhs.displayName,rhs.displayName);
|
2009-12-08 05:33:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|