use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class BeautiApp method main.
// Main entry point
public static void main(String[] args) {
// There is a major issue with languages that use the comma as a decimal separator.
// To ensure compatibility between programs in the package, enforce the US locale.
Locale.setDefault(Locale.US);
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.Option("advanced", "Enable advanced & developer features"), new Arguments.Option("version", "Print the version and credits and stop"), new Arguments.Option("help", "Print this information and stop") });
int argumentCount = 0;
try {
argumentCount = arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
printTitle();
System.out.println();
System.out.println(ae.getMessage());
System.out.println();
printUsage(arguments);
System.exit(1);
}
if (arguments.hasOption("help")) {
printTitle();
printUsage(arguments);
System.exit(0);
}
if (arguments.hasOption("version")) {
printTitle();
}
advanced = arguments.hasOption("advanced");
String[] args2 = arguments.getLeftoverArguments();
if (args2.length > 1) {
System.err.println("Unknown option: " + args2[1]);
System.err.println();
printUsage(arguments);
return;
}
// if (args2.length > 1) {
//
// if (args.length != 3) {
// printTitle();
// printUsage(arguments);
// System.exit(1);
// }
//
// String inputFileName = args[0];
// String templateFileName = args[1];
// String outputFileName = args[2];
//
// new CommandLineBeauti(inputFileName, templateFileName, outputFileName);
//
// } else {
String inputFileName = null;
if (args2.length == 1) {
inputFileName = args2[0];
}
if (OSType.isMac()) {
System.setProperty("apple.awt.graphics.UseQuartz", "true");
System.setProperty("apple.awt.antialiasing", "true");
System.setProperty("apple.awt.rendering", "VALUE_RENDER_QUALITY");
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("apple.awt.draggableWindowBackground", "true");
System.setProperty("apple.awt.showGrowBox", "true");
try {
// set the Quaqua Look and Feel in the UIManager
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
try {
// We need to do this using dynamic class loading to avoid other platforms
// having to link to this class. If the Quaqua library is not on the classpath
// it simply won't be used.
Class<?> qm = Class.forName("ch.randelshofer.quaqua.QuaquaManager");
Method method = qm.getMethod("setExcludedUIs", Set.class);
Set<String> excludes = new HashSet<String>();
excludes.add("Button");
excludes.add("ToolBar");
method.invoke(null, excludes);
} catch (Throwable e) {
}
//set the Quaqua Look and Feel in the UIManager
UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
lafLoaded = true;
} catch (Exception e) {
}
}
});
} catch (Exception e) {
}
UIManager.put("SystemFont", new Font("Lucida Grande", Font.PLAIN, 13));
UIManager.put("SmallSystemFont", new Font("Lucida Grande", Font.PLAIN, 11));
}
try {
if (!lafLoaded) {
try {
// set the System Look and Feel in the UIManager
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
java.net.URL url = BeautiApp.class.getResource("images/beauti.png");
Icon icon = null;
if (url != null) {
icon = new ImageIcon(url);
}
final String nameString = "BEAUti";
final String versionString = version.getVersionString();
String aboutString = "<html>" + "<div style=\"font-family:HelveticaNeue-Light, 'Helvetica Neue Light', Helvetica, Arial, 'Lucida Grande',sans-serif; font-weight: 100\">" + "<center>" + "<div style=\"font-size:13\"><p>Bayesian Evolutionary Analysis Utility<br>" + "Version " + versionString + ", " + version.getDateString() + "</p>" + "<p>by Alexei J. Drummond, Andrew Rambaut, Marc A. Suchard and Walter Xie</p></div>" + "<hr><div style=\"font-size:11;\">Part of the BEAST package:" + version.getHTMLCredits() + "</div></center></div></html>";
String websiteURLString = "http://beast.bio.ed.ac.uk/BEAUti";
String helpURLString = "http://beast.bio.ed.ac.uk/BEAUti";
System.setProperty("BEAST & BEAUTi Version", version.getVersion());
BeautiApp app = new BeautiApp(nameString, aboutString, icon, websiteURLString, helpURLString);
app.setDocumentFrameFactory(new DocumentFrameFactory() {
public DocumentFrame createDocumentFrame(Application app, MenuBarFactory menuBarFactory) {
return new BeautiFrame(nameString);
}
});
app.initialize();
if (inputFileName != null) {
app.doOpen(inputFileName);
} else {
app.doNew();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(new JFrame(), "Fatal exception: " + e, "Please report this to the authors", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
// }
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class BeastRemote method main.
public static void main(String[] oldArgs) throws java.io.IOException {
// First populate args from MPI.WORLD
// String[] args = null;
MPI.Init(oldArgs);
System.err.println(oldArgs[0]);
System.err.println(oldArgs[1]);
System.err.println(oldArgs[2]);
int rank = MPI.COMM_WORLD.Rank();
int argLength = oldArgs.length - 3;
String[] args = new String[argLength];
for (int i = 0; i < argLength; i++) {
args[i] = oldArgs[i + 3];
System.err.println(i + " : " + args[i]);
if (args[i].contains(".xml")) {
// append rank
args[i] = args[i].replace(".xml", Integer.toString(rank) + ".xml");
System.err.println("Attempting to load: " + args[i]);
}
}
/* for (String str : args)
System.err.println(str);*/
//System.exit(1);
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.Option("verbose", "verbose XML parsing messages"), new Arguments.Option("warnings", "Show warning messages about BEAST XML file"), new Arguments.Option("window", "provide a console window"), new Arguments.Option("working", "change working directory to input file's directory"), new Arguments.LongOption("seed", "specify a random number generator seed"), new Arguments.Option("help", "option to print this message") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
System.out.println();
System.out.println(ae.getMessage());
System.out.println();
printTitle();
printUsage(arguments);
MPI.Finalize();
System.exit(1);
}
if (arguments.hasOption("help")) {
printTitle();
printUsage(arguments);
MPI.Finalize();
System.exit(0);
}
boolean verbose = arguments.hasOption("verbose");
// if dev, then auto turn on, otherwise default to turn off
boolean parserWarning = arguments.hasOption("pwarning");
// boolean window = arguments.hasOption("window");
boolean working = arguments.hasOption("working");
long seed = MathUtils.getSeed();
if (arguments.hasOption("seed")) {
seed = arguments.getLongOption("seed");
MathUtils.setSeed(seed);
}
// if (System.getProperty("dr.app.beast.main.window", "false").toLowerCase().equals("true")) {
// window = true;
// }
BeastConsoleApp consoleApp = null;
/* if (window) {
System.setProperty("com.apple.macos.useScreenMenuBar", "true");
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("apple.awt.showGrowBox", "true");
javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
String nameString = "BEAST " + version.getVersionString();
String aboutString = "<html><center><p>Bayesian Evolutionary Analysis Sampling Trees<br>" +
"Version " + version.getVersionString() + ", 2002-2006</p>" +
"<p>by<br>" +
"Alexei J. Drummond and Andrew Rambaut</p>" +
"<p>Department of Computer Science, University of Auckland<br>" +
"<a href=\"mailto:alexei@cs.auckland.ac.nz\">alexei@cs.auckland.ac.nz</a></p>" +
"<p>Institute of Evolutionary Biology, University of Edinburgh<br>" +
"<a href=\"mailto:a.rambaut@ed.ac.uk\">a.rambaut@ed.ac.uk</a></p>" +
"<p><a href=\"http://evolve.zoo.ox.ac.uk/beast/\">http://evolve.zoo.ox.ac.uk/beast/</a></p>" +
"<p>Source code distributed under the GNU LGPL:<br>" +
"<a href=\"http://github.com/beast-dev/beast-mcmc/\">http://github.com/beast-dev/beast-mcmc/</a></p>" +
"<p>Additional programming by:<br>" +
"Roald Forsberg, Gerton Lunter, Sidney Markowitz, Oliver Pybus</p>" +
"<p>Thanks to Korbinian Strimmer for use of his code</p>" +
"</center></html>";
consoleApp = new BeastConsoleApp(nameString, aboutString, icon);
}*/
// Remote can never be interactive
String inputFileName;
String[] args2 = arguments.getLeftoverArguments();
if (args2.length > 1) {
System.err.println("Unknown option: " + args2[1]);
System.err.println();
printTitle();
printUsage(arguments);
MPI.Finalize();
System.exit(1);
}
File inputFile = null;
if (args2.length > 0) {
inputFileName = args2[0];
inputFile = new File(inputFileName);
}
if (inputFile != null && working) {
System.setProperty("user.dir", inputFile.getParent());
}
printTitle();
System.out.println();
System.out.println("Random number seed: " + seed);
System.out.println();
new BeastRemote(inputFile, consoleApp, verbose, parserWarning);
//System.err.println("Did I get here");
if (rank == 0)
terminateSlaves();
MPI.Finalize();
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class AntigenicPlotter method main.
//Main method
public static void main(String[] args) throws IOException {
String inputFileName = null;
String outputFileName = null;
String treeFileName = null;
printTitle();
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in' [default = 0]"), new Arguments.Option("discrete", "generated under the discrete antigenic model [default = continuous]"), new Arguments.Option("tab", "generate tab delimited file [default = KML]"), new Arguments.Option("help", "option to print this message") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
System.out.println(ae);
printUsage(arguments);
System.exit(1);
}
if (arguments.hasOption("help")) {
printUsage(arguments);
System.exit(0);
}
int burnin = -1;
if (arguments.hasOption("burnin")) {
burnin = arguments.getIntegerOption("burnin");
}
boolean tabFormat = arguments.hasOption("tab");
boolean discreteModel = arguments.hasOption("discrete");
String[] args2 = arguments.getLeftoverArguments();
if (args2.length > 3) {
System.err.println("Unknown option: " + args2[3]);
System.err.println();
printUsage(arguments);
System.exit(1);
}
if (args2.length == 2) {
inputFileName = args2[0];
outputFileName = args2[1];
} else if (args2.length == 3) {
inputFileName = args2[0];
treeFileName = args2[1];
outputFileName = args2[2];
} else {
System.err.println("Missing input or output file name");
printUsage(arguments);
System.exit(1);
}
new AntigenicPlotter(burnin, tabFormat, discreteModel, inputFileName, treeFileName, outputFileName);
System.exit(0);
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class BeastParserDoc method main.
//Main method
public static void main(String[] args) throws java.io.IOException, XMLParseException {
printTitle();
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.Option("help", "option to print this message") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
System.out.println(ae);
printUsage(arguments);
return;
}
if (arguments.hasOption("help")) {
printUsage(arguments);
return;
}
String outputDirectory = null;
String[] args2 = arguments.getLeftoverArguments();
if (args2.length > 1) {
System.err.println("Unknown option: " + args2[1]);
System.err.println();
printUsage(arguments);
return;
}
if (args2.length > 0) {
outputDirectory = args2[0];
}
if (outputDirectory == null) {
// No input file name was given so throw up a dialog box...
outputDirectory = System.getProperty("user.dir") + System.getProperty("file.separator") + "release" + System.getProperty("file.separator") + "common" + System.getProperty("file.separator") + "doc" + System.getProperty("file.separator");
}
System.out.println("Output directory : " + outputDirectory);
// BeastParserDoc(BeastParser parser, String directory, boolean wikiFormat)
new BeastParserDoc(new BeastParser(new String[] {}, null, false, false, false), outputDirectory, true);
System.exit(0);
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class Branch2dRateToGrid method main.
public static void main(String[] args) throws IOException {
String inputFileName = null;
String outputFileName = null;
String traitName = "location";
boolean trait2DNoise = true;
boolean rate2DNoise = false;
Normalization normalize = Normalization.LENGTH;
int burnin = -1;
int skipEvery = 1;
double latMax = 90;
double latMin = -90;
double longMax = 180;
double longMin = -180;
int gridXcells = 360;
int gridYcells = 180;
String rateString = "rate";
double maxPathLength = Double.MAX_VALUE;
double posteriorCutoff = 0;
//slicing
double[] sliceHeights = null;
double mrsd = 0;
boolean getStdevs = true;
String discreteTraitName = null;
String[] discreteTraitStates = null;
String historyAnnotation = "history";
printTitle();
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption(BURNIN, "the number of states to be considered as 'burn-in' [default = 0]"), new Arguments.IntegerOption(SKIP, "skip every i'th tree [default = 0]"), new Arguments.StringOption(TRAIT, "trait_name", "specifies an attribute to use to summarize the 2D trait info [default = location]"), new Arguments.StringOption(RATE_ATTRIBUTE, "rate_attribute", "specifies the trait rate attribute string [default=rate]"), new Arguments.Option(HELP, "option to print this message"), new Arguments.StringOption(TRAIT_NOISE, falseTrue, false, "add true noise to 2D traits [default = true])"), new Arguments.StringOption(RATE_NOISE, falseTrue, false, "add true noise to rates [default = true])"), new Arguments.StringOption(NORMALIZATION, enumNamesToStringArray(Normalization.values()), false, "tree normalization [default = length"), new Arguments.RealOption(LATMAX, "specifies the maximum latitude for the grid [default=90]"), new Arguments.RealOption(LATMIN, "specifies the minimum latitude for the grid [default=-90]"), new Arguments.RealOption(LONGMAX, "specifies the maximum longitude for the grid [default=180]"), new Arguments.RealOption(LONGMIN, "specifies the minimum longitude for the grid [default=-180]"), new Arguments.IntegerOption(GRIDXCELLS, "the number of cells along the x-axis (longitude) of the grid [default = 360]"), new Arguments.IntegerOption(GRIDYCELLS, "the number of cells along the y-axis (latitude) of the grid [default = 180]"), new Arguments.RealOption(MAXPATHLENGTH, "specifies the maximum (time) length a branch can go in one direction before adding Brownian noise to it [default=MAX_VALUE (no noise)]"), new Arguments.StringOption(SLICE_TIMES, "slice_times", "specifies a slice time-list [default=none]"), new Arguments.StringOption(SLICE_HEIGHTS, "slice_heights", "specifies a slice height-list [default=none]"), new Arguments.StringOption(SLICE_FILE_HEIGHTS, "heights_file", "specifies a file with a slice heights-list, is overwritten by command-line specification of slice heights [default=none]"), new Arguments.StringOption(SLICE_FILE_TIMES, "Times_file", "specifies a file with a slice Times-list, is overwritten by command-line specification of slice times [default=none]"), new Arguments.StringOption(STDEVS, falseTrue, true, "get standard deviations for the rates [default = true])"), new Arguments.RealOption(CUTOFF, "specifies the posterior cut-off for summarize grid values [default=-0]"), new Arguments.StringOption(DISCRETE_TRAIT_NAME, "discrete_traitName", "specifies the name for a discrete trait that is annotated to the tree nodes and by which states the grid needs to be summarized [default=none]"), new Arguments.StringOption(DISCRETE_TRAIT_STATES, "discrete_traitStates", "specifies the state of a discrete trait by which the grid needs to be summarized [default=none]"), new Arguments.StringOption(HISTORY_ANNOTATION, "history_annotation", "specifies the name for the history annotation for the discrete trait [default=history]") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
progressStream.println(ae);
printUsage(arguments);
System.exit(1);
}
if (arguments.hasOption(HELP)) {
printUsage(arguments);
System.exit(0);
}
try {
if (arguments.hasOption(LATMAX)) {
latMax = arguments.getRealOption(LATMAX);
}
if (arguments.hasOption(LATMIN)) {
latMin = arguments.getRealOption(LATMIN);
}
if (arguments.hasOption(LONGMAX)) {
longMax = arguments.getRealOption(LONGMAX);
}
if (arguments.hasOption(LONGMIN)) {
longMin = arguments.getRealOption(LONGMIN);
}
if (arguments.hasOption(MAXPATHLENGTH)) {
maxPathLength = arguments.getRealOption(MAXPATHLENGTH);
}
if (arguments.hasOption(GRIDXCELLS)) {
gridXcells = arguments.getIntegerOption(GRIDXCELLS);
}
if (arguments.hasOption(GRIDYCELLS)) {
gridYcells = arguments.getIntegerOption(GRIDYCELLS);
}
String traitRateString = arguments.getStringOption(RATE_ATTRIBUTE);
if (traitRateString != null) {
rateString = traitRateString;
}
if (arguments.hasOption(BURNIN)) {
burnin = arguments.getIntegerOption(BURNIN);
System.err.println("Ignoring a burnin of " + burnin + " trees.");
}
if (arguments.hasOption(SKIP)) {
skipEvery = arguments.getIntegerOption(SKIP);
System.err.println("Skipping every " + skipEvery + " trees.");
}
if (skipEvery < 1) {
System.err.println("Skipping every " + skipEvery + " is not possible, no trees will be skipped");
skipEvery = 1;
}
String traitString = arguments.getStringOption(TRAIT);
if (traitString != null) {
traitName = traitString;
}
String trait2DnoiseString = arguments.getStringOption(TRAIT_NOISE);
if (trait2DnoiseString != null && trait2DnoiseString.compareToIgnoreCase("false") == 0)
trait2DNoise = false;
String rate2DNoiseString = arguments.getStringOption(TRAIT_NOISE);
if (rate2DNoiseString != null && rate2DNoiseString.compareToIgnoreCase("true") == 0)
rate2DNoise = true;
String normalizeString = arguments.getStringOption(NORMALIZATION);
if (normalizeString != null) {
try {
normalize = Normalization.valueOf(normalizeString.toUpperCase());
} catch (IllegalArgumentException iae) {
System.err.println("Unrecognized normalization mode: " + normalizeString);
}
}
String sliceTimeString = arguments.getStringOption(SLICE_TIMES);
if (sliceTimeString != null) {
double[] sliceTimes = parseVariableLengthDoubleArray(sliceTimeString);
sliceHeights = new double[sliceTimes.length];
for (int i = 0; i < sliceTimes.length; i++) {
if (mrsd == 0) {
sliceHeights[i] = sliceTimes[i];
} else {
sliceHeights[i] = mrsd - sliceTimes[i];
}
}
}
String stdevString = arguments.getStringOption(STDEVS);
if (stdevString != null && stdevString.compareToIgnoreCase("false") == 0)
getStdevs = false;
if (arguments.hasOption(CUTOFF)) {
posteriorCutoff = arguments.getRealOption(CUTOFF);
}
String discreteTraitNameString = arguments.getStringOption(DISCRETE_TRAIT_NAME);
if (discreteTraitNameString != null) {
discreteTraitName = discreteTraitNameString;
if (!arguments.hasOption(DISCRETE_TRAIT_STATES)) {
System.err.print("a discrete trait name is specified (" + discreteTraitName + "), but no associated states of that trait are specified");
System.exit(-1);
}
}
String discreteTraitStatesString = arguments.getStringOption(DISCRETE_TRAIT_STATES);
if (discreteTraitStatesString != null) {
discreteTraitStates = parseVariableLengthStringArray(discreteTraitStatesString);
if (discreteTraitName == null) {
System.err.print("states for a discrete trait are specified, but no associated trait name for trait annotation is specified");
System.exit(-1);
}
}
String historyString = arguments.getStringOption(HISTORY_ANNOTATION);
if (historyString != null) {
historyAnnotation = historyString;
}
//slicing
String sliceHeightString = arguments.getStringOption(SLICE_HEIGHTS);
if (sliceHeightString != null) {
if (sliceTimeString != null) {
progressStream.println("Either sliceTimes, sliceHeights, timesFile or sliceCount" + "nt.");
System.exit(-1);
}
sliceHeights = parseVariableLengthDoubleArray(sliceHeightString);
}
if (arguments.hasOption(SLICE_COUNT)) {
int sliceCount = arguments.getIntegerOption(SLICE_COUNT);
double startTime;
if (arguments.hasOption(START_TIME)) {
startTime = arguments.getRealOption(START_TIME);
} else {
progressStream.println("slice count specified, but no associated start time?");
System.exit(-1);
startTime = 0;
}
double delta;
if (mrsd != 0) {
if (sliceCount == 1) {
delta = (mrsd - startTime);
} else {
delta = (mrsd - startTime) / (sliceCount - 1);
}
} else {
if (sliceCount == 1) {
delta = startTime;
} else {
delta = startTime / (sliceCount - 1);
}
}
sliceHeights = new double[sliceCount];
// double height = mrsd - startTime;
// for (int i = 0; i < sliceCount; i++) {
// sliceHeights[i] = height;
// height -= delta;
// }
double height = 0;
for (int i = 0; i < sliceCount; i++) {
sliceHeights[i] = height;
height += delta;
}
}
if ((sliceTimeString == null) && (sliceHeightString == null) && (!arguments.hasOption(SLICE_COUNT))) {
sliceHeights = new double[] { 0 };
}
} catch (Arguments.ArgumentException e) {
progressStream.println(e);
printUsage(arguments);
System.exit(-1);
}
final String[] args2 = arguments.getLeftoverArguments();
switch(args2.length) {
case 0:
printUsage(arguments);
System.exit(1);
case 2:
outputFileName = args2[1];
// fall to
case 1:
inputFileName = args2[0];
break;
default:
{
System.err.println("Unknown option: " + args2[2]);
System.err.println();
printUsage(arguments);
System.exit(1);
}
}
Branch2dRateToGrid grid = new Branch2dRateToGrid(inputFileName, burnin, skipEvery, traitName, trait2DNoise, rate2DNoise, rateString, maxPathLength, normalize, latMin, latMax, longMin, longMax, gridXcells, gridYcells, sliceHeights, getStdevs, posteriorCutoff, discreteTraitName, discreteTraitStates, historyAnnotation);
grid.output(outputFileName);
System.exit(0);
}
Aggregations