Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.analysis

File AverageDistanceEngineTest.java

 

Code metrics

4
33
3
1
128
95
5
0.15
11
3
1.67

Classes

Class Line # Actions
AverageDistanceEngineTest 52 33 5
0.87587.5%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
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   
 
52    public class AverageDistanceEngineTest
53    {
54   
 
55  1 toggle @BeforeClass(alwaysRun = true)
56    public void setUpJvOptionPane()
57    {
58  1 JvOptionPane.setInteractiveMode(false);
59  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
60    }
61   
 
62  1 toggle @BeforeMethod(alwaysRun = true)
63    public void loadProperties()
64    {
65  1 Cache.loadProperties("test/jalview/bin/TestProps.jvprops");
66    }
67   
 
68  1 toggle @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    // 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
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    }