Skip to content

Commit

Permalink
migrate to BEAST v2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Oct 4, 2022
1 parent 1511a48 commit 7dc7bd9
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 151 deletions.
76 changes: 20 additions & 56 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<property name="srcBeast2" location="${beast2path}/src" />
<property name="beast2classpath" location="${beast2path}/build" />
<property name="Add_on_dir" value="${release_dir}/add-on" />
<property name="version" value="0.3.0" />

<import file="${beast2path}/build.xml" />

Expand All @@ -27,19 +26,27 @@

<path id="classpath">
<pathelement path="${buildmgsm}"/>
<fileset dir="${beast2path}/lib" includes="junit-4.8.2.jar"/>
<fileset dir="${beast2path}/lib/junit" includes="junit-platform-console-standalone-1.8.2.jar"/>
<fileset dir="${beast2path}/lib" includes="jam.jar"/>
<fileset dir="${beast2path}/lib" includes="beagle.jar"/>
<fileset dir="${beast2path}/lib" includes="fest.jar"/>
<fileset dir="${beast2path}/lib" includes="colt.jar"/>
<fileset dir="${beast2path}/lib" includes="antlr-runtime-4.7.jar"/>
<fileset dir="${beast2path}/lib" includes="antlr-runtime-4.10.1.jar"/>
<pathelement path="${beast2classpath}"/>
</path>

<!-- start -->
<target name="initMGSM">
<echo message="${ant.project.name}: ${ant.file}" />
</target>
<available file="./version.xml" property="versionAvailable"/>
<fail unless="versionAvailable">
** Required file version.xml does not exist. **
</fail>

<!-- Read package name and version from xml file -->
<xmlproperty file="./version.xml" prefix="fromVersionFile" />
<property name="MGSMversion" value="${fromVersionFile.package(version)}" />
</target>

<target name="cleanMGSM">
<delete dir="${buildmgsm}" />
Expand Down Expand Up @@ -79,7 +86,7 @@
memorymaximumsize="1024m"
source="1.8"
target="1.8">
<include name="beast/**/**" />
<include name="mgsm/**/**" />
<!-- compile JUnit test classes -->
<include name="test/beast/**" />
</javac>
Expand All @@ -91,61 +98,18 @@
<!-- Create the distribution directory -->
<mkdir dir="${distmgsm}" />

<!-- Put everything in ${buildmgsm} into the beast.jar file -->
<jar jarfile="${distmgsm}/beastmgsm.jar">
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Main-Class" value="${main_class_BEAST}" />
</manifest>
<fileset dir="${buildmgsm}">
<include name="beast/**/*.class" />
</fileset>
<fileset dir="${beast2classpath}">
<include name="beast/**/*.class" />
<include name="beast/**/*.properties" />
<include name="beast/**/*.png" />
<include name="beagle/**/*.class" />
<include name="org/**/*.class" />
</fileset>
<zipgroupfileset dir="${beast2path}/lib" includes="jam.jar" />
<zipgroupfileset dir="${beast2path}/lib" includes="beagle.jar" />
<zipgroupfileset dir="${beast2path}/lib" includes="colt.jar" />
<zipgroupfileset dir="${beast2path}/lib" includes="commons-math3-3.1.1.jar" />
<zipgroupfileset dir="${beast2path}/lib" includes="antlr-runtime-4.7.jar" />
</jar>

<jar jarfile="${distmgsm}/treeannotator.jar">
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Main-Class" value="beast.app.treeannotator.TreeAnnotator" />
</manifest>
<fileset dir="${buildmgsm}">
<include name="beast/**/*.class" />
</fileset>
<fileset dir="${beast2classpath}">
<include name="beast/**/*.class" />
<include name="beast/**/*.properties" />
<include name="beast/**/*.png" />
<include name="beagle/**/*.class" />
<include name="org/**/*.class" />
</fileset>
<zipgroupfileset dir="${beast2path}/lib" includes="jam.jar" />
<!--zipgroupfileset dir="${lib}" includes="commons-math-II.0.jar" /-->
</jar>
<jar jarfile="${distmgsm}/MGSM.src.jar">
<fileset dir="${srcmgsm}">
<include name="beast/**/*.java" />
<include name="mgsm/**/*.java" />
<include name="test/**/*.java" />
<include name="beast/**/*.png" />
<include name="beast/**/*.xsl" />
</fileset>
</jar>
<jar jarfile="${distmgsm}/MGSM.addon.jar">
<manifest>
<attribute name="Built-By" value="${user.name}" />
</manifest>
<fileset dir="${buildmgsm}">
<include name="beast/**/*.class" />
<include name="mgsm/**/*.class" />
<include name="**/*.properties" />
</fileset>
</jar>
Expand Down Expand Up @@ -192,15 +156,15 @@
</target>

