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 public void testUPGMAEngine() throws Exception
50 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded("examples/test_fab41.result/sample.a3m",DataSourceType.FILE);
51 AlignmentI seqs = af.getViewport().getAlignment();
52 SequenceI target = seqs.getSequenceAt(0);
53 File testPAE = new File("examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json");
54 List<Object> pae_obj = (List<Object>) Platform.parseJSON(new FileInputStream(testPAE));
57 Assert.fail("JSON PAE file did not parse properly.");
59 ContactMatrixI matrix = new PAEContactMatrix(target,
60 (Map<String, Object>) pae_obj.get(0));
61 AlignmentAnnotation aa = target.addContactList(matrix);
62 System.out.println("Matrix has max="+matrix.getMax()+" and min="+matrix.getMin());
63 long start = System.currentTimeMillis();
64 AverageDistanceEngine clusterer = new AverageDistanceEngine(af.getViewport(), null, matrix);
65 System.out.println("built a tree in "+(System.currentTimeMillis()-start)*0.001+" seconds.");
66 StringBuffer sb = new StringBuffer();
67 System.out.println("Newick string\n"+ new jalview.io.NewickFile(clusterer.getTopNode(),true,true).print());
69 double height = clusterer.findHeight(clusterer.getTopNode());
70 // compute height fraction to cut
71 // PAE matrixes are absolute measure in angstrom, so
72 // cluster all regions within threshold (e.g. 2A) - if height above threshold. Otherwise all nodes are in one cluster
74 List<BinaryNode> groups;
77 float cut = (float) (thr/height);
78 System.out.println("Threshold "+cut+" for height="+height);
79 groups = clusterer.groupNodes(cut);
81 groups=new ArrayList<BinaryNode>();
82 groups.add(clusterer.getTopNode());
85 for (BinaryNode root:groups)
87 System.out.println("Cluster "+n++);
88 for (BinaryNode leaf:clusterer.findLeaves(root))
90 System.out.print(" "+leaf.getName());
92 System.out.println("\\");