Clover icon

Coverage Report

  1. Project Clover database Wed Jan 7 2026 02:39:37 GMT
  2. Package jalview.workers

File SecondaryStructureConsensusThread.java

 

Coverage histogram

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

Code metrics

30
70
14
1
283
181
36
0.51
5
14
2.57

Classes

Class Line # Actions
SecondaryStructureConsensusThread 40 70 36
0.833333383.3%
 

Contributing tests

This file is covered by 211 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  1089 toggle @Override
49    public void run()
50    {
51  1089 List<AlignmentAnnotation> ssConsensus = getSSConsensusAnnotation();
52  1089 if (ssConsensus == null)
53    {
54  0 return;
55    }
56  1089 if (alignViewport.isClosed())
57    {
58  0 abortAndDestroy();
59  0 return;
60    }
61   
62  1089 AlignmentI alignment = alignViewport.getAlignment();
63   
64  1089 int aWidth = -1;
65   
66  ? if (alignment == null || (aWidth = alignment.getWidth()) < 0)
67    {
68  0 return;
69    }
70   
71  1089 alignViewport.setSecondaryStructureSources();
72  1089 eraseSSConsensus(aWidth);
73  1089 computeSSConsensus(alignment);
74  1089 updateResultAnnotation(true);
75   
76  1089 if (ap != null)
77    {
78  1089 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  1089 toggle protected void eraseSSConsensus(int aWidth)
89    {
90  1089 List<AlignmentAnnotation> ssConsensuses = getSSConsensusAnnotation();
91  1089 for (AlignmentAnnotation ssConsensus : ssConsensuses)
92    {
93  1165 if (ssConsensus != null)
94    {
95  1165 ssConsensus.annotations = new Annotation[aWidth];
96    }
97    }
98  1089 AlignmentAnnotation gap = getGapAnnotation();
99  1089 if (gap != null)
100    {
101  1081 gap.annotations = new Annotation[aWidth];
102    }
103    }
104   
105    /**
106    * @param alignment
107    */
 
108  1089 toggle protected void computeSSConsensus(AlignmentI alignment)
109    {
110   
111  1089 SequenceI[] aseqs = getSequences();
112  1089 int width = alignment.getWidth();
113  1089 Map<String, ProfilesI> hSSConsensusProfileMap = new HashMap<String, ProfilesI>();
114  1089 List<String> ssSources = getSecondaryStructureSources();
115  1089 for (String ssSource : ssSources)
116    {
117  1165 ProfilesI hSSConsensus = AAFrequency.calculateSS(aseqs, width, 0,
118    width, true, ssSource, null);
119  1165 hSSConsensusProfileMap.put(ssSource, hSSConsensus);
120    }
121   
122  1089 alignViewport.setSequenceSSConsensusHash(hSSConsensusProfileMap);
123  1089 setColourSchemeConsensus(hSSConsensusProfileMap);
124    }
125   
126    /**
127    * @return
128    */
 
129  2253 toggle protected SequenceI[] getSequences()
130    {
131  2253 return alignViewport.getAlignment().getSequencesArray();
132    }
133   
134    /**
135    * @param hconsensus
136    */
 
137  1089 toggle protected void setColourSchemeConsensus(
138    Map<String, ProfilesI> ssConsensusProfileMap)
139    {
140  1089 ResidueShaderI cs = alignViewport.getResidueShading();
141  1089 if (cs != null)
142    {
143  1088 cs.setSSConsensusProfileMap(ssConsensusProfileMap);
144    }
145    }
146   
147    /**
148    * Get the Consensus annotation for the alignment
149    *
150    * @return
151    */
 
152  3267 toggle protected List<AlignmentAnnotation> getSSConsensusAnnotation()
153    {
154  3267 return alignViewport
155    .getAlignmentSecondaryStructureConsensusAnnotation();
156    }
157   
 
158  1089 toggle protected List<String> getSecondaryStructureSources()
159    {
160  1089 return alignViewport.getSecondaryStructureSources();
161    }
162   
163    /**
164    * Get the Gap annotation for the alignment
165    *
166    * @return
167    */
 
168  1089 toggle protected AlignmentAnnotation getGapAnnotation()
169    {
170  1089 return alignViewport.getAlignmentGapAnnotation();
171    }
172   
173    /**
174    * update the consensus annotation from the sequence profile data using
175    * current visualization settings.
176    */
 
177  0 toggle @Override
178    public void updateAnnotation()
179    {
180  0 updateResultAnnotation(false);
181    }
182   
 
183  1089 toggle public void updateResultAnnotation(boolean immediate)
184    {
185  1089 List<AlignmentAnnotation> ssConsensuses = getSSConsensusAnnotation();
186  1089 Map<String, ProfilesI> ssConsensusProfileMap = getViewportSSConsensus();
187   
188    // we might be called when there is no SS available..
189  1089 if (ssConsensuses==null || ssConsensusProfileMap==null)
190    {
191  1 return;
192    }
193  1088 boolean singleProvider = false;
194   
195  1088 if(ssConsensusProfileMap.keySet() != null && ssConsensusProfileMap.keySet().size() == 2)
196    {
197  44 singleProvider = true; //Single provider if size is 2 (All, Provider 1)
198    }
199   
200  1088 for (AlignmentAnnotation ssConsensus : ssConsensuses)
201    {
202  1164 ProfilesI ssConsensusProfile = null;
203  1164 for (String source : ssConsensusProfileMap.keySet())
204    {
205  1294 if (ssConsensus.description.startsWith(source))
206    {
207  1164 ssConsensusProfile = ssConsensusProfileMap.get(source);
208  1164 ssConsensus.visible = source.equals(Constants.SS_ALL_PROVIDERS) && singleProvider ? false : true;
209   
210  1164 break;
211    }
212    }
213  1164 if (ssConsensusProfile == null)
214    {
215  0 continue;
216    }
217  1164 if (immediate || !calcMan.isWorking(this) && ssConsensus != null
218    && ssConsensusProfile != null)
219    {
220  1164 deriveSSConsensus(ssConsensus, ssConsensusProfile);
221   
222  1164 if (ssConsensusProfile.get(1) != null)
223    {
224  1164 ssConsensus.setNoOfSequencesIncluded(
225    ssConsensusProfile.get(1).getSeqWithSSCount());
226    }
227  1164 ssConsensus.setNoOfTracksIncluded(ssConsensusProfile.getCount());
228  1164 ssConsensus.hasData=ssConsensusProfile.getCount()>0;
229  1164 if (!ssConsensus.hasData) {
230  1034 ssConsensus.visible = false;
231    }
232    }
233    }
234    }
235   
236    /**
237    * Convert the computed consensus data into the desired annotation for
238    * display.
239    *
240    * @param consensusAnnotation
241    * the annotation to be populated
242    * @param hconsensus
243    * the computed consensus data
244    */
 
245  1164 toggle protected void deriveSSConsensus(AlignmentAnnotation ssConsensus,
246    ProfilesI hSSConsensus)
247    {
248   
249  1164 long nseq = getSequences().length;
250  1164 AAFrequency.completeSSConsensus(ssConsensus, hSSConsensus,
251    hSSConsensus.getStartColumn(), hSSConsensus.getEndColumn() + 1,
252    alignViewport.isIgnoreGapsConsensus(),
253    alignViewport.isShowSequenceLogo(), nseq);
254    }
255   
256    /**
257    * Convert the computed consensus data into a gap annotation row for display.
258    *
259    * @param gapAnnotation
260    * the annotation to be populated
261    * @param hconsensus
262    * the computed consensus data
263    */
 
264  0 toggle protected void deriveGap(AlignmentAnnotation gapAnnotation,
265    ProfilesI hconsensus)
266    {
267  0 long nseq = getSequences().length;
268  0 AAFrequency.completeGapAnnot(gapAnnotation, hconsensus,
269    hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1,
270    nseq);
271    }
272   
273    /**
274    * Get the consensus data stored on the viewport.
275    *
276    * @return
277    */
 
278  1089 toggle protected Map<String, ProfilesI> getViewportSSConsensus()
279    {
280    // TODO convert ComplementConsensusThread to use Profile
281  1089 return alignViewport.getSequenceSSConsensusHash();
282    }
283    }