2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.analysis;
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;
31 import org.junit.Assert;
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.BeforeMethod;
34 import org.testng.annotations.Test;
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;
52 public class AverageDistanceEngineTest
55 @BeforeClass(alwaysRun = true)
56 public void setUpJvOptionPane()
58 JvOptionPane.setInteractiveMode(false);
59 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
62 @BeforeMethod(alwaysRun = true)
63 public void loadProperties()
65 Cache.loadProperties("test/jalview/bin/TestProps.jvprops");
68 @Test(groups = { "Functional" })
69 public void testUPGMAEngine() throws Exception
71 AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded(
72 "examples/test_fab41.result/sample.a3m", DataSourceType.FILE);
73 AlignmentI seqs = af.getViewport().getAlignment();
74 SequenceI target = seqs.getSequenceAt(0);
75 File testPAE = new File(
76 "examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json");
77 List<Object> pae_obj = (List<Object>) Platform
78 .parseJSON(new FileInputStream(testPAE));
81 Assert.fail("JSON PAE file did not parse properly.");
83 ContactMatrixI matrix = new PAEContactMatrix(target,
84 (Map<String, Object>) pae_obj.get(0));
85 AlignmentAnnotation aa = target.addContactList(matrix);
86 System.out.println("Matrix has max=" + matrix.getMax() + " and min="
88 long start = System.currentTimeMillis();
89 AverageDistanceEngine clusterer = new AverageDistanceEngine(
90 af.getViewport(), null, matrix, false);
91 System.out.println("built a tree in "
92 + (System.currentTimeMillis() - start) * 0.001 + " seconds.");
93 StringBuffer sb = new StringBuffer();
94 System.out.println("Newick string\n"
95 + new jalview.io.NewickFile(clusterer.getTopNode(), true, true)
98 double height = clusterer.findHeight(clusterer.getTopNode());
99 // compute height fraction to cut
100 // PAE matrixes are absolute measure in angstrom, so
101 // cluster all regions within threshold (e.g. 2A) - if height above
102 // threshold. Otherwise all nodes are in one cluster
104 List<BinaryNode> groups;
107 float cut = (float) (thr / height);
108 System.out.println("Threshold " + cut + " for height=" + height);
109 groups = clusterer.groupNodes(cut);
113 groups = new ArrayList<BinaryNode>();
114 groups.add(clusterer.getTopNode());
117 for (BinaryNode root : groups)
119 System.out.println("Cluster " + n++);
120 for (BinaryNode leaf : clusterer.findLeaves(root))
122 System.out.print(" " + leaf.getName());
124 System.out.println("\\");