1 package jalview.analysis;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.util.ArrayList;
11 import org.junit.Assert;
12 import org.testng.annotations.BeforeClass;
13 import org.testng.annotations.BeforeMethod;
14 import org.testng.annotations.Test;
16 import jalview.bin.Cache;
17 import jalview.bin.Console;
18 import jalview.datamodel.AlignmentAnnotation;
19 import jalview.datamodel.AlignmentI;
20 import jalview.datamodel.BinaryNode;
21 import jalview.datamodel.ContactMatrixI;
22 import jalview.datamodel.SequenceI;
23 import jalview.gui.AlignFrame;
24 import jalview.gui.JvOptionPane;
25 import jalview.io.DataSourceType;
26 import jalview.io.FastaFile;
27 import jalview.io.FileLoader;
28 import jalview.io.FormatAdapter;
29 import jalview.util.Platform;
30 import jalview.ws.datamodel.alphafold.PAEContactMatrix;
32 public class AverageDistanceEngineTest
35 @BeforeClass(alwaysRun = true)
36 public void setUpJvOptionPane()
38 JvOptionPane.setInteractiveMode(false);
39 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
42 @BeforeMethod(alwaysRun = true)
43 public void loadProperties()
45 Cache.loadProperties("test/jalview/bin/TestProps.jvprops");
48 @Test(groups = { "Functional" })
49 public void testUPGMAEngine() throws Exception
51 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
52 "examples/test_fab41.result/sample.a3m", DataSourceType.FILE);
53 AlignmentI seqs = af.getViewport().getAlignment();
54 SequenceI target = seqs.getSequenceAt(0);
55 File testPAE = new File(
56 "examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json");
57 List<Object> pae_obj = (List<Object>) Platform
58 .parseJSON(new FileInputStream(testPAE));
61 Assert.fail("JSON PAE file did not parse properly.");
63 ContactMatrixI matrix = new PAEContactMatrix(target,
64 (Map<String, Object>) pae_obj.get(0));
65 AlignmentAnnotation aa = target.addContactList(matrix);
66 System.out.println("Matrix has max=" + matrix.getMax() + " and min="
68 long start = System.currentTimeMillis();
69 AverageDistanceEngine clusterer = new AverageDistanceEngine(
70 af.getViewport(), null, matrix, false);
71 System.out.println("built a tree in "
72 + (System.currentTimeMillis() - start) * 0.001 + " seconds.");
73 StringBuffer sb = new StringBuffer();
74 System.out.println("Newick string\n"
75 + new jalview.io.NewickFile(clusterer.getTopNode(), true, true)
78 double height = clusterer.findHeight(clusterer.getTopNode());
79 // compute height fraction to cut
80 // PAE matrixes are absolute measure in angstrom, so
81 // cluster all regions within threshold (e.g. 2A) - if height above
82 // threshold. Otherwise all nodes are in one cluster
84 List<BinaryNode> groups;
87 float cut = (float) (thr / height);
88 System.out.println("Threshold " + cut + " for height=" + height);
89 groups = clusterer.groupNodes(cut);
93 groups = new ArrayList<BinaryNode>();
94 groups.add(clusterer.getTopNode());
97 for (BinaryNode root : groups)
99 System.out.println("Cluster " + n++);
100 for (BinaryNode leaf : clusterer.findLeaves(root))
102 System.out.print(" " + leaf.getName());
104 System.out.println("\\");