Search in sources :

Example 21 with MCMC

use of beast.core.MCMC in project beast2 by CompEvol.

the class ExampleXmlParsingTest method test_ThatXmlExamplesRun.

public void test_ThatXmlExamplesRun(String dir) {
    try {
        Logger.FILE_MODE = Logger.LogFileMode.overwrite;
        System.out.println("Test that XML Examples run 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>();
        int seed = 127;
        for (String fileName : exampleFiles) {
            Randomizer.setSeed(seed);
            // need more than one to prevent trouble with multiMCMC logs
            seed += 10;
            System.out.println("Processing " + fileName);
            XMLParser parser = new XMLParser();
            try {
                beast.core.Runnable runable = parser.parseFile(new File(dir + "/" + fileName));
                if (runable instanceof MCMC) {
                    MCMC mcmc = (MCMC) runable;
                    mcmc.setInputValue("preBurnin", 0);
                    mcmc.setInputValue("chainLength", 1000l);
                    mcmc.run();
                }
            } 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_ThatXmlExamplesRun::Failed for : " + failedFiles.toString());
        } else {
            System.out.println("SUCCESS!!!");
        }
        assertTrue(failedFiles.toString(), failedFiles.size() == 0);
    } catch (Exception e) {
        System.out.println("exception thrown ");
        System.out.println(e.getMessage());
        ;
    }
}
Also used : ArrayList(java.util.ArrayList) MCMC(beast.core.MCMC) FilenameFilter(java.io.FilenameFilter) XMLParser(beast.util.XMLParser) File(java.io.File)

Example 22 with MCMC

use of beast.core.MCMC in project beast2 by CompEvol.

the class ResumeTest method test_ThatXmlExampleResumes.

@Test
public void test_ThatXmlExampleResumes() throws Exception {
    Randomizer.setSeed(127);
    Logger.FILE_MODE = Logger.LogFileMode.overwrite;
    String dir = System.getProperty("user.dir") + "/examples";
    String fileName = dir + "/" + XML_FILE;
    System.out.println("Processing " + fileName);
    XMLParser parser = new XMLParser();
    beast.core.Runnable runable = parser.parseFile(new File(fileName));
    runable.setStateFile("tmp.state", false);
    if (runable instanceof MCMC) {
        MCMC mcmc = (MCMC) runable;
        mcmc.setInputValue("preBurnin", 0);
        mcmc.setInputValue("chainLength", 1000l);
        mcmc.run();
    }
    System.out.println("Done " + fileName);
    System.out.println("Resuming " + fileName);
    Logger.FILE_MODE = Logger.LogFileMode.resume;
    parser = new XMLParser();
    runable = parser.parseFile(new File(fileName));
    runable.setStateFile("tmp.state", true);
    if (runable instanceof MCMC) {
        MCMC mcmc = (MCMC) runable;
        mcmc.setInputValue("preBurnin", 0);
        mcmc.setInputValue("chainLength", 1000l);
        mcmc.run();
    }
    System.out.println("Done " + fileName);
}
Also used : MCMC(beast.core.MCMC) XMLParser(beast.util.XMLParser) File(java.io.File) Test(org.junit.Test)

Aggregations

MCMC (beast.core.MCMC)22 State (beast.core.State)10 RealParameter (beast.core.parameter.RealParameter)10 Test (org.junit.Test)10 Operator (beast.core.Operator)9 SCMigrationModel (beast.evolution.tree.SCMigrationModel)9 TypeSet (beast.evolution.tree.TypeSet)9 StructuredCoalescentTreeDensity (multitypetree.distributions.StructuredCoalescentTreeDensity)9 MultiTypeTreeStatLogger (multitypetree.util.MultiTypeTreeStatLogger)9 BEASTInterface (beast.core.BEASTInterface)7 MultiTypeTreeFromNewick (beast.evolution.tree.MultiTypeTreeFromNewick)6 File (java.io.File)5 ArrayList (java.util.ArrayList)4 IntegerParameter (beast.core.parameter.IntegerParameter)3 CompoundDistribution (beast.core.util.CompoundDistribution)3 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)3 MultiTypeTree (beast.evolution.tree.MultiTypeTree)3 StructuredCoalescentMultiTypeTree (beast.evolution.tree.StructuredCoalescentMultiTypeTree)3 XMLParser (beast.util.XMLParser)3 Input (beast.core.Input)2