use of beast.util.XMLProducer in project beast2 by CompEvol.
the class BeautiDoc method toXML.
public String toXML() {
Set<BEASTInterface> beastObjects = new HashSet<>();
// for (BEASTObject beastObject : pluginmap.values()) {
// String name = beastObject.getClass().getName();
// if (!name.startsWith("beast.app.beauti")) {
// beastObjects.add(beastObject);
// }
// }
String xml = new XMLProducer().toXML(mcmc.get(), beastObjects);
xml = xml.replaceFirst("<beast ", "<beast beautitemplate='" + templateName + "' beautistatus='" + getBeautiStatus() + "' ");
return xml + "\n";
}
use of beast.util.XMLProducer in project beast2 by CompEvol.
the class XMLProducerTest method test_ThatNexusExamplesProduces.
// @Test
// public void test_ThatXmlExamplesProduces() {
// System.setProperty("java.only", "true");
// String dir = System.getProperty("user.dir") + "/examples";
// //String dir = "/tmp";
// List<String> exceptions = new ArrayList<String>();
// exceptions.add("testExponentialGrowth.xml");
// test_ThatXmlExamplesProduces(dir, exceptions);
// }
@Test
public void test_ThatNexusExamplesProduces() {
try {
String dirName = System.getProperty("user.dir") + "/examples/nexus";
System.out.println("Test Nexus Examples in " + dirName);
File exampleDir = new File(dirName);
String[] exampleFiles = exampleDir.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".nex") || name.endsWith(".nxs");
}
});
List<String> failedFiles = new ArrayList<>();
for (String fileName : exampleFiles) {
System.out.println("Processing " + fileName);
NexusParser parser = new NexusParser();
try {
parser.parseFile(new File(dirName + "/" + fileName));
} catch (Exception e) {
System.out.println("ExampleNexusParsing::Failed for " + fileName + ": " + e.getMessage());
failedFiles.add(fileName);
}
XMLProducer producer = new XMLProducer();
BEASTInterface o = parser.m_alignment;
if (o != null) {
String xml = producer.toXML(o);
// FileWriter outfile = new FileWriter(new File("/tmp/XMLProducerTest.xml"));
// outfile.write(xml);
// outfile.close();
XMLParser parser2 = new XMLParser();
try {
BEASTInterface o2 = parser2.parseFragment(xml, false);
System.out.println(o2);
} catch (Exception e) {
System.out.println("test_ThatNexusExamplesProduces::Failed for " + fileName + ": " + e.getMessage());
failedFiles.add(fileName);
}
}
System.out.println("Done " + fileName);
}
if (failedFiles.size() > 0) {
System.out.println("\test_ThatNexusExamplesProduces::Failed for : " + failedFiles.toString());
} else {
System.out.println("\test_ThatNexusExamplesProduces::Success");
}
assertTrue(failedFiles.toString(), failedFiles.size() == 0);
} catch (Exception e) {
System.out.println("exception thrown ");
System.out.println(e.getMessage());
}
}
use of beast.util.XMLProducer in project beast2 by CompEvol.
the class BEASTObjectDialog method main.
/**
* rudimentary test *
*/
public static void main(String[] args) {
BEASTObjectDialog dlg = null;
try {
if (args.length == 0) {
dlg = new BEASTObjectDialog(new BEASTObjectPanel(new MCMC(), Runnable.class, null), null);
} else if (args[0].equals("-x")) {
StringBuilder text = new StringBuilder();
String NL = System.getProperty("line.separator");
Scanner scanner = new Scanner(new File(args[1]));
try {
while (scanner.hasNextLine()) {
text.append(scanner.nextLine() + NL);
}
} finally {
scanner.close();
}
BEASTInterface beastObject = new beast.util.XMLParser().parseBareFragment(text.toString(), false);
dlg = new BEASTObjectDialog(new BEASTObjectPanel(beastObject, beastObject.getClass(), null), null);
} else if (args.length == 1) {
dlg = new BEASTObjectDialog(new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[0]), null), null);
} else if (args.length == 2) {
dlg = new BEASTObjectDialog(new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[1]), null), null);
} else {
throw new IllegalArgumentException("Incorrect number of arguments");
}
} catch (Exception e) {
e.printStackTrace();
System.err.println("Usage: " + BEASTObjectDialog.class.getName() + " [-x file ] [class [type]]\n" + "where [class] (optional, default MCMC) is a BEASTObject to edit\n" + "and [type] (optional only if class is specified, default Runnable) the type of the BEASTObject.\n" + "for example\n" + "");
System.exit(1);
}
dlg.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
if (dlg.showDialog()) {
BEASTInterface beastObject = dlg.m_panel.m_beastObject;
String xml = new XMLProducer().modelToXML(beastObject);
System.out.println(xml);
}
}
use of beast.util.XMLProducer in project beast2 by CompEvol.
the class BEASTObjectPanel method main.
/**
* rudimentary test *
*/
public static void main(String[] args) {
init();
BEASTObjectPanel pluginPanel = null;
try {
if (args.length == 0) {
pluginPanel = new BEASTObjectPanel(new MCMC(), Runnable.class, null);
} else if (args[0].equals("-x")) {
StringBuilder text = new StringBuilder();
String NL = System.getProperty("line.separator");
Scanner scanner = new Scanner(new File(args[1]));
try {
while (scanner.hasNextLine()) {
text.append(scanner.nextLine() + NL);
}
} finally {
scanner.close();
}
BEASTInterface beastObject = new beast.util.XMLParser().parseBareFragment(text.toString(), false);
pluginPanel = new BEASTObjectPanel(beastObject, beastObject.getClass(), null);
} else if (args.length == 1) {
pluginPanel = new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[0]), null);
} else if (args.length == 2) {
pluginPanel = new BEASTObjectPanel((BEASTInterface) Class.forName(args[0]).newInstance(), Class.forName(args[1]), null);
} else {
throw new IllegalArgumentException("Incorrect number of arguments");
}
} catch (Exception e) {
e.printStackTrace();
System.err.println("Usage: " + BEASTObjectPanel.class.getName() + " [-x file ] [class [type]]\n" + "where [class] (optional, default MCMC) is a BEASTObject to edit\n" + "and [type] (optional only if class is specified, default Runnable) the type of the BEASTObject.\n" + "for example\n" + "");
System.exit(1);
}
pluginPanel.setVisible(true);
if (pluginPanel.m_bOK) {
BEASTInterface beastObject = pluginPanel.m_beastObject;
String xml = new XMLProducer().modelToXML(beastObject);
System.out.println(xml);
}
}
use of beast.util.XMLProducer in project beast2 by CompEvol.
the class Document method toXML.
// parseNode
public String toXML() {
XMLProducer xmlProducer = new XMLProducer();
BEASTObjectSet pluginSet = calcPluginSet();
if (pluginSet.m_plugins.get().size() == 1) {
return xmlProducer.toXML(pluginSet.m_plugins.get().get(0));
}
return xmlProducer.toXML(pluginSet);
}
Aggregations