Code Monkey home page Code Monkey logo

dynamic-beast's Introduction

Dynamic BEAST

PyPi tests cov DOI

This command line tool can be used to create a dynamic version of BEAST2 XML files. This dynamic XML file can be used to set BEAST parameters at runtime, which can be useful for testing different configurations or quickly modifying parameters without having to edit the XML file.

Install

Install dynamic-beast with pip (requires python -V >= 3.6.2).

pip install dynamic-beast

Usage

Give dynamic-beast the path to a BEAST2 XML file and specify where to save the dynamic XML file (if --outfile is not specified XML will be printed to stdout).

dynamic-beast hcv_coal.xml > dynamic_hcv_coal.xml

This will produce a dynamic_hcv_coal.xml file that can be used as standard in a BEAST analysis.

beast dynamic_hcv_coal.xml

To modify parameters at runtime use the beast definitions option -D.

# Change the chain length to 1000. 
beast -D 'mcmc.chainLength=1000' dynamic_hcv_coal.xml

Multiple definitions can be passed at the same time.

# Change the treelog and tracelog sampling freq to 10000. 
beast -D 'treelog.logEvery=10000,tracelog.logEvery=10000' dynamic_hcv_coal.xml

The full id of a parameter you'd like to set must be specified.

beast -D 'clockRate.c:hcv=7.9E-4' dynamic_hcv_coal.xml

Explanation

The dynamic-beast tool replaces all the parameter values in the XML file with the $(id.key=value) format. The value variable is the default value that was initially specified in the XML file. However, the value can be redefined when running a BEAST analysis by making use of the BEAST2 definitions option (-D) that allows for user specified values.

To ensure reproducibility you should recreate static XML files of runs using dynamic parameters, this can be achieved using the -DFout argument e.g., beast -D 'clockRate.c:hcv=7.9E-4' -DFout static_hcv_coal.xml dynamic_hcv_coal.xml.

Addtional features

CoupledMCMC

MC3 options for the BEAST package CoupledMCMC can be added by using the --mc3 option. This will add the default CoupledMCMC options which can then be configured at runtime with -D.

# Create dynamic MC3 XML 
dynamic-beast --mc3 hcv_coal.xml > dynamic_mc3_hcv_coal.xml 
# Configure MC3 with BEAST
beast -D 'mcmc.chains=4' dynamic_mc3_hcv_coal.xml

Path Sampling (Stepping Stone)

Path sampling options for the package model-selection can be add by using the --ps option. This will add the default model-selection options (e.g. stepping stone) which can then be configured at runtime with -D.

# Create dynamic Path Sampling XML 
dynamic-beast --ps hcv_coal.xml > dynamic_ps_hcv_coal.xml
# Configure Path Sampling with BEAST
beast -D "ps.doNotRun=true,ps.rootdir=$(pwd)" dynamic_ps_hcv_coal.xml

Nested sampling

Nested sampling for the package nested-sampling can be add by using the --ns option. This will add the default model-selection options which can then be configured at runtime with -D.

# Create dynamic Nested Sampling XML 
dynamic-beast --ns hcv_coal.xml > dynamic_ns_hcv_coal.xml
# Configure Path Sampling with BEAST
beast -D "mcmc.threads=6,mcmc.chainLength=40000" dynamic_ns_hcv_coal.xml

Auto apply optimisation suggestion

At the end of a analysis BEAST provides suggestions for optimising operators e.g. Try setting scaleFactor to about 0.96. See the end of the example file. A path to the output file can be provided to the --optimise flag and the suggestions will automatically be extracted and applied to the generated dynamic XML file.

dynamic-beast --optimise hcv_coal.out hcv_coal.xml > dynamic_hcv_coal.xml

Dynamic-beast will look for a line starting with Operator and extract the suggestion from the lines that follow. So if you make your own .out file (i.e. by copy-pasting the BEAST output) you need to make sure the file starts with Operator on the first line.

Produce a json file of dynamic variables

Use the --json-out file to produce a json file for all the dynamic variables.

dynamic-beast --json-out hcv_coal.json hcv_coal.xml > dynamic_hcv_coal.xml

Can be used with the beast -DF flag

beast -DF hcv_coal.json dynamic_hcv_coal.xml

dynamic-beast's People

Contributors

wytamma avatar

Stargazers

 avatar  avatar

Watchers

 avatar

dynamic-beast's Issues

auto-apply optimisation

Parse the BEAST operator output (at the end of a log) and set the suggested changes as the defaults in the dynamic xml

Can't set traits

The way that defaults are passed means you can't use '=' in the values... I fixed this with a PR to BEAST2 CompEvol/beast2#991, however, it will take a while before those changes are available.

Add --sequence option

This would allow users to replace the sequence/trait data using -DF and a JSON file.

dynamic-beast --sequence beast.xml 

Resulting in a dynamic XML file that has the sequence data replaced with $(sequence) and trait replaced with $(trait). The user can then specify these in a JSON file.

{
"sequences":"
<sequence taxon='D4Brazi82'>            ATGCGATGCG        </sequence>
<sequence taxon='D4ElSal83'>            ATGCGATGCG        </sequence>
<sequence taxon='D4Thai84'>             GTGCGATGCG        </sequence>
","trait":"
D4Brazi82  = 1982,
D4ElSal83  = 1983,
D4Thai84   = 1984"
}

This file would be run with beast as folows.

beast -DF dynamic.json dynamic.xml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.