Skip to content

Commit

Permalink
unifies root patch and clean up with master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
JT committed Mar 26, 2021
2 parents 9788ba2 + ade547a commit 16d1c75
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 77 deletions.
4 changes: 2 additions & 2 deletions build.xml
Expand Up @@ -348,10 +348,10 @@
<!--
<property name="version" value="1.9"/>
-->
<property name="version" value="1.10.5pre"/>
<property name="version" value="1.10.5pre_thorney_0.1.1"/>
<property name="jvm_version" value="1.7+"/>

<property name="version_number" value="1.10.5"/>
<property name="version_number" value="1.10.5pre_thorney_0.1.1"/>
<property name="copyright" value="Copyright 2002-2019"/>

<property name="release_dir" value="release"/>
Expand Down
2 changes: 1 addition & 1 deletion build_beastgen.xml
Expand Up @@ -72,7 +72,7 @@
</jar>
</target>

<property name="version" value="1.0.2" />
<property name="version" value="0.3pre_thorney" />
<property name="release_dir" value="release_beastgen" />
<property name="name" value="BEASTGen" />

Expand Down
190 changes: 138 additions & 52 deletions src/dr/app/tools/LogCombiner.java
Expand Up @@ -124,76 +124,162 @@ public LogCombiner(long[] burnins, long resample, String[] inputFileNames, Strin
System.out.println();
}

boolean processTrees = stripAnnotations || convertToDecimal;

if (treeFiles) {

TreeImporter importer = new NexusImporter(new FileReader(inputFile), stripAnnotations);
try {
while (importer.hasTree()) {
Tree tree = importer.importNextTree();
if (firstTree) {
startLog(tree, writer);
firstTree = false;
}
if (processTrees) { // then we need to read each tree and write it.
TreeImporter importer = new NexusImporter(new FileReader(inputFile), stripAnnotations);
try {
while (importer.hasTree()) {
Tree tree = importer.importNextTree();
if (firstTree) {
startLog(tree, writer);
firstTree = false;
}

String name = tree.getId();
if (name == null) {
System.err.println("ERROR: Trees do not give state numbers as tree attributes.");
return;
}
String name = tree.getId();
if (name == null) {
System.err.println("ERROR: Trees do not give state numbers as tree attributes.");
return;
}

// split on underscore in STATE_xxxx
String[] bits = name.split("_");
long state = Long.parseLong(bits[1]);
// split on underscore in STATE_xxxx
String[] bits = name.split("_");
long state = Long.parseLong(bits[1]);

if (stateStep < 0 && state > 0) {
stateStep = state;
}
if (stateStep < 0 && state > 0) {
stateStep = state;
}

if (state >= burnin) {
if (stateStep > 0) {
if (!renumberOutput) {
stateCount += stateStep;
} else {
stateCount += 1;
}
}

if (resample >= 0) {
if (resample % stateStep != 0) {
System.err.println("ERROR: Resampling frequency is not a multiple of existing sampling frequency");
return;
}
}

boolean logThis;
if (resample < 0) {
// not resampling, log every state
logThis = true;
} else if (!renumberOutput) {
// resampling but not renumbering
logThis = (stateCount % resample == 0);
} else {
logThis = (stateCount * stateStep % resample == 0);
}

if (state >= burnin) {
if (stateStep > 0) {
long stateLineEntry;
if (!renumberOutput) {
stateCount += stateStep;
stateLineEntry = stateCount;
} else {
stateCount += 1;
stateLineEntry = stateCount / (resample / stateStep);
}
}

if (resample >= 0) {
if (resample % stateStep != 0) {
System.err.println("ERROR: Resampling frequency is not a multiple of existing sampling frequency");
return;
if (logThis) {
writeTree(stateLineEntry, tree, convertToDecimal, writer);
}
}

boolean logThis;
if (resample < 0) {
// not resampling, log every state
logThis=true;
} else if (!renumberOutput) {
// resampling but not renumbering
logThis=(stateCount % resample == 0);
} else {
logThis=(stateCount*stateStep % resample == 0);
}
}
} catch (Importer.ImportException e) {
System.err.println("Error Parsing Input Tree: " + e.getMessage());
return;
}
} else {
BufferedReader reader = new BufferedReader(new FileReader(inputFile));

long stateLineEntry;
if (!renumberOutput){
stateLineEntry=stateCount;
} else {
stateLineEntry=stateCount/(resample/stateStep);
}
String line = reader.readLine();

if (logThis){
writeTree(stateLineEntry, tree, convertToDecimal, writer);
}
// skip (or write) the headers
while (line != null && !line.trim().startsWith("tree ")) {
if (firstFile) {
writer.println(line);
}
line = reader.readLine();
}

Pattern pattern = Pattern.compile("tree STATE_(\\d+)\\s(.*)");

while (line != null) {
Matcher m = pattern.matcher(line);
if (m.matches()) {

long state = Long.parseLong(m.group(1));

String treeString = m.group(2);

boolean skip = false;
if (!skip) {
if (stateStep < 0 && state > 0) {
stateStep = state;
}

// if the columnCount is not the same then perhaps the line is corrupt so skip it.
if (state >= burnin) {
if (stateStep > 0) {
if (!renumberOutput) {
stateCount += stateStep;
} else {
stateCount += 1;
}
}

if (resample >= 0) {
if (resample % stateStep != 0) {
System.err.println("ERROR: Resampling frequency is not a multiple of existing sampling frequency");
return;
}
}

boolean logThis;
if (resample < 0) {
logThis = true;
} else if (!renumberOutput) {
logThis = (stateCount % resample == 0);
} else {
logThis = ((stateCount * stateStep) % resample == 0);
}

long stateLineEntry;
if (!renumberOutput) {
stateLineEntry = stateCount;
} else {

// System.out.println("stateCount: " + stateCount);
// System.out.println("resample: " + resample);
// System.out.println("stateStep: " + stateStep);
// System.out.println("resample / stateStep: " + (resample / stateStep));

stateLineEntry = stateCount / (resample / stateStep);
}

if (logThis) {
writer.print("tree STATE_");
writer.print(stateLineEntry);
writer.println(treeString);
}
}
}
}
line = reader.readLine();
//lineCount++;
}
} catch (Importer.ImportException e) {
System.err.println("Error Parsing Input Tree: " + e.getMessage());
return;
}

firstFile = false;


} else {
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
//int lineCount = 1;
Expand Down Expand Up @@ -290,12 +376,12 @@ public LogCombiner(long[] burnins, long resample, String[] inputFileNames, Strin
if (!renumberOutput){
stateLineEntry = stateCount;
} else {

// System.out.println("stateCount: " + stateCount);
// System.out.println("resample: " + resample);
// System.out.println("stateStep: " + stateStep);
// System.out.println("resample / stateStep: " + (resample / stateStep));

stateLineEntry = stateCount / (resample / stateStep);
}

Expand Down
10 changes: 6 additions & 4 deletions src/dr/evomodel/coalescent/GMRFMultilocusSkyrideLikelihood.java
Expand Up @@ -309,10 +309,12 @@ public GMRFMultilocusSkyrideLikelihood(List<Tree> treeList,
this.delta = deltaList;
}else{
this.delta = new ArrayList<Parameter>();
for(int i = 0; i < betaList.size(); i++){
Parameter deltaParam = new Parameter.Default(1.0);
deltaParam.setParameterValue(0,1.0);
this.delta.add(deltaParam);
if (betaList != null) {
for (int i = 0; i < betaList.size(); i++) {
Parameter deltaParam = new Parameter.Default(1.0);
deltaParam.setParameterValue(0, 1.0);
this.delta.add(deltaParam);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/dr/evomodel/coalescent/TreeIntervals.java
Expand Up @@ -158,7 +158,7 @@ private NodeRef getIncludedMRCA(Tree tree) {
*/
private Set<NodeRef> getExcludedMRCAs(Tree tree) {

if (excludedLeafSets==null || excludedLeafSets.length == 0) return null;
if (excludedLeafSets == null || excludedLeafSets.length == 0) return null;

Set<NodeRef> excludeNodesBelow = new HashSet<NodeRef>();
for (Set<String> excludedLeafSet : excludedLeafSets) {
Expand Down Expand Up @@ -380,4 +380,4 @@ public double getStatisticValue(int i) {

private boolean eventsKnown = false;
private boolean storedEventsKnown = false;
}
}
Expand Up @@ -29,12 +29,16 @@ public MultiMoveUniformNodeHeightOperator(TreeModel tree, double weight, double
}

/**
* Do a subtree leap move.
* Do operation.
*
* @return the log-transformed hastings ratio
*/
public double doOperation() {

//TODO the order in which nodes are picked matters but there is more than
// one way to pick the nodes I don't trust the hasting ration of 1.
throw new UnsupportedOperationException("Multimove node heights operations are not supported");
/*
List<NodeRef> selected = new ArrayList<>();
Set<NodeRef> ignore = new HashSet<>();
ignore.add(tree.getRoot());
Expand Down Expand Up @@ -64,7 +68,7 @@ public double doOperation() {
}
return logL;

*/
}

private double doMove(NodeRef node){
Expand Down
12 changes: 7 additions & 5 deletions src/dr/evomodelxml/operators/NodeHeightOperatorParser.java
Expand Up @@ -30,7 +30,7 @@
import dr.evomodel.operators.ScaleNodeHeightOperator;
import dr.evomodel.operators.UniformNodeHeightOperator;
import dr.evomodel.tree.TreeModel;
import dr.evomodel.treelikelihood.thorneytreelikelihood.MultiMoveUniformNodeHeightOperator;
//import dr.evomodel.treelikelihood.thorneytreelikelihood.MultiMoveUniformNodeHeightOperator;
import dr.inference.operators.AdaptableMCMCOperator;
import dr.inference.operators.AdaptationMode;
import dr.inference.operators.MCMCOperator;
Expand All @@ -45,8 +45,10 @@ public enum OperatorType {
UNIFORM("uniform"),
RANDOMWALK("random walk"),
SCALEROOT("scale root"),
SCALEALL("scale all internal"),
MULTIMOVEUNIFORM("multiMoveUniform");
SCALEALL("scale all internal");
// MULTIMOVEUNIFORM("multiMoveUniform");
// -JT the order in which nodes are picked matters but there is more than
// one way to pick the nodes I don't trust the multimove operator

OperatorType(String name) {
this.name = name;
Expand Down Expand Up @@ -122,8 +124,8 @@ public Object parseXMLObject(XMLObject xo) throws XMLParseException {
case SCALEROOT:
case SCALEALL:
return new ScaleNodeHeightOperator(treeModel, weight, tuningParameter, operatorType, mode, targetAcceptance);
case MULTIMOVEUNIFORM:
return new MultiMoveUniformNodeHeightOperator(treeModel, weight, tuningParameter,mode,targetAcceptance);
// case MULTIMOVEUNIFORM:
// return new MultiMoveUniformNodeHeightOperator(treeModel, weight, tuningParameter,mode,targetAcceptance);
default:
throw new IllegalArgumentException("Unknown operator type");
}
Expand Down
12 changes: 3 additions & 9 deletions src/dr/math/MathUtils.java
Expand Up @@ -89,17 +89,11 @@ public static int randomChoicePDF(double[] pdf) {
}

}

// fallen through so throw error...
StringBuilder sb = new StringBuilder("pdf=[");
sb.append(pdf[0]);
for (int i = 1; i < pdf.length; i++) {
sb.append(",");
sb.append(pdf[i]);
for (int i = 0; i < pdf.length; i++) {
System.err.println(i + "\t" + pdf[i]);
}
sb.append("]");
throw new Error("randomChoicePDF falls through -- negative, infinite or NaN components in input " +
"distribution, or all zeroes? " + sb.toString());
"distribution, or all zeroes? " );
}

/**
Expand Down

0 comments on commit 16d1c75

Please sign in to comment.