1 package jalview.analysis;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
10 import org.junit.Assert;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.BeforeMethod;
13 import org.testng.annotations.Test;
15 import jalview.bin.Cache;
16 import jalview.bin.Console;
17 import jalview.datamodel.AlignmentAnnotation;
18 import jalview.datamodel.AlignmentI;
19 import jalview.datamodel.BinaryNode;
20 import jalview.datamodel.ContactMatrixI;
21 import jalview.datamodel.SequenceI;
22 import jalview.gui.AlignFrame;
23 import jalview.gui.JvOptionPane;
24 import jalview.io.DataSourceType;
25 import jalview.io.FastaFile;
26 import jalview.io.FileLoader;
27 import jalview.io.FormatAdapter;
28 import jalview.util.Platform;
29 import jalview.ws.datamodel.alphafold.PAEContactMatrix;
31 public class AverageDistanceEngineTest
34 @BeforeClass(alwaysRun = true)
35 public void setUpJvOptionPane()
37 JvOptionPane.setInteractiveMode(false);
38 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
41 @BeforeMethod(alwaysRun = true)
42 public void loadProperties()
44 Cache.loadProperties("test/jalview/bin/TestProps.jvprops");
47 public void testUPGMAEngine() throws Exception
49 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded("examples/test_fab41.result/sample.a3m",DataSourceType.FILE);
50 AlignmentI seqs = af.getViewport().getAlignment();
51 SequenceI target = seqs.getSequenceAt(0);
52 File testPAE = new File("examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json");
53 List<Object> pae_obj = (List<Object>) Platform.parseJSON(new FileInputStream(testPAE));
56 Assert.fail("JSON PAE file did not parse properly.");
58 ContactMatrixI matrix = new PAEContactMatrix(target,
59 (Map<String, Object>) pae_obj.get(0));
60 AlignmentAnnotation aa = target.addContactList(matrix);
61 long start = System.currentTimeMillis();
62 AverageDistanceEngine clusterer = new AverageDistanceEngine(af.getViewport(), null, matrix);
63 System.out.println("built a tree in "+(System.currentTimeMillis()-start)*0.001+" seconds.");
64 StringBuffer sb = new StringBuffer();
65 System.out.println("Newick string\n"+ new jalview.io.NewickFile(clusterer.getTopNode(),true,true).print());
67 clusterer.findHeight(clusterer.getTopNode());
68 List<BinaryNode> groups = clusterer.groupNodes(0.8f);
70 for (BinaryNode root:groups)
72 System.out.println("Cluster "+n++);
73 for (BinaryNode leaf:clusterer.findLeaves(root))
75 System.out.print(" "+leaf.getName());
77 System.out.println("\\");