-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Simulator-Piecewise-model' into hmc-clock
- Loading branch information
Showing
9 changed files
with
283 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* CoalescentRescaler.java | ||
* | ||
* Copyright © 2002-2024 the BEAST Development Team | ||
* http://beast.community/about | ||
* | ||
* This file is part of BEAST. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership and licensing. | ||
* | ||
* BEAST is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* BEAST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with BEAST; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
* | ||
*/ | ||
|
||
package dr.evomodel.coalescent; | ||
|
||
import dr.evolution.coalescent.ConstantPopulation; | ||
import dr.evolution.tree.Tree; | ||
import dr.evomodel.bigfasttree.BigFastTreeIntervals; | ||
import dr.evomodel.coalescent.demographicmodel.ConstantPopulationModel; | ||
import dr.evomodel.coalescent.demographicmodel.RescaleAwareDemographic; | ||
import dr.evomodel.tree.TreeModel; | ||
|
||
/** | ||
* Simulates a set of coalescent intervals given a demographic model. | ||
* | ||
* @author Xiang Ji | ||
* @author Marc Suchard | ||
* @author Filippo Monti | ||
*/ | ||
public class CoalescentRescaler { | ||
|
||
private TreeModel tree; | ||
|
||
private ConstantPopulationModel constantPopulationModel; | ||
|
||
private RescaleAwareDemographic rescaleAwareDemographic; | ||
|
||
private BigFastTreeIntervals bigFastTreeIntervals; | ||
|
||
public CoalescentRescaler(TreeModel tree, ConstantPopulationModel constantPopulationModel, RescaleAwareDemographic rescaleAwareDemographic) { | ||
this.tree = tree; | ||
this.constantPopulationModel = constantPopulationModel; | ||
this.rescaleAwareDemographic = rescaleAwareDemographic; | ||
this.bigFastTreeIntervals = new BigFastTreeIntervals("constant.population.size.tree", tree); | ||
} | ||
|
||
public TreeModel rescaleTree() { | ||
double[] intensityTimeProducts = new double[bigFastTreeIntervals.getIntervalCount()]; | ||
double[] intervals = new double[bigFastTreeIntervals.getIntervalCount()]; | ||
for (int i = 0; i < bigFastTreeIntervals.getIntervalCount(); i++) { | ||
intervals[i] = bigFastTreeIntervals.getInterval(i); | ||
intensityTimeProducts[i] = intervals[i] / ((ConstantPopulation) constantPopulationModel.getDemographicFunction()).getN0(); | ||
} | ||
double[] scaledIntervals = rescaleAwareDemographic.rescaleInterval(intervals, intensityTimeProducts); | ||
|
||
double height = 0; | ||
for (int i = 0; i < scaledIntervals.length; i++) { | ||
height += scaledIntervals[i]; | ||
int[] intervalNodeNumbers = bigFastTreeIntervals.getNodeNumbersForInterval(i); | ||
tree.setNodeHeightQuietly(tree.getNode(intervalNodeNumbers[1]), height); | ||
} | ||
tree.pushTreeChangedEvent(); | ||
|
||
return tree; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1418,4 +1418,4 @@ public List<Citation> getCitations() { | |
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/dr/evomodel/coalescent/demographicmodel/RescaleAwareDemographic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* RescaleAwareDemographic.java | ||
* | ||
* Copyright © 2002-2024 the BEAST Development Team | ||
* http://beast.community/about | ||
* | ||
* This file is part of BEAST. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership and licensing. | ||
* | ||
* BEAST is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* BEAST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with BEAST; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
* | ||
*/ | ||
|
||
package dr.evomodel.coalescent.demographicmodel; | ||
|
||
public interface RescaleAwareDemographic { | ||
|
||
double[] rescaleInterval(double[] intervals, double[] targetIntensityIntervalProducts); | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
src/dr/evomodelxml/coalescent/CoalescentRescalerParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* CoalescentRescalerParser.java | ||
* | ||
* Copyright © 2002-2024 the BEAST Development Team | ||
* http://beast.community/about | ||
* | ||
* This file is part of BEAST. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership and licensing. | ||
* | ||
* BEAST is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* BEAST is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with BEAST; if not, write to the | ||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
* Boston, MA 02110-1301 USA | ||
* | ||
*/ | ||
|
||
package dr.evomodelxml.coalescent; | ||
|
||
import dr.evolution.coalescent.ConstantPopulation; | ||
import dr.evolution.tree.Tree; | ||
import dr.evolution.util.TaxonList; | ||
import dr.evomodel.coalescent.CoalescentRescaler; | ||
import dr.evomodel.coalescent.demographicmodel.ConstantPopulationModel; | ||
import dr.evomodel.coalescent.demographicmodel.DemographicModel; | ||
import dr.evomodel.coalescent.demographicmodel.RescaleAwareDemographic; | ||
import dr.evomodel.tree.DefaultTreeModel; | ||
import dr.evomodel.tree.TreeModel; | ||
import dr.xml.*; | ||
|
||
public class CoalescentRescalerParser extends AbstractXMLObjectParser { | ||
|
||
public static final String COALESCENT_RESCALER = "coalescentRescaler"; | ||
|
||
@Override | ||
public Object parseXMLObject(XMLObject xo) throws XMLParseException { | ||
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class); | ||
if (tree == null) { | ||
tree = new DefaultTreeModel((Tree) xo.getChild(Tree.class)); | ||
} | ||
ConstantPopulationModel constantPopulation = (ConstantPopulationModel) xo.getChild(ConstantPopulationModel.class); | ||
RescaleAwareDemographic rescaleAwareDemographic = (RescaleAwareDemographic) xo.getChild(RescaleAwareDemographic.class); | ||
CoalescentRescaler coalescentRescaler = new CoalescentRescaler(tree, constantPopulation, rescaleAwareDemographic); | ||
return coalescentRescaler.rescaleTree(); | ||
} | ||
|
||
@Override | ||
public XMLSyntaxRule[] getSyntaxRules() { | ||
return rules; | ||
} | ||
|
||
private final XMLSyntaxRule[] rules = { | ||
new XORRule(new ElementRule(TreeModel.class), | ||
new ElementRule(Tree.class)), | ||
new ElementRule(ConstantPopulationModel.class, 0, Integer.MAX_VALUE), | ||
new ElementRule(RescaleAwareDemographic.class, 0, Integer.MAX_VALUE), | ||
}; | ||
|
||
@Override | ||
public String getParserDescription() { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public Class getReturnType() { | ||
return TreeModel.class; | ||
} | ||
|
||
@Override | ||
public String getParserName() { | ||
return COALESCENT_RESCALER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters