| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.analysis; |
| 22 |
|
|
| 23 |
|
import java.io.File; |
| 24 |
|
import java.io.FileInputStream; |
| 25 |
|
import java.io.IOException; |
| 26 |
|
import java.io.InputStream; |
| 27 |
|
import java.util.ArrayList; |
| 28 |
|
import java.util.List; |
| 29 |
|
import java.util.Map; |
| 30 |
|
|
| 31 |
|
import org.junit.Assert; |
| 32 |
|
import org.testng.annotations.BeforeClass; |
| 33 |
|
import org.testng.annotations.BeforeMethod; |
| 34 |
|
import org.testng.annotations.Test; |
| 35 |
|
|
| 36 |
|
import jalview.bin.Cache; |
| 37 |
|
import jalview.bin.Console; |
| 38 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 39 |
|
import jalview.datamodel.AlignmentI; |
| 40 |
|
import jalview.datamodel.BinaryNode; |
| 41 |
|
import jalview.datamodel.ContactMatrixI; |
| 42 |
|
import jalview.datamodel.SequenceI; |
| 43 |
|
import jalview.gui.AlignFrame; |
| 44 |
|
import jalview.gui.JvOptionPane; |
| 45 |
|
import jalview.io.DataSourceType; |
| 46 |
|
import jalview.io.FastaFile; |
| 47 |
|
import jalview.io.FileLoader; |
| 48 |
|
import jalview.io.FormatAdapter; |
| 49 |
|
import jalview.util.Platform; |
| 50 |
|
import jalview.ws.datamodel.alphafold.PAEContactMatrix; |
| 51 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 5 (40) |
Complexity: 5 |
Complexity Density: 0.15 |
|
| 52 |
|
public class AverageDistanceEngineTest |
| 53 |
|
{ |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 55 |
1 |
@BeforeClass(alwaysRun = true)... |
| 56 |
|
public void setUpJvOptionPane() |
| 57 |
|
{ |
| 58 |
1 |
JvOptionPane.setInteractiveMode(false); |
| 59 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
| 60 |
|
} |
| 61 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
1 |
@BeforeMethod(alwaysRun = true)... |
| 63 |
|
public void loadProperties() |
| 64 |
|
{ |
| 65 |
1 |
Cache.loadProperties("test/jalview/bin/TestProps.jvprops"); |
| 66 |
|
} |
| 67 |
|
|
| |
|
| 85.3% |
Uncovered Elements: 5 (34) |
Complexity: 3 |
Complexity Density: 0.1 |
1PASS
|
|
| 68 |
1 |
@Test(groups = { "Functional" })... |
| 69 |
|
public void testUPGMAEngine() throws Exception |
| 70 |
|
{ |
| 71 |
1 |
AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( |
| 72 |
|
"examples/test_fab41.result/sample.a3m", DataSourceType.FILE); |
| 73 |
1 |
AlignmentI seqs = af.getViewport().getAlignment(); |
| 74 |
1 |
SequenceI target = seqs.getSequenceAt(0); |
| 75 |
1 |
File testPAE = new File( |
| 76 |
|
"examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json"); |
| 77 |
1 |
List<Object> pae_obj = (List<Object>) Platform |
| 78 |
|
.parseJSON(new FileInputStream(testPAE)); |
| 79 |
1 |
if (pae_obj == null) |
| 80 |
|
{ |
| 81 |
0 |
Assert.fail("JSON PAE file did not parse properly."); |
| 82 |
|
} |
| 83 |
1 |
ContactMatrixI matrix = new PAEContactMatrix(target, |
| 84 |
|
(Map<String, Object>) pae_obj.get(0)); |
| 85 |
1 |
AlignmentAnnotation aa = target.addContactList(matrix); |
| 86 |
1 |
System.out.println("Matrix has max=" + matrix.getMax() + " and min=" |
| 87 |
|
+ matrix.getMin()); |
| 88 |
1 |
long start = System.currentTimeMillis(); |
| 89 |
1 |
AverageDistanceEngine clusterer = new AverageDistanceEngine( |
| 90 |
|
af.getViewport(), null, matrix, false); |
| 91 |
1 |
System.out.println("built a tree in " |
| 92 |
|
+ (System.currentTimeMillis() - start) * 0.001 + " seconds."); |
| 93 |
1 |
StringBuffer sb = new StringBuffer(); |
| 94 |
1 |
System.out.println("Newick string\n" |
| 95 |
|
+ new jalview.io.NewickFile(clusterer.getTopNode(), true, true) |
| 96 |
|
.print()); |
| 97 |
|
|
| 98 |
1 |
double height = clusterer.findHeight(clusterer.getTopNode()); |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
1 |
double thr = .2; |
| 104 |
1 |
List<BinaryNode> groups; |
| 105 |
1 |
if (height > thr) |
| 106 |
|
{ |
| 107 |
1 |
float cut = (float) (thr / height); |
| 108 |
1 |
System.out.println("Threshold " + cut + " for height=" + height); |
| 109 |
1 |
groups = clusterer.groupNodes(cut); |
| 110 |
|
} |
| 111 |
|
else |
| 112 |
|
{ |
| 113 |
0 |
groups = new ArrayList<BinaryNode>(); |
| 114 |
0 |
groups.add(clusterer.getTopNode()); |
| 115 |
|
} |
| 116 |
1 |
int n = 1; |
| 117 |
1 |
for (BinaryNode root : groups) |
| 118 |
|
{ |
| 119 |
2 |
System.out.println("Cluster " + n++); |
| 120 |
2 |
for (BinaryNode leaf : clusterer.findLeaves(root)) |
| 121 |
|
{ |
| 122 |
59 |
System.out.print(" " + leaf.getName()); |
| 123 |
|
} |
| 124 |
2 |
System.out.println("\\"); |
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
} |