Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 11:45:30 GMT
  2. Package jalview.workers

File StrucConsensusThread.java

 

Coverage histogram

../../img/srcFileCovDistChart7.png
31% of files have more coverage

Code metrics

22
49
4
1
170
121
25
0.51
12.25
4
6.25

Classes

Class Line # Actions
StrucConsensusThread 33 49 25
0.6266666762.7%
 

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.workers;
22   
23    import jalview.analysis.StructureFrequency;
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.SequenceI;
30   
31    import java.util.Hashtable;
32   
 
33    public class StrucConsensusThread extends AlignCalcWorker
34    {
 
35  3 toggle public StrucConsensusThread(AlignViewportI alignViewport,
36    AlignmentViewPanel alignPanel)
37    {
38  3 super(alignViewport, alignPanel);
39    }
40   
41    AlignmentAnnotation strucConsensus;
42   
43    Hashtable[] hStrucConsensus;
44   
45    private long nseq = -1;
46   
 
47  5 toggle @Override
48    public void run()
49    {
50  5 try
51    {
52  5 if (calcMan.isPending(this))
53    {
54  1 return;
55    }
56  4 calcMan.notifyStart(this);
57  4 while (!calcMan.notifyWorking(this))
58    {
59  0 try
60    {
61  0 if (ap != null)
62    {
63    // ap.paintAlignment(false);
64    }
65   
66  0 Thread.sleep(200);
67    } catch (Exception ex)
68    {
69  0 ex.printStackTrace();
70    }
71    }
72  4 if (alignViewport.isClosed())
73    {
74  0 abortAndDestroy();
75  0 return;
76    }
77  4 AlignmentI alignment = alignViewport.getAlignment();
78   
79  4 int aWidth = -1;
80   
81  ? if (alignment == null || (aWidth = alignment.getWidth()) < 0)
82    {
83  0 calcMan.workerComplete(this);
84  0 return;
85    }
86  4 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
87  4 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
88  4 strucConsensus.annotations = null;
89  4 strucConsensus.annotations = new Annotation[aWidth];
90   
91  4 hStrucConsensus = new Hashtable[aWidth];
92   
93  4 AlignmentAnnotation[] aa = alignViewport.getAlignment()
94    .getAlignmentAnnotation();
95  4 AlignmentAnnotation rnaStruc = null;
96    // select rna struct to use for calculation
97  4 if (aa != null)
98    {
99  4 for (int i = 0; i < aa.length; i++)
100    {
101  4 if (aa[i].isForDisplay() && aa[i].isRNA() && aa[i].isValidStruc())
102    {
103  4 rnaStruc = aa[i];
104  4 break;
105    }
106    }
107    }
108    // check to see if its valid
109   
110  4 if (rnaStruc == null || !rnaStruc.isValidStruc())
111    {
112  0 calcMan.workerComplete(this);
113  0 return;
114    }
115   
116  4 try
117    {
118  4 final SequenceI[] arr = alignment.getSequencesArray();
119  4 nseq = arr.length;
120  4 jalview.analysis.StructureFrequency.calculate(arr, 0,
121    alignment.getWidth(), hStrucConsensus, true, rnaStruc);
122    } catch (ArrayIndexOutOfBoundsException x)
123    {
124  0 calcMan.workerComplete(this);
125  0 return;
126    }
127  4 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
128    // TODO AlignmentAnnotation rnaStruc!!!
129  4 updateResultAnnotation(true);
130    } catch (OutOfMemoryError error)
131    {
132  0 calcMan.disableWorker(this);
133   
134    // consensus = null;
135    // hconsensus = null;
136  0 ap.raiseOOMWarning("calculating RNA structure consensus", error);
137    } finally
138    {
139  5 calcMan.workerComplete(this);
140  5 if (ap != null)
141    {
142  5 ap.paintAlignment(true, true);
143    }
144    }
145   
146    }
147   
148    /**
149    * update the consensus annotation from the sequence profile data using
150    * current visualization settings.
151    */
 
152  0 toggle @Override
153    public void updateAnnotation()
154    {
155  0 updateResultAnnotation(false);
156    }
157   
 
158  4 toggle public void updateResultAnnotation(boolean immediate)
159    {
160  4 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
161    && hStrucConsensus != null)
162    {
163  4 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
164    0, hStrucConsensus.length,
165    alignViewport.isIgnoreGapsConsensus(),
166    alignViewport.isShowSequenceLogo(), nseq);
167    }
168    }
169   
170    }