Skip to content

Commit

Permalink
restore master dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jordandouglas committed Dec 15, 2022
1 parent ea8abd3 commit c0d3e54
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 25 deletions.
12 changes: 6 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
<fileset dir="${beastDir}/lib" includes="*.jar"/>
<fileset dir="${libBeast2}/junit" includes="*.jar"/>
<pathelement path="../BeastFX/build"/>
<pathelement path="../sampled-ancestors/build"/>
<pathelement path="../MultiTypeTree2.7/build"/>
<pathelement path="../MultiTypeTree/build"/>
<pathelement path="../MASTER/build"/>

</classpath>
</javac>
Expand Down Expand Up @@ -167,8 +167,8 @@
<fileset dir="${libBeast2}" includes="*.jar"/>
<fileset dir="${libBeast2}/junit" includes="*.jar"/>
<pathelement path="../BeastFX/build"/>
<pathelement path="../sampled-ancestors/build"/>
<pathelement path="../MultiTypeTree2.7/build"/>
<pathelement path="../MultiTypeTree/build"/>
<pathelement path="../MASTER/build"/>
</classpath>
</javac>
</target>
Expand Down Expand Up @@ -196,8 +196,8 @@
<fileset dir="${libBeast2}" includes="*.jar"/>
<fileset dir="${libBeast2}/junit" includes="*.jar"/>
<pathelement path="../BeastFX/build"/>
<pathelement path="../sampled-ancestors/build"/>
<pathelement path="../MultiTypeTree2.7/build"/>
<pathelement path="../MultiTypeTree/build"/>
<pathelement path="../MASTER/build"/>
</classpath>
<batchtest fork="yes" todir="${test-reports}">
<fileset dir="${build}">
Expand Down
8 changes: 4 additions & 4 deletions examples/BDMUC_example_SequenceSimAnaLyzer.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><beast beautitemplate='Standard' beautistatus='' namespace="beast.pkgmgmt:beast.base.core:beast.base.inference:beast.base.evolution.alignment:beast.base.evolution.tree.coalescent:beast.base.util:beast.base.math:beast.evolution.nuc:beast.base.evolution.operator:beast.base.inference.operator:beast.base.evolution.sitemodel
:beast.evolution.substitutionmodel:beast.evolution.likelihood:beast.core.parameter:beast.evolution.tree.coalescent:multitypetree.operators:multitypetree.util:master.beast:master.conditions:master.model:master.postprocessors:master.outputs:master" version="2.0">
:beast.evolution.substitutionmodel:beast.base.evolution.likelihood:beast.evolution.likelihood:beast.core.parameter:beastfx.app.seqgen:beast.evolution.tree.coalescent:multitypetree.operators:multitypetree.util:master.beast:master.conditions:beast.base.evolution.substitutionmodel:master.model:master.postprocessors:master.outputs:master" version="2.0">

<map name="Beta">beast.base.inference.distribution.Beta</map>
<map name="Exponential">beast.base.inference.distribution.Exponential</map>
Expand Down Expand Up @@ -115,7 +115,7 @@
<sequence spec="Sequence" taxon="100" value="?" />
</alignment>

<tree spec='BeastTreeFromMaster' id="mastertree"
<tree spec='master.BeastTreeFromMaster' id="mastertree"
samplePopulationSizes="true"
nSamples="1"
reverseTime="false">
Expand Down Expand Up @@ -194,7 +194,7 @@
</tree>


<data spec='beast.app.seqgen.SimulatedAlignment' id='alignment'
<data spec='SimulatedAlignment' id='alignment'
data="@input_alignment"
sequencelength="2000"
outputFileName="BDMUC_SequenceSimAnaLyzer_alignment.txt"
Expand Down Expand Up @@ -232,7 +232,7 @@
<run chainLength="5000000" id="mcmc" spec="MCMC" storeEvery="10000" numInitializationAttempts="100">


<init spec="RandomTreeFromMaster" masterTree="@mastertree" taxa="@input_alignment">
<init spec="bdmm.core.util.RandomTreeFromMaster" masterTree="@mastertree" taxa="@input_alignment">
<tree spec="beast.base.evolution.tree.coalescent.RandomTree" id="tree" taxa="@input_alignment">
<populationModel spec="ConstantPopulation">
<parameter name="popSize">5.0</parameter>
Expand Down
5 changes: 2 additions & 3 deletions examples/BDMUC_example_rho_sampling.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
<map name="Normal">beast.base.inference.distribution.Normal</map>

