Search in sources :

Example 1 with XMLProducer

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";
}
Also used : XMLProducer(beast.util.XMLProducer) BEASTInterface(beast.core.BEASTInterface) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with XMLProducer

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());
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) XMLProducer(beast.util.XMLProducer) ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface) NexusParser(beast.util.NexusParser) XMLParser(beast.util.XMLParser) File(java.io.File) Test(org.junit.Test)

Example 3 with XMLProducer

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);
    }
}
Also used : Scanner(java.util.Scanner) XMLProducer(beast.util.XMLProducer) MCMC(beast.core.MCMC) BEASTInterface(beast.core.BEASTInterface) File(java.io.File)

Example 4 with XMLProducer

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);
    }
}
Also used : Scanner(java.util.Scanner) XMLProducer(beast.util.XMLProducer) MCMC(beast.core.MCMC) BEASTInterface(beast.core.BEASTInterface) File(java.io.File)

Example 5 with XMLProducer

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);
}
Also used : XMLProducer(beast.util.XMLProducer)

Aggregations

XMLProducer (beast.util.XMLProducer)13 BEASTInterface (beast.core.BEASTInterface)9 File (java.io.File)6 XMLParser (beast.util.XMLParser)5 PrintStream (java.io.PrintStream)4 Alignment (beast.evolution.alignment.Alignment)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 MCMC (beast.core.MCMC)2 FileNotFoundException (java.io.FileNotFoundException)2 FileWriter (java.io.FileWriter)2 FilenameFilter (java.io.FilenameFilter)2 HashSet (java.util.HashSet)2 Scanner (java.util.Scanner)2 Input (beast.core.Input)1 Sequence (beast.evolution.alignment.Sequence)1 Taxon (beast.evolution.alignment.Taxon)1 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)1 Nucleotide (beast.evolution.datatype.Nucleotide)1 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)1