Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 18:06:40 GMT
  2. Package jalview.workers

File SecondaryStructureConsensusThread.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
63% of files have more coverage

Code metrics

20
53
11
1
223
139
28
0.53
4.82
11
2.55

Classes

Class Line # Actions
SecondaryStructureConsensusThread 33 53 28
0.00%
 

Contributing tests

No tests hitting this source file were found.

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 jalview.analysis.AAFrequency;
24    import jalview.api.AlignViewportI;
25    import jalview.api.AlignmentViewPanel;
26    import jalview.datamodel.AlignmentAnnotation;
27    import jalview.datamodel.AlignmentI;
28    import jalview.datamodel.Annotation;
29    import jalview.datamodel.ProfilesI;
30    import jalview.datamodel.SequenceI;
31    import jalview.renderer.ResidueShaderI;
32   
 
33    public class SecondaryStructureConsensusThread extends AlignCalcWorker
34    {
 
35  0 toggle public SecondaryStructureConsensusThread(AlignViewportI alignViewport,
36    AlignmentViewPanel alignPanel)
37    {
38  0 super(alignViewport, alignPanel);
39    }
40   
 
41  0 toggle @Override
42    public void run()
43    {
44  0 if (calcMan.isPending(this))
45    {
46  0 return;
47    }
48  0 calcMan.notifyStart(this);
49    // long started = System.currentTimeMillis();
50  0 try
51    {
52  0 AlignmentAnnotation ssConsensus = getSSConsensusAnnotation();
53  0 if ((ssConsensus == null) || calcMan.isPending(this))
54    {
55  0 calcMan.workerComplete(this);
56  0 return;
57    }
58  0 while (!calcMan.notifyWorking(this))
59    {
60  0 try
61    {
62  0 if (ap != null)
63    {
64  0 ap.paintAlignment(false, false);
65    }
66  0 Thread.sleep(200);
67    } catch (Exception ex)
68    {
69  0 ex.printStackTrace();
70    }
71    }
72  0 if (alignViewport.isClosed())
73    {
74  0 abortAndDestroy();
75  0 return;
76    }
77  0 AlignmentI alignment = alignViewport.getAlignment();
78   
79  0 int aWidth = -1;
80   
81  0 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
82    {
83  0 calcMan.workerComplete(this);
84  0 return;
85    }
86   
87  0 eraseSSConsensus(aWidth);
88  0 computeSSConsensus(alignment);
89  0 updateResultAnnotation(true);
90   
91  0 if (ap != null)
92    {
93  0 ap.paintAlignment(true, true);
94    }
95    } catch (OutOfMemoryError error)
96    {
97  0 calcMan.disableWorker(this);
98  0 ap.raiseOOMWarning("calculating consensus", error);
99    } finally
100    {
101    /*
102    * e.g. ArrayIndexOutOfBoundsException can happen due to a race condition
103    * - alignment was edited at same time as calculation was running
104    */
105  0 calcMan.workerComplete(this);
106    }
107    }
108   
109    /**
110    * Clear out any existing consensus annotations
111    *
112    * @param aWidth
113    * the width (number of columns) of the annotated alignment
114    */
 
115  0 toggle protected void eraseSSConsensus(int aWidth)
116    {
117  0 AlignmentAnnotation ssConsensus = getSSConsensusAnnotation();
118  0 if (ssConsensus != null)
119    {
120  0 ssConsensus.annotations = new Annotation[aWidth];
121    }
122    }
123   
124    /**
125    * @param alignment
126    */
 
127  0 toggle protected void computeSSConsensus(AlignmentI alignment)
128    {
129   
130  0 SequenceI[] aseqs = getSequences();
131  0 int width = alignment.getWidth();
132  0 ProfilesI hSSConsensus = AAFrequency.calculateSS(aseqs, width, 0, width,
133    true);
134   
135  0 alignViewport.setSequenceSSConsensusHash(hSSConsensus);
136  0 setColourSchemeConsensus(hSSConsensus);
137    }
138   
139    /**
140    * @return
141    */
 
142  0 toggle protected SequenceI[] getSequences()
143    {
144  0 return alignViewport.getAlignment().getSequencesArray();
145    }
146   
147    /**
148    * @param hconsensus
149    */
 
150  0 toggle protected void setColourSchemeConsensus(ProfilesI hSSconsensus)
151    {
152  0 ResidueShaderI cs = alignViewport.getResidueShading();
153  0 if (cs != null)
154    {
155  0 cs.setSsConsensus(hSSconsensus);
156    }
157    }
158   
159    /**
160    * Get the Consensus annotation for the alignment
161    *
162    * @return
163    */
 
164  0 toggle protected AlignmentAnnotation getSSConsensusAnnotation()
165    {
166  0 return alignViewport
167    .getAlignmentSecondaryStructureConsensusAnnotation();
168    }
169   
170    /**
171    * update the consensus annotation from the sequence profile data using
172    * current visualization settings.
173    */
 
174  0 toggle @Override
175    public void updateAnnotation()
176    {
177  0 updateResultAnnotation(false);
178    }
179   
 
180  0 toggle public void updateResultAnnotation(boolean immediate)
181    {
182  0 AlignmentAnnotation ssConsensus = getSSConsensusAnnotation();
183  0 ProfilesI hSSConsensus = (ProfilesI) getViewportSSConsensus();
184  0 if (immediate || !calcMan.isWorking(this) && ssConsensus != null
185    && hSSConsensus != null)
186    {
187  0 deriveSSConsensus(ssConsensus, hSSConsensus);
188   
189  0 ssConsensus.hasData=hSSConsensus.getCount()>0;
190    }
191    }
192   
193    /**
194    * Convert the computed consensus data into the desired annotation for
195    * display.
196    *
197    * @param consensusAnnotation
198    * the annotation to be populated
199    * @param hconsensus
200    * the computed consensus data
201    */
 
202  0 toggle protected void deriveSSConsensus(
203    AlignmentAnnotation ssConsensusAnnotation, ProfilesI hSSConsensus)
204    {
205   
206  0 long nseq = getSequences().length;
207  0 AAFrequency.completeSSConsensus(ssConsensusAnnotation, hSSConsensus,
208    hSSConsensus.getStartColumn(), hSSConsensus.getEndColumn() + 1,
209    alignViewport.isIgnoreGapsConsensus(),
210    alignViewport.isShowSequenceLogo(), nseq);
211    }
212   
213    /**
214    * Get the consensus data stored on the viewport.
215    *
216    * @return
217    */
 
218  0 toggle protected Object getViewportSSConsensus()
219    {
220    // TODO convert ComplementConsensusThread to use Profile
221  0 return alignViewport.getSequenceSSConsensusHash();
222    }
223    }