diff --git a/build.xml b/build.xml index ec7cc19..b949195 100644 --- a/build.xml +++ b/build.xml @@ -105,8 +105,8 @@ - - + + @@ -167,8 +167,8 @@ - - + + @@ -196,8 +196,8 @@ - - + + diff --git a/examples/BDMUC_example_SequenceSimAnaLyzer.xml b/examples/BDMUC_example_SequenceSimAnaLyzer.xml index 8314b58..fe54977 100644 --- a/examples/BDMUC_example_SequenceSimAnaLyzer.xml +++ b/examples/BDMUC_example_SequenceSimAnaLyzer.xml @@ -1,5 +1,5 @@ +: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"> beast.base.inference.distribution.Beta beast.base.inference.distribution.Exponential @@ -115,7 +115,7 @@ - @@ -194,7 +194,7 @@ - - + 5.0 diff --git a/examples/BDMUC_example_rho_sampling.xml b/examples/BDMUC_example_rho_sampling.xml index c85e2e4..5cb06aa 100644 --- a/examples/BDMUC_example_rho_sampling.xml +++ b/examples/BDMUC_example_rho_sampling.xml @@ -33,10 +33,9 @@ beast.base.inference.distribution.Normal - - + diff --git a/examples/MASTER_SEIT2_simulation_E_0.4_R0_1.3_1.1.xml b/examples/MASTER_SEIT2_simulation_E_0.4_R0_1.3_1.1.xml index c2e5f14..c48ef39 100644 --- a/examples/MASTER_SEIT2_simulation_E_0.4_R0_1.3_1.1.xml +++ b/examples/MASTER_SEIT2_simulation_E_0.4_R0_1.3_1.1.xml @@ -1,15 +1,16 @@ masterTreeInput = new Input( + "masterTree", + "The tree from which traits should be inherited", Input.Validate.REQUIRED); + + public Input popSize = new Input("popSize", "popSize for tree initialization",1.); + + public Input typesKnown = new Input("typesKnown", "Set to false if the tree should not known the leave types. Default true.", true); + public Input printTypes = new Input("printTypes", "print the tip types of simulated tree (default false)",false); + public Input> 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 stateNodes){ + + stateNodes.add(this); + } + +} diff --git a/src/bdmm/core/util/RandomTreeFromMaster.java b/src/bdmm/core/util/RandomTreeFromMaster.java new file mode 100644 index 0000000..da9d28a --- /dev/null +++ b/src/bdmm/core/util/RandomTreeFromMaster.java @@ -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 masterTreeInput = new Input( + "masterTree", + "The tree from which traits should be inherited", Input.Validate.REQUIRED); + + public Input treeInput = new Input( + "tree", + "The initial tree which is to inherited traits from masterTree", Input.Validate.REQUIRED); + + public Input taxaInput = new Input("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 stateNodes){ + + stateNodes.add(treeInput.get()); + } + +} diff --git a/src/bdmm/evolution/tree/InitialMultiTypeTreeFromMaster.java b/src/bdmm/evolution/tree/InitialMultiTypeTreeFromMaster.java new file mode 100644 index 0000000..b1ac626 --- /dev/null +++ b/src/bdmm/evolution/tree/InitialMultiTypeTreeFromMaster.java @@ -0,0 +1,181 @@ +package bdmm.evolution.tree; + + + +import master.BeastTreeFromMaster; +import multitypetree.evolution.tree.MultiTypeNode; +import multitypetree.evolution.tree.MultiTypeTree; +import multitypetree.evolution.tree.SCMigrationModel; +import multitypetree.evolution.tree.StructuredCoalescentMultiTypeTree; + +import java.util.Arrays; +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.inference.StateNode; +import beast.base.inference.StateNodeInitialiser; +import beast.base.inference.parameter.RealParameter; +import beast.base.util.Randomizer; + +/** + * User: Denise + * Date: 11.06.14 + * Time: 14:35 + */ +@Description("Make a MultiTypeTree with tip dates and states obtained from MASTER simulation") +public class InitialMultiTypeTreeFromMaster extends MultiTypeTree implements StateNodeInitialiser { + + final public Input taxaInput = new Input<>("taxa", "set of taxa to initialise tree specified by alignment"); + + public Input masterTreeInput = new Input( + "masterTree", + "The tree from which traits should be inherited", Input.Validate.REQUIRED); + + public Input muInput = new Input("mu", + "Migration rate for tree proposal", Input.Validate.REQUIRED); + + public Input popSizeInput = new Input("popSize", + "Population size for tree proposal", Input.Validate.REQUIRED); + + public Input nTypes = new Input<>("nTypes", "The number of types", Input.Validate.REQUIRED); + + public Input random = new Input<>("random", "Built random tree with traits from BeastTreeFromMaster? If false, tree will copy BeastTreeFromMaster (default true)", true); + + StateNode tree; + + @Override + public void initAndValidate() { + + initStateNodes(); + super.initAndValidate(); + } + + @Override + public void initStateNodes() { + + typeLabel = typeLabelInput.get(); +// nTypes = nTypesInput.get(); + + BeastTreeFromMaster masterTree = masterTreeInput.get(); + + TraitSet typeTrait = new TraitSet(); + TraitSet dateTrait = new TraitSet(); + + 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); + + Alignment taxa = taxaInput.get(); + TaxonSet taxonset = new TaxonSet(); + + Alignment actualTaxa = new Alignment(); + int taxonCount = masterTree.getLeafNodeCount(); + for (int i=0; i()); + //newRoot.changeTypes.addAll(new ArrayList()); + //newRoot.nodeType = 0; + newRoot.setNr(oldRoot.getNr()); + //newRoot.labelNr = oldRoot.labelNr; + + newRoot.addChild(copyFromFlatNode(oldRoot.getLeft())); + newRoot.addChild(copyFromFlatNode(oldRoot.getRight())); + + tree = new MultiTypeTree(newRoot); + } + + tree.setInputValue("trait",typeTrait); + tree.setInputValue("trait",dateTrait); + tree.initAndValidate(); + + setInputValue("trait",dateTrait); + setInputValue("trait",typeTrait); + + assignFromWithoutID(tree); + } + + @Override + public void getInitialisedStateNodes(List stateNodeList) { + stateNodeList.add(this); + } + + MultiTypeNode copyFromFlatNode(Node node){ + + MultiTypeNode mNode = new MultiTypeNode(); + + mNode.setHeight(node.getHeight()); + //mNode.parent = node.parent; + mNode.setParent(node.getParent(), false); + + //mNode.nTypeChanges = 0; + // mNode.changeTimes.addAll(new ArrayList()); + // mNode.changeTypes.addAll(new ArrayList()); + //mNode.nodeType = 0; + + //mNode.labelNr = node.labelNr; + mNode.setNr(node.getNr()); + + if (node.isLeaf()){ + + int type = (int) node.getMetaData("location"); + + if (type!=0) { + + mNode.setNodeType(type); + mNode.addChange(0, (node.getHeight() + (node.getParent().getHeight() -node.getHeight()) * Randomizer.nextDouble())); + } + + } else { + + mNode.addChild(copyFromFlatNode(node.getLeft())); + mNode.addChild(copyFromFlatNode(node.getRight())); + } + + return mNode; + } + +} + + diff --git a/version.xml b/version.xml index 05ccdb2..567f748 100644 --- a/version.xml +++ b/version.xml @@ -1,8 +1,8 @@ - + - - + + @@ -12,6 +12,9 @@ + + +