Search in sources :

Example 6 with XMLParser

use of beast.util.XMLParser in project beast2 by CompEvol.

the class ExampleXmlParsingTest method test_ThatXmlExamplesParse.

public void test_ThatXmlExamplesParse(String dir) {
    try {
        Randomizer.setSeed(127);
        Logger.FILE_MODE = Logger.LogFileMode.overwrite;
        System.out.println("Test XML Examples in " + dir);
        File exampleDir = new File(dir);
        String[] exampleFiles = exampleDir.list(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".xml");
            }
        });
        List<String> failedFiles = new ArrayList<String>();
        for (String fileName : exampleFiles) {
            System.out.println("Processing " + fileName);
            XMLParser parser = new XMLParser();
            try {
                parser.parseFile(new File(dir + "/" + fileName));
            } catch (Exception e) {
                System.out.println("ExampleXmlParsing::Failed for " + fileName + ": " + e.getMessage());
                failedFiles.add(fileName);
            }
            System.out.println("Done " + fileName);
        }
        if (failedFiles.size() > 0) {
            System.out.println("\ntest_ThatXmlExamplesParse::Failed for : " + failedFiles.toString());
        } else {
            System.out.println("\ntest_ThatXmlExamplesParse::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) ArrayList(java.util.ArrayList) XMLParser(beast.util.XMLParser) File(java.io.File)

Example 7 with XMLParser

use of beast.util.XMLParser 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 8 with XMLParser

use of beast.util.XMLParser in project bacter by tgvaughan.

the class AddRemoveDetourTest method test5Taxon.

@Test
public void test5Taxon() throws Exception {
    Randomizer.setSeed(1);
    XMLParser parser = new XMLParser();
    beast.core.Runnable runnable = parser.parseFile(new File("examples/addRemoveDetourTests/addRemoveDetourTest5taxon.xml"));
    disableScreenLog(runnable);
    runnable.run();
    List<Expectation> expectations = new ArrayList<>();
    expectations.add(new Expectation("acg.CFheight", 1.606, 0.2));
    expectations.add(new Expectation("acg.CFlength", 4.181, 0.5));
    expectations.add(new Expectation("acg.nConv", 21.0, 0.5));
    LogAnalyser logAnalyser = new LogAnalyser("addRemoveDetourTest5taxon.stats", expectations);
    for (int i = 0; i < expectations.size(); i++) {
        assertTrue(expectations.get(i).isValid());
        assertTrue(expectations.get(i).isPassed());
    }
    Files.deleteIfExists(Paths.get("addRemoveDetourTest5taxon.stats"));
    Files.deleteIfExists(Paths.get("addRemoveDetourTest5taxon.converted"));
    Files.deleteIfExists(Paths.get("addRemoveDetourTest5taxon.trees"));
    Files.deleteIfExists(Paths.get("addRemoveDetourTest5taxon_trimmed.trees"));
    Files.deleteIfExists(Paths.get("addRemoveDetourTest5taxon.cf"));
    Files.deleteIfExists(Paths.get("addRemoveDetourTest5taxon.xml.state"));
}
Also used : LogAnalyser(test.beast.beast2vs1.trace.LogAnalyser) ArrayList(java.util.ArrayList) XMLParser(beast.util.XMLParser) Expectation(test.beast.beast2vs1.trace.Expectation) File(java.io.File) Test(org.junit.Test)

Example 9 with XMLParser

use of beast.util.XMLParser in project bacter by tgvaughan.

the class AllOperatorTest method testMultiLocus.

@Test
public void testMultiLocus() throws Exception {
    Randomizer.setSeed(1);
    XMLParser parser = new XMLParser();
    beast.core.Runnable runnable = parser.parseFile(new File("examples/allOperatorTests/allOperatorTestSSMultiLocus.xml"));
    disableScreenLog(runnable);
    runnable.run();
    List<Expectation> expectations = new ArrayList<>();
    expectations.add(new Expectation("acg.CFheight", 1.909, 0.2));
    expectations.add(new Expectation("acg.CFlength", 4.655, 0.5));
    expectations.add(new Expectation("acg.nConv", 23.381, 0.5));
    LogAnalyser logAnalyser = new LogAnalyser("allOperatorTestSSMultiLocus.stats", expectations);
    for (Expectation expectation : expectations) {
        assertTrue(expectation.isValid());
        assertTrue(expectation.isPassed());
    }
    Files.deleteIfExists(Paths.get("allOperatorTestSSMultiLocus.stats"));
    Files.deleteIfExists(Paths.get("allOperatorTestSSMultiLocus.converted"));
    Files.deleteIfExists(Paths.get("allOperatorTestSSMultiLocus.trees"));
    Files.deleteIfExists(Paths.get("allOperatorTestSSMultiLocus.cf"));
    Files.deleteIfExists(Paths.get("allOperatorTestSSMultiLocus.xml.state"));
}
Also used : LogAnalyser(test.beast.beast2vs1.trace.LogAnalyser) ArrayList(java.util.ArrayList) XMLParser(beast.util.XMLParser) Expectation(test.beast.beast2vs1.trace.Expectation) File(java.io.File) Test(org.junit.Test)

Example 10 with XMLParser

use of beast.util.XMLParser in project bacter by tgvaughan.

the class CFOperatorTest method testCFUniform.

@Test
public void testCFUniform() throws Exception {
    Randomizer.setSeed(1);
    XMLParser parser = new XMLParser();
    beast.core.Runnable runnable = parser.parseFile(new File("examples/CFOperatorTests/CFUniformTest5taxon.xml"));
    disableScreenLog(runnable);
    runnable.run();
    List<Expectation> expectations = new ArrayList<>();
    expectations.add(new Expectation("acg.CFheight", 1.606, 0.2));
    expectations.add(new Expectation("acg.CFlength", 4.181, 0.5));
    expectations.add(new Expectation("acg.nConv", 21.0, 0.5));
    new LogAnalyser("CFUniformTest5taxon.stats", expectations);
    for (Expectation expectation : expectations) {
        assertTrue(expectation.isValid());
        assertTrue(expectation.isPassed());
    }
    Files.deleteIfExists(Paths.get("CFUniformTest5taxon.stats"));
    Files.deleteIfExists(Paths.get("CFUniformTest5taxon.converted"));
    Files.deleteIfExists(Paths.get("CFUniformTest5taxon.trees"));
    Files.deleteIfExists(Paths.get("CFUniformTest5taxon.cf"));
    Files.deleteIfExists(Paths.get("CFUniformTest5taxon.xml.state"));
}
Also used : LogAnalyser(test.beast.beast2vs1.trace.LogAnalyser) ArrayList(java.util.ArrayList) XMLParser(beast.util.XMLParser) Expectation(test.beast.beast2vs1.trace.Expectation) File(java.io.File) Test(org.junit.Test)

Aggregations

XMLParser (beast.util.XMLParser)46 File (java.io.File)36 ArrayList (java.util.ArrayList)29 Test (org.junit.Test)27 Expectation (test.beast.beast2vs1.trace.Expectation)23 LogAnalyser (test.beast.beast2vs1.trace.LogAnalyser)23 BEASTInterface (beast.core.BEASTInterface)11 XMLProducer (beast.util.XMLProducer)5 IOException (java.io.IOException)5 FilenameFilter (java.io.FilenameFilter)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 SAXException (org.xml.sax.SAXException)4 MCMC (beast.core.MCMC)3 Alignment (beast.evolution.alignment.Alignment)3 XMLParserException (beast.util.XMLParserException)3 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 Input (beast.core.Input)2 StateNode (beast.core.StateNode)2 CompoundDistribution (beast.core.util.CompoundDistribution)2