├── examples ├── nexus │ ├── anolis.nex_phyml_stats.txt │ ├── anolis.nex_phyml_tree.txt │ ├── avian-ovomucoids.nex │ ├── old.nex │ ├── maddison.nex │ └── traitlab.nex ├── testDirichlet │ ├── testDirichletMarginalDensity2.pdf │ ├── testDirichletNoPrior.xml │ ├── testDirichlet.xml │ ├── testDirichletBact.xml │ └── testDirichlet2.xml ├── benchmark │ ├── 1 │ │ └── experiment.sh │ ├── mrbayes │ │ ├── run1044.nex │ │ ├── run1366.nex │ │ ├── run1510.nex │ │ ├── run1748.nex │ │ ├── run1749.nex │ │ ├── run1809.nex │ │ ├── run336.nex │ │ ├── run3475.nex │ │ ├── run501.nex │ │ ├── run520.nex │ │ ├── run755.nex │ │ ├── run767.nex │ │ └── experiment.sh │ └── II │ │ └── experiment.sh ├── ringe_ctmc.xml.state ├── parameterised │ └── README.md ├── testDirectSimulator2.xml ├── bitflip.xml ├── testDirectSimulatorHierarchical.xml ├── testDirectSimulator.xml └── testCalYule_5t_2c.xml ├── lib ├── colt.jar ├── beagle.jar ├── bundler │ ├── jsign-3.1.jar │ └── jarbundler-core-3.3.0.jar ├── antlr-runtime-4.10.1.jar ├── commons-math3-3.6.1.jar └── junit │ └── junit-platform-console-standalone-1.8.2.jar ├── release ├── Mac │ ├── install.png │ └── README.md ├── common │ ├── icons │ │ ├── beast.icns │ │ ├── beast.ico │ │ ├── beast.png │ │ ├── beauti.ico │ │ ├── beauti.png │ │ ├── beauti.icns │ │ ├── utility.icns │ │ ├── utility.ico │ │ └── utility.png │ └── tools │ │ ├── DensiTree.icns │ │ ├── DensiTree.ico │ │ ├── DensiTree.jar │ │ ├── DensiTree.png │ │ ├── DensiTree_launch4j.xml │ │ └── DensiTree_launch4j_jre.xml ├── Windows │ ├── bat │ │ ├── packagemanager.bat │ │ ├── applauncher.bat │ │ ├── logcombiner.bat │ │ ├── treeannotator.bat │ │ ├── beast.bat │ │ ├── loganalyser.bat │ │ └── beauti.bat │ ├── windowsCertificationNotes.txt │ ├── AppLauncher_launch4j.xml │ ├── LogCombiner_launch4j_jre.xml │ ├── TreeAnnotator_launch4j.xml │ ├── TreeAnnotator_launch4j_jre.xml │ ├── AppLauncher_launch4j_jre.xml │ ├── LogCombiner_launch4j.xml │ ├── BEAUti_launch4j.xml │ ├── BEAUti_launch4j_jre.xml │ ├── BEAST_launch4j.xml │ └── BEAST_launch4j_jre.xml └── Linux │ └── jrebin │ ├── packagemanager │ ├── densitree │ ├── logcombiner │ ├── treeannotator │ ├── beauti │ ├── applauncher │ └── loganalyser ├── src ├── beast │ ├── pkgmgmt │ │ ├── icons │ │ │ └── beauti.png │ │ ├── launcher │ │ │ ├── LogCombinerLauncher.java │ │ │ ├── TreeAnnotatorLauncher.java │ │ │ ├── BeautiLauncher.java │ │ │ └── AppLauncherLauncher.java │ │ └── PackageDependency.java │ └── base │ │ ├── inference │ │ ├── Evaluator.java │ │ ├── distribution │ │ │ ├── LogNormal.java │ │ │ ├── ChiSquare.java │ │ │ ├── OneOnX.java │ │ │ ├── Beta.java │ │ │ └── Poisson.java │ │ ├── operator │ │ │ ├── kernel │ │ │ │ └── KernelOperator.java │ │ │ ├── IntUniformOperator.java │ │ │ └── IntRandomWalkOperator.java │ │ ├── parameter │ │ │ ├── BooleanParameterList.java │ │ │ ├── IntegerParameterList.java │ │ │ └── RealParameterList.java │ │ ├── StateNodeInitialiser.java │ │ ├── Runnable.java │ │ └── util │ │ │ └── InputUtil.java │ │ ├── evolution │ │ ├── tree │ │ │ ├── treeparser │ │ │ │ ├── README │ │ │ │ ├── NewickParser.g4 │ │ │ │ └── NewickLexer.g4 │ │ │ ├── TreeMetric.java │ │ │ ├── TreeDistribution.java │ │ │ ├── TreeHeightLogger.java │ │ │ ├── TreeInterface.java │ │ │ └── coalescent │ │ │ │ └── ScaledPopulationFunction.java │ │ ├── substitutionmodel │ │ │ └── EigenSystem.java │ │ ├── alignment │ │ │ ├── AscertainedAlignment.java │ │ │ └── TreeTipData.java │ │ ├── datatype │ │ │ ├── Binary.java │ │ │ ├── TwoStateCovarion.java │ │ │ ├── IntegerData.java │ │ │ ├── Aminoacid.java │ │ │ └── Nucleotide.java │ │ ├── distance │ │ │ ├── HammingDistance.java │ │ │ └── SMMDistance.java │ │ ├── branchratemodel │ │ │ ├── BranchRateModel.java │ │ │ └── StrictClockModel.java │ │ ├── speciation │ │ │ ├── TreeTopFinder.java │ │ │ ├── CalibrationPoint.java │ │ │ └── RandomGeneTree.java │ │ ├── likelihood │ │ │ └── GenericTreeLikelihood.java │ │ └── operator │ │ │ └── kernel │ │ │ └── BactrianTipDatesRandomWalker.java │ │ ├── parser │ │ ├── NexusParserListener.java │ │ ├── XMLModelLogger.java │ │ ├── InputType.java │ │ ├── OutputUtils.java │ │ └── PartitionContext.java │ │ ├── math │ │ ├── MathUtils.java │ │ └── matrixalgebra │ │ │ ├── IllegalDimension.java │ │ │ ├── CholeskyDecomposition.java │ │ │ └── NonSymmetricComponents.java │ │ ├── core │ │ ├── Loggable.java │ │ ├── ProgramStatus.java │ │ ├── BEASTVersion2.java │ │ ├── Param.java │ │ └── Description.java │ │ ├── util │ │ ├── FileUtils.java │ │ ├── CredibleSet.java │ │ └── CollectionUtils.java │ │ └── CudaDetector.java └── org │ ├── apache │ └── commons │ │ └── math │ │ ├── analysis │ │ ├── DifferentiableUnivariateRealFunction.java │ │ ├── UnivariateRealFunction.java │ │ ├── BivariateRealFunction.java │ │ ├── MultivariateRealFunction.java │ │ └── solvers │ │ │ └── UnivariateRealSolverFactoryImpl.java │ │ └── distribution │ │ ├── DiscreteDistribution.java │ │ ├── TDistribution.java │ │ ├── ExponentialDistribution.java │ │ ├── HasDensity.java │ │ ├── ChiSquaredDistribution.java │ │ ├── CauchyDistribution.java │ │ ├── BinomialDistribution.java │ │ ├── FDistribution.java │ │ ├── WeibullDistribution.java │ │ ├── GammaDistribution.java │ │ └── PoissonDistribution.java │ └── json │ └── JSONException.java ├── .gitignore ├── .github └── workflows │ ├── beauti.yml │ └── core.yml ├── test └── test │ └── beast │ ├── beast2vs1 │ └── trace │ │ ├── TraceType.java │ │ └── TraceException.java │ ├── core │ ├── PrimitiveInterface.java │ ├── StateNodeInitialiserTest.java │ └── util │ │ └── SumTest.java │ ├── evolution │ ├── tree │ │ ├── TreeUtilsTest.java │ │ ├── coalescent │ │ │ ├── BayesianSkylineTest.java │ │ │ └── CoalescentTest.java │ │ └── TreeTest.java │ ├── datatype │ │ ├── IntegerDataTest.java │ │ └── DataTypeDeEncodeTest.java │ ├── likelihood │ │ └── BeagleTreeLikelihoodTest.java │ └── operator │ │ ├── CompoundParameterHelperTest.java │ │ ├── ScaleOperatorTest.java │ │ ├── TestOperator.java │ │ └── DeltaExchangeOperatorTest.java │ └── util │ ├── RandomizerTest.java │ └── XMLTest.java ├── Dockerfile └── README.md /examples/nexus/anolis.nex_phyml_stats.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/nexus/anolis.nex_phyml_tree.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/colt.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/lib/colt.jar -------------------------------------------------------------------------------- /lib/beagle.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/lib/beagle.jar -------------------------------------------------------------------------------- /release/Mac/install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/Mac/install.png -------------------------------------------------------------------------------- /lib/bundler/jsign-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/lib/bundler/jsign-3.1.jar -------------------------------------------------------------------------------- /lib/antlr-runtime-4.10.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/lib/antlr-runtime-4.10.1.jar -------------------------------------------------------------------------------- /lib/commons-math3-3.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/lib/commons-math3-3.6.1.jar -------------------------------------------------------------------------------- /release/common/icons/beast.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/beast.icns -------------------------------------------------------------------------------- /release/common/icons/beast.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/beast.ico -------------------------------------------------------------------------------- /release/common/icons/beast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/beast.png -------------------------------------------------------------------------------- /release/common/icons/beauti.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/beauti.ico -------------------------------------------------------------------------------- /release/common/icons/beauti.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/beauti.png -------------------------------------------------------------------------------- /release/common/icons/beauti.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/beauti.icns -------------------------------------------------------------------------------- /release/common/icons/utility.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/utility.icns -------------------------------------------------------------------------------- /release/common/icons/utility.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/utility.ico -------------------------------------------------------------------------------- /release/common/icons/utility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/icons/utility.png -------------------------------------------------------------------------------- /examples/nexus/avian-ovomucoids.nex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/examples/nexus/avian-ovomucoids.nex -------------------------------------------------------------------------------- /release/common/tools/DensiTree.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/tools/DensiTree.icns -------------------------------------------------------------------------------- /release/common/tools/DensiTree.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/tools/DensiTree.ico -------------------------------------------------------------------------------- /release/common/tools/DensiTree.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/tools/DensiTree.jar -------------------------------------------------------------------------------- /release/common/tools/DensiTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/release/common/tools/DensiTree.png -------------------------------------------------------------------------------- /src/beast/pkgmgmt/icons/beauti.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/src/beast/pkgmgmt/icons/beauti.png -------------------------------------------------------------------------------- /lib/bundler/jarbundler-core-3.3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/lib/bundler/jarbundler-core-3.3.0.jar -------------------------------------------------------------------------------- /lib/junit/junit-platform-console-standalone-1.8.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/lib/junit/junit-platform-console-standalone-1.8.2.jar -------------------------------------------------------------------------------- /examples/testDirichlet/testDirichletMarginalDensity2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CompEvol/beast2/HEAD/examples/testDirichlet/testDirichletMarginalDensity2.pdf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ ignores 2 | /.idea 3 | /beast2.iml 4 | /META-INF 5 | /out 6 | 7 | # Eclipse ignores 8 | /.classpath 9 | 10 | # OS X ignores 11 | .DS_Store 12 | /build/ 13 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run1044.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY1044.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run1366.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY1366.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run1510.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY1510.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run1748.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY1748.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run1749.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY1749.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run1809.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY1809.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run336.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY336.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run3475.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY3475.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run501.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY501.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run520.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY520.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run755.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY755.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/run767.nex: -------------------------------------------------------------------------------- 1 | begin mrbayes; 2 | set autoclose=yes nowarn=yes; 3 | execute testHKY767.nex; 4 | lset nst=2; 5 | mcmc nruns=1 ngen=1000000 samplefreq=10000 file=testHKY.nex1; 6 | end; 7 | -------------------------------------------------------------------------------- /src/beast/base/inference/Evaluator.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference; 2 | 3 | /** 4 | * @author Andrew Rambaut 5 | * @version $Id$ 6 | */ 7 | public interface Evaluator { 8 | double evaluate(); 9 | } 10 | -------------------------------------------------------------------------------- /.github/workflows/beauti.yml: -------------------------------------------------------------------------------- 1 | name: BEAUti tests 2 | on: [ workflow_dispatch ] 3 | 4 | jobs: 5 | test-beauti: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | - run: docker build -t beast2-test . 10 | - run: docker run beast2-test test-beauti -------------------------------------------------------------------------------- /.github/workflows/core.yml: -------------------------------------------------------------------------------- 1 | name: Core tests 2 | on: [ push, pull_request, workflow_dispatch ] 3 | 4 | jobs: 5 | test-core: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | - run: docker build -t beast2-test . 10 | - run: docker run beast2-test test-core 11 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/treeparser/README: -------------------------------------------------------------------------------- 1 | To generate the java code from the parser, in this directory run 2 | 3 | java -jar antlr-complete.jar -o /tmp -visitor -listener -package beast.base.evolution.tree.treeparser *.g4 4 | 5 | where antlr-complete.jar is the complete version of jar, including the parser generator (not just the runtime). -------------------------------------------------------------------------------- /examples/nexus/old.nex: -------------------------------------------------------------------------------- 1 | #nexus 2 | 3 | BEGIN Taxa; 4 | DIMENSIONS ntax=1; 5 | TAXLABELS 6 | [1] cae 7 | ; 8 | END; [Taxa] 9 | 10 | BEGIN Characters; 11 | DIMENSIONS nchar=4; 12 | format datatype=standard 13 | missing=? 14 | gap=- 15 | symbols="01" 16 | labels=left 17 | transpose=no 18 | interleave=no 19 | ; 20 | MATRIX 21 | cae 1000 22 | ; 23 | END; [Characters] 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/beast/base/evolution/substitutionmodel/EigenSystem.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.substitutionmodel; 2 | 3 | /** 4 | * @author Andrew Rambaut 5 | * @version $Id$ 6 | */ 7 | public interface EigenSystem { 8 | /** 9 | * Set the instantaneous rate matrix 10 | * This changes the values in matrix as side effect 11 | * @param matrix 12 | */ 13 | EigenDecomposition decomposeMatrix(double[][] matrix); 14 | } 15 | -------------------------------------------------------------------------------- /release/Windows/bat/packagemanager.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Check whether the JRE is included 4 | IF EXIST "%~dp0\..\jre" ( 5 | 6 | REM for BEAST version that includes JRE 7 | "%~dp0\..\jre\bin\java" -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.PackageManager %* 8 | 9 | ) ELSE ( 10 | REM for version that does not include JRE 11 | java -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.PackageManager %* 12 | ) -------------------------------------------------------------------------------- /examples/ringe_ctmc.xml.state: -------------------------------------------------------------------------------- 1 | 2 | ((0:0.25,1:0.25)4:0.25,(2:0.25,3:0.25)5:0.25)6:0.0 3 | birthRate.t:tree[1 1] (-Infinity,Infinity): 1.0 4 | 5 | 10 | -------------------------------------------------------------------------------- /release/Windows/bat/applauncher.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Check whether the JRE is included 4 | IF EXIST "%~dp0\..\jre" ( 5 | 6 | REM for BEAST version that includes JRE 7 | "%~dp0\..\jre\bin\java" -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher %* 8 | 9 | ) ELSE ( 10 | REM for version that does not include JRE 11 | java -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher %* 12 | ) -------------------------------------------------------------------------------- /release/Windows/bat/logcombiner.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Check whether the JRE is included 4 | IF EXIST "%~dp0\..\jre" ( 5 | 6 | REM for BEAST version that includes JRE 7 | "%~dp0\..\jre\bin\java" -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.LogCombinerLauncher %* 8 | 9 | ) ELSE ( 10 | REM for version that does not include JRE 11 | java -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.LogCombinerLauncher %* 12 | ) -------------------------------------------------------------------------------- /release/Windows/bat/treeannotator.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Check whether the JRE is included 4 | IF EXIST "%~dp0\..\jre" ( 5 | 6 | REM for BEAST version that includes JRE 7 | "%~dp0\..\jre\bin\java" -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.TreeAnnotatorLauncher %* 8 | 9 | ) ELSE ( 10 | REM for version that does not include JRE 11 | java -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.TreeAnnotatorLauncher %* 12 | ) -------------------------------------------------------------------------------- /src/beast/base/evolution/alignment/AscertainedAlignment.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.alignment; 2 | 3 | import beast.base.core.Description; 4 | 5 | 6 | @Description("Alignemnt that allows ascertainment correction") 7 | /** 8 | * This class has merged with Alignment 9 | * @deprecated use Alignment() instead setting isAscertainedInput to true. 10 | */ 11 | @Deprecated 12 | public class AscertainedAlignment extends Alignment { 13 | 14 | } // class AscertainedAlignment 15 | -------------------------------------------------------------------------------- /release/Windows/bat/beast.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Check whether the JRE is included 4 | IF EXIST %~dp0\..\jre ( 5 | 6 | REM for BEAST version that includes JRE 7 | "%~dp0\..\jre\bin\java" -Xss256m -Xmx8g -Dfile.encoding=UTF-8 -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.BeastLauncher %* 8 | 9 | ) ELSE ( 10 | REM for version that does not include JRE 11 | java -Xss256m -Xmx8g -Dfile.encoding=UTF-8 -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.BeastLauncher %* 12 | ) -------------------------------------------------------------------------------- /release/Windows/bat/loganalyser.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Check whether the JRE is included 4 | IF EXIST "%~dp0\..\jre" ( 5 | 6 | REM for BEAST version that includes JRE 7 | "%~dp0\..\jre\bin\java" -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher LogAnalyser %* 8 | 9 | ) ELSE ( 10 | REM for version that does not include JRE 11 | java -Xss256m -Xmx8g -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher LogAnalyser %* 12 | ) -------------------------------------------------------------------------------- /release/Windows/bat/beauti.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Check whether the JRE is included 4 | IF EXIST "%~dp0\..\jre" ( 5 | 6 | REM for BEAST version that includes JRE 7 | "%~dp0\..\jre\bin\java" -Xss256m -Xmx8g -Dfile.encoding=UTF-8 -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.BeautiLauncher %* 8 | 9 | ) ELSE ( 10 | REM for version that does not include JRE 11 | java -Xss256m -Xmx8g -Dfile.encoding=UTF-8 -cp "%~dp0\..\lib\launcher.jar" beast.pkgmgmt.launcher.BeautiLauncher %* 12 | ) -------------------------------------------------------------------------------- /release/Windows/windowsCertificationNotes.txt: -------------------------------------------------------------------------------- 1 | Windows certification notes: 2 | 3 | Create certificate: 4 | 5 | "C:\Program Files\Java\jdk1.8.0_161\bin\keytool.exe" -genkey -dname "CN=RemcoBouckaert, L=Auckland, ST=ST, C=NZ, OU=, O=http://beast2/org" -alias http://beast2.org -keyalg RSA -destkeystore keystore.pfx -keysize 2048 -storetype pkcs12 6 | 7 | 8 | keystore password = UoA password 9 | 10 | Signing with ant: add jsign-3.1.jar from 11 | 12 | -------------------------------------------------------------------------------- /src/beast/base/parser/NexusParserListener.java: -------------------------------------------------------------------------------- 1 | package beast.base.parser; 2 | 3 | import beast.base.evolution.tree.Tree; 4 | 5 | /** 6 | * @author Alexei Drummond 7 | */ 8 | public interface NexusParserListener { 9 | 10 | /** 11 | * This method is called to alert a listener that a tree has been parsed by the nexus parser 12 | * @param treeIndex the index of the tree (starting from zero) 13 | * @param tree the tree that has been parsed 14 | */ 15 | void treeParsed(int treeIndex, Tree tree); 16 | } 17 | -------------------------------------------------------------------------------- /src/beast/base/math/MathUtils.java: -------------------------------------------------------------------------------- 1 | package beast.base.math; 2 | 3 | /** 4 | * Methods from MathUtils in BEAST1 5 | */ 6 | public class MathUtils { 7 | /** 8 | * Returns sqrt(a^2 + b^2) without under/overflow. 9 | */ 10 | public static double hypot(double a, double b) { 11 | double r; 12 | 13 | if (Math.abs(a) > Math.abs(b)) { 14 | r = b/a; 15 | r = Math.abs(a)*Math.sqrt(1+r*r); 16 | } else if (b != 0) { 17 | r = a/b; 18 | r = Math.abs(b)*Math.sqrt(1+r*r); 19 | } else { 20 | r = 0.0; 21 | } 22 | return r; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/beast/base/parser/XMLModelLogger.java: -------------------------------------------------------------------------------- 1 | package beast.base.parser; 2 | 3 | import beast.base.core.BEASTInterface; 4 | import beast.base.inference.ModelLogger; 5 | 6 | 7 | /** Hack to get around dependency of beast.inferece.Logger to XMLProducer **/ 8 | public class XMLModelLogger extends ModelLogger { 9 | 10 | 11 | @Override 12 | protected int canHandleObject(Object o) { 13 | if (o instanceof BEASTInterface) { 14 | return 1; 15 | } 16 | return -1; 17 | } 18 | 19 | 20 | @Override 21 | public String modelToStringImp(Object o) { 22 | return new XMLProducer().modelToXML((BEASTInterface) o); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/treeparser/NewickParser.g4: -------------------------------------------------------------------------------- 1 | parser grammar NewickParser; 2 | 3 | options { tokenVocab=NewickLexer; } 4 | 5 | tree: node ';'? EOF; 6 | 7 | node: ('(' node (COMMA node)* ')')? post ; 8 | 9 | post: label? nodeMeta=meta? (':' lengthMeta=meta? length=number)? ; 10 | 11 | label: number | STRING ; 12 | 13 | meta: '[&' attrib (ACOMMA attrib)* ']' ; 14 | 15 | attrib: attribKey=ASTRING '=' attribValue ; 16 | 17 | attribValue: attribNumber | ASTRING | vector; 18 | 19 | number: INT | FLOAT | FLOAT_SCI; 20 | attribNumber: AINT | AFLOAT | AFLOAT_SCI; 21 | 22 | vector: '{' attribValue (ACOMMA attribValue)* '}' ; 23 | 24 | -------------------------------------------------------------------------------- /examples/nexus/maddison.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | 3 | [ 4 | Example from Nexus: An Extensible File Format for Systematic Information 5 | David R. Maddison David L. Swofford Wayne P. Maddison David Cannatella 6 | Syst Biol (1997) 46 (4): 590-621. 7 | ] 8 | 9 | 10 | BEGIN TAXA; 11 | DIMENSIONS NTAX=4; 12 | TAXLABELS fish frog snake mouse; 13 | END; 14 | 15 | BEGIN CHARACTERS; 16 | DIMENSIONS NCHAR=20; 17 | FORMAT DATATYPE=DNA; 18 | MATRIX 19 | fish ACATAGAGGGTACCTCTAAG 20 | frog ACTTAGAGGCTACCTCTACG 21 | snake ACTCACTGGGTACCTTTGCG 22 | mouse ACTCAGACGGTACCTTTGCG; 23 | END; 24 | 25 | BEGIN TREES; 26 | TREE best = (fish,(frog,(snake,mouse))); 27 | END; 28 | -------------------------------------------------------------------------------- /src/beast/pkgmgmt/launcher/LogCombinerLauncher.java: -------------------------------------------------------------------------------- 1 | package beast.pkgmgmt.launcher; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.InvocationTargetException; 5 | 6 | /** Launches log-combiner 7 | * @see BeastLauncher 8 | * **/ 9 | public class LogCombinerLauncher extends BeastLauncher { 10 | 11 | public static void main(String[] args) throws NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException { 12 | if (javaVersionCheck("LogCombiner")) { 13 | String classpath = getPath(false, null); 14 | run(classpath, "beastfx.app.tools.LogCombiner", args); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/beast/pkgmgmt/launcher/TreeAnnotatorLauncher.java: -------------------------------------------------------------------------------- 1 | package beast.pkgmgmt.launcher; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.InvocationTargetException; 5 | 6 | /** Launches TreeAnnotator 7 | * @see BeastLauncher 8 | * **/ 9 | public class TreeAnnotatorLauncher extends BeastLauncher { 10 | 11 | public static void main(String[] args) throws NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException { 12 | if (javaVersionCheck("TreeAnnotator")) { 13 | String classpath = getPath(false, null); 14 | run(classpath, "beastfx.app.treeannotator.TreeAnnotator", args); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/beast/base/evolution/datatype/Binary.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.datatype; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.evolution.datatype.DataType.Base; 5 | 6 | @Description("Datatype for binary sequences") 7 | public class Binary extends Base { 8 | int[][] x = { 9 | {0}, // 0 10 | {1}, // 1 11 | {0, 1}, // - 12 | {0, 1}, // ? 13 | }; 14 | 15 | public Binary() { 16 | stateCount = 2; 17 | mapCodeToStateSet = x; 18 | codeLength = 1; 19 | codeMap = "01" + GAP_CHAR + MISSING_CHAR; 20 | } 21 | 22 | @Override 23 | public String getTypeDescription() { 24 | return "binary"; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/beast/base/inference/distribution/LogNormal.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.distribution; 2 | 3 | import beast.base.core.Description; 4 | 5 | /** 6 | * A subclass of LogNormalDistributionModel with a shorter, more user-friendly name. 7 | * This class provides exactly the same functionality as LogNormalDistributionModel 8 | * but can be referenced as "LogNormal" in XML and model scripts. 9 | */ 10 | @Description("A log-normal distribution with mean and variance parameters. Alias for LogNormalDistributionModel.") 11 | public class LogNormal extends LogNormalDistributionModel { 12 | // No need to override anything - this class simply provides a nicer name 13 | // while inheriting all functionality from LogNormalDistributionModel 14 | } -------------------------------------------------------------------------------- /src/beast/base/inference/operator/kernel/KernelOperator.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.operator.kernel; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.core.Input; 5 | import beast.base.inference.Operator; 6 | 7 | 8 | @Description("Operator with a flexible kernel distribution") 9 | public abstract class KernelOperator extends Operator { 10 | public final Input kernelDistributionInput = new Input<>("kernelDistribution", "provides sample distribution for proposals", 11 | KernelDistribution.newDefaultKernelDistribution()); 12 | 13 | protected KernelDistribution kernelDistribution; 14 | 15 | @Override 16 | public void initAndValidate() { 17 | kernelDistribution = kernelDistributionInput.get(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/nexus/traitlab.nex: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | [file format produced by TraitLab] 3 | 4 | BEGIN DATA; 5 | 6 | DIMENSIONS NTAX=9 NCHAR=30; 7 | FORMAT MISSING=? GAP=- INTERLEAVE ; 8 | 9 | MATRIX 10 | 11 | taxon_1 00?1111010110101000101001?0000 12 | taxon_2 101111010?11001111001011011000 13 | taxon_3 01101101??1110111?001010011000 14 | taxon_4 010111100111011100110000100100 15 | taxon_5 110111101111011??0110100100100 16 | taxon_6 111111010111?01111001011011011 17 | taxon_7 1111???101101011110??011011011 18 | taxon_8 111111000111101110001011011011 19 | taxon_9 11111101?111101111001011?11011 20 | ; 21 | END; 22 | 23 | BEGIN CLADES; 24 | 25 | CLADE NAME = Clade_1 26 | ROOTMIN = 346 27 | ROOTMAX = 422 28 | TAXA = taxon_4, taxon_5; 29 | 30 | CLADE NAME = Clade_2 31 | ORIGINATEMIN = 346 32 | TAXA = taxon_1, taxon_8, taxon_9; 33 | 34 | END; 35 | 36 | -------------------------------------------------------------------------------- /release/common/tools/DensiTree_launch4j.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ./DensiTree.ico 4 | 5 | viz.DensiTree 6 | ./DensiTree.jar 7 | 8 | 9 | 10 | 1.8.0 11 | 256 12 | 4096 13 | -Duser.language=en 14 | 15 | 16 | DensiTree 17 | http://compevol.auckland.ac.nz/software/DensiTree/ 18 | DensiTree 19 | DensiTree 20 | DensiTree.exe 21 | 22 | 23 | -------------------------------------------------------------------------------- /release/Windows/AppLauncher_launch4j.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/utility.ico 4 | 5 | beast.pkgmgmt.launcher.AppLauncherLauncher 6 | ./lib/launcher.jar 7 | 8 | 9 | 10 | 1.6.0 11 | 256 12 | 8096 13 | -Duser.language=en 14 | 15 | 16 | AppLauncher 17 | Beast 2 development team 2002-2022 18 | AppLauncher 19 | AppLauncher 20 | AppLauncher.exe 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/beast/base/evolution/distance/HammingDistance.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.distance; 2 | 3 | import beast.base.core.Description; 4 | 5 | 6 | @Description("Hamming distance is the mean number of characters that differ between sequences. " + 7 | "Note that unknowns are not ignored, so if both are unknowns '?' the distance is zero.") 8 | public class HammingDistance extends Distance.Base { 9 | 10 | @Override 11 | public double pairwiseDistance(int taxon1, int taxon2) { 12 | double dist = 0; 13 | for (int i = 0; i < patterns.getPatternCount(); i++) { 14 | if (patterns.getPattern(taxon1, i) != patterns.getPattern(taxon2, i)) { 15 | dist += patterns.getPatternWeight(i); 16 | } 17 | } 18 | return dist / patterns.getSiteCount(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /release/common/tools/DensiTree_launch4j_jre.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ./DensiTree.ico 4 | 5 | viz.DensiTree 6 | ./DensiTree.jar 7 | 8 | 9 | 10 | 1.8.0 11 | 256 12 | 4096 13 | -Duser.language=en 14 | jre 15 | 16 | 17 | DensiTree 18 | http://compevol.auckland.ac.nz/software/DensiTree/ 19 | DensiTree 20 | DensiTree 21 | DensiTree.exe 22 | 23 | 24 | -------------------------------------------------------------------------------- /release/Windows/LogCombiner_launch4j_jre.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/utility.ico 4 | 5 | beast.pkgmgmt.launcher.LogCombinerLauncher 6 | ./lib/launcher.jar 7 | 8 | 9 | 1.6.0 10 | 256 11 | 8096 12 | -Duser.language=en 13 | jre 14 | 15 | 16 | LogCombiner 17 | Beast 2 development team 2002-2022 18 | LogCombiner 19 | LogCombiner 20 | LogCombiner.exe 21 | 22 | 23 | -------------------------------------------------------------------------------- /release/Windows/TreeAnnotator_launch4j.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/utility.ico 4 | 5 | beast.pkgmgmt.launcher.TreeAnnotatorLauncher 6 | ./lib/launcher.jar 7 | 8 | 9 | 1.6.0 10 | 256 11 | 8096 12 | -Duser.language=en 13 | 14 | 15 | TreeAnnotator 16 | Beast 2 development team 2002-2022 17 | TreeAnnotator 18 | TreeAnnotator 19 | TreeAnnotator.exe 20 | 21 | 22 | -------------------------------------------------------------------------------- /release/Windows/TreeAnnotator_launch4j_jre.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/utility.ico 4 | 5 | beast.pkgmgmt.launcher.TreeAnnotatorLauncher 6 | ./lib/launcher.jar 7 | 8 | 9 | 1.6.0 10 | 256 11 | 8096 12 | -Duser.language=en 13 | jre 14 | 15 | 16 | TreeAnnotator 17 | Beast 2 development team 2002-2022 18 | TreeAnnotator 19 | TreeAnnotator 20 | TreeAnnotator.exe 21 | 22 | 23 | -------------------------------------------------------------------------------- /release/Windows/AppLauncher_launch4j_jre.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/utility.ico 4 | 5 | beast.pkgmgmt.launcher.AppLauncherLauncher 6 | ./lib/launcher.jar 7 | 8 | 9 | 10 | 1.6.0 11 | 256 12 | 8096 13 | -Duser.language=en 14 | jre 15 | 16 | 17 | AppLauncher 18 | Beast 2 development team 2002-2022 19 | AppLauncher 20 | AppLauncher 21 | AppLauncher.exe 22 | 23 | 24 | -------------------------------------------------------------------------------- /release/Windows/LogCombiner_launch4j.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/utility.ico 4 | 5 | beast.pkgmgmt.launcher.LogCombinerLauncher 6 | ./lib/launcher.jar 7 | 8 | 9 | 10 | 1.6.0 11 | 256 12 | 8096 13 | -Duser.language=en 14 | 15 | 16 | LogCombiner 17 | Beast 2 development team 2002-2022 18 | LogCombiner 19 | LogCombiner 20 | LogCombiner.exe 21 | 22 | 23 | -------------------------------------------------------------------------------- /release/Windows/BEAUti_launch4j.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/beauti.ico 4 | 5 | beast.pkgmgmt.launcher.BeautiLauncher 6 | ./lib/launcher.jar 7 | 8 | -capture 9 | 10 | 1.6.0 11 | 256 12 | 8096 13 | -Duser.language=en 14 | -Dfile.encoding=UTF-8 15 | 16 | 17 | BEAUti2 18 | Beast 2 development team 2002-2022 19 | BEAUti2 20 | BEAUti2 21 | BEAUti2.exe 22 | 23 | 24 | -------------------------------------------------------------------------------- /release/Windows/BEAUti_launch4j_jre.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/beauti.ico 4 | 5 | beast.pkgmgmt.launcher.BeautiLauncher 6 | ./lib/launcher.jar 7 | 8 | -capture 9 | 10 | 1.6.0 11 | 256 12 | 8096 13 | -Duser.language=en 14 | -Dfile.encoding=UTF-8 15 | jre 16 | 17 | 18 | BEAUti2 19 | Beast 2 development team 2002-2022 20 | BEAUti2 21 | BEAUti2 22 | BEAUti2.exe 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/test/beast/beast2vs1/trace/TraceType.java: -------------------------------------------------------------------------------- 1 | package test.beast.beast2vs1.trace; 2 | 3 | /** 4 | * @author Alexei Drummond 5 | * @author Walter Xie 6 | */ 7 | public enum TraceType { 8 | DOUBLE("double", "D", Double.class), 9 | INTEGER("integer", "I", Integer.class), 10 | STRING("string", "S", String.class); 11 | 12 | TraceType(String name, String brief, Class type) { 13 | this.name = name; 14 | this.brief = brief; 15 | this.type = type; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return name; 21 | } 22 | 23 | public String getBrief() { 24 | return brief; 25 | } 26 | 27 | public Class getType() { 28 | return type; 29 | } 30 | 31 | private final String name; 32 | private final String brief; 33 | private final Class type; 34 | } 35 | -------------------------------------------------------------------------------- /release/Linux/jrebin/packagemanager: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$BEAST" ]; then 4 | ## resolve links - $0 may be a link to application 5 | PRG="$0" 6 | 7 | # need this for relative symlinks 8 | while [ -h "$PRG" ] ; do 9 | ls=`ls -ld "$PRG"` 10 | link=`expr "$ls" : '.*-> \(.*\)$'` 11 | if expr "$link" : '/.*' > /dev/null; then 12 | PRG="$link" 13 | else 14 | PRG="`dirname "$PRG"`/$link" 15 | fi 16 | done 17 | 18 | # make it fully qualified 19 | saveddir=`pwd` 20 | BEAST0=`dirname "$PRG"`/.. 21 | BEAST=`cd "$BEAST0" && pwd` 22 | cd "$saveddir" 23 | fi 24 | 25 | BEAST_LIB="$BEAST/lib" 26 | export JAVA_HOME="$BEAST/jre" 27 | 28 | if [ -z "$JAVA_HOME" ]; then 29 | JAVA=java 30 | else 31 | JAVA="$JAVA_HOME"/bin/java 32 | fi 33 | "$JAVA" -Xss256m -Xmx8g -Djava.library.path="$BEAST_LIB" -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.PackageManager $* 34 | 35 | -------------------------------------------------------------------------------- /release/Windows/BEAST_launch4j.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/beast.ico 4 | 5 | beast.pkgmgmt.launcher.BeastLauncher 6 | ./lib/launcher.jar 7 | 8 | -window -working -options 9 | 10 | 1.6.0 11 | 256 12 | 8096 13 | -Duser.language=en 14 | -Dfile.encoding=UTF-8 15 | 16 | 17 | BEAST2 18 | Beast 2 development team 2002-2022 19 | BEAST2 20 | BEAST2 21 | BEAST2.exe 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/beast/base/evolution/datatype/TwoStateCovarion.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.datatype; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.evolution.datatype.DataType.Base; 5 | 6 | @Description("Datatype for two state covarion sequences") 7 | public class TwoStateCovarion extends Base { 8 | int[][] x = { 9 | {0, 2}, // 0 10 | {1, 3}, // 1 11 | {0}, // a 12 | {1}, // b 13 | {2}, // c 14 | {3}, // d 15 | {0, 1, 2, 3}, // - 16 | {0, 1, 2, 3}, // ? 17 | }; 18 | 19 | public TwoStateCovarion() { 20 | stateCount = 4; 21 | mapCodeToStateSet = x; 22 | codeLength = 1; 23 | codeMap = "01ABCD" + GAP_CHAR + MISSING_CHAR; 24 | } 25 | 26 | @Override 27 | public String getTypeDescription() { 28 | return "twoStateCovarion"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/parameterised/README.md: -------------------------------------------------------------------------------- 1 | Run with BEAST using the -D and -DF options. 2 | 3 | The -D option specifies attribute-value pairs to be replaced in the XML, e.g., `-D arg1=10,arg2=20` 4 | The -DF option is as -D, but has attribute-value pairs defined in file in JSON format 5 | 6 | Note that the `$(filebase)` definition is automatically replaced by the base name of the XML file. 7 | 8 | 9 | To run the RSV2.xml example in this directory with a chain length of 1000000 and alignment and date trait defined in RSV2.json, on OS X and Linux: 10 | 11 | ''' 12 | /path/to/beast/bin/beast -D chainLength=1000000 -DF RSV2.json RSV2.xml 13 | ''' 14 | 15 | where `/path/to/beast` the path to where BEAST is installed. 16 | 17 | To run on Windows: 18 | 19 | ''' 20 | \path\to\beast\bat\beast.bat -D chainLength=1000000 -DF RSV2.json RSV2.xml 21 | ''' 22 | 23 | where `\path\to\beast` the path to where BEAST is installed. 24 | 25 | -------------------------------------------------------------------------------- /release/Windows/BEAST_launch4j_jre.xml: -------------------------------------------------------------------------------- 1 | 2 | gui 3 | ../common/icons/beast.ico 4 | 5 | beast.pkgmgmt.launcher.BeastLauncher 6 | ./lib/launcher.jar 7 | 8 | -window -working -options 9 | 10 | 1.6.0 11 | 256 12 | 8096 13 | -Duser.language=en 14 | -Dfile.encoding=UTF-8 15 | jre 16 | 17 | 18 | BEAST2 19 | Beast 2 development team 2002-2022 20 | BEAST2 21 | BEAST2 22 | BEAST2.exe 23 | 24 | 25 | -------------------------------------------------------------------------------- /test/test/beast/core/PrimitiveInterface.java: -------------------------------------------------------------------------------- 1 | package test.beast.core; 2 | 3 | 4 | import beast.base.core.BEASTObject; 5 | import beast.base.core.Description; 6 | import beast.base.core.Param; 7 | 8 | @Description("PrimitiveInterface is used for testing inner class inside interface") 9 | public interface PrimitiveInterface { 10 | 11 | 12 | @Description("InterfaceInnerClass is used for testing inner class inside interface") 13 | public class InterfaceInnerClass extends BEASTObject implements PrimitiveInterface { 14 | private int i; 15 | 16 | public InterfaceInnerClass(@Param(name="i", description="input of primitive type") int i) { 17 | this.i = i; 18 | } 19 | 20 | public InterfaceInnerClass() {} 21 | 22 | @Override 23 | public void initAndValidate() { 24 | } 25 | 26 | public int getI() { 27 | return i; 28 | } 29 | public void setI(int i) { 30 | this.i = i; 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /release/Linux/jrebin/densitree: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$BEAST" ]; then 4 | ## resolve links - $0 may be a link to application 5 | PRG="$0" 6 | 7 | # need this for relative symlinks 8 | while [ -h "$PRG" ] ; do 9 | ls=`ls -ld "$PRG"` 10 | link=`expr "$ls" : '.*-> \(.*\)$'` 11 | if expr "$link" : '/.*' > /dev/null; then 12 | PRG="$link" 13 | else 14 | PRG="`dirname "$PRG"`/$link" 15 | fi 16 | done 17 | 18 | # make it fully qualified 19 | saveddir=`pwd` 20 | BEAST0=`dirname "$PRG"`/.. 21 | BEAST=`cd "$BEAST0" && pwd` 22 | cd "$saveddir" 23 | fi 24 | 25 | BEAST_LIB="$BEAST/lib" 26 | export JAVA_HOME="$BEAST/jre" 27 | 28 | if [ -z "$JAVA_HOME" ]; then 29 | JAVA=java 30 | else 31 | JAVA="$JAVA_HOME"/bin/java 32 | fi 33 | "$JAVA" -Xss256m -Xmx8g -Djava.library.path="$BEAST_LIB" -cp "$BEAST_LIB/DensiTree.jar:$BEAST/DensiTree.app/Contents/Resources/Java/DensiTree.jar" viz.DensiTree $* 34 | 35 | -------------------------------------------------------------------------------- /src/beast/base/evolution/branchratemodel/BranchRateModel.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.branchratemodel; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.core.Function; 5 | import beast.base.core.Input; 6 | import beast.base.evolution.tree.Node; 7 | import beast.base.inference.CalculationNode; 8 | 9 | /** 10 | * @author Alexei Drummond 11 | */ 12 | @Description("Defines a mean rate for each branch in the beast.tree.") 13 | public interface BranchRateModel { 14 | 15 | public double getRateForBranch(Node node); 16 | 17 | @Description(value = "Base implementation of a clock model.", isInheritable = false) 18 | public abstract class Base extends CalculationNode implements BranchRateModel { 19 | final public Input meanRateInput = new Input<>("clock.rate", "mean clock rate (defaults to 1.0)"); 20 | 21 | // empty at the moment but brings together the required interfaces 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/TreeMetric.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.tree; 2 | 3 | /** 4 | * @author Alexei Drummond 5 | */ 6 | public interface TreeMetric { 7 | 8 | /** 9 | * Distance between two trees that may have different taxa sets but must have an overlap of taxa. 10 | * @param tree1 11 | * @param tree2 12 | * @return 13 | */ 14 | public double distance(TreeInterface tree1, TreeInterface tree2); 15 | 16 | 17 | /** 18 | * Distance between a tree and a reference tree. Must set the reference tree first using setReference 19 | * @param tree1 20 | * @return 21 | */ 22 | public double distance(TreeInterface tree); 23 | 24 | 25 | /** 26 | * Set the reference tree and cache. Faster than calling distance(tree1, tree2) everytime 27 | * @param ref 28 | */ 29 | public void setReference(TreeInterface ref); 30 | 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /release/Linux/jrebin/logcombiner: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$BEAST" ]; then 4 | ## resolve links - $0 may be a link to application 5 | PRG="$0" 6 | 7 | # need this for relative symlinks 8 | while [ -h "$PRG" ] ; do 9 | ls=`ls -ld "$PRG"` 10 | link=`expr "$ls" : '.*-> \(.*\)$'` 11 | if expr "$link" : '/.*' > /dev/null; then 12 | PRG="$link" 13 | else 14 | PRG="`dirname "$PRG"`/$link" 15 | fi 16 | done 17 | 18 | # make it fully qualified 19 | saveddir=`pwd` 20 | BEAST0=`dirname "$PRG"`/.. 21 | BEAST=`cd "$BEAST0" && pwd` 22 | cd "$saveddir" 23 | fi 24 | 25 | BEAST_LIB="$BEAST/lib" 26 | export JAVA_HOME="$BEAST/jre" 27 | 28 | if [ -z "$JAVA_HOME" ]; then 29 | JAVA=java 30 | else 31 | JAVA="$JAVA_HOME"/bin/java 32 | fi 33 | "$JAVA" -Dlauncher.wait.for.exit=true -Xss256m -Xmx8g -Djava.library.path="$BEAST_LIB" -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.launcher.LogCombinerLauncher $* 34 | 35 | -------------------------------------------------------------------------------- /release/Linux/jrebin/treeannotator: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$BEAST" ]; then 4 | ## resolve links - $0 may be a link to application 5 | PRG="$0" 6 | 7 | # need this for relative symlinks 8 | while [ -h "$PRG" ] ; do 9 | ls=`ls -ld "$PRG"` 10 | link=`expr "$ls" : '.*-> \(.*\)$'` 11 | if expr "$link" : '/.*' > /dev/null; then 12 | PRG="$link" 13 | else 14 | PRG="`dirname "$PRG"`/$link" 15 | fi 16 | done 17 | 18 | # make it fully qualified 19 | saveddir=`pwd` 20 | BEAST0=`dirname "$PRG"`/.. 21 | BEAST=`cd "$BEAST0" && pwd` 22 | cd "$saveddir" 23 | fi 24 | 25 | BEAST_LIB="$BEAST/lib" 26 | export JAVA_HOME="$BEAST/jre" 27 | 28 | if [ -z "$JAVA_HOME" ]; then 29 | JAVA=java 30 | else 31 | JAVA="$JAVA_HOME"/bin/java 32 | fi 33 | "$JAVA" -Dlauncher.wait.for.exit=true -Xss256m -Xmx8g -Djava.library.path="$BEAST_LIB" -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.launcher.TreeAnnotatorLauncher $* 34 | 35 | -------------------------------------------------------------------------------- /release/Linux/jrebin/beauti: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$BEAST" ]; then 4 | ## resolve links - $0 may be a link to application 5 | PRG="$0" 6 | 7 | # need this for relative symlinks 8 | while [ -h "$PRG" ] ; do 9 | ls=`ls -ld "$PRG"` 10 | link=`expr "$ls" : '.*-> \(.*\)$'` 11 | if expr "$link" : '/.*' > /dev/null; then 12 | PRG="$link" 13 | else 14 | PRG="`dirname "$PRG"`/$link" 15 | fi 16 | done 17 | 18 | # make it fully qualified 19 | saveddir=`pwd` 20 | BEAST0=`dirname "$PRG"`/.. 21 | BEAST=`cd "$BEAST0" && pwd` 22 | cd "$saveddir" 23 | fi 24 | 25 | BEAST_LIB="$BEAST/lib" 26 | export JAVA_HOME="$BEAST/jre" 27 | 28 | if [ -z "$JAVA_HOME" ]; then 29 | JAVA=java 30 | else 31 | JAVA="$JAVA_HOME"/bin/java 32 | fi 33 | 34 | "$JAVA" -Dlauncher.wait.for.exit=true -Xss256m -Xmx8g -Djava.library.path="$BEAST_LIB" -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.launcher.BeautiLauncher -capture $* 35 | 36 | -------------------------------------------------------------------------------- /examples/benchmark/mrbayes/experiment.sh: -------------------------------------------------------------------------------- 1 | echo FILE M1044 > times.dat 2 | time mb < run1044.nex >> times.dat 2>&1 3 | echo FILE M1366 >> times.dat 4 | time mb < run1366.nex >> times.dat 2>&1 5 | echo FILE M1510 >> times.dat 6 | time mb < run1510.nex >> times.dat 2>&1 7 | echo FILE M1748 >> times.dat 8 | time mb < run1748.nex >> times.dat 2>&1 9 | echo FILE M1749 >> times.dat 10 | time mb < run1749.nex >> times.dat 2>&1 11 | echo FILE M1809 >> times.dat 12 | time mb < run1809.nex >> times.dat 2>&1 13 | echo FILE M336 >> times.dat 14 | time mb < run336.nex >> times.dat 2>&1 15 | echo FILE M3475 >> times.dat 16 | time mb < run3475.nex >> times.dat 2>&1 17 | echo FILE M501 >> times.dat 18 | time mb < run501.nex >> times.dat 2>&1 19 | echo FILE M520 >> times.dat 20 | time mb < run520.nex >> times.dat 2>&1 21 | echo FILE M755 >> times.dat 22 | time mb < run755.nex >> times.dat 2>&1 23 | echo FILE M767 >> times.dat 24 | time mb < run767.nex >> times.dat 2>&1 25 | -------------------------------------------------------------------------------- /src/beast/base/evolution/distance/SMMDistance.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.distance; 2 | 3 | import beast.base.core.Description; 4 | 5 | 6 | /** 7 | * @author Chieh-Hsi Wu 8 | */ 9 | @Description("Calculate the distance between different microsatellite alleles") 10 | public class SMMDistance extends Distance.Base { 11 | 12 | /** 13 | * constructor taking a pattern source 14 | * 15 | * @param patterns a pattern of a microsatellite locus 16 | */ 17 | @Override 18 | public double pairwiseDistance(int taxon1, int taxon2) { 19 | 20 | int[] pattern = patterns.getPattern(0); 21 | int state1 = pattern[taxon1]; 22 | 23 | int state2 = pattern[taxon2]; 24 | double distance = 0.0; 25 | 26 | if (!dataType.isAmbiguousCode(state1) && !dataType.isAmbiguousCode(state2)) 27 | distance = Math.abs(state1 - state2); 28 | 29 | return distance; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/testDirectSimulator2.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/beast/base/evolution/datatype/IntegerData.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.datatype; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.evolution.datatype.DataType.Base; 5 | 6 | @Description("Datatype for integer sequences") 7 | public class IntegerData extends Base { 8 | 9 | public IntegerData() { 10 | stateCount = -1; 11 | mapCodeToStateSet = null; 12 | codeLength = -1; 13 | codeMap = null; 14 | } 15 | 16 | @Override 17 | public String getTypeDescription() { 18 | return "integer"; 19 | } 20 | 21 | @Override 22 | public boolean isAmbiguousCode(int code) { 23 | return code < 0; 24 | } 25 | 26 | @Override 27 | public String getCharacter(int code) { 28 | if (code < 0) { 29 | return "?"; 30 | } 31 | return code + ""; 32 | } 33 | 34 | @Override 35 | public int[] getStatesForCode(int code) { 36 | return new int[]{code}; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/beast/pkgmgmt/launcher/BeautiLauncher.java: -------------------------------------------------------------------------------- 1 | package beast.pkgmgmt.launcher; 2 | 3 | 4 | 5 | import java.io.IOException; 6 | import java.lang.reflect.InvocationTargetException; 7 | 8 | /** 9 | * Loads beast.jar and launches BEAUti through the Beauti class 10 | * 11 | * This class should be compiled against 1.6 and packaged by itself. 12 | * The remained of BEAST can be compiled against Java 1.8 13 | * **/ 14 | public class BeautiLauncher extends BeastLauncher { 15 | 16 | public static void main(String[] args) throws NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException { 17 | // Utils6.startSplashScreen(); 18 | if (javaVersionCheck("BEAUti")) { 19 | // loadBEASTJars(); 20 | BeastLauncher.testCudaStatusOnMac(); 21 | String classpath = getPath(false, null); 22 | run(classpath, "beastfx.app.beauti.Beauti", args); 23 | } 24 | // Utils6.endSplashScreen(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/benchmark/1/experiment.sh: -------------------------------------------------------------------------------- 1 | echo FILE M1044 > times.dat 2 | time beast testHKY1044.xml >> times.dat 2>&1 3 | echo FILE M1366 >> times.dat 4 | time beast testHKY1366.xml >> times.dat 2>&1 5 | echo FILE M1510 >> times.dat 6 | time beast testHKY1510.xml >> times.dat 2>&1 7 | echo FILE M1748 >> times.dat 8 | time beast testHKY1748.xml >> times.dat 2>&1 9 | echo FILE M1749 >> times.dat 10 | time beast testHKY1749.xml >> times.dat 2>&1 11 | echo FILE M1809 >> times.dat 12 | time beast testHKY1809.xml >> times.dat 2>&1 13 | echo FILE M336 >> times.dat 14 | time beast testHKY336.xml >> times.dat 2>&1 15 | echo FILE M3475 >> times.dat 16 | time beast testHKY3475.xml >> times.dat 2>&1 17 | echo FILE M501 >> times.dat 18 | time beast testHKY501.xml >> times.dat 2>&1 19 | echo FILE M520 >> times.dat 20 | time beast testHKY520.xml >> times.dat 2>&1 21 | echo FILE M755 >> times.dat 22 | time beast testHKY755.xml >> times.dat 2>&1 23 | echo FILE M767 >> times.dat 24 | time beast testHKY767.xml >> times.dat 2>&1 25 | -------------------------------------------------------------------------------- /src/beast/base/core/Loggable.java: -------------------------------------------------------------------------------- 1 | package beast.base.core; 2 | 3 | import java.io.PrintStream; 4 | 5 | /** 6 | * @author Andrew Rambaut 7 | * @version $Id$ 8 | */ 9 | 10 | /** 11 | * interface for items that can be logged through a Logger * 12 | */ 13 | public interface Loggable { 14 | 15 | /** 16 | * write header information, e.g. labels of a parameter, 17 | * or Nexus tree preamble 18 | * 19 | * @param out log stream 20 | */ 21 | void init(PrintStream out); 22 | 23 | /** 24 | * log this sample for current state to PrintStream, 25 | * e.g. value of a parameter, list of parameters or Newick tree 26 | * 27 | * @param sample chain sample number 28 | * @param out log stream 29 | */ 30 | void log(long sample, PrintStream out); 31 | 32 | /** 33 | * close log. An end of log message can be left (as in End; for Nexus trees) 34 | * 35 | * @param out log stream 36 | */ 37 | void close(PrintStream out); 38 | } 39 | -------------------------------------------------------------------------------- /test/test/beast/evolution/tree/TreeUtilsTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.tree; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import beast.base.evolution.tree.TreeParser; 7 | import beast.base.evolution.tree.TreeUtils; 8 | 9 | /** 10 | * Test class for TreeUtils methods 11 | */ 12 | public class TreeUtilsTest { 13 | 14 | @Test 15 | public void testSortTreeAlphabetically() { 16 | 17 | String newick = "((D:5.0,C:4.0):6.0,(A:1.0,B:2.0):3.0):0.0;"; 18 | 19 | TreeParser treeParser = new TreeParser(); 20 | treeParser.initByName("IsLabelledNewick", true, 21 | "newick", newick, 22 | "adjustTipHeights", false); 23 | 24 | 25 | TreeUtils.rotateTreeAlphabetically(treeParser.getRoot()); 26 | 27 | String result = treeParser.getRoot().toNewick(); 28 | String goal = "((A:1.0,B:2.0):3.0,(C:4.0,D:5.0):6.0):0.0"; 29 | 30 | assertEquals(goal, result); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/beast/base/evolution/datatype/Aminoacid.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.datatype; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.evolution.datatype.DataType.Base; 5 | 6 | @Description("DataType for amino acids.") 7 | public class Aminoacid extends Base { 8 | 9 | public Aminoacid() { 10 | stateCount = 20; 11 | codeLength = 1; 12 | codeMap = "ACDEFGHIKLMNPQRSTVWY" + "X" + GAP_CHAR + MISSING_CHAR; 13 | 14 | mapCodeToStateSet = new int[23][]; 15 | for (int i = 0; i < 20; i++) { 16 | mapCodeToStateSet[i] = new int[1]; 17 | mapCodeToStateSet[i][0] = i; 18 | } 19 | int[] all = new int[20]; 20 | for (int i = 0; i < 20; i++) { 21 | all[i] = i; 22 | } 23 | mapCodeToStateSet[20] = all; 24 | mapCodeToStateSet[21] = all; 25 | mapCodeToStateSet[22] = all; 26 | } 27 | 28 | @Override 29 | public String getTypeDescription() { 30 | return "aminoacid"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /test/test/beast/evolution/datatype/IntegerDataTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.datatype; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import beast.base.evolution.datatype.IntegerData; 6 | import beast.base.util.Randomizer; 7 | import static org.junit.jupiter.api.Assertions.assertEquals;; 8 | 9 | public class IntegerDataTest { 10 | 11 | 12 | @Test 13 | public void testIntegerData() { 14 | IntegerData datatype = new IntegerData(); 15 | assertEquals("?", datatype.getCharacter(-1)); 16 | assertEquals("0", datatype.getCharacter(0)); 17 | assertEquals("1", datatype.getCharacter(1)); 18 | assertEquals("10", datatype.getCharacter(10)); 19 | assertEquals("123", datatype.getCharacter(123)); 20 | Randomizer.setSeed(127); 21 | for (int i = 0; i < 100; i++) { 22 | int state = Randomizer.nextInt(100000000); 23 | int x = state; 24 | String str = ""; 25 | while (state > 0) { 26 | str = (char)('0' + state%10) + str; 27 | state /= 10; 28 | } 29 | assertEquals(str, datatype.getCharacter(x)); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/test/beast/util/RandomizerTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.util; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import beast.base.util.DiscreteStatistics; 6 | import beast.base.util.Randomizer; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | public class RandomizerTest { 11 | 12 | @Test 13 | public void logNormalTest() { 14 | 15 | Randomizer.setSeed(1); 16 | 17 | double M1=1, M2=0, S=0.5; 18 | 19 | int reps=10000000; 20 | 21 | double [] vals1 = new double[reps]; 22 | double [] vals2 = new double[reps]; 23 | 24 | for (int i=0; i 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /release/Mac/README.md: -------------------------------------------------------------------------------- 1 | # Mac Release 2 | 3 | Last update 28-07-2020 4 | 5 | 6 | ## No JRE 7 | 8 | 1. `ant mac` and then check all messages. 9 | 10 | This will build the disk image and do the notarization. 11 | 12 | 2. `cd ~/tmp` to find _BEAST.v2.?.?.dmg_. 13 | 14 | Note: this path is depend on the path of beast2 project, which is equivalent to `beast2/../../tmp`. 15 | 16 | 3. `xcrun altool --notarization-info *-*-*-*-* -u username -p passwd` 17 | 18 | 4. `xcrun stapler staple BEAST.v2.?.?.dmg` 19 | 20 | 5. upload dmg to Github. 21 | 22 | 23 | ## With JRE 24 | 25 | 1. `ant macjre` and then check all messages. 26 | 27 | 2. `cd ~/tmp` to find _BEAST\_with\_JRE.v2.?.?.dmg_. 28 | 29 | 3. `xcrun altool --notarization-info *-*-*-*-* -u username -p passwd` 30 | 31 | 4. `xcrun stapler staple BEAST_with_JRE.v2.?.?.dmg` 32 | 33 | 5. upload dmg to Github. 34 | 35 | 36 | ## Workflow 37 | 38 | Refer to https://stackoverflow.com/questions/53112078/how-to-upload-dmg-file-for-notarization-in-xcode 39 | 40 | 41 | ## TODO 42 | 43 | 1. the hard code of JRE path in `universalJavaApplicationJREStub` must match JRE path in the `build.xml` 44 | 45 | 46 | -------------------------------------------------------------------------------- /examples/benchmark/II/experiment.sh: -------------------------------------------------------------------------------- 1 | echo FILE M1044 > times.dat 2 | time beastII -overwrite testHKY1044.xml >> times.dat 2>&1 3 | echo FILE M1366 >> times.dat 4 | time beastII -overwrite testHKY1366.xml >> times.dat 2>&1 5 | echo FILE M1510 >> times.dat 6 | time beastII -overwrite testHKY1510.xml >> times.dat 2>&1 7 | echo FILE M1748 >> times.dat 8 | time beastII -overwrite testHKY1748.xml >> times.dat 2>&1 9 | echo FILE M1749 >> times.dat 10 | time beastII -overwrite testHKY1749.xml >> times.dat 2>&1 11 | echo FILE M1809 >> times.dat 12 | time beastII -overwrite testHKY1809.xml >> times.dat 2>&1 13 | echo FILE M336 >> times.dat 14 | time beastII -overwrite testHKY336.xml >> times.dat 2>&1 15 | echo FILE M3475 >> times.dat 16 | time beastII -overwrite testHKY3475.xml >> times.dat 2>&1 17 | echo FILE M501 >> times.dat 18 | time beastII -overwrite testHKY501.xml >> times.dat 2>&1 19 | echo FILE M520 >> times.dat 20 | time beastII -overwrite testHKY520.xml >> times.dat 2>&1 21 | echo FILE M755 >> times.dat 22 | time beastII -overwrite testHKY755.xml >> times.dat 2>&1 23 | echo FILE M767 >> times.dat 24 | time beastII -overwrite testHKY767.xml >> times.dat 2>&1 25 | -------------------------------------------------------------------------------- /src/beast/base/core/BEASTVersion2.java: -------------------------------------------------------------------------------- 1 | package beast.base.core; 2 | 3 | import beast.pkgmgmt.BEASTVersion; 4 | 5 | /** 6 | * This is a duplicate of BEASTVersion, however the BEASTVersion class should be used by BEASTLauncher 7 | * and derivatives, but this class should be used in any other place 8 | * */ 9 | public class BEASTVersion2 extends BEASTVersion { 10 | 11 | /** 12 | * Version string: assumed to be in format x.x.x 13 | */ 14 | private static final String VERSION = "2.7.8"; 15 | 16 | private static final String DATE_STRING = "2002-2025"; 17 | 18 | private static final boolean IS_PRERELEASE = true; 19 | // 20 | // private static final String BEAST2_WEBPAGE = "http://beast2.org/"; 21 | // 22 | // private static final String BEAST2_SOURCE = "http://github.com/CompEvol/beast2"; 23 | // 24 | @Override 25 | public String getVersion() { 26 | return VERSION; 27 | } 28 | 29 | @Override 30 | public String getVersionString() { 31 | return "v" + VERSION + (IS_PRERELEASE ? " Prerelease" : ""); 32 | } 33 | 34 | @Override 35 | public String getDateString() { 36 | return DATE_STRING; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/beast/base/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package beast.base.util; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | 9 | public class FileUtils { 10 | 11 | 12 | static public String load(String fileName) throws IOException { 13 | return load(new File(fileName)); 14 | } // load 15 | 16 | static public String load(File file) throws IOException { 17 | BufferedReader fin = new BufferedReader(new FileReader(file)); 18 | StringBuffer buf = new StringBuffer(); 19 | String str = null; 20 | while (fin.ready()) { 21 | str = fin.readLine(); 22 | buf.append(str); 23 | buf.append('\n'); 24 | } 25 | fin.close(); 26 | return buf.toString(); 27 | } // load 28 | 29 | 30 | public void save(String fileName, String text) throws IOException { 31 | save(new File(fileName), text); 32 | } // save 33 | 34 | public void save(File file, String text) throws IOException { 35 | FileWriter outfile = new FileWriter(file); 36 | outfile.write(text); 37 | outfile.close(); 38 | } // save 39 | } 40 | -------------------------------------------------------------------------------- /src/beast/base/evolution/datatype/Nucleotide.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.datatype; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.evolution.datatype.DataType.Base; 5 | 6 | @Description("Nucleotide datatype for DNA sequences") 7 | public class Nucleotide extends Base { 8 | int[][] x = { 9 | {0}, // A 10 | {1}, // C 11 | {2}, // G 12 | {3}, // T 13 | {3}, // U 14 | {0, 2}, // R 15 | {1, 3}, // Y 16 | {0, 1}, // M 17 | {0, 3}, // W 18 | {1, 2}, // S 19 | {2, 3}, // K 20 | {1, 2, 3}, // B 21 | {0, 2, 3}, // D 22 | {0, 1, 3}, // H 23 | {0, 1, 2}, // V 24 | {0, 1, 2, 3}, // N 25 | {0, 1, 2, 3}, // X 26 | {0, 1, 2, 3}, // - 27 | {0, 1, 2, 3}, // ? 28 | }; 29 | 30 | public Nucleotide() { 31 | stateCount = 4; 32 | mapCodeToStateSet = x; 33 | codeLength = 1; 34 | codeMap = "ACGTURYMWSKBDHVNX" + GAP_CHAR + MISSING_CHAR; 35 | } 36 | 37 | @Override 38 | public String getTypeDescription() { 39 | return "nucleotide"; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/treeparser/NewickLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar NewickLexer; 2 | 3 | // Default mode rules 4 | 5 | SEMI: ';' ; 6 | COMMA: ',' ; 7 | OPENP: '(' ; 8 | CLOSEP: ')' ; 9 | COLON: ':' ; 10 | 11 | FLOAT_SCI: '-'? ((NNINT? ('.' D+)) | (NNINT ('.' D+)?)) ([eE] ('-'|'+')? D+); 12 | FLOAT : '-'? ((NNINT? ('.' D+)) | (NNINT ('.' D*))); 13 | INT : '-'? NNINT; 14 | fragment NNINT : '0' | NZD D* ; 15 | fragment NZD : [1-9] ; 16 | fragment D : [0-9] ; 17 | 18 | OPENA: '[&' -> mode(ATTRIB_MODE); 19 | 20 | WHITESPACE : [ \t\r\n]+ -> skip ; 21 | 22 | STRING : 23 | [a-zA-Z0-9|#*%/.\-+_&]+ // these chars don't need quotes 24 | | '"' .*? '"' 25 | | '\'' .*? '\'' 26 | ; 27 | 28 | // Attrib mode rules 29 | 30 | mode ATTRIB_MODE; 31 | 32 | EQ: '=' ; 33 | ACOMMA: ',' ; 34 | OPENV: '{' ; 35 | CLOSEV: '}' ; 36 | 37 | AFLOAT_SCI: '-'? ((NNINT? ('.' D+)) | (NNINT ('.' D+)?)) ([eE] '-'? D+); 38 | AFLOAT : '-'? ((NNINT? ('.' D+)) | (NNINT ('.' D*))); 39 | AINT : '-'? NNINT; 40 | 41 | AWHITESPACE : [ \t\r\n]+ -> skip ; 42 | 43 | ASTRING : 44 | [a-zA-Z0-9|#*%/.\-+_&:]+ // these chars don't need quotes 45 | | '"' .*? '"' 46 | | '\'' .*? '\'' 47 | ; 48 | 49 | CLOSEA: ']' -> mode(DEFAULT_MODE); 50 | 51 | ATTRIBWS : [ \t\r\n]+ -> skip ; 52 | -------------------------------------------------------------------------------- /test/test/beast/evolution/operator/CompoundParameterHelperTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.operator; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | import beast.base.inference.operator.CompoundParameterHelper; 9 | import beast.base.inference.parameter.RealParameter; 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | public class CompoundParameterHelperTest { 13 | 14 | 15 | @Test 16 | public void testCompoundParameterHelper() { 17 | RealParameter p1 = new RealParameter("1.0 2.0"); 18 | RealParameter p2 = new RealParameter("3.0 4.0 5.0"); 19 | List list = new ArrayList<>(); 20 | list.add(p1); 21 | list.add(p2); 22 | 23 | CompoundParameterHelper cph = new CompoundParameterHelper(list); 24 | 25 | // prints 5 26 | System.out.println("Dim = " + cph.getDimension()); 27 | // results in java.lang.ArrayIndexOutOfBoundsException: 2 28 | for (int i = 0; i < cph.getDimension(); i++) { 29 | System.out.println("value[" + i + "] = " +cph.getValue(i)); 30 | } 31 | 32 | assertEquals(5, cph.getDimension()); 33 | for (int i = 0; i < 4; i++) { 34 | assertEquals(i+1.0, cph.getValue(i), 1e-15); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/testDirectSimulatorHierarchical.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/testDirichlet/testDirichletNoPrior.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 0.25 0.25 0.25 0.25 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test/test/beast/evolution/tree/coalescent/BayesianSkylineTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.tree.coalescent; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import beast.base.evolution.tree.Tree; 7 | import beast.base.evolution.tree.TreeIntervals; 8 | import beast.base.evolution.tree.coalescent.BayesianSkyline; 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | 11 | 12 | 13 | /** 14 | * @author Alexei Drummond 15 | */ 16 | public class BayesianSkylineTest { 17 | 18 | @Test 19 | public void testSkyline() throws Exception { 20 | 21 | //RealParameter popSize = new RealParameter("1.0", 0.0, 10.0, 2); 22 | //IntegerParameter groupSize = new IntegerParameter("2", 1, 4, 2); 23 | 24 | //popSize.setValue(1, 2.0); 25 | 26 | Tree tree = new Tree("(((1:1,2:1):2.5,(3:1.5,4:1.5):2):2,5:5.5);"); 27 | TreeIntervals intervals = new TreeIntervals(tree); 28 | 29 | BayesianSkyline skyline = new BayesianSkyline(); 30 | //skyline.init(popSize, groupSize, intervals); 31 | skyline.initByName("popSizes", "1.0 2.0", 32 | "groupSizes", "2 2", 33 | "treeIntervals", intervals); 34 | 35 | assertEquals(skyline.getPopSize(0.01), 1.0); 36 | assertEquals(skyline.getPopSize(1.49), 1.0); 37 | assertEquals(skyline.getPopSize(1.51), 2.0); 38 | assertEquals(skyline.getPopSize(5.51), 2.0); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/beast/base/inference/parameter/BooleanParameterList.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.parameter; 2 | 3 | import java.util.List; 4 | 5 | import beast.base.core.Description; 6 | 7 | /** 8 | * @author Tim Vaughan 9 | */ 10 | @Description("State node describing a list of boolean parameters.") 11 | public class BooleanParameterList extends GeneralParameterList { 12 | 13 | @Override 14 | public void initAndValidate() { 15 | lowerBound = false; 16 | upperBound = true; 17 | 18 | super.initAndValidate(); 19 | } 20 | 21 | @Override 22 | protected void readStateFromString(String[] boundsString, 23 | List parameterValueStrings, 24 | List keys) { 25 | 26 | lowerBound = Boolean.parseBoolean(boundsString[0]); 27 | upperBound = Boolean.parseBoolean(boundsString[1]); 28 | 29 | pList.clear(); 30 | 31 | for (int pidx=0; pidx type; 11 | 12 | /** whether this is Input or Param annotation **/ 13 | boolean isInput; 14 | 15 | /** default value when no value is specified, if any **/ 16 | Object defaultValue; 17 | 18 | /** c'tor **/ 19 | public InputType(String name, Class type, boolean isInput, Object defaultValue) { 20 | this.name = name; 21 | this.type = type; 22 | this.isInput = isInput; 23 | this.defaultValue = defaultValue; 24 | } 25 | 26 | 27 | /** getters & setters **/ 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public Class getType() { 37 | return type; 38 | } 39 | 40 | public void setType(Class type) { 41 | this.type = type; 42 | } 43 | 44 | public boolean isInput() { 45 | return isInput; 46 | } 47 | 48 | public void setInput(boolean isInput) { 49 | this.isInput = isInput; 50 | } 51 | 52 | 53 | public Object getDefaultValue() { 54 | return defaultValue; 55 | } 56 | 57 | 58 | public void setDefaultValue(Object defaultValue) { 59 | this.defaultValue = defaultValue; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return getName() + " " + getType().getName() + " " + isInput() + " " + getDefaultValue(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /test/test/beast/beast2vs1/trace/TraceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TraceException.java 3 | * 4 | * Copyright (C) 2002-2006 Alexei Drummond and Andrew Rambaut 5 | * 6 | * This file is part of BEAST. 7 | * See the NOTICE file distributed with this work for additional 8 | * information regarding copyright ownership and licensing. 9 | * 10 | * BEAST is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation; either version 2 13 | * of the License, or (at your option) any later version. 14 | * 15 | * BEAST is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with BEAST; if not, write to the 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 23 | * Boston, MA 02110-1301 USA 24 | */ 25 | 26 | package test.beast.beast2vs1.trace; 27 | 28 | /** 29 | * An exception for traces 30 | * 31 | * @author Andrew Rambaut 32 | * @author Alexei Drummond 33 | */ 34 | 35 | public class TraceException extends Exception { 36 | private static final long serialVersionUID = 1L; 37 | 38 | public TraceException() { 39 | super(); 40 | } 41 | 42 | public TraceException(String message) { 43 | super(message); 44 | } 45 | } -------------------------------------------------------------------------------- /src/org/apache/commons/math/analysis/UnivariateRealFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.analysis; 18 | 19 | import org.apache.commons.math.FunctionEvaluationException; 20 | 21 | /** 22 | * An interface representing a univariate real function. 23 | * 24 | * @version $Revision: 811786 $ $Date: 2009-09-06 05:36:08 -0400 (Sun, 06 Sep 2009) $ 25 | */ 26 | public interface UnivariateRealFunction { 27 | 28 | /** 29 | * Compute the value for the function. 30 | * 31 | * @param x the point for which the function value should be computed 32 | * @return the value 33 | * @throws FunctionEvaluationException if the function evaluation fails 34 | */ 35 | double value(double x) throws FunctionEvaluationException; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /test/test/beast/evolution/operator/ScaleOperatorTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.operator; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import beast.base.evolution.operator.ScaleOperator; 6 | import beast.base.evolution.tree.Node; 7 | import beast.base.evolution.tree.TreeParser; 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | public class ScaleOperatorTest { 11 | final static double EPSILON = 1e-10; 12 | 13 | 14 | @Test 15 | public void testTreeScaling() { 16 | String newick = "((0:1.0,1:1.0)4:1.0,(2:1.0,3:1.0)5:0.5)6:0.0;"; 17 | 18 | TreeParser tree = new TreeParser(newick, false, false, false, 0); 19 | 20 | Node [] node = tree.getNodesAsArray(); 21 | 22 | ScaleOperator operator = new ScaleOperator(); 23 | operator.initByName("tree", tree, "weight", 1.0); 24 | operator.proposal(); 25 | 26 | // leaf node 27 | node = tree.getNodesAsArray(); 28 | assertEquals(0.0, node[0].getHeight(), EPSILON); 29 | assertEquals(0.0, node[1].getHeight(), EPSILON); 30 | // leaf node, not scaled 31 | assertEquals(0.5, node[2].getHeight(), EPSILON); 32 | assertEquals(0.5, node[3].getHeight(), EPSILON); 33 | 34 | // internal nodes, all scaled 35 | // first determine scale factor 36 | double scale = node[4].getHeight() / 1.0; 37 | assertEquals(1.0 * scale, node[4].getHeight(), EPSILON); 38 | assertEquals(1.5 * scale, node[5].getHeight(), EPSILON); 39 | assertEquals(2.0 * scale, node[6].getHeight(), EPSILON); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/beast/base/inference/distribution/ChiSquare.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.distribution; 2 | 3 | 4 | import org.apache.commons.math.distribution.ChiSquaredDistributionImpl; 5 | import org.apache.commons.math.distribution.ContinuousDistribution; 6 | 7 | import beast.base.core.Description; 8 | import beast.base.core.Input; 9 | import beast.base.inference.parameter.IntegerParameter; 10 | 11 | 12 | 13 | @Description("Chi square distribution, f(x; k) = \\frac{1}{2^{k/2}Gamma(k/2)} x^{k/2-1} e^{-x/2} " + 14 | "If the input x is a multidimensional parameter, each of the dimensions is considered as a " + 15 | "separate independent component.") 16 | public class ChiSquare extends ParametricDistribution { 17 | final public Input dfInput = new Input<>("df", "degrees if freedin, defaults to 1"); 18 | 19 | org.apache.commons.math.distribution.ChiSquaredDistribution m_dist = new ChiSquaredDistributionImpl(1); 20 | 21 | @Override 22 | public void initAndValidate() { 23 | refresh(); 24 | } 25 | 26 | /** 27 | * make sure internal state is up to date * 28 | */ 29 | @SuppressWarnings("deprecation") 30 | void refresh() { 31 | int dF; 32 | if (dfInput.get() == null) { 33 | dF = 1; 34 | } else { 35 | dF = dfInput.get().getValue(); 36 | if (dF <= 0) { 37 | dF = 1; 38 | } 39 | } 40 | m_dist.setDegreesOfFreedom(dF); 41 | } 42 | 43 | @Override 44 | public ContinuousDistribution getDistribution() { 45 | refresh(); 46 | return m_dist; 47 | } 48 | 49 | } // class ChiSquare 50 | -------------------------------------------------------------------------------- /src/beast/base/math/matrixalgebra/IllegalDimension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IllegalDimension.java 3 | * 4 | * Copyright (C) 2002-2006 Alexei Drummond and Andrew Rambaut 5 | * 6 | * This file is part of BEAST. 7 | * See the NOTICE file distributed with this work for additional 8 | * information regarding copyright ownership and licensing. 9 | * 10 | * BEAST is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation; either version 2 13 | * of the License, or (at your option) any later version. 14 | * 15 | * BEAST is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with BEAST; if not, write to the 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 23 | * Boston, MA 02110-1301 USA 24 | */ 25 | 26 | package beast.base.math.matrixalgebra; 27 | 28 | /** 29 | * @author Didier H. Besset 30 | */ 31 | public class IllegalDimension extends Exception { 32 | 33 | /** 34 | * 35 | */ 36 | private static final long serialVersionUID = 8101918570370620261L; 37 | /** 38 | * DhbIllegalDimension constructor comment. 39 | */ 40 | public IllegalDimension() { 41 | super(); 42 | } 43 | /** 44 | * DhbIllegalDimension constructor comment. 45 | * @param s java.lang.String 46 | */ 47 | public IllegalDimension(String s) { 48 | super(s); 49 | } 50 | } -------------------------------------------------------------------------------- /src/beast/base/evolution/branchratemodel/StrictClockModel.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.branchratemodel; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.core.Function; 5 | import beast.base.evolution.tree.Node; 6 | import beast.base.inference.parameter.RealParameter; 7 | 8 | /** 9 | * @author Alexei Drummond 10 | */ 11 | 12 | @Description("Defines a mean rate for each branch in the beast.tree.") 13 | public class StrictClockModel extends BranchRateModel.Base { 14 | 15 | //public Input muParameterInput = new Input<>("clock.rate", "the clock rate (defaults to 1.0)"); 16 | 17 | Function muParameter; 18 | 19 | @Override 20 | public void initAndValidate() { 21 | muParameter = meanRateInput.get(); 22 | if (muParameter != null) { 23 | if (muParameter instanceof RealParameter) { 24 | RealParameter mu = (RealParameter) muParameter; 25 | mu.setBounds(Math.max(0.0, mu.getLower()), mu.getUpper()); 26 | } 27 | mu = muParameter.getArrayValue(); 28 | } 29 | } 30 | 31 | @Override 32 | public double getRateForBranch(final Node node) { 33 | return mu; 34 | } 35 | 36 | @Override 37 | public boolean requiresRecalculation() { 38 | mu = muParameter.getArrayValue(); 39 | return true; 40 | } 41 | 42 | @Override 43 | protected void restore() { 44 | mu = muParameter.getArrayValue(); 45 | super.restore(); 46 | } 47 | 48 | @Override 49 | protected void store() { 50 | mu = muParameter.getArrayValue(); 51 | super.store(); 52 | } 53 | 54 | private double mu = 1.0; 55 | } 56 | -------------------------------------------------------------------------------- /src/beast/base/math/matrixalgebra/CholeskyDecomposition.java: -------------------------------------------------------------------------------- 1 | package beast.base.math.matrixalgebra; 2 | 3 | import beast.base.core.Description; 4 | 5 | /** 6 | * Created by IntelliJ IDEA. 7 | * User: msuchard 8 | * Date: Jan 12, 2007 9 | * Time: 9:05:44 PM 10 | * To change this template use File | Settings | File Templates. 11 | */ 12 | @Description("Class ported from BEAST1") 13 | public class CholeskyDecomposition { 14 | 15 | /** 16 | * Dimension of square matrix 17 | */ 18 | private int n; 19 | 20 | public boolean isSPD() { 21 | return isspd; 22 | } 23 | 24 | /** 25 | * Symmetric and positive definite flag. 26 | */ 27 | private boolean isspd; 28 | 29 | public double[][] getL() { 30 | return L; 31 | } 32 | 33 | private double[][] L; 34 | 35 | public CholeskyDecomposition(double[][] A) throws IllegalDimension { 36 | 37 | n = A.length; 38 | L = new double[n][n]; 39 | isspd = (A[0].length == n); 40 | if (!isspd) 41 | throw new IllegalDimension("Cholesky decomposition is only defined for square matrices"); 42 | // Main loop. 43 | for (int j = 0; j < n; j++) { 44 | double[] Lrowj = L[j]; 45 | double d = 0.0; 46 | for (int k = 0; k < j; k++) { 47 | double[] Lrowk = L[k]; 48 | double s = 0.0; 49 | for (int i = 0; i < k; i++) { 50 | s += Lrowk[i] * Lrowj[i]; 51 | } 52 | Lrowj[k] = s = (A[j][k] - s) / L[k][k]; 53 | d = d + s * s; 54 | isspd = isspd & (A[k][j] == A[j][k]); 55 | } 56 | d = A[j][j] - d; 57 | isspd = isspd & (d > 0.0); 58 | L[j][j] = Math.sqrt(Math.max(d, 0.0)); 59 | /*for (int k = j+1; k < n; k++) { 60 | L[j][k] = 0.0; 61 | }*/ 62 | } 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/DiscreteDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | 20 | /** 21 | * Base interface for discrete distributions. 22 | * 23 | * @version $Revision: 811685 $ $Date: 2009-09-05 13:36:48 -0400 (Sat, 05 Sep 2009) $ 24 | */ 25 | public interface DiscreteDistribution extends Distribution { 26 | /** 27 | * For a random variable X whose values are distributed according 28 | * to this distribution, this method returns P(X = x). In other words, this 29 | * method represents the probability mass function, or PMF for the distribution. 30 | * 31 | * @param x the value at which the probability mass function is evaluated. 32 | * @return the value of the probability mass function at x 33 | */ 34 | double probability(double x); 35 | } 36 | -------------------------------------------------------------------------------- /src/beast/pkgmgmt/PackageDependency.java: -------------------------------------------------------------------------------- 1 | package beast.pkgmgmt; 2 | 3 | 4 | /** 5 | * modified by Walter Xie 6 | */ 7 | /** BEAUti beastObject dependency class **/ 8 | public class PackageDependency { 9 | public final String dependencyName; 10 | public final PackageVersion atLeast, atMost; 11 | 12 | public PackageDependency(String dependencyName, 13 | PackageVersion minimumVersion, 14 | PackageVersion maximumVersion) { 15 | if (dependencyName.equals("beast2")) { 16 | dependencyName = PackageManager.BEAST_PACKAGE_NAME; 17 | } 18 | this.dependencyName = dependencyName; 19 | 20 | atLeast = minimumVersion; 21 | atMost = maximumVersion; 22 | } 23 | 24 | /** 25 | * Test to see whether given version of package satisfies 26 | * version range of this package dependency. 27 | * 28 | * @param version version of package to check 29 | * @return true iff version meets criterion 30 | */ 31 | public boolean isMetBy(PackageVersion version) { 32 | return (atLeast == null || version.compareTo(atLeast)>=0) 33 | && (atMost == null || version.compareTo(atMost)<=0); 34 | } 35 | 36 | public String getRangeString() { 37 | if (atLeast != null && atMost != null) 38 | return "versions " + atLeast + " to " + atMost; 39 | 40 | if (atLeast != null) 41 | return "version " + atLeast + " or greater"; 42 | 43 | return "version " + atMost + " or lesser"; 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | return dependencyName + " " + getRangeString(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/beast/base/math/matrixalgebra/NonSymmetricComponents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * NonSymmetricComponents.java 3 | * 4 | * Copyright (C) 2002-2006 Alexei Drummond and Andrew Rambaut 5 | * 6 | * This file is part of BEAST. 7 | * See the NOTICE file distributed with this work for additional 8 | * information regarding copyright ownership and licensing. 9 | * 10 | * BEAST is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation; either version 2 13 | * of the License, or (at your option) any later version. 14 | * 15 | * BEAST is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with BEAST; if not, write to the 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 23 | * Boston, MA 02110-1301 USA 24 | */ 25 | 26 | package beast.base.math.matrixalgebra; 27 | 28 | /** 29 | * @author Didier H. Besset 30 | */ 31 | public class NonSymmetricComponents extends Exception { 32 | 33 | /** 34 | * 35 | */ 36 | private static final long serialVersionUID = 9046634992672041256L; 37 | /** 38 | * DhbNonSymmetricComponents constructor comment. 39 | */ 40 | public NonSymmetricComponents() { 41 | super(); 42 | } 43 | /** 44 | * DhbNonSymmetricComponents constructor comment. 45 | * @param s java.lang.String 46 | */ 47 | public NonSymmetricComponents(String s) { 48 | super(s); 49 | } 50 | } -------------------------------------------------------------------------------- /src/org/apache/commons/math/analysis/BivariateRealFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.math.analysis; 19 | 20 | import org.apache.commons.math.FunctionEvaluationException; 21 | 22 | 23 | /** 24 | * An interface representing a bivariate real function. 25 | * 26 | * @version $Revision: 924453 $ $Date: 2010-03-17 16:05:20 -0400 (Wed, 17 Mar 2010) $ 27 | * @since 2.1 28 | */ 29 | public interface BivariateRealFunction { 30 | 31 | /** 32 | * Compute the value for the function. 33 | * 34 | * @param x abscissa for which the function value should be computed 35 | * @param y ordinate for which the function value should be computed 36 | * @return the value 37 | * @throws FunctionEvaluationException if the function evaluation fails 38 | */ 39 | double value(double x, double y) throws FunctionEvaluationException; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/beast/base/inference/operator/IntUniformOperator.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.operator; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.core.Input; 5 | import beast.base.core.Log; 6 | import beast.base.core.Input.Validate; 7 | import beast.base.inference.Operator; 8 | import beast.base.inference.parameter.IntegerParameter; 9 | import beast.base.inference.util.InputUtil; 10 | import beast.base.util.Randomizer; 11 | 12 | 13 | @Description("A uniform random operator that selects a random dimension of the integer parameter and picks a new random value within the bounds.") 14 | @Deprecated 15 | public class IntUniformOperator extends Operator { 16 | final public Input parameterInput = new Input<>("parameter", "the parameter to operate a random walk on.", Validate.REQUIRED); 17 | 18 | 19 | @Override 20 | public void initAndValidate() { 21 | Log.warning.println("\n\nIntUniformOperator is depracated. Use UniformOperator instead.\n\n"); 22 | } 23 | 24 | /** 25 | * override this for proposals, 26 | * returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted * 27 | */ 28 | @Override 29 | public double proposal() { 30 | 31 | IntegerParameter param = (IntegerParameter) InputUtil.get(parameterInput, this); 32 | 33 | int i = Randomizer.nextInt(param.getDimension()); 34 | int newValue = Randomizer.nextInt(param.getUpper() - param.getLower() + 1) + param.getLower(); 35 | 36 | param.setValue(i, newValue); 37 | 38 | return 0.0; 39 | } 40 | 41 | @Override 42 | public void optimize(double logAlpha) { 43 | // nothing to optimise 44 | } 45 | 46 | } // class IntUniformOperator -------------------------------------------------------------------------------- /examples/testDirectSimulator.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/beast/base/evolution/speciation/TreeTopFinder.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.speciation; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import beast.base.core.Description; 8 | import beast.base.core.Input; 9 | import beast.base.evolution.tree.Tree; 10 | import beast.base.inference.CalculationNode; 11 | 12 | 13 | @Description("Finds height of highest tree among a set of trees") 14 | public class TreeTopFinder extends CalculationNode { 15 | final public Input> treeInputs = new Input<>("tree", "set of trees to search among", new ArrayList<>()); 16 | 17 | List trees; 18 | 19 | double oldHeight; 20 | double height; 21 | 22 | @Override 23 | public void initAndValidate() { 24 | oldHeight = Double.NaN; 25 | trees = treeInputs.get(); 26 | height = calcHighestTreeHeight(); 27 | } 28 | 29 | public double getHighestTreeHeight() { 30 | return calcHighestTreeHeight(); 31 | } 32 | 33 | private double calcHighestTreeHeight() { 34 | double top = 0; 35 | for (Tree tree : trees) { 36 | top = Math.max(tree.getRoot().getHeight(), top); 37 | } 38 | return top; 39 | } 40 | 41 | @Override 42 | protected boolean requiresRecalculation() { 43 | double top = calcHighestTreeHeight(); 44 | if (top != height) { 45 | height = top; 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | @Override 52 | protected void store() { 53 | oldHeight = height; 54 | super.store(); 55 | } 56 | 57 | @Override 58 | protected void restore() { 59 | height = oldHeight; 60 | super.restore(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/beast/base/util/CredibleSet.java: -------------------------------------------------------------------------------- 1 | package beast.base.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Credible Set results 8 | * 9 | * @author Walter Xie 10 | */ 11 | public class CredibleSet { 12 | 13 | public List credibleSetList; 14 | 15 | final double credSetProbability; 16 | 17 | public int sumFrequency = 0; 18 | 19 | public int targetIndex = -1; 20 | public double targetProb = 0.0; 21 | public double targetCum = 1.0; 22 | 23 | public CredibleSet(double credSetProbability) { 24 | credibleSetList = new ArrayList<>(); 25 | this.credSetProbability = credSetProbability; 26 | } 27 | 28 | public void setCredibleSetList(T target, FrequencySet frequencySet) { 29 | int total = frequencySet.getSumFrequency(); 30 | 31 | for (int i = 0; i < frequencySet.size(); i++) { 32 | final int freq = frequencySet.getFrequency(i); 33 | final double prop = ((double) freq) / total; 34 | 35 | sumFrequency += freq; 36 | final double sumProp = ((double) sumFrequency) / (double)total; 37 | 38 | T obj = frequencySet.get(i); 39 | credibleSetList.add(obj); 40 | if (target != null && obj.equals(target)) { 41 | targetIndex = i + 1; 42 | targetProb = prop; 43 | targetCum = sumProp; 44 | } 45 | 46 | if (sumProp >= credSetProbability) { 47 | break; 48 | } 49 | } 50 | } 51 | 52 | /** 53 | * get frequency of ith object 54 | */ 55 | public int getFrequency(int i, FrequencySet frequencySet) { 56 | return frequencySet.getFrequency(credibleSetList.get(i)); 57 | } 58 | } -------------------------------------------------------------------------------- /src/beast/base/util/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | package beast.base.util; 2 | 3 | 4 | import java.util.Arrays; 5 | import java.util.BitSet; 6 | import java.util.List; 7 | 8 | /** 9 | * some useful methods 10 | */ 11 | public class CollectionUtils { 12 | 13 | // not use set because hard to get element given index 14 | public static List intersection(List list1, List list2) { 15 | list1.retainAll(list2); 16 | return list1; 17 | } 18 | 19 | public static List intersection(E[] array1, E[] array2) { 20 | return intersection(Arrays.asList(array1), Arrays.asList(array2)); 21 | } 22 | 23 | public static int indexof(E label, E[] m_sLabels) { 24 | for (int i = 0; i < m_sLabels.length ; i++) { 25 | if (m_sLabels[i].equals(label)) { 26 | return i; 27 | } 28 | } 29 | return -1; 30 | } 31 | 32 | /** 33 | * 34 | * @param array the array to be converted into list 35 | * @param fromIndex the index of the first element, inclusive, to be sorted 36 | * @param toIndex the index of the last element, exclusive, to be sorted 37 | * @return 38 | */ 39 | public static List toList(E[] array, int fromIndex, int toIndex) { 40 | List list = Arrays.asList(array); 41 | return list.subList(fromIndex, toIndex); 42 | } 43 | 44 | /** 45 | * very inefficient, but Java wonderful bitset has no subset op 46 | * perhaps using bit iterator would be faster, I can't be bothered. 47 | * @param x 48 | * @param y 49 | * @return 50 | */ 51 | public static boolean isSubSet(BitSet x, BitSet y) { 52 | y = (BitSet) y.clone(); 53 | y.and(x); 54 | return y.equals(x); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/TreeDistribution.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.tree; 2 | 3 | 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | import beast.base.core.Description; 8 | import beast.base.core.Input; 9 | import beast.base.core.Input.Validate; 10 | import beast.base.inference.Distribution; 11 | import beast.base.inference.State; 12 | 13 | 14 | @Description("Distribution on a tree, typically a prior such as Coalescent or Yule") 15 | public class TreeDistribution extends Distribution { 16 | final public Input treeInput = new Input<>("tree", "tree over which to calculate a prior or likelihood"); 17 | final public Input treeIntervalsInput = new Input<>("treeIntervals", "Intervals for a phylogenetic beast tree", Validate.XOR, treeInput); 18 | 19 | @Override 20 | public List getArguments() { 21 | return null; 22 | } 23 | 24 | @Override 25 | public List getConditions() { 26 | return null; 27 | } 28 | 29 | @Override 30 | public void sample(State state, Random random) { 31 | } 32 | 33 | @Override 34 | protected boolean requiresRecalculation() { 35 | final TreeIntervals ti = treeIntervalsInput.get(); 36 | if (ti != null) { 37 | //boolean d = ti.isDirtyCalculation(); 38 | //assert d; 39 | assert ti.isDirtyCalculation(); 40 | return true; 41 | } 42 | return treeInput.get().somethingIsDirty(); 43 | } 44 | 45 | /** Indicate that the tree distribution can deal with dated tips in the tree 46 | * Some tree distributions like the Yule prior cannot handle this. 47 | * @return true by default 48 | */ 49 | public boolean canHandleTipDates() { 50 | return true; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/analysis/MultivariateRealFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.math.analysis; 19 | 20 | import org.apache.commons.math.FunctionEvaluationException; 21 | 22 | /** 23 | * An interface representing a multivariate real function. 24 | * 25 | * @version $Revision: 811685 $ $Date: 2009-09-05 13:36:48 -0400 (Sat, 05 Sep 2009) $ 26 | * @since 2.0 27 | */ 28 | public interface MultivariateRealFunction { 29 | 30 | /** 31 | * Compute the value for the function at the given point. 32 | * 33 | * @param point point at which the function must be evaluated 34 | * @return function value for the given point 35 | * @throws FunctionEvaluationException if the function evaluation fails 36 | * @throws IllegalArgumentException if points dimension is wrong 37 | */ 38 | double value(double[] point) 39 | throws FunctionEvaluationException, IllegalArgumentException; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/test/beast/evolution/tree/TreeTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.tree; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import beast.base.evolution.tree.Node; 6 | import beast.base.evolution.tree.TreeParser; 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | public class TreeTest { 10 | final static double EPSILON = 1e-10; 11 | 12 | @Test 13 | public void testTreeScaling() { 14 | String newick = "((0:1.0,1:1.0)4:1.0,(2:1.0,3:1.0)5:0.5)6:0.0;"; 15 | 16 | TreeParser treeParser = new TreeParser(newick, false, false, false, 0); 17 | 18 | Node [] node = treeParser.getNodesAsArray(); 19 | assertEquals(0.0, node[0].getHeight(), EPSILON); 20 | assertEquals(0.0, node[1].getHeight(), EPSILON); 21 | // leaf node, not scaled 22 | assertEquals(0.5, node[2].getHeight(), EPSILON); 23 | assertEquals(0.5, node[3].getHeight(), EPSILON); 24 | // internal nodes, all scaled 25 | assertEquals(1.0, node[4].getHeight(), EPSILON); 26 | assertEquals(1.5, node[5].getHeight(), EPSILON); 27 | assertEquals(2.0, node[6].getHeight(), EPSILON); 28 | 29 | treeParser.scale(2.0); 30 | 31 | // leaf node 32 | node = treeParser.getNodesAsArray(); 33 | assertEquals(0.0, node[0].getHeight(), EPSILON); 34 | assertEquals(0.0, node[1].getHeight(), EPSILON); 35 | // leaf node, not scaled 36 | assertEquals(0.5, node[2].getHeight(), EPSILON); 37 | assertEquals(0.5, node[3].getHeight(), EPSILON); 38 | // internal nodes, all scaled 39 | assertEquals(2.0, node[4].getHeight(), EPSILON); 40 | assertEquals(3.0, node[5].getHeight(), EPSILON); 41 | assertEquals(4.0, node[6].getHeight(), EPSILON); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/TreeHeightLogger.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.tree; 2 | 3 | 4 | 5 | import java.io.PrintStream; 6 | 7 | import beast.base.core.Description; 8 | import beast.base.core.Function; 9 | import beast.base.core.Input; 10 | import beast.base.core.Loggable; 11 | import beast.base.core.Input.Validate; 12 | import beast.base.inference.CalculationNode; 13 | 14 | 15 | @Description("Logger to report height of a tree -- deprecated: use TreeStatLogger instead") 16 | @Deprecated 17 | public class TreeHeightLogger extends CalculationNode implements Loggable, Function { 18 | final public Input treeInput = new Input<>("tree", "tree to report height for.", Validate.REQUIRED); 19 | 20 | @Override 21 | public void initAndValidate() { 22 | // nothing to do 23 | } 24 | 25 | @Override 26 | public void init(PrintStream out) { 27 | final Tree tree = treeInput.get(); 28 | if (getID() == null || getID().matches("\\s*")) { 29 | out.print(tree.getID() + ".height\t"); 30 | } else { 31 | out.print(getID() + "\t"); 32 | } 33 | } 34 | 35 | @Override 36 | public void log(long sample, PrintStream out) { 37 | final Tree tree = treeInput.get(); 38 | out.print(tree.getRoot().getHeight() + "\t"); 39 | } 40 | 41 | @Override 42 | public void close(PrintStream out) { 43 | // nothing to do 44 | } 45 | 46 | @Override 47 | public int getDimension() { 48 | return 1; 49 | } 50 | 51 | @Override 52 | public double getArrayValue() { 53 | return treeInput.get().getRoot().getHeight(); 54 | } 55 | 56 | @Override 57 | public double getArrayValue(int dim) { 58 | return treeInput.get().getRoot().getHeight(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/test/beast/evolution/datatype/DataTypeDeEncodeTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.datatype; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import beast.base.evolution.datatype.Aminoacid; 10 | import beast.base.evolution.datatype.Binary; 11 | import beast.base.evolution.datatype.IntegerData; 12 | import beast.base.evolution.datatype.Nucleotide; 13 | import beast.base.evolution.datatype.TwoStateCovarion; 14 | import beast.base.evolution.datatype.DataType.Base; 15 | 16 | public class DataTypeDeEncodeTest { 17 | 18 | @Test 19 | public void testDataTypeDeEncode() { 20 | Base dAa = new Aminoacid(); 21 | Base dBi = new Binary(); 22 | Base dIn = new IntegerData(); 23 | Base dNt = new Nucleotide(); 24 | Base d2C = new TwoStateCovarion(); 25 | 26 | for (Object [] o : Arrays.asList(new Object[][] { 27 | { dIn, "1,2,14,23,?", Arrays.asList(new Integer[] { 1, 2, 14, 23, -1 }) }, 28 | { dNt, "ACGTURYMWSKBDHVNX", Arrays.asList( 29 | new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }) }, 30 | { dBi, "01-?10", Arrays.asList(new Integer[] { 0, 1, 2, 3, 1, 0 }) }, 31 | { d2C, "01ABCD-?", Arrays.asList(new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7 }) }, 32 | { dAa, "ACDEFGHIKLMNPQRSTVWY", Arrays.asList( 33 | new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }) } 34 | })) { 35 | Base d = (Base) o[0]; 36 | String s = (String) o[1]; 37 | List c = (List) o[2]; 38 | // o.testStingToEncoding(); 39 | assertEquals(c, d.stringToEncoding(s)); 40 | //o.testRoundTrip(); 41 | assertEquals(s, d.encodingToString(d.stringToEncoding(s))); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/TDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | /** 20 | * Student's t-Distribution. 21 | *

