use of beast.util.XMLParserException in project beast2 by CompEvol.
the class BeautiDoc method extractSequences.
void extractSequences(String xml) throws XMLParserException, SAXException, IOException, ParserConfigurationException {
// parse the XML fragment into a DOM document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
doc.normalize();
// find top level beast element
NodeList nodes = doc.getElementsByTagName("*");
Node topNode = nodes.item(0);
String beautiTemplate = XMLParser.getAttribute(topNode, "beautitemplate");
if (beautiTemplate == null) {
int choice = JOptionPane.showConfirmDialog(getFrame(), "This file does not appear to be generated by BEAUti. If you load it, unexpected behaviour may follow");
if (choice != JOptionPane.OK_OPTION) {
return;
}
// load standard template
if (beautiConfig == null) {
String templateXML = processTemplate(STANDARD_TEMPLATE);
loadTemplate(templateXML);
}
} else {
String templateXML = processTemplate(beautiTemplate + ".xml");
loadTemplate(templateXML);
}
String beautiStatus = XMLParser.getAttribute(topNode, "beautistatus");
if (beautiStatus == null) {
beautiStatus = "";
}
autoSetClockRate = !beautiStatus.contains("noAutoSetClockRate");
beauti.autoSetClockRate.setSelected(autoSetClockRate);
allowLinking = beautiStatus.contains("allowLinking");
beauti.allowLinking.setSelected(allowLinking);
autoUpdateFixMeanSubstRate = !beautiStatus.contains("noAutoUpdateFixMeanSubstRate");
beauti.autoUpdateFixMeanSubstRate.setSelected(autoUpdateFixMeanSubstRate);
// parse file
XMLParser parser = new XMLParser();
BEASTInterface MCMC = parser.parseFragment(xml, true);
mcmc.setValue(MCMC, this);
BEASTObjectPanel.addPluginToMap(MCMC, this);
// reconstruct all objects from templates
try {
CompoundDistribution posterior = (CompoundDistribution) ((beast.core.MCMC) mcmc.get()).posteriorInput.get();
for (Distribution distr : posterior.pDistributions.get()) {
if (distr.getID().equals("likelihood")) {
for (Distribution likelihood : ((CompoundDistribution) distr).pDistributions.get()) {
if (likelihood instanceof GenericTreeLikelihood) {
GenericTreeLikelihood treeLikelihood = (GenericTreeLikelihood) likelihood;
PartitionContext context = new PartitionContext(treeLikelihood);
try {
beautiConfig.partitionTemplate.get().createSubNet(context, false);
} catch (Exception e) {
// e.printStackTrace();
}
for (BeautiSubTemplate subTemplate : beautiConfig.subTemplates) {
try {
subTemplate.createSubNet(context, false);
} catch (Exception e) {
// e.printStackTrace();
}
}
}
}
}
}
} catch (Exception e) {
// e.printStackTrace();
}
// MCMC = parser.parseFragment(xml, true);
// mcmc.setValue(MCMC, this);
// PluginPanel.addPluginToMap(MCMC, this);
// if (xml.indexOf(XMLProducer.DO_NOT_EDIT_WARNING) > 0) {
// int start = xml.indexOf(XMLProducer.DO_NOT_EDIT_WARNING);
// int end = xml.lastIndexOf("-->");
// xml = xml.substring(start, end);
// xml = xml.replaceAll(XMLProducer.DO_NOT_EDIT_WARNING, "");
// xml = "<beast namespace='" + XMLProducer.DEFAULT_NAMESPACE + "'>" + xml + "</beast>";
// List<BEASTObject> beastObjects = parser.parseBareFragments(xml, true);
// for (BEASTObject beastObject : beastObjects) {
// PluginPanel.addPluginToMap(beastObject, this);
// }
// }
// extract alignments
determinePartitions();
}
use of beast.util.XMLParserException in project beast2 by CompEvol.
the class BeautiDoc method parseArgs.
public ActionOnExit parseArgs(String[] args) throws XMLParserException, SAXException, IOException, ParserConfigurationException {
ActionOnExit endState = ActionOnExit.UNKNOWN;
String outputFileName = "beast.xml";
String xml = null;
String templateXML = null;
TraitSet traitset = null;
int i = 0;
try {
while (i < args.length) {
int old = i;
if (args[i].equals("")) {
i += 1;
} else if (args[i].equals("-capture")) {
// capture stderr and stdout
// already done in beast.app.beauti.Beauti
i += 1;
} else if (args[i].equals("-xml")) {
String fileName = args[i + 1];
xml = load(fileName);
// XMLParser parser = new XMLParser();
// m_doc.m_mcmc.setValue(parser.parseFile(fileName),
// m_doc);
this.fileName = nameFromFile(fileName);
i += 2;
} else if (args[i].equals("-template")) {
String fileName = args[i + 1];
templateXML = processTemplate(fileName);
templateFileName = fileName;
templateName = nameFromFile(fileName);
i += 2;
} else if (args[i].equals("-nex")) {
// NB: multiple -nex/-xmldata commands can be processed!
String fileName = args[i + 1];
NexusParser parser = new NexusParser();
parser.parseFile(new File(fileName));
if (parser.filteredAlignments.size() > 0) {
for (Alignment data : parser.filteredAlignments) {
alignments.add(data);
}
} else {
alignments.add(parser.m_alignment);
}
i += 2;
traitset = parser.traitSet;
} else if (args[i].equals("-xmldata")) {
// NB: multiple -xmldata/-nex commands can be processed!
String fileName = args[i + 1];
Alignment alignment = (Alignment) BeautiAlignmentProvider.getXMLData(new File(fileName));
alignments.add(alignment);
i += 2;
} else if (args[i].equals("-exitaction")) {
if (args[i + 1].equals("writexml")) {
endState = ActionOnExit.WRITE_XML;
} else if (args[i + 1].equals("usetemplate")) {
endState = ActionOnExit.SHOW_DETAILS_USE_TEMPLATE;
} else if (args[i + 1].equals("usexml")) {
endState = ActionOnExit.SHOW_DETAILS_USE_XML_SPEC;
} else if (args[i + 1].equals("merge")) {
endState = ActionOnExit.MERGE_AND_WRITE_XML;
} else {
throw new IllegalArgumentException("Expected one of 'writexml','usetemplate' or 'usexml', not " + args[i + 1]);
}
i += 2;
} else if (args[i].equals("-out")) {
outputFileName = args[i + 1];
i += 2;
} else if (args[i].equals("-noerr")) {
System.setErr(new PrintStream(new OutputStream() {
@Override
public void write(int b) {
}
}));
i += 1;
}
if (i == old) {
throw new IllegalArgumentException("Wrong argument: " + args[i]);
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
e.printStackTrace();
System.exit(1);
}
initialize(endState, xml, templateXML, outputFileName);
addTraitSet(traitset);
return endState;
}
use of beast.util.XMLParserException in project beast2 by CompEvol.
the class BeastMain method main.
// Main method
public static void main(final String[] args) throws java.io.IOException {
final List<String> MCMCargs = new ArrayList<>();
// Utils.loadUIManager();
final Arguments arguments = new Arguments(new Arguments.Option[] { // new Arguments.Option("strict", "Fail on non-conforming BEAST XML file"),
new Arguments.Option("window", "Provide a console window"), new Arguments.Option("options", "Display an options dialog"), new Arguments.Option("working", "Change working directory to input file's directory"), new Arguments.LongOption("seed", "Specify a random number generator seed"), new Arguments.StringOption("prefix", "PREFIX", "Specify a prefix for all output log filenames"), new Arguments.StringOption("statefile", "STATEFILE", "Specify the filename for storing/restoring the state"), new Arguments.Option("overwrite", "Allow overwriting of log files"), new Arguments.Option("resume", "Allow appending of log files"), new Arguments.Option("validate", "Parse the XML, but do not run -- useful for debugging XML"), // RRB: not sure what effect this option has
new Arguments.IntegerOption("errors", "Specify maximum number of numerical errors before stopping"), new Arguments.IntegerOption("threads", "The number of computational threads to use (default 1), -1 for number of cores"), new Arguments.Option("java", "Use Java only, no native implementations"), new Arguments.Option("noerr", "Suppress all output to standard error"), new Arguments.StringOption("loglevel", "LEVEL", "error,warning,info,debug,trace"), new Arguments.IntegerOption("instances", "divide site patterns amongst number of threads (use with -threads option)"), new Arguments.Option("beagle", "Use beagle library if available"), new Arguments.Option("beagle_info", "BEAGLE: show information on available resources"), new Arguments.StringOption("beagle_order", "order", "BEAGLE: set order of resource use"), new Arguments.Option("beagle_CPU", "BEAGLE: use CPU instance"), new Arguments.Option("beagle_GPU", "BEAGLE: use GPU instance if available"), new Arguments.Option("beagle_SSE", "BEAGLE: use SSE extensions if available"), new Arguments.Option("beagle_single", "BEAGLE: use single precision if available"), new Arguments.Option("beagle_double", "BEAGLE: use double precision if available"), new Arguments.StringOption("beagle_scaling", new String[] { "default", "none", "dynamic", "always" }, false, "BEAGLE: specify scaling scheme to use"), new Arguments.Option("help", "Print this information and stop"), new Arguments.Option("version", "Print version and stop"), new Arguments.Option("strictversions", "Use only package versions as specified in the 'required' attribute"), new Arguments.StringOption("D", "DEFINITIONS", "attribute-value pairs to be replaced in the XML, e.g., -D \"arg1=10,arg2=20\"") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
Log.info.println();
Log.info.println(ae.getMessage());
Log.info.println();
printUsage(arguments);
System.exit(1);
}
if (arguments.hasOption("version")) {
Log.info.println((new BEASTVersion2()).getVersionString());
System.exit(0);
}
if (arguments.hasOption("help")) {
printUsage(arguments);
System.exit(0);
}
// final boolean verbose = arguments.hasOption("verbose");
// final boolean parserWarning = arguments.hasOption("warnings"); // if dev, then auto turn on, otherwise default to turn off
// final boolean strictXML = arguments.hasOption("strict");
final boolean window = arguments.hasOption("window");
final boolean options = arguments.hasOption("options");
final boolean working = arguments.hasOption("working");
final boolean doNotRun = arguments.hasOption("validate");
String fileNamePrefix = null;
String stateFileName = null;
// boolean allowOverwrite = arguments.hasOption("overwrite");
long seed = Randomizer.getSeed();
boolean useJava = false;
int threadCount = 1;
if (arguments.hasOption("java")) {
useJava = true;
}
if (arguments.hasOption("prefix")) {
fileNamePrefix = arguments.getStringOption("prefix");
}
if (arguments.hasOption("statefile")) {
stateFileName = arguments.getStringOption("statefile");
}
long beagleFlags = 0;
boolean useBeagle = arguments.hasOption("beagle") || arguments.hasOption("beagle_CPU") || arguments.hasOption("beagle_GPU") || arguments.hasOption("beagle_SSE") || arguments.hasOption("beagle_double") || arguments.hasOption("beagle_single") || arguments.hasOption("beagle_order");
if (arguments.hasOption("beagle_scaling")) {
System.setProperty("beagle.scaling", arguments.getStringOption("beagle_scaling"));
}
boolean beagleShowInfo = arguments.hasOption("beagle_info");
boolean useSSE = true;
if (arguments.hasOption("beagle_CPU")) {
beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
useSSE = false;
}
if (arguments.hasOption("beagle_GPU")) {
beagleFlags |= BeagleFlag.PROCESSOR_GPU.getMask();
useSSE = false;
}
if (arguments.hasOption("beagle_SSE")) {
beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
useSSE = true;
}
if (useSSE) {
beagleFlags |= BeagleFlag.VECTOR_SSE.getMask();
}
if (arguments.hasOption("beagle_double")) {
beagleFlags |= BeagleFlag.PRECISION_DOUBLE.getMask();
}
if (arguments.hasOption("beagle_single")) {
beagleFlags |= BeagleFlag.PRECISION_SINGLE.getMask();
}
if (arguments.hasOption("noerr")) {
System.setErr(new PrintStream(new OutputStream() {
@Override
public void write(int b) {
}
}));
}
if (arguments.hasOption("beagle_order")) {
System.setProperty("beagle.resource.order", arguments.getStringOption("beagle_order"));
}
if (arguments.hasOption("instances")) {
System.setProperty("beast.instance.count", Integer.toString(arguments.getIntegerOption("instances")));
}
if (arguments.hasOption("beagle_scaling")) {
System.setProperty("beagle.scaling", arguments.getStringOption("beagle_scaling"));
}
if (arguments.hasOption("threads")) {
threadCount = arguments.getIntegerOption("threads");
}
if (threadCount <= 0) {
threadCount = Runtime.getRuntime().availableProcessors();
Log.warning.println("Setting number of threads to " + threadCount);
}
if (arguments.hasOption("seed")) {
seed = arguments.getLongOption("seed");
if (seed <= 0) {
printTitle();
Log.err.println("The random number seed should be > 0");
System.exit(1);
}
}
int maxErrorCount = 0;
if (arguments.hasOption("errors")) {
maxErrorCount = arguments.getIntegerOption("errors");
if (maxErrorCount < 0) {
maxErrorCount = 0;
}
}
BeastConsoleApp consoleApp = null;
final String nameString = "BEAST " + version.getVersionString();
if (window) {
Utils.loadUIManager();
System.setProperty("com.apple.macos.useScreenMenuBar", "true");
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("apple.awt.showGrowBox", "true");
System.setProperty("beast.useWindow", "true");
final javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
final String aboutString = "<html><div style=\"font-family:sans-serif;\"><center>" + "<div style=\"font-size:12;\"><p>Bayesian Evolutionary Analysis Sampling Trees<br>" + "Version " + version.getVersionString() + ", " + version.getDateString() + "</p>" + version.getHTMLCredits() + "</div></center></div></html>";
consoleApp = new BeastConsoleApp(nameString, aboutString, icon);
// ensure error and info information is shown in console
// but not warning, debug or trace, since that typically just
// results in a lot of clutter
Log.err = System.err;
Log.info = System.out;
}
printTitle();
File inputFile = null;
if (options) {
Utils.loadUIManager();
final String titleString = "<html><center><p>Bayesian Evolutionary Analysis Sampling Trees<br>" + "Version " + version.getVersionString() + ", " + version.getDateString() + "</p></center></html>";
final javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
final BeastDialog dialog = new BeastDialog(new JFrame(), titleString, icon);
if (!dialog.showDialog(nameString, seed)) {
System.exit(0);
}
// }
switch(dialog.getLogginMode()) {
case 0:
/* do not ovewrite */
break;
case 1:
MCMCargs.add("-overwrite");
break;
case 2:
MCMCargs.add("-resume");
break;
}
seed = dialog.getSeed();
threadCount = dialog.getThreadPoolSize();
useBeagle = dialog.useBeagle();
if (useBeagle) {
beagleShowInfo = dialog.showBeagleInfo();
if (dialog.preferBeagleCPU()) {
beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
}
if (dialog.preferBeagleSSE()) {
beagleFlags |= BeagleFlag.VECTOR_SSE.getMask();
}
if (dialog.preferBeagleGPU()) {
beagleFlags |= BeagleFlag.PROCESSOR_GPU.getMask();
}
if (dialog.preferBeagleDouble()) {
beagleFlags |= BeagleFlag.PRECISION_DOUBLE.getMask();
}
if (dialog.preferBeagleSingle()) {
beagleFlags |= BeagleFlag.PRECISION_SINGLE.getMask();
}
}
inputFile = dialog.getInputFile();
if (!beagleShowInfo && inputFile == null) {
Log.err.println("No input file specified");
System.exit(1);
}
if (dialog.useStrictVersions()) {
MCMCargs.add("-strictversions");
}
} else {
if (arguments.hasOption("overwrite")) {
MCMCargs.add("-overwrite");
}
if (arguments.hasOption("resume")) {
MCMCargs.add("-resume");
}
}
if (arguments.hasOption("strictversions")) {
MCMCargs.add("-strictversions");
}
if (arguments.hasOption("D")) {
MCMCargs.add("-D");
MCMCargs.add(arguments.getStringOption("D"));
}
if (beagleShowInfo) {
Log.info.println("\n--- BEAGLE RESOURCES ---\n");
for (beagle.ResourceDetails details : BeagleFactory.getResourceDetails()) Log.info.println(details.toString());
if (window)
return;
else
System.exit(0);
}
if (inputFile == null) {
final String[] args2 = arguments.getLeftoverArguments();
if (args2.length > 1) {
Log.err.println("Unknown option: " + args2[1]);
Log.err.println();
printUsage(arguments);
System.exit(1);
}
String inputFileName = null;
if (args2.length > 0) {
inputFileName = args2[0];
inputFile = new File(inputFileName);
}
if (inputFileName == null) {
// No input file name was given so throw up a dialog box...
String fileName = getFileNameByDialog("BEAST " + version.getVersionString() + " - Select XML input file");
if (fileName == null) {
System.exit(0);
}
inputFile = new File(fileName);
}
}
if (inputFile != null && inputFile.getParent() != null && working) {
System.setProperty("file.name.prefix", inputFile.getParentFile().getAbsolutePath() + File.separator);
}
if (window) {
if (inputFile == null) {
consoleApp.setTitle("null");
} else {
consoleApp.setTitle(inputFile.getName());
}
}
if (useJava) {
System.setProperty("java.only", "true");
}
if (arguments.hasOption("loglevel")) {
String l = arguments.getStringOption("loglevel");
switch(l) {
case "error":
Log.setLevel(Log.Level.error);
break;
case "warning":
Log.setLevel(Log.Level.warning);
break;
case "info":
Log.setLevel(Log.Level.info);
break;
case "debug":
Log.setLevel(Log.Level.debug);
break;
case "trace":
Log.setLevel(Log.Level.trace);
break;
}
}
if (fileNamePrefix != null && fileNamePrefix.trim().length() > 0) {
System.setProperty("file.name.prefix", fileNamePrefix.trim());
}
if (stateFileName != null && stateFileName.trim().length() > 0) {
System.setProperty("state.file.name", stateFileName.trim());
Log.info.println("Writing state to file " + stateFileName);
}
if (beagleFlags != 0) {
System.setProperty("beagle.preferred.flags", Long.toString(beagleFlags));
}
if (threadCount > 0) {
System.setProperty("thread.count", String.valueOf(threadCount));
MCMCargs.add("-threads");
MCMCargs.add(threadCount + "");
}
MCMCargs.add("-seed");
MCMCargs.add(seed + "");
Randomizer.setSeed(seed);
Log.info.println("Random number seed: " + seed);
Log.info.println();
// Construct the beast object
final BeastMCMC beastMCMC = new BeastMCMC();
try {
// set all the settings...
MCMCargs.add(inputFile.getAbsolutePath());
beastMCMC.parseArgs(MCMCargs.toArray(new String[0]));
if (!doNotRun) {
new BeastMain(beastMCMC, consoleApp, maxErrorCount);
} else {
Log.info.println("Done!");
}
} catch (RuntimeException rte) {
if (window) {
// appears at the end of the console.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.info.println();
Log.info.println("BEAST has terminated with an error. Please select QUIT from the menu.");
} else {
rte.printStackTrace();
}
// logger.severe will throw a RTE but we want to keep the console visible
} catch (XMLParserException e) {
Log.info.println(e.getMessage());
if (!window) {
System.exit(1);
}
} catch (Exception e) {
e.printStackTrace();
if (!window) {
System.exit(1);
}
}
if (!window) {
System.exit(0);
}
}
use of beast.util.XMLParserException in project beast2 by CompEvol.
the class BeastMCMC method parseArgs.
/**
* parse command line arguments, and load file if specified
* @throws IOException
* @throws JSONException
* @throws JSONParserException
*/
public void parseArgs(String[] args) throws IOException, XMLParserException, JSONException {
int i = 0;
boolean resume = false;
boolean useStrictVersions = false;
Map<String, String> parserDefinitions = new HashMap<>();
File beastFile = null;
try {
while (i < args.length) {
int old = i;
if (i < args.length) {
if (args[i].equals("")) {
i += 1;
} else if (args[i].equals("-batch")) {
Logger.FILE_MODE = Logger.LogFileMode.only_new_or_exit;
i += 1;
} else if (args[i].equals("-resume")) {
resume = true;
Logger.FILE_MODE = Logger.LogFileMode.resume;
System.setProperty("beast.resume", "true");
System.setProperty("beast.debug", "false");
i += 1;
} else if (args[i].equals("-overwrite")) {
Logger.FILE_MODE = Logger.LogFileMode.overwrite;
i += 1;
} else if (args[i].equals("-seed")) {
if (args[i + 1].equals("random")) {
m_nSeed = Randomizer.getSeed();
} else {
m_nSeed = Long.parseLong(args[i + 1]);
}
i += 2;
} else if (args[i].equals("-threads")) {
m_nThreads = Integer.parseInt(args[i + 1]);
g_exec = Executors.newFixedThreadPool(m_nThreads);
i += 2;
// use BEAST environment variable to set Beast directories as colon separated list
// } else if (args[i].equals("-beastlib")) {
// ClassDiscovery.setJarPath(args[i + 1]);
// i += 2;
} else if (args[i].equals("-prefix")) {
System.setProperty("file.name.prefix", args[i + 1].trim());
i += 2;
} else if (args[i].equals("-D")) {
String[] strs = args[i + 1].split(",");
for (String str : strs) {
String[] strs2 = str.split("=");
if (strs2.length != 2) {
throw new IllegalArgumentException("Argument \"" + str + "\" is not well-formed: expecting name=value pairs");
}
String name = strs2[0];
String value = strs2[1];
parserDefinitions.put(name, value);
}
i += 2;
} else if (args[i].equals("-strictversions")) {
useStrictVersions = true;
i += 1;
}
if (i == old) {
if (i == args.length - 1) {
beastFile = new File(args[i]);
i++;
} else {
throw new IllegalArgumentException("Wrong argument");
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException("Error parsing command line arguments: " + Arrays.toString(args) + "\nArguments ignored\n\n" + getUsage());
}
if (beastFile == null) {
// Not resuming so get starting options...
List<String> MCMCargs = new ArrayList<>();
Version version = new BEASTVersion2();
String titleString = "<html><center><p>Bayesian Evolutionary Analysis Sampling Trees<br>" + "Version " + version.getVersionString() + ", " + version.getDateString() + "</p></center></html>";
javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
String nameString = "BEAST " + version.getVersionString();
BeastDialog dialog = new BeastDialog(new JFrame(), titleString, icon);
if (!dialog.showDialog(nameString, m_nSeed)) {
return;
}
switch(dialog.getLogginMode()) {
case 0:
/* do not ovewrite */
break;
case 1:
MCMCargs.add("-overwrite");
break;
case 2:
MCMCargs.add("-resume");
break;
}
MCMCargs.add("-seed");
MCMCargs.add(dialog.getSeed() + "");
if (dialog.getThreadPoolSize() > 0) {
MCMCargs.add("-threads");
MCMCargs.add(dialog.getThreadPoolSize() + "");
}
boolean useBeagle = dialog.useBeagle();
boolean beagleShowInfo = false;
long beagleFlags = 0;
if (useBeagle) {
beagleShowInfo = dialog.showBeagleInfo();
if (dialog.preferBeagleCPU()) {
beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
}
if (dialog.preferBeagleSSE()) {
beagleFlags |= BeagleFlag.VECTOR_SSE.getMask();
}
if (dialog.preferBeagleGPU()) {
beagleFlags |= BeagleFlag.PROCESSOR_GPU.getMask();
}
if (dialog.preferBeagleDouble()) {
beagleFlags |= BeagleFlag.PRECISION_DOUBLE.getMask();
}
if (dialog.preferBeagleSingle()) {
beagleFlags |= BeagleFlag.PRECISION_SINGLE.getMask();
}
}
if (beagleFlags != 0) {
System.setProperty("beagle.preferred.flags", Long.toString(beagleFlags));
}
if (!useBeagle) {
System.setProperty("java.only", "true");
}
File inputFile = dialog.getInputFile();
if (!beagleShowInfo && inputFile == null) {
System.err.println("No input file specified");
System.exit(1);
}
MCMCargs.add(inputFile.getAbsolutePath());
// BeastStartDialog dlg = new BeastStartDialog();
// if (dlg.m_bOK) {
// parseArgs(dlg.getArgs());
// }
parseArgs(MCMCargs.toArray(new String[0]));
return;
}
Log.warning.println("File: " + beastFile.getName() + " seed: " + m_nSeed + " threads: " + m_nThreads);
if (resume) {
Log.info.println("Resuming from file");
}
if (useStrictVersions) {
// grab "required" attribute from beast spec
if (beastFile.getPath().toLowerCase().endsWith(".json")) {
throw new IllegalArgumentException("The -strictversions flag is not implemented for JSON files yet (only XML files are supported).");
} else {
BufferedReader fin = new BufferedReader(new FileReader(beastFile));
StringBuffer buf = new StringBuffer();
String str = null;
int lineCount = 0;
while (fin.ready() && lineCount < 100) {
str = fin.readLine();
buf.append(str);
buf.append(' ');
}
fin.close();
str = buf.toString();
int start = str.indexOf("required=");
if (start < 0) {
throw new IllegalArgumentException("Could not find a 'required' attribute in the XML. Add the required attribute, or run without the -strictversions flag");
}
char c = str.charAt(start + 9);
start += 10;
int end = str.indexOf(c, start);
String packages = str.substring(start, end);
PackageManager.loadExternalJars(packages);
}
} else {
PackageManager.loadExternalJars();
}
// parse xml
Randomizer.setSeed(m_nSeed);
if (beastFile.getPath().toLowerCase().endsWith(".json")) {
m_runnable = new JSONParser(parserDefinitions).parseFile(beastFile);
} else {
try {
m_runnable = new XMLParser(parserDefinitions).parseFile(beastFile);
} catch (SAXException | ParserConfigurationException e) {
throw new IllegalArgumentException(e);
}
}
m_runnable.setStateFile(beastFile.getName() + ".state", resume);
}
Aggregations