Skip to content

Commit 28f2a11

Browse files
committed
Refactor to use forester 1.005
git-svn-id: http://code.open-bio.org/repos/biojava/biojava-live/trunk@9793 7c6358e6-4a41-0410-a743-a5b2a554c398
1 parent 8d20772 commit 28f2a11

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

biojava3-alignment/src/main/java/org/biojava3/alignment/GuideTree.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343
import org.forester.phylogeny.Phylogeny;
4444
import org.forester.phylogeny.PhylogenyNode;
45-
import org.forester.phylogenyinference.BasicSymmetricalDistanceMatrix;
46-
import org.forester.phylogenyinference.NeighborJoining;
45+
import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
46+
import org.forester.evoinference.distance.NeighborJoining;
4747

4848
/**
4949
* Implements a data structure for a guide tree used during progressive multiple sequence alignment. Leaf
@@ -72,16 +72,20 @@ public GuideTree(List<S> sequences, List<PairwiseSequenceScorer<S, C>> scorers)
7272
this.sequences = Collections.unmodifiableList(sequences);
7373
this.scorers = Collections.unmodifiableList(scorers);
7474
distances = new BasicSymmetricalDistanceMatrix(sequences.size());
75+
BasicSymmetricalDistanceMatrix distclone = new BasicSymmetricalDistanceMatrix(sequences.size());
7576
for (int i = 0, n = 0; i < sequences.size(); i++) {
7677
AccessionID id = sequences.get(i).getAccession();
77-
distances.setIdentifier(i, (id == null) ? Integer.toString(i + 1) : id.getID());
78+
String str = (id == null) ? Integer.toString(i + 1) : id.getID();
79+
distances.setIdentifier(i, str);
80+
distclone.setIdentifier(i, str);
7881
for (int j = i+1; j < sequences.size(); j++) {
79-
PairwiseSequenceScorer<S, C> scorer = scorers.get(n++);
80-
distances.setValue(i, j, scorer.getDistance());
82+
double dist = scorers.get(n++).getDistance();
83+
distances.setValue(i, j, dist);
84+
distclone.setValue(i, j, dist);
8185
}
8286
}
8387
// TODO UPGMA and other hierarchical clustering routines
84-
Phylogeny phylogeny = NeighborJoining.createInstance().execute(distances);
88+
Phylogeny phylogeny = NeighborJoining.createInstance().execute(distclone);
8589
newick = phylogeny.toString();
8690
root = new Node(phylogeny.getRoot(), null);
8791
}
@@ -181,7 +185,7 @@ public class Node implements GuideTreeNode<S, C> {
181185
private Node(PhylogenyNode node, Node parent) {
182186
this.parent = parent;
183187
distance = node.getDistanceToParent();
184-
name = node.getNodeName();
188+
name = node.getName();
185189
if(isLeaf = node.isExternal()) {
186190
profile = new SimpleProfile<S, C>(sequences.get(distances.getIndex(name)));
187191
} else {

biojava3-alignment/src/test/java/org/biojava3/alignment/GuideTreeTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ public void testGetAllPairsScores() {
6666
assertArrayEquals(tree.getAllPairsScores(), new int[] {4, 0, 3, 0, 3, 0});
6767
}
6868

69-
// FIXME [0][3] and [3][0] should be 0.4
7069
@Test
7170
public void testGetDistanceMatrix() {
7271
assertArrayEquals(tree.getDistanceMatrix(), new double[][] {
73-
{0.0, 0.0, 1.0, 0.19999999999999996},
72+
{0.0, 0.0, 1.0, 0.4},
7473
{0.0, 0.0, 1.0, 0.4},
7574
{1.0, 1.0, 0.0, 1.0},
76-
{0.19999999999999996, 0.4, 1.0, 0.0}});
75+
{0.4, 0.4, 1.0, 0.0}});
7776
}
7877

7978
@Test
@@ -124,7 +123,7 @@ public void testIterator() {
124123
@Test
125124
public void testToString() {
126125
assertEquals(tree.toString(),
127-
"(((1:0.0,2:0.0):0.19999999999999996,3:0.8):0.09999999999999998,4:0.09999999999999998)");
126+
"(((1:0.0,2:0.0):-1.4,3:0.8999999999999999):-0.7,4:-0.7)");
128127
}
129128

130129
}

biojava3-phylo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>org</groupId>
6363
<artifactId>forester</artifactId>
64-
<version>0.955</version>
64+
<version>1.005</version>
6565
<type>jar</type>
6666
<scope>compile</scope>
6767
</dependency>

biojava3-phylo/src/main/java/org/biojava3/phylo/CheckTreeAccuracy.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
package org.biojava3.phylo;
66

77
import java.util.HashMap;
8+
import java.util.HashSet;
9+
import java.util.List;
810
import java.util.Set;
911
import org.forester.phylogeny.Phylogeny;
1012
import org.forester.phylogeny.PhylogenyNode;
11-
import org.forester.phylogenyinference.BasicSymmetricalDistanceMatrix;
12-
import org.forester.phylogenyinference.DistanceMatrix;
13+
import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
14+
import org.forester.evoinference.matrix.distance.DistanceMatrix;
1315

1416
/**
1517
*
@@ -36,11 +38,12 @@ public static DistanceMatrix copyMatrix(DistanceMatrix matrix) {
3638

3739
public void process(Phylogeny tree, DistanceMatrix matrix) {
3840
int numSequences = matrix.getSize();
39-
Set<PhylogenyNode> externalNodes = tree.getExternalNodes();
41+
List<PhylogenyNode> externalNodes = tree.getExternalNodes();
4042
HashMap<String, PhylogenyNode> externalNodesHashMap = new HashMap<String, PhylogenyNode>();
43+
Set<PhylogenyNode> path = new HashSet<PhylogenyNode>();
4144

4245
for (PhylogenyNode node : externalNodes) {
43-
externalNodesHashMap.put(node.getNodeName(), node);
46+
externalNodesHashMap.put(node.getName(), node);
4447
}
4548
int count = 0;
4649
double averageMatrixDistance = 0.0;
@@ -49,14 +52,14 @@ public void process(Phylogeny tree, DistanceMatrix matrix) {
4952
for (int row = 0; row < numSequences - 1; row++) {
5053
String nodeName1 = matrix.getIdentifier(row);
5154
PhylogenyNode node1 = externalNodesHashMap.get(nodeName1);
52-
markPathToRoot(node1, true);
55+
markPathToRoot(node1, path);
5356
for (int col = row + 1; col < numSequences; col++) {
5457
count++;
5558
String nodeName2 = matrix.getIdentifier(col);
5659
PhylogenyNode node2 = externalNodesHashMap.get(nodeName2);
5760
double distance = matrix.getValue(col, row);
5861
averageMatrixDistance = averageMatrixDistance + distance;
59-
PhylogenyNode commonParent = findCommonParent(node2);
62+
PhylogenyNode commonParent = findCommonParent(node2, path);
6063
if (commonParent != null) {
6164
double treeDistance = getNodeDistance(commonParent, node1) + getNodeDistance(commonParent, node2);
6265

@@ -67,7 +70,7 @@ public void process(Phylogeny tree, DistanceMatrix matrix) {
6770
System.out.println("Unable to find common parent with " + node1 + " " + node2);
6871
}
6972
}
70-
markPathToRoot(node1, false);
73+
path.clear();
7174
}
7275

7376
System.out.println("Average matrix distance:" + averageMatrixDistance / count);
@@ -86,18 +89,18 @@ public double getNodeDistance(PhylogenyNode parentNode, PhylogenyNode childNode)
8689
return distance;
8790
}
8891

89-
public PhylogenyNode findCommonParent(PhylogenyNode node) {
90-
while (!node.getPathToParent()) {
92+
public PhylogenyNode findCommonParent(PhylogenyNode node, Set<PhylogenyNode> path) {
93+
while (!path.contains(node)) {
9194
node = node.getParent();
9295
}
9396
return node;
9497
}
9598

96-
public void markPathToRoot(PhylogenyNode node, boolean value) {
97-
node.setPathToParent(value);
99+
public void markPathToRoot(PhylogenyNode node, Set<PhylogenyNode> path) {
100+
path.add(node);
98101
while (!node.isRoot()) {
99102
node = node.getParent();
100-
node.setPathToParent(value);
103+
path.add(node);
101104
}
102105
}
103106
}

biojava3-phylo/src/main/java/org/biojava3/phylo/TreeConstructor.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
import org.forester.io.writers.PhylogenyWriter;
2828
import org.forester.phylogeny.Phylogeny;
29-
import org.forester.phylogenyinference.BasicSymmetricalDistanceMatrix;
30-
import org.forester.phylogenyinference.DistanceMatrix;
31-
import org.forester.phylogenyinference.NeighborJoining;
29+
import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix;
30+
import org.forester.evoinference.matrix.distance.DistanceMatrix;
31+
import org.forester.evoinference.distance.NeighborJoining;
3232

3333
/**
3434
* Tree constructor uses the forrester tree library to build phylogenetic trees using neighbor joining algorithm. The distance matrix
@@ -51,7 +51,7 @@ public TreeConstructor(MultipleSequenceAlignment<C, D> multipleSequenceAlignment
5151

5252
}
5353

54-
public TreeConstructor(DistanceMatrix _matrix, TreeType _treeType, TreeConstructionAlgorithm _treeConstructionAlgorithm, NJTreeProgressListener _treeProgessListener) {
54+
public TreeConstructor(BasicSymmetricalDistanceMatrix _matrix, TreeType _treeType, TreeConstructionAlgorithm _treeConstructionAlgorithm, NJTreeProgressListener _treeProgessListener) {
5555
matrix = _matrix;
5656
copyDistanceMatrix = CheckTreeAccuracy.copyMatrix(matrix);
5757
treeType = _treeType;
@@ -166,7 +166,7 @@ public void cancel() {
166166
}
167167
boolean verbose = false;
168168
Phylogeny p = null;
169-
DistanceMatrix matrix = null;
169+
BasicSymmetricalDistanceMatrix matrix = null;
170170
DistanceMatrix copyDistanceMatrix = null;
171171

172172
public void process() throws Exception {
@@ -188,8 +188,7 @@ public void process() throws Exception {
188188
}
189189

190190
final List<Phylogeny> ps = new ArrayList<Phylogeny>();
191-
final NeighborJoining nj = NeighborJoining.createInstance();
192-
nj.setVerbose(verbose);
191+
final NeighborJoining nj = NeighborJoining.createInstance(verbose);
193192

194193
ps.add(nj.execute(matrix));
195194
p = ps.get(0);

0 commit comments

Comments
 (0)