|
| 1 | +package org.biojava.nbio.phylo; |
| 2 | + |
| 3 | +import org.forester.evoinference.matrix.distance.BasicSymmetricalDistanceMatrix; |
| 4 | +import org.forester.phylogeny.Phylogeny; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import static org.junit.Assert.*; |
| 8 | + |
| 9 | +/** |
| 10 | + * Test for the evaluation of distance trees. |
| 11 | + * |
| 12 | + * @author Aleix Lafita |
| 13 | + * |
| 14 | + */ |
| 15 | +public class TestDistanceTreeEvaluator { |
| 16 | + |
| 17 | + @Test |
| 18 | + public void testErrorFree() throws Exception { |
| 19 | + |
| 20 | + // Create a perfect additive distance matrix |
| 21 | + BasicSymmetricalDistanceMatrix DM = new BasicSymmetricalDistanceMatrix(3); |
| 22 | + |
| 23 | + // dAB = 0.8, dBC = 0.4, dAC = 0.8 |
| 24 | + for (int i = 0; i < 3; i++){ |
| 25 | + char id = (char) ('A' + i); |
| 26 | + DM.setIdentifier(i, id + ""); |
| 27 | + for (int j = i; j < 3; j++){ |
| 28 | + if (i == j){ |
| 29 | + DM.setValue(i, j, 0.0); |
| 30 | + } |
| 31 | + else if (i == 0) { |
| 32 | + DM.setValue(i, j, 0.8); |
| 33 | + DM.setValue(j, i, 0.8); |
| 34 | + } else { |
| 35 | + DM.setValue(i, j, 0.4); |
| 36 | + DM.setValue(j, i, 0.4); |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + BasicSymmetricalDistanceMatrix cloneDM = ForesterWrapper.cloneDM(DM); |
| 42 | + |
| 43 | + //Calculate error free tree and get the cv |
| 44 | + Phylogeny tree = TreeConstructor.distanceTree(cloneDM, TreeConstructorType.NJ); |
| 45 | + double cv = DistanceTreeEvaluator.evaluate(tree, DM); |
| 46 | + |
| 47 | + // Assert error free |
| 48 | + assertEquals(0.0, cv, 0.001); |
| 49 | + |
| 50 | + } |
| 51 | +} |
0 commit comments