2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.workers;
23 import jalview.analysis.StructureFrequency;
24 import jalview.api.AlignCalcWorkerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.SequenceI;
32 import java.util.Hashtable;
41 public class StrucConsensusThread extends AlignCalcWorker implements
45 private AlignmentAnnotation rnaStruc = null;
46 private AlignmentAnnotation strucConsensus;
48 private Hashtable[] hStrucConsensus;
50 private long nseq = -1;
52 private AlignmentAnnotation[] aa;
53 private SequenceI[] arr;
57 public AlignCalcWorkerI getNewWorker() {
58 return new StrucConsensusThread(alignViewport, ap);
61 public StrucConsensusThread(AlignViewportI alignViewport,
62 AlignmentViewPanel alignPanel)
64 super(alignViewport, alignPanel);
68 protected void run1(int state) {
69 if (alignViewport.isClosed()) {
73 while (!interrupted()) {
77 if (calcMan.isPending(this))
79 calcMan.notifyStart(this);
83 while (!calcMan.notifyWorking(this)) {
85 ap.paintAlignment(false);
88 if (sleepAndReturn(200, state))
90 } catch (InterruptedException e) {
95 if (alignViewport.isClosed()) {
100 alignment = alignViewport.getAlignment();
102 if (alignment == null || (aWidth = alignment.getWidth()) < 0) {
105 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
106 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
107 strucConsensus.annotations = null;
108 strucConsensus.annotations = new Annotation[aWidth];
110 hStrucConsensus = new Hashtable[aWidth];
112 aa = alignViewport.getAlignment().getAlignmentAnnotation();
113 // select rna struct to use for calculation
114 for (int i = 0; i < aa.length; i++)
116 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
122 // check to see if its valid
124 if (rnaStruc == null || !rnaStruc.isValidStruc())
126 calcMan.workerComplete(this);
129 arr = alignment.getSequencesArray();
132 state = LOOP_CALCULATE;
136 iLast = Math.min(iLast + nPer, aWidth);
137 if (iLast == iFirst) {
140 StructureFrequency.calculate(arr, 0,
141 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
142 if (sleepAndReturn(0, state))
147 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
148 // TODO AlignmentAnnotation rnaStruc!!!
149 updateResultAnnotation(true);
150 if (alignViewport.getGlobalColourScheme() != null)
152 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
157 } catch (OutOfMemoryError error) {
158 calcMan.workerCannotRun(this);
159 ap.raiseOOMWarning("calculating RNA structure consensus", error);
160 } catch (Throwable e) {
161 System.out.println("Error in ConsensusThread: " + e);
163 calcMan.workerComplete(this);
169 * update the consensus annotation from the sequence profile data using
170 * current visualization settings.
173 public void updateAnnotation()
175 updateResultAnnotation(false);
178 public void updateResultAnnotation(boolean immediate)
180 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
181 && hStrucConsensus != null)
183 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
184 0, hStrucConsensus.length,
185 alignViewport.isIgnoreGapsConsensus(),
186 alignViewport.isShowSequenceLogo(), nseq);