Skip to content

Commit

Permalink
Merge pull request #14 from bjoelle/offsets
Browse files Browse the repository at this point in the history
Offsets
  • Loading branch information
gavryushkina authored Apr 9, 2019
2 parents 3eeb5ab + ea3760c commit 279b455
Show file tree
Hide file tree
Showing 48 changed files with 755 additions and 3,571 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Build output
/out
/bin

# IntelliJ cruft
/.idea
/sampled-ancestors.iml

# Eclipse files
.classpath
.project
/build
/build-lib
Binary file added dist/SA.v2.0.1.zip
Binary file not shown.
236 changes: 236 additions & 0 deletions examples/brachiopods.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/beast/app/simulators/SABDSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.io.*;
import java.util.*;
import java.util.concurrent.ExecutionException;

/**
*
Expand Down
15 changes: 7 additions & 8 deletions src/beast/app/simulators/SABDSkylineTreeSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import beast.core.Description;
import beast.evolution.tree.Node;
import beast.evolution.tree.ZeroBranchSANode;
import beast.util.Randomizer;

import java.io.File;
Expand Down Expand Up @@ -60,7 +59,7 @@ public SABDSkylineTreeSimulator(double newLambda, double newMu, double newPsi, d
public int simulate(PrintStream writer) {

//create an initial node (origin of tree)
Node initial = new ZeroBranchSANode();
Node initial = new Node();
initial.setNr(-1);
initial.setHeight(0.0);
ArrayList<Node> tipNodes = new ArrayList<Node>(); // an array of temporary tip nodes sorted by their heights
Expand Down Expand Up @@ -160,7 +159,7 @@ public int simulate(PrintStream writer) {
}

//the unique node remains in the array is the root of the sampled tree
Node root = new ZeroBranchSANode();
Node root = new Node();
for (Node node:children) {
root=node;
}
Expand Down Expand Up @@ -214,9 +213,9 @@ private ArrayList<Node> getNewNodes(Node node, int typeOfEvent, double timeInter

switch (typeOfEvent) {
case BIRTH: {
Node left = new ZeroBranchSANode();
Node left = new Node();
left.setNr(-1);
Node right = new ZeroBranchSANode();
Node right = new Node();
right.setNr(-1);
left.setHeight(height);
right.setHeight(height);
Expand All @@ -238,9 +237,9 @@ private ArrayList<Node> getNewNodes(Node node, int typeOfEvent, double timeInter

double remain = Randomizer.nextDouble();
if (r < remain) {
Node left = new ZeroBranchSANode();
Node left = new Node();
left.setNr(-1);
Node right = new ZeroBranchSANode();
Node right = new Node();
right.setNr(sampleCount);
left.setHeight(height);
right.setHeight(height);
Expand Down Expand Up @@ -434,7 +433,7 @@ private int countSA(Node node){
if (!node.isLeaf()) {
return countSA(node.getLeft()) + countSA(node.getRight());
} else {
if (((ZeroBranchSANode)node).isDirectAncestor()) {
if (node.isDirectAncestor()) {
return 1;
} else return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import beast.core.Description;
import beast.evolution.tree.Node;
import beast.evolution.tree.ZeroBranchSANode;
import beast.util.Randomizer;

import java.util.*;
Expand Down Expand Up @@ -65,7 +64,7 @@ public SABDSkylineTreeSimulatorArbitraryRateChanges(double[] newLambda, double[]
public int simulate() {

//create an initial node (origin of tree)
Node initial = new ZeroBranchSANode();
Node initial = new Node();
initial.setNr(-1);
initial.setHeight(0.0);
ArrayList<Node> tipNodes = new ArrayList<Node>(); // an array of nodes at the previous stage of simulation
Expand Down Expand Up @@ -171,7 +170,7 @@ public int simulate() {
}

//the unique node remained in the array is the root of the sampled tree
Node root = new ZeroBranchSANode();
Node root = new Node();
for (Node node:children) {
root=node;
}
Expand Down Expand Up @@ -266,9 +265,9 @@ private ArrayList<Node> getNewNodes(Node node, int typeOfEvent, double timeInter
node.setHeight(height);
switch (typeOfEvent) {
case BIRTH: {
Node left = new ZeroBranchSANode();
Node left = new Node();
left.setNr(-1);
Node right = new ZeroBranchSANode();
Node right = new Node();
right.setNr(-1);
left.setHeight(height);
right.setHeight(height);
Expand All @@ -284,9 +283,9 @@ private ArrayList<Node> getNewNodes(Node node, int typeOfEvent, double timeInter
case SAMPLING: {
double remain = Randomizer.nextDouble();
if (r[currentInterval] < remain) {
Node left = new ZeroBranchSANode();
Node left = new Node();
left.setNr(-1);
Node right = new ZeroBranchSANode();
Node right = new Node();
right.setNr(sampleCount);
left.setHeight(height);
right.setHeight(height);
Expand Down
25 changes: 12 additions & 13 deletions src/beast/app/simulators/SABDTreeSimulator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package beast.app.simulators;

import beast.evolution.tree.Node;
import beast.evolution.tree.ZeroBranchSANode;
import beast.math.distributions.LogNormalDistributionModel;
import beast.util.Randomizer;

Expand Down Expand Up @@ -77,7 +76,7 @@ public SABDTreeSimulator(double newLambda, double newMu, double newPsi, double n
*/
public int simulate(PrintStream writer) {
//create an initial node (origin of tree)
Node initial = new ZeroBranchSANode();
Node initial = new Node();
initial.setNr(-1);
initial.setHeight(0.0);
ArrayList<Node> tipNodes = new ArrayList<Node>(); // an array of nodes at the previous stage of simulation
Expand Down Expand Up @@ -145,7 +144,7 @@ public int simulate(PrintStream writer) {
}

//the unique node remained in the array is the root of the sampled tree
Node root = new ZeroBranchSANode();
Node root = new Node();
for (Node node:children) {
root=node;
}
Expand All @@ -170,7 +169,7 @@ public int simulate(PrintStream writer) {
}

public int simulateWithRho(PrintStream writer, double[] rootHeight) {
Node initial = new ZeroBranchSANode();
Node initial = new Node();
initial.setNr(-1);
initial.setHeight(0.0);
ArrayList<Node> tipNodes = new ArrayList<Node>(); // an array of nodes at the previous stage of simulation
Expand Down Expand Up @@ -261,7 +260,7 @@ public int simulateWithRho(PrintStream writer, double[] rootHeight) {
}

//the unique node remained in the array is the root of the sampled tree
Node root = new ZeroBranchSANode();
Node root = new Node();
for (Node node:children) {
root=node;
}
Expand Down Expand Up @@ -295,7 +294,7 @@ public int simulateWithRho(PrintStream writer, double[] rootHeight) {
*/
public int simulateWithRhoSamplingTime(PrintStream treeWriter, PrintStream writer, int[] leafCount) {
//create an initial node (origin of tree)
Node initial = new ZeroBranchSANode();
Node initial = new Node();
initial.setNr(-1);
initial.setHeight(0.0);
ArrayList<Node> tipNodes = new ArrayList<Node>(); // an array of nodes at the previous stage of simulation
Expand Down Expand Up @@ -345,7 +344,7 @@ public int simulateWithRhoSamplingTime(PrintStream treeWriter, PrintStream write
}

//the unique node remained in the array is the root of the sampled tree
Node root = new ZeroBranchSANode();
Node root = new Node();
for (Node node:children) {
root=node;
}
Expand Down Expand Up @@ -426,9 +425,9 @@ private ArrayList<Node> getNewNodes(Node node, int typeOfEvent, double timeInter
node.setHeight(height);
switch (typeOfEvent) {
case BIRTH: {
Node left = new ZeroBranchSANode();
Node left = new Node();
left.setNr(-1);
Node right = new ZeroBranchSANode();
Node right = new Node();
right.setNr(-1);
left.setHeight(height);
right.setHeight(height);
Expand All @@ -444,9 +443,9 @@ private ArrayList<Node> getNewNodes(Node node, int typeOfEvent, double timeInter
case SAMPLING: {
double remain = Randomizer.nextDouble();
if (r < remain) {
Node left = new ZeroBranchSANode();
Node left = new Node();
left.setNr(-1);
Node right = new ZeroBranchSANode();
Node right = new Node();
right.setNr(sampleCount);
left.setHeight(height);
right.setHeight(height);
Expand Down Expand Up @@ -723,7 +722,7 @@ private int countSA(Node node){
if (!node.isLeaf()) {
return countSA(node.getLeft()) + countSA(node.getRight());
} else {
if (((ZeroBranchSANode)node).isDirectAncestor()) {
if (node.isDirectAncestor()) {
return 1;
} else return 0;
}
Expand All @@ -749,7 +748,7 @@ private void printTraitsWithRhoSamplingTime(Node node, PrintStream writer){

private double printSAWithRhoSamplingTime(Node node, PrintStream writer){
if (node.isLeaf()){
if (((ZeroBranchSANode)node).isDirectAncestor()) {
if (node.isDirectAncestor()) {
writer.println(node.getNr() + "=1");
} else {
writer.println(node.getNr() + "=0");
Expand Down
6 changes: 3 additions & 3 deletions src/beast/app/tools/FullToExtantTreeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ private void printConvertedTrees(List<Tree> trees, String outputFile) throws Exc

tree.init(out);
out.println();
tree.log(0, out);
tree.log((long) 0, out);
out.println();

for (int i=1; i< trees.size(); i++) {
oldTree = trees.get(i);
removeFossils(oldTree.getRoot(), oldTree, new ArrayList<>());
numberNodes(oldTree.getRoot(), new int[] {extantTaxa.size()});
tree = new Tree(oldTree.getRoot());
tree.log(i, out);
tree.log((long) i, out);
out.println();
}
out.println("End;");
Expand Down Expand Up @@ -144,7 +144,7 @@ public void initAndValidate() {

@Override
public void run() throws Exception {
java.io.File file, file_out;
java.io.File file;
String outputFile = "";
double customThreshold = -1.;
// ArrayList<String> taxa = null;
Expand Down
1 change: 0 additions & 1 deletion src/beast/app/tools/NexusImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Map;

/**
* @author Alexandra Gavryushkina
Expand Down
10 changes: 4 additions & 6 deletions src/beast/app/tools/SATreeComparingAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import beast.evolution.tree.Node;
import beast.evolution.tree.Tree;
import beast.evolution.tree.ZeroBranchSANode;
import beast.evolution.tree.ZeroBranchSATree;
import beast.util.NexusParser;

import java.util.ArrayList;
Expand Down Expand Up @@ -50,7 +48,7 @@ private SATreeComparingAnalysis.TreeSummary[] makeTreeSummaryForAllTrees(List<Tr
Tree tree = trees.get(treeIndex);
ArrayList<Integer> dAPattern = new ArrayList<Integer>();
for (int i=tree.getLeafNodeCount(); i< tree.getNodeCount(); i++){
if (((ZeroBranchSANode)tree.getNode(i)).isFake()) {
if (tree.getNode(i).isFake()) {
int descendantsCount = tree.getNode(i).getLeafNodeCount() - 1;
if (descendantsCount > 0) {
for(int j=dAPattern.size(); j<descendantsCount; j++){
Expand All @@ -62,7 +60,7 @@ private SATreeComparingAnalysis.TreeSummary[] makeTreeSummaryForAllTrees(List<Tr
}
}
}
treeSummary[treeIndex] = new TreeSummary(tree.getRoot().getHeight(), tree.getLeafNodeCount() - ((ZeroBranchSATree)tree).getDirectAncestorNodeCount(), dAPattern);
treeSummary[treeIndex] = new TreeSummary(tree.getRoot().getHeight(), tree.getLeafNodeCount() - tree.getDirectAncestorNodeCount(), dAPattern);
}
return treeSummary;
}
Expand Down Expand Up @@ -115,7 +113,7 @@ public static void main (String[] arg) throws Exception{
//process tree. consider Fake SA trees
ArrayList<Integer> dAPattern = new ArrayList<Integer>();
for (int i=tree.getLeafNodeCount(); i< tree.getNodeCount(); i++){
if (((ZeroBranchSANode)tree.getNode(i)).isFake()) {
if (tree.getNode(i).isFake()) {
int descendantsCount = tree.getNode(i).getLeafNodeCount() - 1;
if (descendantsCount > 0) {
for(int j=dAPattern.size(); j<descendantsCount; j++){
Expand All @@ -128,7 +126,7 @@ public static void main (String[] arg) throws Exception{
}
}

SATreeComparingAnalysis.TreeSummary treeSummary = analysis.new TreeSummary(tree.getRoot().getHeight(), tree.getLeafNodeCount() - ((ZeroBranchSATree)tree).getDirectAncestorNodeCount(), dAPattern);
SATreeComparingAnalysis.TreeSummary treeSummary = analysis.new TreeSummary(tree.getRoot().getHeight(), tree.getLeafNodeCount() - tree.getDirectAncestorNodeCount(), dAPattern);

System.out.println(treeSummary.dAPattern.toString());
ArrayList<Integer> a = new ArrayList<Integer> (Arrays.asList(new Integer[]{1, 1}));
Expand Down
12 changes: 5 additions & 7 deletions src/beast/app/tools/SATreeToBinaryTreeConverter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package beast.app.tools;

import beast.evolution.tree.ZeroBranchSANode;
import beast.util.SANexusParser;

import java.io.BufferedOutputStream;
Expand All @@ -19,14 +18,14 @@
* **/
public class SATreeToBinaryTreeConverter {

public static void perform(SampledAncestorTreeTrace trace, boolean useNumbers, String outputFile) throws Exception {
public static void perform(SANexusParser trace, boolean useNumbers, String outputFile) throws Exception {
PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile)));

trace.beastTrees.get(0).init(out);
trace.trees.get(0).init(out);
out.println();
for (int i=0; i< trace.beastTrees.size(); i++) {
for (int i=0; i< trace.trees.size(); i++) {
out.print("tree STATE_" + i + " = ");
out.print(((ZeroBranchSANode)trace.beastTrees.get(i).getRoot()).toSortedNewickWithZeroBranches(new int[]{0}));
out.print(trace.trees.get(i).getRoot().toSortedNewick(new int[]{0}, false));
out.println(";");
}
out.println("End;");
Expand Down Expand Up @@ -66,8 +65,7 @@ public static void main(String[] args) throws IOException, Exception {
reader = new FileReader(file);
SANexusParser parser = new SANexusParser();
parser.parseFile(file);
SampledAncestorTreeTrace trace = new SampledAncestorTreeTrace(parser);
perform(trace, useNumbers, outputFile);
perform(parser, useNumbers, outputFile);
}
catch (IOException e) {
//
Expand Down
Loading

0 comments on commit 279b455

Please sign in to comment.