<target name="addon"
depends="build_jar_all_MGSM_NoJUnitTest"
depends="initMGSM,build_jar_all_MGSM_NoJUnitTest"
description="release BEAST 2 add-on version of MGSM">

<delete dir="${Add_on_dir}" />
<!-- Create the release directory -->
<mkdir dir="${Add_on_dir}" />
<mkdir dir="${Add_on_dir}/lib" />
<mkdir dir="${Add_on_dir}/examples" />
<mkdir dir="${Add_on_dir}/templates" />
<mkdir dir="${Add_on_dir}/fxtemplates" />

<copy todir="${Add_on_dir}">
<fileset file="version.xml"/>
Expand All @@ -217,16 +181,16 @@
<fileset file="${distmgsm}/MGSM.src.jar" />
</copy>

<copy todir="${Add_on_dir}/templates">
<fileset file="templates/MGSM.xml" />
<copy todir="${Add_on_dir}/fxtemplates">
<fileset file="fxtemplates/MGSM.xml" />
</copy>

<jar jarfile="${distmgsm}/MGSM.addon.v${version}.zip">
<jar jarfile="${distmgsm}/MGSM.addon.v${MGSMversion}.zip">
<fileset dir="${Add_on_dir}">
<include name="**/*" />
</fileset>
</jar>
<echo message="Add-on version release is finished." />
<echo message="Add-on version ${MGSMversion} release is finished." />
</target>

</project>
28 changes: 14 additions & 14 deletions templates/MGSM.xml → fxtemplates/MGSM.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<beast version='2.0'
namespace='beast.app.beauti:beast.core:beast.evolution.branchratemodel:beast.evolution.speciation:beast.evolution.tree.coalescent:beast.core.util:beast.evolution.nuc:beast.evolution.operators:beast.evolution.sitemodel:beast.evolution.substitutionmodel:beast.evolution.likelihood:beast.evolution:beast.math.distributions'>
namespace='beast.app.beauti:beast.pkgmgmt:beast.base.core:beast.base.inference:beast.base.evolution.branchratemodel:beast.base.evolution.speciation:beast.base.evolution.tree.coalescent:beast.pkgmgmt:beast.base.core:beast.base.inference.util:beast.evolution.nuc:beast.base.evolution.operator:beast.base.inference.operator:beast.base.evolution.sitemodel:beast.base.evolution.substitutionmodel:beast.base.evolution.likelihood:beast.evolution:beast.base.math.distributions'>

<mergewith point='substModelTemplates'>

<!-- site models -->

<!-- multi gamma site model -->
<subtemplate id='Multi-Gamma Site Model' class='beast.evolution.sitemodel.MultiGammaSiteModel' mainid='MultiGammaSiteModel.s:$(n)'>
<subtemplate id='Multi-Gamma Site Model' class='mgsm.evolution.sitemodel.MultiGammaSiteModel' mainid='MultiGammaSiteModel.s:$(n)'>
<![CDATA[
<plugin spec='MultiGammaSiteModel' id="MultiGammaSiteModel.s:$(n)" gammaCategoryCount='4'>
<plugin spec='mgsm.evolution.sitemodel.MultiGammaSiteModel' id="MultiGammaSiteModel.s:$(n)" gammaCategoryCount='4'>
<!--substModel will be automatically detected /-->
<proportionInvariant spec='parameter.RealParameter' id='MGSMproportionInvariant.s:$(n)' value='0.1' lower='0' upper='1' estimate='true'/>
<mutationRate spec='parameter.RealParameter' id='MGSMMutationRate.s:$(n)' value='1.0' estimate='false'/>
<shapes spec='parameter.RealParameter' id='MGSMgammaShape.s:$(n)' value='1.0' estimate='true'/>
</plugin>
<prior id='MGSMMutationRatePrior.s:$(n)' x='@MGSMMutationRate.s:$(n)'><distr spec="OneOnX"/></prior>
<prior id='MGSMGammaShapePrior.s:$(n)' x='@MGSMgammaShape.s:$(n)'><distr spec="beast.math.distributions.Exponential" mean='1'/></prior>
<prior id='MGSMGammaShapePrior.s:$(n)' x='@MGSMgammaShape.s:$(n)'><distr spec="beast.base.inference.distribution.Exponential" mean='1'/></prior>
<operator id='MGSMproportionInvariantScaler.s:$(n)' spec='ScaleOperator' scaleFactor="0.5" weight="0.1" parameter="@MGSMproportionInvariant.s:$(n)"/>
<operator id='MGSMMutationRateScaler.s:$(n)' spec='ScaleOperator' scaleFactor="0.5" weight="0.1" parameter="@MGSMMutationRate.s:$(n)"/>
<operator id='MGSMgammaShapeScaler1.s:$(n)' spec='ScaleOperator' scaleFactor="0.5" weight="5.0" parameter="@MGSMgammaShape.s:$(n)" scaleAll="false"/>
<operator id='MGSMgammaShapeScaler2.s:$(n)' spec='ScaleOperator' scaleFactor="0.5" weight="0.5" parameter="@MGSMgammaShape.s:$(n)" scaleAll="true"/>
<distribution id='MGSMMultiGammaSiteModelPrior.s:$(n)' spec="MultiGammaSiteModelPrior" shapes="@MGSMgammaShape.s:$(n)" tree="@Tree.t:$(n)"/>
<distribution id='MGSMMultiGammaSiteModelPrior.s:$(n)' spec="mgsm.evolution.sitemodel.MultiGammaSiteModelPrior" shapes="@MGSMgammaShape.s:$(n)" tree="@Tree.t:$(n)"/>
]]>

<connect srcID='MGSMMutationRatePrior.s:$(n)' targetID='prior' inputName='distribution' if='nooperator(FixMeanMutationRatesOperator) and inlikelihood(MGSMMutationRate.s:$(n)) and MGSMMutationRate.s:$(n)/estimate=true'/>
Expand Down Expand Up @@ -52,11 +52,11 @@


<!-- relaxed gamma site model -->
<subtemplate id='Relaxed Gamma Site Model' class='beast.evolution.sitemodel.RelaxedGammaSiteModel' mainid='RelaxedGammaSiteModel.s:$(n)'
suppressInputs='beast.evolution.sitemodel.RelaxedGammaSiteModel.tree,
beast.evolution.sitemodel.RelaxedGammaSiteModel.distr,
beast.evolution.sitemodel.RelaxedGammaSiteModel.rateCategories,
beast.evolution.sitemodel.RelaxedGammaSiteModel.shape
<subtemplate id='Relaxed Gamma Site Model' class='mgsm.evolution.sitemodel.RelaxedGammaSiteModel' mainid='RelaxedGammaSiteModel.s:$(n)'
suppressInputs='mgsm.evolution.sitemodel.RelaxedGammaSiteModel.tree,
mgsm.evolution.sitemodel.RelaxedGammaSiteModel.distr,
mgsm.evolution.sitemodel.RelaxedGammaSiteModel.rateCategories,
mgsm.evolution.sitemodel.RelaxedGammaSiteModel.shape
'>
<![CDATA[
Expand All @@ -65,16 +65,16 @@
<parameter id="RGSMucldStdevGamma.s:$(n)" lower="0.0" name="stateNode" upper="5.0">0.5</parameter>
<stateNode dimension="100" id="RGSMrateCategoriesGamma.s:$(n)" spec="parameter.IntegerParameter" value="1"/>
<plugin spec='RelaxedGammaSiteModel' id="RelaxedGammaSiteModel.s:$(n)" gammaCategoryCount='4' rateCategories="@RGSMrateCategoriesGamma.s:$(n)" tree="@Tree.t:$(n)">
<plugin spec='mgsm.evolution.sitemodel.RelaxedGammaSiteModel' id="RelaxedGammaSiteModel.s:$(n)" gammaCategoryCount='4' rateCategories="@RGSMrateCategoriesGamma.s:$(n)" tree="@Tree.t:$(n)">
<!--substModel will be automatically detected /-->
<proportionInvariant spec='parameter.RealParameter' id='RGSMproportionInvariant.s:$(n)' value='0.1' lower='0' upper='1' estimate='true'/>
<mutationRate spec='parameter.RealParameter' id='RGSMmutationRate.s:$(n)' value='1.0' estimate='false'/>
<LogNormal id="LogNormalDistributionModelGamma.c:atpB_3" name="distr" S="@RGSMucldStdevGamma.s:$(n)" M="@RGSMucldMeanGamma.s:$(n)" meanInRealSpace="true"/>
</plugin>
<prior id='RGSMMutationRatePrior.s:$(n)' x='@RGSMmutationRate.s:$(n)'><distr spec="OneOnX"/></prior>
<prior id='RGSMMeanPrior.s:$(n)' x='@RGSMucldMeanGamma.s:$(n)'><distr spec="beast.math.distributions.Exponential" mean='1'/></prior>
<prior id='RGSMStdDevPrior.s:$(n)' x='@RGSMucldStdevGamma.s:$(n)'><distr spec="beast.math.distributions.Exponential" mean='0.33'/></prior>
<prior id='RGSMMeanPrior.s:$(n)' x='@RGSMucldMeanGamma.s:$(n)'><distr spec="beast.base.inference.distribution.Exponential" mean='1'/></prior>
<prior id='RGSMStdDevPrior.s:$(n)' x='@RGSMucldStdevGamma.s:$(n)'><distr spec="beast.base.inference.distribution.Exponential" mean='0.33'/></prior>
<operator id='RGSMproportionInvariantScaler.s:$(n)' spec='ScaleOperator' scaleFactor="0.5" weight="0.1" parameter="@RGSMproportionInvariant.s:$(n)"/>
<operator id='RGSMmutationRateScaler.s:$(n)' spec='ScaleOperator' scaleFactor="0.5" weight="0.1" parameter="@RGSMmutationRate.s:$(n)"/>
Expand All @@ -85,7 +85,7 @@
<operator id="RGSMCategoriesSwapGammaOperator.s:$(n)" spec="SwapOperator" intparameter="@RGSMrateCategoriesGamma.s:$(n)" weight="10.0"/>
<operator id="RGSMCategoriesUniformGamma.s:$(n)" spec="UniformOperator" parameter="@RGSMrateCategoriesGamma.s:$(n)" weight="10.0"/>
<distribution id='RelaxedGammaSiteModelPrior.s:$(n)' spec="MultiGammaSiteModelPrior" shapes="@RGSMrateCategoriesGamma.s:$(n)" tree="@Tree.t:$(n)"/>
<distribution id='RelaxedGammaSiteModelPrior.s:$(n)' spec="mgsm.evolution.sitemodel.MultiGammaSiteModelPrior" shapes="@RGSMrateCategoriesGamma.s:$(n)" tree="@Tree.t:$(n)"/>
]]>