<tree id="tree" spec='feast.fileio.TreeFromNexusFile'
fileName='/Users/scirej/Documents/BEASTdev/bdmm/examples/BDMUC_example_rho_sampling.tree'
fileName='BDMUC_example_rho_sampling.tree'
IsLabelledNewick="true" adjustTipHeights="false"/>
<!-- TODO: CHANGE fileName ABOVE TO YOUR LOCAL PATH -->
<!-- fileName='~/Documents/BEASTdev/bdmm/examples/BDMUC_example_rho_sampling.tree'-->


<distribution spec="bdmm.evolution.speciation.BirthDeathMigrationModelUncoloured" id="treePrior" tree="@tree"
typeLabel="type" stateNumber="2" conditionOnSurvival="true" checkRho="true">
Expand Down
19 changes: 10 additions & 9 deletions examples/MASTER_SEIT2_simulation_E_0.4_R0_1.3_1.1.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beast beautitemplate='Standard' beautistatus=''
namespace="beast.pkgmgmt:beast.base.core:beast.base.inference
:beast.evolution.tree.coalescent
:beast.core.util
:beast.evolution.nuc
:beast.evolution.operators
:beast.evolution.sitemodel
:beast.evolution.substitutionmodel
:beast.evolution.likelihood
:beast.evolution.tree
:beast.core.parameter
:beast.base.evolution.tree.coalescent
:beast.base.core.util
:beast.base.evolution.nuc
:beast.base.evolution.operator
:beast.base.inference.operator
:beast.base.evolution.sitemodel
:beast.base.evolution.substitutionmodel
:beast.base.evolution.likelihood
:beast.base.evolution.tree
:beast.base.core.parameter
:multitypetree.operators
:multitypetree.util
:multitypetree.distributions
Expand Down
127 changes: 127 additions & 0 deletions src/bdmm/core/util/RandomCoalescentTreeFromMaster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package bdmm.core.util;



import master.BeastTreeFromMaster;

import java.util.ArrayList;
import java.util.List;

import beast.base.core.Description;
import beast.base.core.Input;
import beast.base.evolution.alignment.Alignment;
import beast.base.evolution.alignment.TaxonSet;
import beast.base.evolution.tree.Node;
import beast.base.evolution.tree.TraitSet;
import beast.base.evolution.tree.coalescent.RandomTree;
import beast.base.inference.StateNode;
import beast.base.inference.StateNodeInitialiser;
import beast.base.inference.parameter.IntegerParameter;

/**
* User: [email protected]
* Date: 07.03.17
*/
@Description("Make a random tree with tip dates and states obtained from MASTER simulation")
public class RandomCoalescentTreeFromMaster extends RandomTree implements StateNodeInitialiser {

public Input<BeastTreeFromMaster> masterTreeInput = new Input<BeastTreeFromMaster>(
"masterTree",
"The tree from which traits should be inherited", Input.Validate.REQUIRED);

public Input<Double> popSize = new Input<Double>("popSize", "popSize for tree initialization",1.);

public Input<Boolean> typesKnown = new Input<Boolean>("typesKnown", "Set to false if the tree should not known the leave types. Default true.", true);
public Input<Boolean> printTypes = new Input<Boolean>("printTypes", "print the tip types of simulated tree (default false)",false);
public Input<List<IntegerParameter>> changeType = new Input<>("changeType", "Change the type of tip tip with type changeType at index 0 to the changeType at index 1.", new ArrayList<>(), Input.Validate.OPTIONAL);


StateNode tree;

@Override
public void initAndValidate() {

init();

super.initAndValidate();

}

public void init() {

BeastTreeFromMaster masterTree = masterTreeInput.get();

int taxonCount = masterTree.getLeafNodeCount();
System.out.println("taxonCount: " + taxonCount);
nodeCount = masterTree.getNodeCount();

tree = new RandomTree();

TraitSet typeTrait = new TraitSet();
TraitSet dateTrait = new TraitSet();

Alignment taxa = taxaInput.get();
TaxonSet taxonset = new TaxonSet();

Alignment actualTaxa = new Alignment();
for (int i=0; i<taxonCount; i++) {
actualTaxa.setInputValue("sequence", taxa.sequenceInput.get().get(i));
}
actualTaxa.initAndValidate();

taxonset.initByName("alignment", actualTaxa);
setInputValue("taxa",actualTaxa);

String types = "";
String dates = "";
Boolean changeTypes = (changeType.get()!=null);
int[] changeTypeArray = new int[2*changeType.get().size()];
boolean changed;

if (changeTypes){
for (int i=0; i<changeType.get().size(); i++) {
changeTypeArray[i*2] = changeType.get().get(i).getValue(0);
changeTypeArray[i*2+1] = changeType.get().get(i).getValue(1);
}
}

if (printTypes.get())
System.out.println("Tip types of simulated tree:");

for (Node beastNode : masterTree.getExternalNodes()){

dates += beastNode.getID() + "=" + beastNode.getHeight() +",";
if (typesKnown.get()) {
if (changeTypes){
changed = false;
for (int i=0; i<changeType.get().size() && !changed; i++) {
if (changeTypeArray[i*2] == (Integer) beastNode.getMetaData("location")) {
beastNode.setMetaData("location", changeTypeArray[i*2+1]);
changed=true;
}}}
types += beastNode.getID() + "=" + (beastNode.getMetaData("location")) + ",";
}
else
types += beastNode.getID() + "= -1,"; // -1 refers to unknown type in bdmm

if (printTypes.get())
System.out.println(beastNode.getID() + "=" + (beastNode.getMetaData("location")) +",");
}

dates = dates.substring(0,dates.length()-1);
types = types.substring(0,types.length()-1);

typeTrait.initByName("value", types, "taxa", taxonset, "traitname", "type");
dateTrait.initByName("value", dates, "taxa", taxonset, "traitname", "date-backward");

setInputValue("trait",dateTrait);
setInputValue("trait",typeTrait);

}

public void getInitialisedStateNodes(List<StateNode> stateNodes){

stateNodes.add(this);
}

}
91 changes: 91 additions & 0 deletions src/bdmm/core/util/RandomTreeFromMaster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package bdmm.core.util;


import master.BeastTreeFromMaster;

import java.util.List;

import beast.base.core.Description;
import beast.base.core.Input;
import beast.base.evolution.alignment.Alignment;
import beast.base.evolution.alignment.TaxonSet;
import beast.base.evolution.tree.Node;
import beast.base.evolution.tree.TraitSet;
import beast.base.evolution.tree.Tree;
import beast.base.evolution.tree.coalescent.RandomTree;
import beast.base.inference.StateNode;
import beast.base.inference.StateNodeInitialiser;

/**
* User: Denise
* Date: 06.06.14
* Time: 16:34
*/
@Description("Make a random tree with tip dates and states obtained from MASTER simulation")
public class RandomTreeFromMaster extends Tree implements StateNodeInitialiser {

public Input<BeastTreeFromMaster> masterTreeInput = new Input<BeastTreeFromMaster>(
"masterTree",
"The tree from which traits should be inherited", Input.Validate.REQUIRED);

public Input<StateNode> treeInput = new Input<StateNode>(
"tree",
"The initial tree which is to inherited traits from masterTree", Input.Validate.REQUIRED);

public Input<Alignment> taxaInput = new Input<Alignment>("taxa", "set of taxa to initialise tree specified by alignment");


StateNode tree;

@Override
public void initAndValidate() {


super.initAndValidate();

initStateNodes();
}

public void initStateNodes() {

BeastTreeFromMaster masterTree = masterTreeInput.get();


tree = new RandomTree();

TraitSet typeTrait = new TraitSet();
TraitSet dateTrait = new TraitSet();

Alignment taxa = taxaInput.get();
TaxonSet taxonset = new TaxonSet();
taxonset.initByName("alignment", taxa);

String types = "";
String dates = "";

for (Node beastNode : masterTree.getExternalNodes()){

dates += beastNode.getID() + "=" + beastNode.getHeight() +",";
types += beastNode.getID() + "=" + (beastNode.getMetaData("location")) +",";

}

dates = dates.substring(0,dates.length()-1);
types = types.substring(0,types.length()-1);

typeTrait.initByName("value", types, "taxa", taxonset, "traitname", "type");
dateTrait.initByName("value", dates, "taxa", taxonset, "traitname", "date-backward");

tree.initByName("trait",dateTrait,"trait",typeTrait, "taxa", taxa, "populationModel", ((RandomTree)treeInput.get()).populationFunctionInput.get());

treeInput.get().setInputValue("trait",dateTrait);
treeInput.get().setInputValue("trait",typeTrait);
treeInput.get().assignFromWithoutID(tree);
}

public void getInitialisedStateNodes(List<StateNode> stateNodes){

stateNodes.add(treeInput.get());
}

}
Loading

0 comments on commit c0d3e54

Please sign in to comment.