22 | *

23 | * References: 24 | *

28 | *

29 | * 30 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 31 | */ 32 | public interface TDistribution extends ContinuousDistribution { 33 | /** 34 | * Modify the degrees of freedom. 35 | * 36 | * @param degreesOfFreedom the new degrees of freedom. 37 | * @deprecated as of v2.1 38 | */ 39 | @Deprecated 40 | void setDegreesOfFreedom(double degreesOfFreedom); 41 | 42 | /** 43 | * Access the degrees of freedom. 44 | * 45 | * @return the degrees of freedom. 46 | */ 47 | double getDegreesOfFreedom(); 48 | } 49 | -------------------------------------------------------------------------------- /src/beast/base/inference/distribution/OneOnX.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.distribution; 2 | 3 | 4 | import org.apache.commons.math.MathException; 5 | import org.apache.commons.math.distribution.ContinuousDistribution; 6 | import org.apache.commons.math.distribution.Distribution; 7 | 8 | import beast.base.core.Description; 9 | 10 | 11 | 12 | @Description("OneOnX distribution. f(x) = C/x for some normalizing constant C. " + 13 | "If the input x is a multidimensional parameter, each of the dimensions is considered as a " + 14 | "separate independent component.") 15 | public class OneOnX extends ParametricDistribution { 16 | 17 | ContinuousDistribution dist = new OneOnXImpl(); 18 | 19 | @Override 20 | public void initAndValidate() { 21 | } 22 | 23 | @Override 24 | public Distribution getDistribution() { 25 | return dist; 26 | } 27 | 28 | class OneOnXImpl implements ContinuousDistribution { 29 | 30 | @Override 31 | public double cumulativeProbability(double x) throws MathException { 32 | throw new MathException("Not implemented yet"); 33 | } 34 | 35 | @Override 36 | public double cumulativeProbability(double x0, double x1) throws MathException { 37 | throw new MathException("Not implemented yet"); 38 | } 39 | 40 | @Override 41 | public double inverseCumulativeProbability(double p) throws MathException { 42 | throw new MathException("Not implemented yet"); 43 | } 44 | 45 | @Override 46 | public double density(double x) { 47 | return 1 / x; 48 | } 49 | 50 | @Override 51 | public double logDensity(double x) { 52 | return -Math.log(x); 53 | } 54 | } // class OneOnXImpl 55 | 56 | 57 | } // class OneOnX 58 | -------------------------------------------------------------------------------- /test/test/beast/evolution/operator/TestOperator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.beast.evolution.operator; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | import beast.base.inference.Operator; 10 | import beast.base.inference.State; 11 | import beast.base.inference.StateNode; 12 | import static org.junit.jupiter.api.Assertions.assertEquals; 13 | 14 | /** 15 | * @author gereon 16 | * 17 | */ 18 | public abstract class TestOperator { 19 | 20 | static public void register(Operator operator, final Object... operands) { 21 | HashMap operandsMap; 22 | operandsMap = new HashMap(); 23 | if (operands.length % 2 == 1) { 24 | throw new RuntimeException("Expected even number of arguments, name-value pairs"); 25 | } 26 | for (int i = 0; i < operands.length; i += 2) { 27 | if (operands[i] instanceof String) { 28 | final String name = (String) operands[i]; 29 | if (operands[i + 1] instanceof StateNode) { 30 | final StateNode node = (StateNode) operands[i + 1]; 31 | operandsMap.put(name, node); 32 | } else { 33 | throw new IllegalArgumentException("Expected a StateNode in " + (i + 1) + "th argument "); 34 | } 35 | } else { 36 | throw new IllegalArgumentException("Expected a String in " + i + "th argument "); 37 | } 38 | } 39 | State state = new State(); 40 | state.initByName("stateNode", new ArrayList(operandsMap.values())); 41 | state.initialise(); 42 | Object[] operandsAndWeight = new Object[operands.length + 2]; 43 | for (int i = 0; i < operands.length; ++i) { 44 | operandsAndWeight[i] = operands[i]; 45 | } 46 | operandsAndWeight[operands.length] = "weight"; 47 | operandsAndWeight[operands.length + 1] = "1"; 48 | operator.initByName(operandsAndWeight); 49 | operator.validateInputs(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile to build container for unit testing. 2 | # 3 | # To build the image, run the following from this directory: 4 | # docker build -t beast_testing . 5 | # 6 | # To run the tests, use 7 | # docker run beast_testing 8 | # 9 | # To run the tests interactively, use 10 | # docker run --entrypoint /bin/bash -it -p 5900:5900 beast_testing 11 | # This will give you a shell in the container. From this 12 | # shell, run 13 | # vncserver $DISPLAY -geometry 1920x1080; ant -f build-testing.xml 14 | # 15 | # The previous command exposes the VNC session, so while the 16 | # BEAUti test suite is running you can run a VNC viewer and 17 | # connect it to localhost (password: password) to observe 18 | # the graphical output of these tests. 19 | 20 | FROM debian:stable 21 | WORKDIR /beast2 22 | 23 | # Install Apache Ant 24 | RUN apt-get update && apt-get install -y openjdk-21-jdk openjfx ant 25 | 26 | # Install and configure VNC server 27 | RUN apt-get update && apt-get install -y tightvncserver twm 28 | RUN mkdir /root/.vnc 29 | RUN echo password | vncpasswd -f > /root/.vnc/passwd 30 | RUN chmod 600 /root/.vnc/passwd 31 | 32 | # Install BEAGLE 33 | RUN apt-get update && apt-get install -y build-essential autoconf automake libtool pkg-config git 34 | # use latest release v3.1.2, issue #786 35 | RUN cd /root && git clone --branch v3.1.2 --depth=1 https://github.com/beagle-dev/beagle-lib.git 36 | RUN cd /root/beagle-lib && ./autogen.sh && ./configure --prefix=/usr/local && make install 37 | RUN ldconfig 38 | 39 | ADD . ./ 40 | 41 | RUN echo "#!/bin/bash\n" \ 42 | "export USER=root\n" \ 43 | "export DISPLAY=:1\n" \ 44 | "vncserver :1 -geometry 1920x1080\n" \ 45 | "ant -lib lib -f build-testing.xml \$1\n" > entrypoint.sh 46 | RUN chmod a+x entrypoint.sh 47 | 48 | ENTRYPOINT ["./entrypoint.sh"] 49 | 50 | CMD ["test-all"] 51 | -------------------------------------------------------------------------------- /src/beast/base/inference/parameter/IntegerParameterList.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.parameter; 2 | 3 | import java.util.List; 4 | 5 | import beast.base.core.Description; 6 | import beast.base.core.Input; 7 | 8 | /** 9 | * @author Tim Vaughan 10 | */ 11 | @Description("State node describing a list of integer-valued parameters.") 12 | public class IntegerParameterList extends GeneralParameterList { 13 | 14 | final public Input lowerBoundInput = new Input<>("lower", 15 | "Lower bound on parameter values.", Integer.MIN_VALUE+1); 16 | final public Input upperBoundInput = new Input<>("upper", 17 | "Upper bound on parameter values.", Integer.MAX_VALUE-1); 18 | 19 | @Override 20 | public void initAndValidate() { 21 | lowerBound = lowerBoundInput.get(); 22 | upperBound = upperBoundInput.get(); 23 | 24 | super.initAndValidate(); 25 | } 26 | 27 | @Override 28 | protected void readStateFromString(String[] boundsString, 29 | List parameterValueStrings, 30 | List keys) { 31 | 32 | lowerBound = Integer.parseInt(boundsString[0]); 33 | upperBound = Integer.parseInt(boundsString[1]); 34 | 35 | pList.clear(); 36 | 37 | for (int pidx=0; pidx 10 | */ 11 | @Description("State node describing a list of real-valued parameters.") 12 | public class RealParameterList extends GeneralParameterList { 13 | 14 | final public Input lowerBoundInput = new Input<>("lower", 15 | "Lower bound on parameter values.", Double.NEGATIVE_INFINITY); 16 | final public Input upperBoundInput = new Input<>("upper", 17 | "Upper bound on parameter values.", Double.POSITIVE_INFINITY); 18 | 19 | @Override 20 | public void initAndValidate() { 21 | lowerBound = lowerBoundInput.get(); 22 | upperBound = upperBoundInput.get(); 23 | 24 | super.initAndValidate(); 25 | } 26 | 27 | @Override 28 | protected void readStateFromString(String[] boundsString, 29 | List parameterValueStrings, 30 | List keys) { 31 | 32 | lowerBound = Double.parseDouble(boundsString[0]); 33 | upperBound = Double.parseDouble(boundsString[1]); 34 | 35 | pList.clear(); 36 | 37 | for (int pidx=0; pidx 1); 31 | assertEquals(11, tree.getNodeCount()); 32 | } 33 | 34 | @Test 35 | public void testNewickTree() throws Exception { 36 | Alignment data = BEASTTestCase.getAlignment(); 37 | Tree tree = new Tree(); 38 | tree.initAndValidate(); 39 | assertEquals(true, tree.getNodeCount() == 1); 40 | 41 | ClusterTree tree2 = new ClusterTree(); 42 | tree2.initByName( 43 | "initial", tree, 44 | "clusterType", "upgma", 45 | "taxa", data); 46 | assertEquals(true, tree.getNodeCount() > 1); 47 | assertEquals(11, tree.getNodeCount()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/testDirichlet/testDirichlet.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 0.25 0.25 0.25 0.25 9 | 10 | 11 | 12 | 13 | 14 | 15 | 2.0 2.0 2.0 2.0 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/beast/base/inference/StateNodeInitialiser.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Typically, StateNodes are initialised through their inputs. However, there are initialisation scenarios 7 | * too complex for this approach to work. For example, initialisation may require additional information not 8 | * provided by the inputs, or several dependent beastObjects need to initialise together, 9 | * such as gene trees and a species tree. 10 | *

11 | * StateNodeInitialisers take one or more StateNodes as input and initializes them in initStateNodes(). 12 | * getInitialisedStateNodes() reports back which nodes has been initialized, but this is currently only used to 13 | * check for multiple initialiser for the same object. 14 | *

15 | * Like any other isEASTObject, a state initialiser must have an initAndValidate(), which is called once. 16 | * getInitialisedStateNodes(), on the other hand, may be called multiple times as its inputs change while the system 17 | * tries to establish a valid starting state. initAndValidate is executed in order that the XML parser see objects, 18 | * so the inputs are not guaranteed to be initialized at this time. initStateNodes is executed in order of appearance 19 | * in MCMC, so inputs requiring initialization are properly initialized when initStateNodes is called. 20 | * 21 | * @author remco 22 | */ 23 | public interface StateNodeInitialiser { 24 | 25 | /** 26 | * Called to set up start state. May be called multiple times. * 27 | */ 28 | void initStateNodes(); 29 | 30 | /** 31 | * @return list of StateNodes that are initialised 32 | * This information is used to ensure StateNode are not initialised more than once. 33 | * @param stateNodes 34 | */ 35 | public void getInitialisedStateNodes(List stateNodes); 36 | } 37 | -------------------------------------------------------------------------------- /examples/testDirichlet/testDirichletBact.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 0.25 0.25 0.25 0.25 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 2.0 2.0 2.0 2.0 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/testDirichlet/testDirichlet2.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 0.25 0.25 0.25 0.25 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 2.0 2.0 2.0 2.0 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/beast/base/inference/Runnable.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference; 2 | 3 | import beast.base.core.BEASTObject; 4 | import beast.base.core.Description; 5 | 6 | @Description("Entry point for running a Beast task, for instance an MCMC or other probabilistic " + 7 | "analysis, a simulation, etc.") 8 | public abstract class Runnable extends BEASTObject { 9 | 10 | /** entry point for anything runnable **/ 11 | abstract public void run() throws Exception; 12 | 13 | 14 | /** make sure whatever is runnable is valid, but do not run yet **/ 15 | public void validate() throws Exception {} 16 | 17 | /** 18 | * Set up information related to the file for (re)storing the State. 19 | * The Runnable implementation is responsible for making its 20 | * State synchronising with the file * 21 | * @param fileName 22 | * @param isRestoreFromFile 23 | */ 24 | public void setStateFile(final String fileName, final boolean isRestoreFromFile) { 25 | if (System.getProperty("state.file.name") != null) { 26 | stateFileName = System.getProperty("state.file.name"); 27 | } else { 28 | if (System.getProperty("file.name.prefix") != null) { 29 | stateFileName = System.getProperty("file.name.prefix") + fileName; 30 | } else { 31 | stateFileName = fileName; 32 | } 33 | } 34 | restoreFromFile = isRestoreFromFile; 35 | } 36 | 37 | /** 38 | * flag to indicate that the State should be restored from File at the start of the analysis * 39 | */ 40 | protected boolean restoreFromFile = false; 41 | 42 | /** 43 | * name of the file store the state in * 44 | */ 45 | protected String stateFileName = "state.backup.xml"; 46 | 47 | /** 48 | * indicate whether this runnable distinguishes partitions, like MCMC, or not 49 | * **/ 50 | public boolean hasPartitions() {return true;} 51 | } 52 | -------------------------------------------------------------------------------- /src/org/json/JSONException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.json; 18 | 19 | // Note: this class was written without inspecting the non-free org.json sourcecode. 20 | 21 | /** 22 | * Thrown to indicate a problem with the JSON API. Such problems include: 23 | *

    24 | *
  • Attempts to parse or construct malformed documents 25 | *
  • Use of null as a name 26 | *
  • Use of numeric types not available to JSON, such as {@link 27 | * Double#isNaN() NaNs} or {@link Double#isInfinite() infinities}. 28 | *
  • Lookups using an out of range index or nonexistent name 29 | *
  • Type mismatches on lookups 30 | *
31 | * 32 | *

Although this is a checked exception, it is rarely recoverable. Most 33 | * callers should simply wrap this exception in an unchecked exception and 34 | * rethrow: 35 | *

  public JSONArray toJSONObject() {
36 |  *     try {
37 |  *         JSONObject result = new JSONObject();
38 |  *         ...
39 |  *     } catch (JSONException e) {
40 |  *         throw new RuntimeException(e);
41 |  *     }
42 |  * }
43 | */ 44 | public class JSONException extends Exception { 45 | 46 | private static final long serialVersionUID = 1L; 47 | 48 | public JSONException(String s) { 49 | super(s); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/test/beast/core/util/SumTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.core.util; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | import beast.base.evolution.Sum; 8 | import beast.base.inference.parameter.BooleanParameter; 9 | import beast.base.inference.parameter.IntegerParameter; 10 | import beast.base.inference.parameter.RealParameter; 11 | 12 | 13 | public class SumTest { 14 | 15 | 16 | @Test 17 | public void testSum() { 18 | RealParameter p1 = new RealParameter("1.0 2.0"); 19 | Sum sum = new Sum(); 20 | 21 | // single argument sum 22 | sum.initByName("arg", p1); 23 | double v = sum.getArrayValue(); 24 | assertEquals(3.0, v, 1e-10); 25 | 26 | // multiple argument sum 27 | sum = new Sum(); 28 | RealParameter p2 = new RealParameter("2.0 2.5"); 29 | sum.initByName("arg", p1, "arg", p2); 30 | v = sum.getArrayValue(); 31 | assertEquals(7.5, v, 1e-10); 32 | 33 | // multiple same argument sum 34 | sum = new Sum(); 35 | sum.initByName("arg", p1, "arg", p1); 36 | v = sum.getArrayValue(); 37 | assertEquals(6.0, v, 1e-10); 38 | 39 | // sum of integers 40 | IntegerParameter p3 = new IntegerParameter("1 2 5"); 41 | sum = new Sum(); 42 | sum.initByName("arg", p3); 43 | v = sum.getArrayValue(); 44 | assertEquals(8.0, v, 1e-10); 45 | 46 | // sum of boolean 47 | BooleanParameter p4 = new BooleanParameter("true false false true true"); 48 | sum = new Sum(); 49 | sum.initByName("arg", p4); 50 | v = sum.getArrayValue(); 51 | assertEquals(3.0, v, 1e-10); 52 | 53 | // sum of booleans and integer 54 | sum = new Sum(); 55 | sum.initByName("arg", p4, "arg", p3); 56 | v = sum.getArrayValue(); 57 | assertEquals(11.0, v, 1e-10); 58 | 59 | // sum of booleans and real 60 | sum = new Sum(); 61 | sum.initByName("arg", p1, "arg", p4); 62 | v = sum.getArrayValue(); 63 | assertEquals(6.0, v, 1e-10); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/beast/base/evolution/speciation/CalibrationPoint.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.speciation; 2 | 3 | import beast.base.core.BEASTObject; 4 | import beast.base.core.Description; 5 | import beast.base.core.Input; 6 | import beast.base.evolution.alignment.TaxonSet; 7 | import beast.base.inference.distribution.ParametricDistribution; 8 | 9 | /** 10 | * @author Joseph Heled 11 | */ 12 | 13 | @Description("Specification of a single calibration point of the calibrated Yule.") 14 | public class CalibrationPoint extends BEASTObject { 15 | final public Input taxonsetInput = new Input<>("taxonset", 16 | "Set of taxa. The prior distribution is applied to their TMRCA.", Input.Validate.REQUIRED); 17 | 18 | final public Input distInput = new Input<>("distr", 19 | "Prior distribution applied to time of clade MRCA", Input.Validate.REQUIRED); 20 | 21 | // public Input m_bIsMonophyleticInput = new Input<>("monophyletic", 22 | // "whether the taxon set is monophyletic (forms a clade without other taxa) or nor. Default is false.", false); 23 | 24 | final public Input forParentInput = new Input<>("parentOf", 25 | "Use time of clade parent. Default is false.", false); 26 | 27 | 28 | private TaxonSet t; 29 | private boolean forPar; 30 | private ParametricDistribution pd; 31 | 32 | public CalibrationPoint() {} 33 | 34 | @Override 35 | public void initAndValidate() { 36 | t = taxonsetInput.get(); 37 | forPar = forParentInput.get(); 38 | pd = distInput.get(); 39 | } 40 | 41 | public TaxonSet taxa() { 42 | return t; 43 | } 44 | 45 | public boolean forParent() { 46 | return forPar; 47 | } 48 | 49 | public ParametricDistribution dist() { 50 | return pd; 51 | } 52 | 53 | public double logPdf(final double x) { 54 | return pd.logDensity(x); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/beast/base/evolution/likelihood/GenericTreeLikelihood.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.likelihood; 2 | 3 | 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | import beast.base.core.Description; 8 | import beast.base.core.Input; 9 | import beast.base.core.Input.Validate; 10 | import beast.base.evolution.alignment.Alignment; 11 | import beast.base.evolution.branchratemodel.BranchRateModel; 12 | import beast.base.evolution.sitemodel.SiteModelInterface; 13 | import beast.base.evolution.tree.TreeInterface; 14 | import beast.base.inference.Distribution; 15 | import beast.base.inference.State; 16 | 17 | 18 | 19 | 20 | 21 | @Description("Generic tree likelihood for an alignment given a generic SiteModel, " + 22 | "a beast tree and a branch rate model") 23 | // Use this as base class to define any non-standard TreeLikelihood. 24 | // Override Distribution.calculatLogP() to make this class functional. 25 | // 26 | // TODO: This could contain a generic traverse() method that takes dirty trees in account. 27 | // 28 | public class GenericTreeLikelihood extends Distribution { 29 | 30 | final public Input dataInput = new Input<>("data", "sequence data for the beast.tree", Validate.REQUIRED); 31 | 32 | final public Input treeInput = new Input<>("tree", "phylogenetic beast.tree with sequence data in the leafs", Validate.REQUIRED); 33 | 34 | final public Input siteModelInput = new Input<>("siteModel", "site model for leafs in the beast.tree", Validate.REQUIRED); 35 | 36 | final public Input branchRateModelInput = new Input<>("branchRateModel", 37 | "A model describing the rates on the branches of the beast.tree."); 38 | 39 | 40 | 41 | @Override 42 | public List getArguments() {return null;} 43 | 44 | @Override 45 | public List getConditions() {return null;} 46 | 47 | @Override 48 | public void sample(State state, Random random) {} 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/beast/base/evolution/operator/kernel/BactrianTipDatesRandomWalker.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.operator.kernel; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.core.Input; 5 | import beast.base.evolution.operator.TipDatesRandomWalker; 6 | import beast.base.evolution.tree.Node; 7 | import beast.base.inference.operator.kernel.KernelDistribution; 8 | import beast.base.util.Randomizer; 9 | 10 | @Description("Randomly moves tip dates on a tree by randomly selecting one from (a subset of) taxa using a Bactrian proposal") 11 | public class BactrianTipDatesRandomWalker extends TipDatesRandomWalker { 12 | public final Input kernelDistributionInput = new Input<>("kernelDistribution", "provides sample distribution for proposals", 13 | KernelDistribution.newDefaultKernelDistribution()); 14 | 15 | protected KernelDistribution kernelDistribution; 16 | 17 | @Override 18 | public void initAndValidate() { 19 | kernelDistribution = kernelDistributionInput.get(); 20 | 21 | super.initAndValidate(); 22 | } 23 | 24 | public double proposal() { 25 | // randomly select leaf node 26 | int i = Randomizer.nextInt(taxonIndices.length); 27 | Node node = treeInput.get().getNode(taxonIndices[i]); 28 | 29 | double value = node.getHeight(); 30 | double newValue = value + kernelDistribution.getRandomDelta(i, value, windowSize); 31 | 32 | if (newValue > node.getParent().getHeight()) { // || newValue < 0.0) { 33 | if (reflectValue) { 34 | newValue = reflectValue(newValue, 0.0, node.getParent().getHeight()); 35 | } else { 36 | return Double.NEGATIVE_INFINITY; 37 | } 38 | } 39 | if (newValue == value) { 40 | // this saves calculating the posterior 41 | return Double.NEGATIVE_INFINITY; 42 | } 43 | node.setHeight(newValue); 44 | 45 | return 0.0; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/TreeInterface.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.tree; 2 | 3 | 4 | 5 | import java.util.List; 6 | 7 | import beast.base.evolution.alignment.TaxonSet; 8 | 9 | public interface TreeInterface { 10 | String getID(); 11 | 12 | int getLeafNodeCount(); 13 | int getInternalNodeCount(); 14 | int getNodeCount(); 15 | 16 | Node getRoot(); 17 | Node getNode(int i); 18 | Node [] getNodesAsArray(); 19 | 20 | List getExternalNodes(); 21 | List getInternalNodes(); 22 | 23 | TaxonSet getTaxonset(); 24 | 25 | boolean somethingIsDirty(); 26 | 27 | public void getMetaData(Node node, Double[] t, String pattern); 28 | public void setMetaData(Node node, Double[] t, String pattern); 29 | 30 | /* 31 | * Note that leaf nodes are always numbered 0,...,nodeCount-1 32 | * Internal nodes are numbered higher, but the root has no guaranteed 33 | * number. 34 | */ 35 | 36 | /** 37 | * @param node top of tree/sub tree (null defaults to whole tree) 38 | * @param nodes array to fill (null will result in creating a new one) 39 | * @return tree nodes in post-order, children before parents 40 | */ 41 | default Node[] listNodesPostOrder(Node node, Node[] nodes) { 42 | if (node == null) { 43 | node = getRoot(); 44 | } 45 | if (nodes == null) { 46 | // overall node count is cached, faster 47 | final int n = node == getRoot() ? getNodeCount() : node.getNodeCount(); 48 | nodes = new Node[n]; 49 | } 50 | getNodesPostOrder(node, nodes, 0); 51 | return nodes; 52 | } 53 | 54 | static int getNodesPostOrder(final Node node, final Node[] nodes, int pos) { 55 | //node.m_tree = this; 56 | for (final Node child : node.getChildren()) { 57 | pos = getNodesPostOrder(child, nodes, pos); 58 | } 59 | nodes[pos] = node; 60 | return pos + 1; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/ExponentialDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | /** 20 | * The Exponential Distribution. 21 | *

22 | *

23 | * References: 24 | *

28 | *

29 | * 30 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 31 | */ 32 | public interface ExponentialDistribution extends ContinuousDistribution /*, HasDensity*/ { 33 | /** 34 | * Modify the mean. 35 | * 36 | * @param mean the new mean. 37 | * @deprecated as of v2.1 38 | */ 39 | @Deprecated 40 | void setMean(double mean); 41 | 42 | /** 43 | * Access the mean. 44 | * 45 | * @return the mean. 46 | */ 47 | double getMean(); 48 | 49 | /** 50 | * Return the probability density for a particular point. 51 | * 52 | * @param x The point at which the density should be computed. 53 | * @return The pdf at point x. 54 | */ 55 | double density(Double x); 56 | } 57 | -------------------------------------------------------------------------------- /release/Linux/jrebin/applauncher: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$BEAST" ]; then 4 | ## resolve links - $0 may be a link to application 5 | PRG="$0" 6 | 7 | # need this for relative symlinks 8 | while [ -h "$PRG" ] ; do 9 | ls=`ls -ld "$PRG"` 10 | link=`expr "$ls" : '.*-> \(.*\)$'` 11 | if expr "$link" : '/.*' > /dev/null; then 12 | PRG="$link" 13 | else 14 | PRG="`dirname "$PRG"`/$link" 15 | fi 16 | done 17 | 18 | # make it fully qualified 19 | saveddir=`pwd` 20 | BEAST0=`dirname "$PRG"`/.. 21 | BEAST=`cd "$BEAST0" && pwd` 22 | cd "$saveddir" 23 | fi 24 | 25 | BEAST_LIB="$BEAST/lib" 26 | export JAVA_HOME="$BEAST/jre" 27 | 28 | if [ -z "$JAVA_HOME" ]; then 29 | JAVA=java 30 | else 31 | JAVA="$JAVA_HOME"/bin/java 32 | fi 33 | 34 | 35 | # use BEAGLE_LIB if the BEAGLE library is not in a standard location 36 | if [ -n "$BEAGLE_LIB" ]; then 37 | if [ -n "$BEAST_EXTRA_LIBS" ]; then 38 | BEAST_EXTRA_LIBS="$BEAST_EXTRA_LIBS:$BEAGLE_LIB" 39 | else 40 | BEAST_EXTRA_LIBS="$BEAGLE_LIB" 41 | fi 42 | fi 43 | 44 | # Explicitly add /usr/local/lib to library search path to ensure 45 | # beast continues to find beagle when installed here. (This is 46 | # necessary due to known problems with certain JREs.) 47 | if [ -z "$LD_LIBRARY_PATH" ]; then 48 | export LD_LIBRARY_PATH=/usr/local/lib 49 | else 50 | export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":/usr/local/lib 51 | fi 52 | 53 | # use BEAST_EXTRA_LIBS variable to load BEAGLE and other libraries from non-default locations 54 | # this assumes that the library path contains all these libraries (or are set through LD_LIBRARY_PATH) 55 | if [ -n "$BEAST_EXTRA_LIBS" ]; then 56 | "$JAVA" -Dlauncher.wait.for.exit=true -Xss256m -Xmx8g -Djava.library.path="$BEAST_EXTRA_LIBS" -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher $* 57 | else 58 | "$JAVA" -Dlauncher.wait.for.exit=true -Xss256m -Xmx8g -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher $* 59 | fi 60 | -------------------------------------------------------------------------------- /src/beast/base/parser/OutputUtils.java: -------------------------------------------------------------------------------- 1 | package beast.base.parser; 2 | 3 | 4 | import java.text.DecimalFormat; 5 | import java.text.DecimalFormatSymbols; 6 | import java.util.List; 7 | import java.util.Locale; 8 | 9 | /** 10 | * some useful methods 11 | * 12 | * @author Remco Bouckaert 13 | * @author Walter Xie 14 | */ 15 | public class OutputUtils { 16 | public final static String SPACE = " "; 17 | 18 | public static String format(String s) { 19 | return format(s, SPACE); 20 | } 21 | public static String format(String s, String space) { 22 | while (s.length() < 8) { 23 | s += " "; 24 | } 25 | return s + space; 26 | } 27 | 28 | public static String format(Double d) { 29 | if (Double.isNaN(d)) { 30 | return "NaN "; 31 | } 32 | if (Math.abs(d) > 1e-4 || d == 0) { 33 | DecimalFormat f = new DecimalFormat("#0.######", new DecimalFormatSymbols(Locale.US)); 34 | String str = f.format(d); 35 | if (str.length() > 8) { 36 | str = str.substring(0, 8); 37 | } 38 | while (str.length() < 8) { 39 | str += " "; 40 | } 41 | return str; 42 | } else { 43 | DecimalFormat f = new DecimalFormat("0.##E0", new DecimalFormatSymbols(Locale.US)); 44 | String str = f.format(d); 45 | if (str.length() > 8) { 46 | String [] strs = str.split("E"); 47 | str = strs[0].substring(0, 8 - strs[1].length() - 1) + "E" + strs[1]; 48 | } 49 | while (str.length() < 8) { 50 | str += " "; 51 | } 52 | return str; 53 | } 54 | } 55 | 56 | public static String toString(List list) { 57 | String s = ""; 58 | for (int i = 0; i < list.size(); i++) { 59 | if (i > 0) s += ", "; 60 | Object o = list.get(i); 61 | s += o.toString(); 62 | } 63 | return s; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /release/Linux/jrebin/loganalyser: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$BEAST" ]; then 4 | ## resolve links - $0 may be a link to application 5 | PRG="$0" 6 | 7 | # need this for relative symlinks 8 | while [ -h "$PRG" ] ; do 9 | ls=`ls -ld "$PRG"` 10 | link=`expr "$ls" : '.*-> \(.*\)$'` 11 | if expr "$link" : '/.*' > /dev/null; then 12 | PRG="$link" 13 | else 14 | PRG="`dirname "$PRG"`/$link" 15 | fi 16 | done 17 | 18 | # make it fully qualified 19 | saveddir=`pwd` 20 | BEAST0=`dirname "$PRG"`/.. 21 | BEAST=`cd "$BEAST0" && pwd` 22 | cd "$saveddir" 23 | fi 24 | 25 | BEAST_LIB="$BEAST/lib" 26 | export JAVA_HOME="$BEAST/jre" 27 | 28 | if [ -z "$JAVA_HOME" ]; then 29 | JAVA=java 30 | else 31 | JAVA="$JAVA_HOME"/bin/java 32 | fi 33 | 34 | 35 | # use BEAGLE_LIB if the BEAGLE library is not in a standard location 36 | if [ -n "$BEAGLE_LIB" ]; then 37 | if [ -n "$BEAST_EXTRA_LIBS" ]; then 38 | BEAST_EXTRA_LIBS="$BEAST_EXTRA_LIBS:$BEAGLE_LIB" 39 | else 40 | BEAST_EXTRA_LIBS="$BEAGLE_LIB" 41 | fi 42 | fi 43 | 44 | # Explicitly add /usr/local/lib to library search path to ensure 45 | # beast continues to find beagle when installed here. (This is 46 | # necessary due to known problems with certain JREs.) 47 | if [ -z "$LD_LIBRARY_PATH" ]; then 48 | export LD_LIBRARY_PATH=/usr/local/lib 49 | else 50 | export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":/usr/local/lib 51 | fi 52 | 53 | # use BEAST_EXTRA_LIBS variable to load BEAGLE and other libraries from non-default locations 54 | # this assumes that the library path contains all these libraries (or are set through LD_LIBRARY_PATH) 55 | if [ -n "$BEAST_EXTRA_LIBS" ]; then 56 | "$JAVA" -Dlauncher.wait.for.exit=true -Xss256m -Xmx8g -Djava.library.path="$BEAST_EXTRA_LIBS" -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher beastfx.app.tools.LogAnalyser $* 57 | else 58 | "$JAVA" -Dlauncher.wait.for.exit=true -Xss256m -Xmx8g -Duser.language=en -cp "$BEAST_LIB/launcher.jar" beast.pkgmgmt.launcher.AppLauncherLauncher beastfx.app.tools.LogAnalyser $* 59 | fi 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/HasDensity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.math.distribution; 19 | 20 | import org.apache.commons.math.MathException; 21 | 22 | /** 23 | *

Interface that signals that a distribution can compute the probability density function 24 | * for a particular point. 25 | * 26 | * @param

the type of the point at which density is to be computed, this 27 | * may be for example Double.

28 | *

29 | *

This interface is deprecated. As of version 2.0, the {@link ContinuousDistribution} 30 | * interface will be extended to include a density(double) method.

31 | * @version $Revision: 924362 $ $Date: 2010-03-17 12:45:31 -0400 (Wed, 17 Mar 2010) $ 32 | * @deprecated to be removed in math 3.0 33 | */ 34 | @Deprecated 35 | public interface HasDensity

{ 36 | 37 | /** 38 | * Compute the probability density function. 39 | * 40 | * @param x point for which the probability density is requested 41 | * @return probability density at point x 42 | * @throws MathException if probability density cannot be computed at specifed point 43 | */ 44 | double density(P x) throws MathException; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/ChiSquaredDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | /** 20 | * The Chi-Squared Distribution. 21 | *

22 | *

23 | * References: 24 | *

28 | *

29 | * 30 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 31 | */ 32 | public interface ChiSquaredDistribution extends ContinuousDistribution /*, HasDensity*/ { 33 | /** 34 | * Modify the degrees of freedom. 35 | * 36 | * @param degreesOfFreedom the new degrees of freedom. 37 | * @deprecated as of v2.1 38 | */ 39 | @Deprecated 40 | void setDegreesOfFreedom(double degreesOfFreedom); 41 | 42 | /** 43 | * Access the degrees of freedom. 44 | * 45 | * @return the degrees of freedom. 46 | */ 47 | double getDegreesOfFreedom(); 48 | 49 | /** 50 | * Return the probability density for a particular point. 51 | * 52 | * @param x The point at which the density should be computed. 53 | * @return The pdf at point x. 54 | */ 55 | double density(Double x); 56 | } 57 | -------------------------------------------------------------------------------- /src/beast/base/inference/util/InputUtil.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.util; 2 | 3 | import java.util.List; 4 | 5 | import beast.base.core.Input; 6 | import beast.base.inference.CalculationNode; 7 | import beast.base.inference.Operator; 8 | import beast.base.inference.StateNode; 9 | 10 | public class InputUtil { 11 | 12 | /** 13 | * As Input.get() but with this difference that the State can manage 14 | * whether to make a copy and register the operator. 15 | *

16 | * Only Operators should call this method. 17 | * Also Operators should never call Input.get(), always Input.get(operator). 18 | * 19 | * @param operator 20 | * @return 21 | */ 22 | static public StateNode get(Input input, final Operator operator) { 23 | return ((StateNode) input.get()).getCurrentEditable(operator); 24 | } 25 | 26 | /** 27 | * Return the dirtiness state for this input. 28 | * For a StateNode or list of StateNodes, report whether for any something is dirty, 29 | * for a CalcationNode or list of CalculationNodes, report whether any is dirty. 30 | * Otherwise, return false. 31 | * * 32 | */ 33 | static public boolean isDirty(Input input) { 34 | final Object value = input.get(); 35 | 36 | if (value == null) { 37 | return false; 38 | } 39 | 40 | if (value instanceof StateNode) { 41 | return ((StateNode) value).somethingIsDirty(); 42 | } 43 | 44 | if (value instanceof CalculationNode) { 45 | return ((CalculationNode) value).isDirtyCalculation(); 46 | } 47 | 48 | if (value instanceof List) { 49 | for (final Object obj : (List) value) { 50 | if (obj instanceof CalculationNode && ((CalculationNode) obj).isDirtyCalculation()) { 51 | return true; 52 | } else if (obj instanceof StateNode && ((StateNode) obj).somethingIsDirty()) { 53 | return true; 54 | } 55 | } 56 | } 57 | 58 | return false; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/beast/base/evolution/speciation/RandomGeneTree.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.speciation; 2 | 3 | import java.util.List; 4 | 5 | import beast.base.core.Description; 6 | import beast.base.core.Input; 7 | import beast.base.core.Input.Validate; 8 | import beast.base.evolution.tree.Node; 9 | import beast.base.evolution.tree.Tree; 10 | import beast.base.evolution.tree.coalescent.PopulationFunction; 11 | import beast.base.evolution.tree.coalescent.RandomTree; 12 | 13 | 14 | 15 | @Description("Generates a random gene tree conditioned on a species tree, such " + 16 | "that the root of the species tree is lower than any coalescent events in " + 17 | "the gene tree") 18 | public class RandomGeneTree extends RandomTree { 19 | final public Input speciesTreeInput = new Input<>("speciesTree", "The species tree in which this random gene tree needs to fit", Validate.REQUIRED); 20 | 21 | @Override 22 | public void initAndValidate() { 23 | super.initAndValidate(); 24 | } 25 | 26 | @Override 27 | public Node simulateCoalescentWithMax(List nodes, PopulationFunction demographic, final double maxHeight) { 28 | // sanity check - disjoint trees 29 | 30 | // if( ! Tree.Utils.allDisjoint(nodes) ) { 31 | // throw new RuntimeException("non disjoint trees"); 32 | // } 33 | 34 | if (nodes.size() == 0) { 35 | throw new IllegalArgumentException("empty nodes set"); 36 | } 37 | 38 | final double lowestHeight = speciesTreeInput.get().getRoot().getHeight(); 39 | 40 | for (int attempts = 0; attempts < 1000; ++attempts) { 41 | try { 42 | final List rootNode = simulateCoalescent(nodes, demographic, lowestHeight, maxHeight); 43 | if (rootNode.size() == 1) { 44 | return rootNode.get(0); 45 | } 46 | } catch (ConstraintViolatedException e) { 47 | // TODO: handle exception 48 | } 49 | } 50 | 51 | throw new RuntimeException("failed to merge trees after 1000 tries!"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/beast/base/CudaDetector.java: -------------------------------------------------------------------------------- 1 | package beast.base; 2 | 3 | import beast.base.core.Log; 4 | import beast.base.core.Log.Level; 5 | import beast.base.evolution.alignment.Alignment; 6 | import beast.base.evolution.alignment.Sequence; 7 | import beast.base.evolution.likelihood.BeagleTreeLikelihood; 8 | import beast.base.evolution.sitemodel.SiteModel; 9 | import beast.base.evolution.substitutionmodel.JukesCantor; 10 | import beast.base.evolution.tree.TreeParser; 11 | 12 | public class CudaDetector { 13 | 14 | /** 15 | * Used to detect whether CUDA with BEAGLE is installed on OS X in {@link Utils6#testCudaStatusOnMac()}, 16 | * which is used by {@link beast.pkgmgmt.launcher.BeastLauncher#main(String[])}. 17 | * @see issues 500. 18 | */ 19 | public static void main(String[] args) { 20 | try { 21 | Log.setLevel(Level.none); 22 | Sequence a = new Sequence("A", "A"); 23 | Sequence b = new Sequence("B", "A"); 24 | Sequence c = new Sequence("C", "A"); 25 | Sequence d = new Sequence("D", "A"); 26 | 27 | Alignment data = new Alignment(); 28 | data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide"); 29 | 30 | TreeParser tree = new TreeParser(); 31 | tree.initByName("taxa", data, 32 | "newick", "(((A:1,B:1):1,C:2):1,D:3)", 33 | "IsLabelledNewick", true); 34 | 35 | JukesCantor JC = new JukesCantor(); 36 | JC.initAndValidate(); 37 | 38 | SiteModel siteModel = new SiteModel(); 39 | siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC); 40 | 41 | BeagleTreeLikelihood likelihood = new BeagleTreeLikelihood(); 42 | likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel); 43 | } catch (Exception e) { 44 | // TODO Auto-generated catch block 45 | e.printStackTrace(); 46 | } 47 | 48 | 49 | // System.out.println("Success"); 50 | // if we got this far, exit with status 0 51 | System.exit(0); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/beast/base/inference/distribution/Beta.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.distribution; 2 | 3 | import org.apache.commons.math.distribution.BetaDistributionImpl; 4 | import org.apache.commons.math.distribution.ContinuousDistribution; 5 | 6 | import beast.base.core.Description; 7 | import beast.base.core.Function; 8 | import beast.base.core.Input; 9 | import beast.base.inference.parameter.RealParameter; 10 | 11 | 12 | 13 | @Description("Beta distribution, used as prior. p(x;alpha,beta) = \frac{x^{alpha-1}(1-x)^{beta-1}} {B(alpha,beta)} " + 14 | "where B() is the beta function. " + 15 | "If the input x is a multidimensional parameter, each of the dimensions is considered as a " + 16 | "separate independent component.") 17 | public class Beta extends ParametricDistribution { 18 | final public Input alphaInput = new Input<>("alpha", "first shape parameter, defaults to 1"); 19 | final public Input betaInput = new Input<>("beta", "the other shape parameter, defaults to 1"); 20 | 21 | org.apache.commons.math.distribution.BetaDistribution m_dist = new BetaDistributionImpl(1, 1); 22 | 23 | @Override 24 | public void initAndValidate() { 25 | refresh(); 26 | } 27 | 28 | /** 29 | * make sure internal state is up to date * 30 | */ 31 | @SuppressWarnings("deprecation") 32 | void refresh() { 33 | double alpha; 34 | double beta; 35 | if (alphaInput.get() == null) { 36 | alpha = 1; 37 | } else { 38 | alpha = alphaInput.get().getArrayValue(); 39 | } 40 | if (betaInput.get() == null) { 41 | beta = 1; 42 | } else { 43 | beta = betaInput.get().getArrayValue(); 44 | } 45 | m_dist.setAlpha(alpha); 46 | m_dist.setBeta(beta); 47 | } 48 | 49 | @Override 50 | public ContinuousDistribution getDistribution() { 51 | refresh(); 52 | return m_dist; 53 | } 54 | 55 | @Override 56 | protected double getMeanWithoutOffset() { 57 | return m_dist.getAlpha() / (m_dist.getAlpha() + m_dist.getBeta()); 58 | } 59 | } // class Beta 60 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/CauchyDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.math.distribution; 19 | 20 | /** 21 | * Cauchy Distribution. 22 | *

23 | *

24 | * References: 25 | *

29 | *

30 | * 31 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 32 | * @since 1.1 33 | */ 34 | public interface CauchyDistribution extends ContinuousDistribution { 35 | 36 | /** 37 | * Access the median. 38 | * 39 | * @return median for this distribution 40 | */ 41 | double getMedian(); 42 | 43 | /** 44 | * Access the scale parameter. 45 | * 46 | * @return scale parameter for this distribution 47 | */ 48 | double getScale(); 49 | 50 | /** 51 | * Modify the median. 52 | * 53 | * @param median for this distribution 54 | * @deprecated as of v2.1 55 | */ 56 | @Deprecated 57 | void setMedian(double median); 58 | 59 | /** 60 | * Modify the scale parameter. 61 | * 62 | * @param s scale parameter for this distribution 63 | * @deprecated as of v2.1 64 | */ 65 | @Deprecated 66 | void setScale(double s); 67 | } 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BEAST 2 2 | ======= 3 | 4 | [![Build Status](https://github.com/CompEvol/beast2/workflows/Core%20tests/badge.svg)](https://github.com/CompEvol/beast2/actions?query=workflow%3A%22Core+tests%22) 5 | 6 | BEAST is a cross-platform program for Bayesian inference using MCMC of 7 | molecular sequences. It is entirely oriented towards rooted, 8 | time-measured phylogenies inferred using strict or relaxed molecular 9 | clock models. It can be used as a method of reconstructing phylogenies 10 | but is also a framework for testing evolutionary hypotheses without 11 | conditioning on a single tree topology. BEAST uses MCMC to average 12 | over tree space, so that each tree is weighted proportional to its 13 | posterior probability. We include a simple to use user-interface 14 | program for setting up standard analyses and a suit of programs for 15 | analysing the results. 16 | 17 | NOTE: This directory contains the BEAST 2 source code, and is 18 | therefore of interest primarily to BEAST 2 developers. For binary 19 | releases, user tutorials and other information you should visit the 20 | project website at [beast2.org](https://www.beast2.org). 21 | 22 | Development Rules and Philosophy 23 | -------------------------------- 24 | 25 | Aspects relating to BEAST 2 development such as coding style, version 26 | numbering and design philosophy are discussed on the BEAST 2 web page at 27 | [beast2.org/package-development-guide/core-development-rules](https://www.beast2.org/package-development-guide/core-development-rules/). 28 | 29 | License 30 | ------- 31 | 32 | BEAST 2 is free software; you can redistribute it and/or modify it 33 | under the terms of the GNU Lesser General Public License as published 34 | by the Free Software Foundation; either version 2.1 of the License, or 35 | (at your option) any later version. A copy of the license is contained 36 | in the file COPYING, located in the root directory of this repository. 37 | 38 | This software is distributed in the hope that it will be useful, but 39 | WITHOUT ANY WARRANTY; without even the implied warranty of 40 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 41 | Lesser General Public License contained in the file COPYING for more 42 | details. 43 | -------------------------------------------------------------------------------- /test/test/beast/evolution/operator/DeltaExchangeOperatorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package test.beast.evolution.operator; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | import org.junit.jupiter.api.Test; 9 | 10 | import beast.base.inference.State; 11 | import beast.base.inference.operator.DeltaExchangeOperator; 12 | import beast.base.inference.parameter.IntegerParameter; 13 | import beast.base.inference.parameter.RealParameter; 14 | 15 | /** 16 | * @author gereon 17 | * 18 | */ 19 | public class DeltaExchangeOperatorTest extends TestOperator { 20 | 21 | @Test 22 | public void testKeepsSum() { 23 | DeltaExchangeOperator operator = new DeltaExchangeOperator(); 24 | RealParameter parameter = new RealParameter(new Double[] {1., 1., 1., 1.}); 25 | register(operator, 26 | "parameter", parameter); 27 | for (int i=0; i<100; ++i) { 28 | operator.proposal(); 29 | } 30 | double i = 0; 31 | for (Double p : parameter.getValues()) { 32 | i += p; 33 | } 34 | assertEquals(i, 4, 0.00001, "The DeltaExchangeOperator should not change the sum of a parameter"); 35 | } 36 | 37 | @Test 38 | public void testKeepsWeightedSum() { 39 | RealParameter parameter = new RealParameter(new Double[] {1., 1., 1., 1.}); 40 | register(new DeltaExchangeOperator(), 41 | "weightvector", new IntegerParameter(new Integer[] {0, 1, 2, 1}), 42 | "parameter", parameter); 43 | Double[] p = parameter.getValues(); 44 | assertEquals(0*p[1]+1*p[1]+2*p[2]+1*p[3], 4, 0.00001, 45 | "The DeltaExchangeOperator should not change the sum of a parameter"); 46 | } 47 | 48 | @Test 49 | public void testCanOperate() { 50 | // Test whether a validly initialised operator may make proposals 51 | State state = new State(); 52 | RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. }); 53 | state.initByName("stateNode", parameter); 54 | state.initialise(); 55 | DeltaExchangeOperator d = new DeltaExchangeOperator(); 56 | // An invalid operator should either fail in initByName or make valid 57 | // proposals 58 | try { 59 | d.initByName("parameter", parameter, "weight", 1.0); 60 | } catch (RuntimeException e) { 61 | return; 62 | } 63 | d.proposal(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/beast/base/inference/operator/IntRandomWalkOperator.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.operator; 2 | 3 | import beast.base.core.Description; 4 | import beast.base.core.Input; 5 | import beast.base.core.Input.Validate; 6 | import beast.base.inference.Operator; 7 | import beast.base.inference.parameter.IntegerParameter; 8 | import beast.base.inference.util.InputUtil; 9 | import beast.base.util.Randomizer; 10 | 11 | 12 | @Description("A random walk operator that selects a random dimension of the integer parameter and perturbs the value a " + 13 | "random amount within +/- windowSize.") 14 | public class IntRandomWalkOperator extends Operator { 15 | final public Input windowSizeInput = 16 | new Input<>("windowSize", "the size of the window both up and down", Validate.REQUIRED); 17 | final public Input parameterInput = 18 | new Input<>("parameter", "the parameter to operate a random walk on.", Validate.REQUIRED); 19 | 20 | int windowSize = 1; 21 | 22 | @Override 23 | public void initAndValidate() { 24 | windowSize = windowSizeInput.get(); 25 | } 26 | 27 | /** 28 | * override this for proposals, 29 | * returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted * 30 | */ 31 | @Override 32 | public double proposal() { 33 | 34 | final IntegerParameter param = (IntegerParameter) InputUtil.get(parameterInput,this); 35 | 36 | final int i = Randomizer.nextInt(param.getDimension()); 37 | final int value = param.getValue(i); 38 | final int newValue = value + Randomizer.nextInt(2 * windowSize + 1) - windowSize; 39 | 40 | if (newValue < param.getLower() || newValue > param.getUpper()) { 41 | // invalid move, can be rejected immediately 42 | return Double.NEGATIVE_INFINITY; 43 | } 44 | if (newValue == value) { 45 | // this saves calculating the posterior 46 | return Double.NEGATIVE_INFINITY; 47 | } 48 | 49 | param.setValue(i, newValue); 50 | 51 | return 0.0; 52 | } 53 | 54 | @Override 55 | public void optimize(final double logAlpha) { 56 | // nothing to optimise 57 | } 58 | 59 | } // class IntRandomWalkOperator -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/BinomialDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | /** 20 | * The Binomial Distribution. 21 | *

22 | *

23 | * References: 24 | *

28 | *

29 | * 30 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 31 | */ 32 | public interface BinomialDistribution extends IntegerDistribution { 33 | /** 34 | * Access the number of trials for this distribution. 35 | * 36 | * @return the number of trials. 37 | */ 38 | int getNumberOfTrials(); 39 | 40 | /** 41 | * Access the probability of success for this distribution. 42 | * 43 | * @return the probability of success. 44 | */ 45 | double getProbabilityOfSuccess(); 46 | 47 | /** 48 | * Change the number of trials for this distribution. 49 | * 50 | * @param trials the new number of trials. 51 | * @deprecated as of v2.1 52 | */ 53 | @Deprecated 54 | void setNumberOfTrials(int trials); 55 | 56 | /** 57 | * Change the probability of success for this distribution. 58 | * 59 | * @param p the new probability of success. 60 | * @deprecated as of v2.1 61 | */ 62 | @Deprecated 63 | void setProbabilityOfSuccess(double p); 64 | } 65 | -------------------------------------------------------------------------------- /src/beast/base/evolution/tree/coalescent/ScaledPopulationFunction.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.tree.coalescent; 2 | 3 | 4 | import java.util.List; 5 | 6 | import beast.base.core.BEASTInterface; 7 | import beast.base.core.Description; 8 | import beast.base.core.Function; 9 | import beast.base.core.Input; 10 | import beast.base.core.Input.Validate; 11 | import beast.base.inference.CalculationNode; 12 | import beast.base.inference.parameter.RealParameter; 13 | 14 | 15 | /** 16 | * @author Joseph Heled 17 | * Date: 2/03/2011 18 | */ 19 | 20 | @Description("Scale a demographic function by a constant factor") 21 | public class ScaledPopulationFunction extends PopulationFunction.Abstract { 22 | final public Input popParameterInput = new Input<>("population", 23 | "population function to scale. ", Validate.REQUIRED); 24 | 25 | final public Input scaleFactorInput = new Input<>("factor", 26 | "scale population by this facor.", Validate.REQUIRED); 27 | 28 | public ScaledPopulationFunction() { 29 | } 30 | 31 | // Implementation of abstract methods 32 | 33 | @Override 34 | public List getParameterIds() { 35 | List ids = popParameterInput.get().getParameterIds(); 36 | if (scaleFactorInput.get() instanceof BEASTInterface) { 37 | ids.add(((BEASTInterface)scaleFactorInput.get()).getID()); 38 | } 39 | return ids; 40 | } 41 | 42 | @Override 43 | public double getPopSize(double t) { 44 | return popParameterInput.get().getPopSize(t) * scaleFactorInput.get().getArrayValue(); 45 | } 46 | 47 | @Override 48 | public double getIntensity(double t) { 49 | double intensity = popParameterInput.get().getIntensity(t); 50 | double scale = scaleFactorInput.get().getArrayValue(); 51 | return intensity / scale; 52 | } 53 | 54 | @Override 55 | public double getInverseIntensity(double x) { 56 | throw new RuntimeException("unimplemented"); 57 | } 58 | 59 | @Override 60 | protected boolean requiresRecalculation() { 61 | return ((CalculationNode) popParameterInput.get()).isDirtyCalculation() 62 | || ((CalculationNode)scaleFactorInput.get()).isDirtyCalculation(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /examples/testCalYule_5t_2c.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/beast/base/inference/distribution/Poisson.java: -------------------------------------------------------------------------------- 1 | package beast.base.inference.distribution; 2 | 3 | 4 | import org.apache.commons.math.distribution.PoissonDistributionImpl; 5 | 6 | import beast.base.core.Description; 7 | import beast.base.core.Function; 8 | import beast.base.core.Input; 9 | import beast.base.inference.parameter.RealParameter; 10 | 11 | 12 | @Description("Poisson distribution, used as prior f(k; lambda)=\\frac{lambda^k e^{-lambda}}{k!} " + 13 | "If the input x is a multidimensional parameter, each of the dimensions is considered as a " + 14 | "separate independent component.") 15 | public class Poisson extends ParametricDistribution { 16 | final public Input lambdaInput = new Input<>("lambda", "rate parameter, defaults to 1"); 17 | 18 | org.apache.commons.math.distribution.PoissonDistribution dist = new PoissonDistributionImpl(1); 19 | 20 | 21 | // Must provide empty constructor for construction by XML. Note that this constructor DOES NOT call initAndValidate(); 22 | public Poisson() { 23 | } 24 | 25 | public Poisson(RealParameter lambda) { 26 | 27 | try { 28 | initByName("lambda", lambda); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | throw new RuntimeException("Failed to initByName lambda parameter when constructing Poisson instance."); 32 | } 33 | } 34 | 35 | @Override 36 | public void initAndValidate() { 37 | refresh(); 38 | } 39 | 40 | /** 41 | * make sure internal state is up to date * 42 | */ 43 | @SuppressWarnings("deprecation") 44 | void refresh() { 45 | double m_fLambda; 46 | if (lambdaInput.get() == null) { 47 | m_fLambda = 1; 48 | } else { 49 | m_fLambda = lambdaInput.get().getArrayValue(); 50 | if (m_fLambda < 0) { 51 | m_fLambda = 1; 52 | } 53 | } 54 | dist.setMean(m_fLambda); 55 | } 56 | 57 | @Override 58 | public org.apache.commons.math.distribution.Distribution getDistribution() { 59 | refresh(); 60 | return dist; 61 | } 62 | 63 | @Override 64 | public double getMeanWithoutOffset() { 65 | return lambdaInput.get().getArrayValue(); 66 | } 67 | 68 | } // class Poisson 69 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/FDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | /** 20 | * F-Distribution. 21 | *

22 | *

23 | * References: 24 | *

28 | *

29 | * 30 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 31 | */ 32 | public interface FDistribution extends ContinuousDistribution { 33 | /** 34 | * Modify the numerator degrees of freedom. 35 | * 36 | * @param degreesOfFreedom the new numerator degrees of freedom. 37 | * @deprecated as of v2.1 38 | */ 39 | @Deprecated 40 | void setNumeratorDegreesOfFreedom(double degreesOfFreedom); 41 | 42 | /** 43 | * Access the numerator degrees of freedom. 44 | * 45 | * @return the numerator degrees of freedom. 46 | */ 47 | double getNumeratorDegreesOfFreedom(); 48 | 49 | /** 50 | * Modify the denominator degrees of freedom. 51 | * 52 | * @param degreesOfFreedom the new denominator degrees of freedom. 53 | * @deprecated as of v2.1 54 | */ 55 | @Deprecated 56 | void setDenominatorDegreesOfFreedom(double degreesOfFreedom); 57 | 58 | /** 59 | * Access the denominator degrees of freedom. 60 | * 61 | * @return the denominator degrees of freedom. 62 | */ 63 | double getDenominatorDegreesOfFreedom(); 64 | } 65 | -------------------------------------------------------------------------------- /src/beast/base/evolution/alignment/TreeTipData.java: -------------------------------------------------------------------------------- 1 | package beast.base.evolution.alignment; 2 | 3 | 4 | import java.io.PrintStream; 5 | 6 | import org.w3c.dom.Node; 7 | 8 | import beast.base.core.Description; 9 | import beast.base.core.Input; 10 | import beast.base.core.Input.Validate; 11 | import beast.base.evolution.datatype.DataType; 12 | import beast.base.inference.StateNode; 13 | import beast.base.inference.parameter.Map; 14 | 15 | @Description("Generic class for associating data to tips of a tree, e.g. an Alignment.") 16 | public class TreeTipData extends Map { 17 | 18 | final public Input taxonSetInput = 19 | new Input<>("taxa", "An optional taxon-set used only to sort the sequences into the same order as they appear in the taxon-set.", new TaxonSet(), Validate.OPTIONAL); 20 | 21 | final public Input userDataTypeInput = new Input<>("userDataType", "non-standard, user specified data type, if specified 'dataType' is ignored"); 22 | 23 | /** Loggable implementation **/ 24 | 25 | @Override 26 | public void init(PrintStream out) { 27 | } 28 | 29 | @Override 30 | public void log(long sample, PrintStream out) { 31 | } 32 | 33 | @Override 34 | public void close(PrintStream out) { 35 | } 36 | 37 | 38 | /** Function implementation **/ 39 | 40 | @Override 41 | public int getDimension() { 42 | return 0; 43 | } 44 | 45 | @Override 46 | public double getArrayValue(int dim) { 47 | return 0; 48 | } 49 | 50 | /** Map implementation **/ 51 | 52 | @Override 53 | protected Class mapType() { 54 | return String.class; 55 | } 56 | 57 | 58 | /** StateNode implementation **/ 59 | 60 | @Override 61 | public void setEverythingDirty(boolean isDirty) { 62 | } 63 | 64 | @Override 65 | public StateNode copy() { 66 | return null; 67 | } 68 | 69 | @Override 70 | public void assignTo(StateNode other) { 71 | } 72 | 73 | @Override 74 | public void assignFrom(StateNode other) { 75 | } 76 | 77 | @Override 78 | public void assignFromFragile(StateNode other) { 79 | } 80 | 81 | @Override 82 | public void fromXML(Node node) { 83 | } 84 | 85 | @Override 86 | public int scale(double scale) { 87 | return 0; 88 | } 89 | 90 | @Override 91 | protected void store() { 92 | } 93 | 94 | @Override 95 | public void restore() { 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/beast/base/core/Param.java: -------------------------------------------------------------------------------- 1 | package beast.base.core; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * This annotation should be used to provide information about parameters in the constructor of a BEAST object, 11 | * as an alternative way to represent inputs. 12 | * 13 | * Note that any object with a constructor with Param annotations should also have a 14 | * public default constructor without arguments to facilitate cloning models in BEAUti. 15 | * 16 | * Furthermore, every Param annotation should come with a public getter and setter, using 17 | * camelcase for name, with annotation CTor(@Param(name="shape",...) double shape) these 18 | * getter and setter signatures should be in the class: 19 | * 20 | * public double getShape() 21 | * public void setShape(double shape) 22 | * 23 | */ 24 | @Target({ElementType.PARAMETER}) 25 | @Retention(RetentionPolicy.RUNTIME) 26 | public @interface Param { 27 | 28 | /** 29 | * The name of this parameter, typically the same as the name 30 | * of the constructor argument. 31 | */ 32 | String name(); 33 | 34 | 35 | /** 36 | * The description of this parameter. Must be specified and contain 37 | * at least 4 words to pass the unit tests. 38 | */ 39 | String description(); 40 | 41 | /** 42 | * @return the default value as a string. An attempt is made to 43 | * convert the String value defaultValue() to the type associated 44 | * with the constructor argument. 45 | */ 46 | String defaultValue() default ""; 47 | 48 | /** 49 | * Indicates the value can be omitted, in which case the default 50 | * value is used (an attempt is made to convert the String value 51 | * defaultValue() to the type associated with the constructor 52 | * argument). 53 | * 54 | * Note that if there are different constructors and an argument 55 | * does not appear in the other constructor it has to be marked 56 | * as optional. 57 | */ 58 | boolean optional() default false; 59 | 60 | /** 61 | * @return true to indicate this description applies to all its 62 | * inherited classes as well, false otherwise 63 | */ 64 | boolean isInheritable() default true; 65 | } -------------------------------------------------------------------------------- /src/beast/base/parser/PartitionContext.java: -------------------------------------------------------------------------------- 1 | package beast.base.parser; 2 | 3 | 4 | import beast.base.core.BEASTInterface; 5 | import beast.base.evolution.likelihood.GenericTreeLikelihood; 6 | 7 | public class PartitionContext { 8 | public String partition; 9 | public String siteModel; 10 | public String clockModel; 11 | public String tree; 12 | 13 | public PartitionContext() {} 14 | 15 | public PartitionContext(String partition) { 16 | this.partition = partition; 17 | siteModel = partition; 18 | clockModel = partition; 19 | tree = partition; 20 | } 21 | 22 | public PartitionContext(String partition, 23 | String siteModel, 24 | String clockModel, 25 | String tree 26 | ) { 27 | this.partition = partition; 28 | this.siteModel = siteModel; 29 | this.clockModel = clockModel; 30 | this.tree = tree; 31 | } 32 | 33 | public PartitionContext(GenericTreeLikelihood treeLikelihood) { 34 | String id = treeLikelihood.dataInput.get().getID(); 35 | id = parsePartition(id); 36 | this.partition = id; 37 | if (treeLikelihood.branchRateModelInput.get() != null) { 38 | id = treeLikelihood.branchRateModelInput.get().getID(); 39 | id = parsePartition(id); 40 | } 41 | this.clockModel = id; 42 | id = ((BEASTInterface) treeLikelihood.siteModelInput.get()).getID(); 43 | id = parsePartition(id); 44 | this.siteModel = id; 45 | id = treeLikelihood.treeInput.get().getID(); 46 | id = parsePartition(id); 47 | this.tree = id; 48 | } 49 | 50 | 51 | static public String parsePartition(String id) { 52 | String partition = id.substring(id.indexOf('.') + 1); 53 | if (partition.indexOf(':') >= 0) { 54 | partition = partition.substring(partition.indexOf(':') + 1); 55 | } 56 | return partition; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return partition + "," + siteModel + "," + clockModel + "," + tree; 62 | } 63 | 64 | @Override 65 | public boolean equals(Object obj) { 66 | if (obj == null) { 67 | return false; 68 | } 69 | if (obj instanceof PartitionContext) { 70 | PartitionContext other = (PartitionContext) obj; 71 | return other.partition.equals(partition) && 72 | other.siteModel.equals(siteModel) && 73 | other.clockModel.equals(clockModel) && 74 | other.tree.equals(tree); 75 | } 76 | return false; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/beast/base/core/Description.java: -------------------------------------------------------------------------------- 1 | /* 2 | * File Description.java 3 | * 4 | * Copyright (C) 2010 Remco Bouckaert remco@cs.auckland.ac.nz 5 | * 6 | * This file is part of BEAST2. 7 | * See the NOTICE file distributed with this work for additional 8 | * information regarding copyright ownership and licensing. 9 | * 10 | * BEAST is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation; either version 2 13 | * of the License, or (at your option) any later version. 14 | * 15 | * BEAST is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with BEAST; if not, write to the 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 23 | * Boston, MA 02110-1301 USA 24 | */ 25 | 26 | package beast.base.core; 27 | 28 | import java.lang.annotation.ElementType; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.RetentionPolicy; 31 | import java.lang.annotation.Target; 32 | 33 | /** 34 | * This is an annotation that can be used to both 35 | * + document a class at the top of the code and 36 | * + create user documentation for XML Beast files. 37 | *

38 | * The idea is to add @Description("bla bla bla") 39 | * just before class declarations of plug-ins. Applications 40 | * like DocMaker then can pick it up through introspection. 41 | *

42 | * To indicate that the description applies to all derived 43 | * classes, the isInheritable flag is set true by default. 44 | * This does not always apply, for instance when the description 45 | * contains text like "Should not be used directly, but by 46 | * implementations". 47 | */ 48 | @Target({ElementType.TYPE}) 49 | @Retention(RetentionPolicy.RUNTIME) 50 | public @interface Description { 51 | 52 | /** 53 | * @return the description of the class 54 | */ 55 | String value(); 56 | 57 | /** 58 | * @return true to indicate this description applies to all its inherited classes as well, false otherwise 59 | */ 60 | boolean isInheritable() default true; 61 | } 62 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/WeibullDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.math.distribution; 19 | 20 | /** 21 | * Weibull Distribution. This interface defines the two parameter form of the 22 | * distribution as defined by 23 | * 24 | * Weibull Distribution, equations (1) and (2). 25 | *

26 | *

27 | * References: 28 | *

32 | *

33 | * 34 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 35 | * @since 1.1 36 | */ 37 | public interface WeibullDistribution extends ContinuousDistribution { 38 | 39 | /** 40 | * Access the shape parameter. 41 | * 42 | * @return the shape parameter. 43 | */ 44 | double getShape(); 45 | 46 | /** 47 | * Access the scale parameter. 48 | * 49 | * @return the scale parameter. 50 | */ 51 | double getScale(); 52 | 53 | /** 54 | * Modify the shape parameter. 55 | * 56 | * @param alpha The new shape parameter value. 57 | * @deprecated as of v2.1 58 | */ 59 | @Deprecated 60 | void setShape(double alpha); 61 | 62 | /** 63 | * Modify the scale parameter. 64 | * 65 | * @param beta The new scale parameter value. 66 | * @deprecated as of v2.1 67 | */ 68 | @Deprecated 69 | void setScale(double beta); 70 | } 71 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/GammaDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | /** 20 | * The Gamma Distribution. 21 | *

22 | *

23 | * References: 24 | *

28 | *

29 | * 30 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 31 | */ 32 | public interface GammaDistribution extends ContinuousDistribution /*, HasDensity*/ { 33 | /** 34 | * Modify the shape parameter, alpha. 35 | * 36 | * @param alpha the new shape parameter. 37 | * @deprecated as of v2.1 38 | */ 39 | @Deprecated 40 | void setAlpha(double alpha); 41 | 42 | /** 43 | * Access the shape parameter, alpha 44 | * 45 | * @return alpha. 46 | */ 47 | double getAlpha(); 48 | 49 | /** 50 | * Modify the scale parameter, beta. 51 | * 52 | * @param beta the new scale parameter. 53 | * @deprecated as of v2.1 54 | */ 55 | @Deprecated 56 | void setBeta(double beta); 57 | 58 | /** 59 | * Access the scale parameter, beta 60 | * 61 | * @return beta. 62 | */ 63 | double getBeta(); 64 | 65 | /** 66 | * Return the probability density for a particular point. 67 | * 68 | * @param x The point at which the density should be computed. 69 | * @return The pdf at point x. 70 | */ 71 | double density(Double x); 72 | } 73 | -------------------------------------------------------------------------------- /test/test/beast/evolution/tree/coalescent/CoalescentTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.evolution.tree.coalescent; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import org.junit.jupiter.api.BeforeEach; 6 | 7 | import beast.base.evolution.alignment.Alignment; 8 | import beast.base.evolution.tree.Tree; 9 | import beast.base.evolution.tree.TreeIntervals; 10 | import beast.base.evolution.tree.coalescent.Coalescent; 11 | import beast.base.evolution.tree.coalescent.ConstantPopulation; 12 | import test.beast.BEASTTestCase; 13 | 14 | /** 15 | * @author Alexei Drummond 16 | * @author Walter Xie 17 | */ 18 | public class CoalescentTest extends BEASTTestCase { 19 | String[] trees = new String[]{"((A:1.0,B:1.0):1.0,C:2.0);", ""}; //more trees ? 20 | Alignment data; 21 | final double pop = 10000; 22 | 23 | @BeforeEach 24 | protected void setUp() throws Exception { 25 | //super.setUp(); 26 | data = getFourTaxaNoData(); 27 | } 28 | 29 | public void testConstantPopulation() throws Exception { 30 | // *********** 3 taxon ********** 31 | Tree tree = getTree(data, trees[0]); 32 | TreeIntervals treeIntervals = new TreeIntervals(); 33 | treeIntervals.initByName("tree", tree); 34 | 35 | ConstantPopulation cp = new ConstantPopulation(); 36 | cp.initByName("popSize", Double.toString(pop)); 37 | 38 | Coalescent coal = new Coalescent(); 39 | coal.initByName("treeIntervals", treeIntervals, "populationModel", cp); 40 | 41 | double logL = coal.calculateLogP(); 42 | 43 | assertEquals(logL, -(4 / pop) - 2 * Math.log(pop), PRECISION); 44 | 45 | // *********** 4 taxon ********** 46 | // tree = getTree(data, trees[1]); 47 | // treeIntervals = new TreeIntervals(); 48 | // treeIntervals.initByName("tree", tree); 49 | // 50 | // cp = new ConstantPopulation(); 51 | // cp.initByName("popSize", Double.toString(pop)); 52 | // 53 | // coal = new Coalescent(); 54 | // coal.initByName("treeIntervals", treeIntervals, "populationModel", cp); 55 | // 56 | // logL = coal.calculateLogP(); 57 | // 58 | // assertEquals(logL, -(4 / pop) - 2 * Math.log(pop), PRECISION); 59 | 60 | } 61 | 62 | public void testExponentialGrowth() throws Exception { 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /test/test/beast/util/XMLTest.java: -------------------------------------------------------------------------------- 1 | package test.beast.util; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertTrue; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | import beast.base.core.BEASTInterface; 9 | import beast.base.evolution.alignment.Taxon; 10 | import beast.base.parser.XMLParser; 11 | import beast.base.parser.XMLParserUtils; 12 | import beast.base.parser.XMLProducer; 13 | import beast.pkgmgmt.BEASTClassLoader; 14 | 15 | import java.io.File; 16 | import java.io.FileWriter; 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | public class XMLTest { 23 | 24 | @Test 25 | public void testAnnotatedConstructor2() throws Exception { 26 | List taxa = new ArrayList<>(); 27 | taxa.add(new Taxon("first one")); 28 | taxa.add(new Taxon("second one")); 29 | 30 | AnnotatedRunnableTestClass t = new AnnotatedRunnableTestClass(3, taxa); 31 | BEASTClassLoader.addService(BEASTInterface.class.getName(), AnnotatedRunnableTestClass.class.getName(), "BEAST.base"); 32 | 33 | XMLProducer producer = new XMLProducer(); 34 | String xml = producer.toXML(t); 35 | 36 | assertEquals(3, (int) t.getParam1()); 37 | 38 | 39 | FileWriter outfile = new FileWriter(new File("/tmp/XMLTest.xml")); 40 | outfile.write(xml); 41 | outfile.close(); 42 | 43 | 44 | XMLParser parser = new XMLParser(); 45 | BEASTInterface b = parser.parseFile(new File("/tmp/XMLTest.xml")); 46 | assertEquals(3, (int) ((AnnotatedRunnableTestClass) b).getParam1()); 47 | assertEquals(2, ((AnnotatedRunnableTestClass) b).getTaxon().size()); 48 | } 49 | 50 | @Test 51 | public void testVariableReplacement() { 52 | 53 | String stringWithVariables = "$(one) $(two) $(three=3)"; 54 | 55 | Map variableDefs = new HashMap<>(); 56 | 57 | XMLParserUtils.extractVariableDefaultsFromString(stringWithVariables, variableDefs); 58 | 59 | assertEquals(1, variableDefs.size()); 60 | assertTrue(variableDefs.containsKey("three")); 61 | assertTrue(variableDefs.containsValue("3")); 62 | 63 | String modifiedString = XMLParserUtils.replaceVariablesInString(stringWithVariables, variableDefs); 64 | assertEquals("$(one) $(two) 3", modifiedString); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/distribution/PoissonDistribution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.distribution; 18 | 19 | import org.apache.commons.math.MathException; 20 | 21 | /** 22 | * Interface representing the Poisson Distribution. 23 | *

24 | *

25 | * References: 26 | *

30 | *

31 | * 32 | * @version $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $ 33 | */ 34 | public interface PoissonDistribution extends IntegerDistribution { 35 | 36 | /** 37 | * Get the mean for the distribution. 38 | * 39 | * @return the mean for the distribution. 40 | */ 41 | double getMean(); 42 | 43 | /** 44 | * Set the mean for the distribution. 45 | * The parameter value must be positive; otherwise an 46 | * IllegalArgument is thrown. 47 | * 48 | * @param p the mean 49 | * @throws IllegalArgumentException if p ≤ 0 50 | * @deprecated as of v2.1 51 | */ 52 | @Deprecated 53 | void setMean(double p); 54 | 55 | /** 56 | * Calculates the Poisson distribution function using a normal approximation. 57 | * 58 | * @param x the upper bound, inclusive 59 | * @return the distribution function value calculated using a normal approximation 60 | * @throws MathException if an error occurs computing the normal approximation 61 | */ 62 | double normalApproximateProbability(int x) throws MathException; 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.math.analysis.solvers; 18 | 19 | /** 20 | * A concrete {@link UnivariateRealSolverFactory}. This is the default solver factory 21 | * used by commons-math. 22 | *

23 | * The default solver returned by this factory is a {@link BrentSolver}.

24 | * 25 | * @version $Revision: 811685 $ $Date: 2009-09-05 13:36:48 -0400 (Sat, 05 Sep 2009) $ 26 | */ 27 | public class UnivariateRealSolverFactoryImpl extends UnivariateRealSolverFactory { 28 | 29 | /** 30 | * Default constructor. 31 | */ 32 | public UnivariateRealSolverFactoryImpl() { 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public UnivariateRealSolver newDefaultSolver() { 40 | return newBrentSolver(); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public UnivariateRealSolver newBisectionSolver() { 48 | return new BisectionSolver(); 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public UnivariateRealSolver newBrentSolver() { 56 | return new BrentSolver(); 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public UnivariateRealSolver newNewtonSolver() { 64 | return new NewtonSolver(); 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @Override 71 | public UnivariateRealSolver newSecantSolver() { 72 | return new SecantSolver(); 73 | } 74 | } 75 | --------------------------------------------------------------------------------