<connect srcID='RGSMMutationRatePrior.s:$(n)' targetID='prior' inputName='distribution' if='nooperator(FixMeanMutationRatesOperator) and inlikelihood(RGSMmutationRate.s:$(n)) and RGSMmutationRate.s:$(n)/estimate=true'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Boston, MA 02110-1301 USA
*/

package beast.evolution.likelihood;
package mgsm.evolution.likelihood;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -34,17 +34,17 @@
import beagle.BeagleInfo;
import beagle.InstanceDetails;
import beagle.ResourceDetails;
import beast.core.CalculationNode;
import beast.core.Description;
import beast.core.util.Log;
import beast.evolution.alignment.Alignment;
import beast.evolution.branchratemodel.StrictClockModel;
import beast.evolution.likelihood.TreeLikelihood;
import beast.evolution.sitemodel.SiteModel;
import beast.evolution.sitemodel.SiteModelInterface.Base;
import beast.evolution.substitutionmodel.EigenDecomposition;
import beast.evolution.tree.Node;
import beast.evolution.tree.Tree;
import beast.base.inference.CalculationNode;
import beast.base.core.Description;
import beast.base.core.Log;
import beast.base.evolution.alignment.Alignment;
import beast.base.evolution.branchratemodel.StrictClockModel;
import beast.base.evolution.likelihood.TreeLikelihood;
import beast.base.evolution.sitemodel.SiteModel;
import beast.base.evolution.sitemodel.SiteModelInterface.Base;
import beast.base.evolution.substitutionmodel.EigenDecomposition;
import beast.base.evolution.tree.Node;
import beast.base.evolution.tree.Tree;


/**
Expand All @@ -63,7 +63,7 @@ public class MGSMBeagleTreeLikelihood extends TreeLikelihood {
// allocate each BEAGLE instance to. If less than the number of instances then
// will wrap around.
// note: to use a different device, say device 2, start beast with
// java -Dbeagle.resource.order=2 beast.app.BeastMCMC
// java -Dbeagle.resource.order=2 beastfx.app.beast.BeastMCMC
private static final String RESOURCE_ORDER_PROPERTY = "beagle.resource.order";
private static final String PREFERRED_FLAGS_PROPERTY = "beagle.preferred.flags";
private static final String REQUIRED_FLAGS_PROPERTY = "beagle.required.flags";
Expand Down Expand Up @@ -149,14 +149,14 @@ private boolean initialize() {
break;
}
}
if (constantPattern != null && constantPattern.size() > dataInput.get().getPatternCount()) {
if (getConstantPattern() != null && getConstantPattern().size() > dataInput.get().getPatternCount()) {
// if there are many more constant patterns than patterns (each pattern can
// have a number of constant patters, one for each state) it is less efficient
// to just calculate the TreeLikelihood for constant sites than optimising
Log.debug("switch off constant sites optimisiation: calculating through separate TreeLikelihood category (as in the olden days)");
invariantCategory = -1;
proportionInvariant = 0;
constantPattern = null;
setConstantPattern(null);
categoryRates = m_siteModel.getCategoryRates(null);
}
}
Expand Down Expand Up @@ -539,7 +539,7 @@ protected boolean requiresRecalculation() {

if (hasNodeIndependentCategories(m_siteModel)) {
double[] categoryRates = m_siteModel.getCategoryRates(null);
if (constantPattern != null) {
if (getConstantPattern() != null) {
double [] tmp = new double [categoryRates.length - 1];
for (int k = 0; k < invariantCategory; k++) {
tmp[k] = categoryRates[k];
Expand Down Expand Up @@ -693,7 +693,7 @@ public double calculateLogP() {
if (updateSiteModel) {
if (hasNodeIndependentCategories(m_siteModel)) {
double[] categoryRates = m_siteModel.getCategoryRates(null);
if (constantPattern != null) {
if (getConstantPattern() != null) {
double [] tmp = new double [categoryRates.length - 1];
for (int k = 0; k < invariantCategory; k++) {
tmp[k] = categoryRates[k];
Expand Down Expand Up @@ -773,7 +773,7 @@ public double calculateLogP() {
int rootIndex = partialBufferHelper.getOffsetIndex(root.getNr());

double[] categoryWeights = m_siteModel.getCategoryProportions(null);
if (constantPattern != null) {
if (getConstantPattern() != null) {
double [] tmp = new double [categoryWeights.length - 1];
for (int k = 0; k < invariantCategory; k++) {
tmp[k] = categoryWeights[k];
Expand Down Expand Up @@ -834,7 +834,7 @@ public double calculateLogP() {
proportionInvariant = m_siteModel.getProportionInvariant();


for (int k : constantPattern) {
for (int k : getConstantPattern()) {
int i = k / m_nStateCount;
int j = k % m_nStateCount;
patternLogLikelihoods[i] = (Math.log(Math.exp(patternLogLikelihoods[i]) + proportionInvariant * frequencies[j]));
Expand Down Expand Up @@ -911,9 +911,9 @@ private double getAscertainmentCorrectedLogLikelihood(Alignment patternList,
double[] patternLogLikelihoods,
int[] patternWeights,
double [] frequencies) {
if (constantPattern != null) {
if (getConstantPattern() != null) {
proportionInvariant = m_siteModel.getProportionInvariant();
for (int k : constantPattern) {
for (int k : getConstantPattern()) {
int i = k / m_nStateCount;
int j = k % m_nStateCount;
patternLogLikelihoods[i] = (Math.log(Math.exp(patternLogLikelihoods[i]) + proportionInvariant * frequencies[j]));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package beast.evolution.sitemodel;
package mgsm.evolution.sitemodel;

import org.apache.commons.math.distribution.GammaDistribution;
import org.apache.commons.math.distribution.GammaDistributionImpl;

import beast.core.Description;
import beast.core.Input;
import beast.core.Input.Validate;
import beast.core.parameter.RealParameter;
import beast.core.util.Log;
import beast.evolution.likelihood.MGSMBeagleTreeLikelihood;
import beast.evolution.tree.Node;
import beast.evolution.tree.Tree;
import beast.base.core.Description;
import beast.base.core.Input;
import beast.base.core.Input.Validate;
import beast.base.inference.parameter.RealParameter;
import mgsm.evolution.likelihood.MGSMBeagleTreeLikelihood;
import beast.base.core.Log;
import beast.base.evolution.sitemodel.SiteModel;
import beast.base.evolution.tree.Node;
import beast.base.evolution.tree.Tree;

@Description("Gamma site model that allows different shape parameters for each branche")
public class MultiGammaSiteModel extends SiteModel {
Expand Down
Loading

0 comments on commit 7dc7bd9

Please sign in to comment.