Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.workers

File SecondaryStructureConsensusThread.java

 

Coverage histogram

../../img/srcFileCovDistChart9.png
13% of files have more coverage

Code metrics

28
65
13
1
263
168
34
0.52
5
13
2.62

Classes

Class Line # Actions
SecondaryStructureConsensusThread 40 65 34
0.858490685.8%
 

Contributing tests

This file is covered by 214 tests. .

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.workers;
22   
23    import java.util.Collections;
24    import java.util.HashMap;
25    import java.util.List;
26    import java.util.Map;
27   
28    import jalview.analysis.AAFrequency;
29    import jalview.api.AlignViewportI;
30    import jalview.api.AlignmentViewPanel;
31    import jalview.datamodel.AlignmentAnnotation;
32    import jalview.datamodel.AlignmentI;
33    import jalview.datamodel.Annotation;
34    import jalview.datamodel.ProfilesI;
35    import jalview.datamodel.SequenceI;
36    import jalview.renderer.ResidueShaderI;
37    import jalview.util.Constants;
38    import jalview.util.MessageManager;
39   
 
40    public class SecondaryStructureConsensusThread extends AlignCalcWorker
41    {
 
42  482 toggle public SecondaryStructureConsensusThread(AlignViewportI alignViewport,
43    AlignmentViewPanel alignPanel)
44    {
45  482 super(alignViewport, alignPanel);
46    }
47   
 
48  1173 toggle @Override
49    public void run()
50    {
51  1173 List<AlignmentAnnotation> ssConsensus = getSSConsensusAnnotation();
52  1173 if (ssConsensus == null)
53    {
54  0 return;
55    }
56  1173 if (alignViewport.isClosed())
57    {
58  0 abortAndDestroy();
59  0 return;
60    }
61   
62  1173 AlignmentI alignment = alignViewport.getAlignment();
63   
64  1173 int aWidth = -1;
65   
66  ? if (alignment == null || (aWidth = alignment.getWidth()) < 0)
67    {
68  0 return;
69    }
70   
71  1173 alignViewport.setSecondaryStructureSources();
72  1173 eraseSSConsensus(aWidth);
73  1173 computeSSConsensus(alignment);
74  1173 updateResultAnnotation(true);
75   
76  1173 if (ap != null)
77    {
78  1173 ap.adjustAnnotationHeight();
79    }
80    }
81   
82    /**
83    * Clear out any existing consensus annotations
84    *
85    * @param aWidth
86    * the width (number of columns) of the annotated alignment
87    */
 
88  1173 toggle protected void eraseSSConsensus(int aWidth)
89    {
90  1173 List<AlignmentAnnotation> ssConsensuses = getSSConsensusAnnotation();
91  1173 for (AlignmentAnnotation ssConsensus : ssConsensuses)
92    {
93  1251 if (ssConsensus != null)
94    {
95  1251 ssConsensus.annotations = new Annotation[aWidth];
96    }
97    }
98    }
99   
100    /**
101    * @param alignment
102    */
 
103  1173 toggle protected void computeSSConsensus(AlignmentI alignment)
104    {
105   
106  1173 SequenceI[] aseqs = getSequences();
107  1172 int width = alignment.getWidth();
108  1173 Map<String, ProfilesI> hSSConsensusProfileMap = new HashMap<String, ProfilesI>();
109  1173 List<String> ssSources = getSecondaryStructureSources();
110  1173 for (String ssSource : ssSources)
111    {
112  1251 ProfilesI hSSConsensus = AAFrequency.calculateSS(aseqs, width, 0,
113    width, true, ssSource, null);
114  1251 hSSConsensusProfileMap.put(ssSource, hSSConsensus);
115    }
116   
117  1173 alignViewport.setSequenceSSConsensusHash(hSSConsensusProfileMap);
118  1173 setColourSchemeConsensus(hSSConsensusProfileMap);
119    }
120   
121    /**
122    * @return
123    */
 
124  2424 toggle protected SequenceI[] getSequences()
125    {
126  2424 return alignViewport.getAlignment().getSequencesArray();
127    }
128   
129    /**
130    * @param hconsensus
131    */
 
132  1173 toggle protected void setColourSchemeConsensus(
133    Map<String, ProfilesI> ssConsensusProfileMap)
134    {
135  1173 ResidueShaderI cs = alignViewport.getResidueShading();
136  1173 if (cs != null)
137    {
138  1171 cs.setSSConsensusProfileMap(ssConsensusProfileMap);
139    }
140    }
141   
142    /**
143    * Get the Consensus annotation for the alignment
144    *
145    * @return
146    */
 
147  3539 toggle protected List<AlignmentAnnotation> getSSConsensusAnnotation()
148    {
149  3539 return alignViewport
150    .getAlignmentSecondaryStructureConsensusAnnotation();
151    }
152   
 
153  1173 toggle protected List<String> getSecondaryStructureSources()
154    {
155  1173 return alignViewport.getSecondaryStructureSources();
156    }
157   
158    /**
159    * Get the Gap annotation for the alignment
160    *
161    * @return
162    */
 
163  0 toggle protected AlignmentAnnotation getGapAnnotation()
164    {
165  0 return alignViewport.getAlignmentGapAnnotation();
166    }
167   
168    /**
169    * update the consensus annotation from the sequence profile data using
170    * current visualization settings.
171    */
 
172  20 toggle @Override
173    public void updateAnnotation()
174    {
175  20 updateResultAnnotation(false);
176    }
177   
 
178  1193 toggle public void updateResultAnnotation(boolean immediate)
179    {
180  1193 List<AlignmentAnnotation> ssConsensuses = getSSConsensusAnnotation();
181  1193 Map<String, ProfilesI> ssConsensusProfileMap = getViewportSSConsensus();
182   
183    // we might be called when there is no SS available..
184  1193 if (ssConsensuses==null || ssConsensusProfileMap==null)
185    {
186  18 return;
187    }
188  1175 boolean singleProvider = false;
189   
190  1175 if(ssConsensusProfileMap.keySet() != null && ssConsensusProfileMap.keySet().size() == 2)
191    {
192  48 singleProvider = true; //Single provider if size is 2 (All, Provider 1)
193    }
194   
195  1175 for (AlignmentAnnotation ssConsensus : ssConsensuses)
196    {
197  1253 ProfilesI ssConsensusProfile = null;
198  1253 for (String source : ssConsensusProfileMap.keySet())
199    {
200  1384 if (ssConsensus.description.startsWith(source))
201    {
202  1253 ssConsensusProfile = ssConsensusProfileMap.get(source);
203  1253 ssConsensus.visible = source.equals(Constants.SS_ALL_PROVIDERS) && singleProvider ? false : true;
204   
205  1253 break;
206    }
207    }
208  1253 if (ssConsensusProfile == null)
209    {
210  0 continue;
211    }
212  1253 if (immediate || !calcMan.isWorking(this) && ssConsensus != null
213    && ssConsensusProfile != null)
214    {
215  1251 deriveSSConsensus(ssConsensus, ssConsensusProfile);
216   
217  1251 if (ssConsensusProfile.get(1) != null)
218    {
219  1251 ssConsensus.setNoOfSequencesIncluded(
220    ssConsensusProfile.get(1).getSeqWithSSCount());
221    }
222  1251 ssConsensus.setNoOfTracksIncluded(ssConsensusProfile.getCount());
223  1251 ssConsensus.hasData=ssConsensusProfile.getCount()>0;
224  1251 if (!ssConsensus.hasData) {
225  1114 ssConsensus.visible = false;
226    }
227    }
228   
229   
230    }
231    }
232   
233    /**
234    * Convert the computed consensus data into the desired annotation for
235    * display.
236    *
237    * @param consensusAnnotation
238    * the annotation to be populated
239    * @param hconsensus
240    * the computed consensus data
241    */
 
242  1251 toggle protected void deriveSSConsensus(AlignmentAnnotation ssConsensus,
243    ProfilesI hSSConsensus)
244    {
245   
246  1251 long nseq = getSequences().length;
247  1251 AAFrequency.completeSSConsensus(ssConsensus, hSSConsensus,
248    hSSConsensus.getStartColumn(), hSSConsensus.getEndColumn() + 1,
249    alignViewport.isIgnoreGapsConsensus(),
250    alignViewport.isShowSequenceLogo(), nseq);
251    }
252   
253    /**
254    * Get the consensus data stored on the viewport.
255    *
256    * @return
257    */
 
258  1193 toggle protected Map<String, ProfilesI> getViewportSSConsensus()
259    {
260    // TODO convert ComplementConsensusThread to use Profile
261  1193 return alignViewport.getSequenceSSConsensusHash();
262    }
263    }