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.Conservation;
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.schemes.ResidueProperties;
31 import java.util.ArrayList;
32 import java.util.List;
34 public class ConservationThread extends AlignCalcWorker implements
38 private int ConsPercGaps = 25; // JBPNote : This should be a configurable
41 public ConservationThread(AlignViewportI alignViewport,
42 AlignmentViewPanel alignPanel)
44 super(alignViewport, alignPanel);
45 ConsPercGaps = alignViewport.getConsPercGaps();
48 private Conservation cons;
50 AlignmentAnnotation conservation, quality;
53 protected void run1(int state) {
54 while (!interrupted()) {
58 if (calcMan.isPending(this))
60 calcMan.notifyStart(this);
64 while (!calcMan.notifyWorking(this)) {
66 ap.paintAlignment(false);
69 if (sleepAndReturn(200, state))
71 } catch (InterruptedException e) {
76 if (alignViewport.isClosed()) {
81 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
82 alignment = alignViewport.getAlignment();
83 conservation = alignViewport.getAlignmentConservationAnnotation();
84 quality = alignViewport.getAlignmentQualityAnnot();
85 ourAnnot.add(conservation);
86 ourAnnot.add(quality);
88 ConsPercGaps = alignViewport.getConsPercGaps();
89 // AlignViewport.UPDATING_CONSERVATION = true;
91 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
93 calcMan.workerComplete(this);
94 // .updatingConservation = false;
95 // AlignViewport.UPDATING_CONSERVATION = false;
99 state = LOOP_CALCULATE;
103 nPer = aWidth + 1; // for now - one big chunk
104 iLast = Math.min(iLast + nPer, aWidth);
105 if (iLast == iFirst) {
109 if (sleepAndReturn(0, state))
114 updateResultAnnotation(true);
117 } catch (OutOfMemoryError error) {
118 calcMan.workerCannotRun(this);
119 ap.raiseOOMWarning("calculating conservation", error);
120 } catch (Throwable e) {
121 System.out.println("Error in ConsensusThread: " + e);
123 calcMan.workerComplete(this);
128 private void computeConsensus() {
129 cons = Conservation.calculateConservation("All",
130 ResidueProperties.propHash, 3,
131 alignment.getSequences(), 0, aWidth - 1, false,
132 ConsPercGaps, quality != null);
136 private void updateResultAnnotation(boolean b)
138 if (b || !calcMan.isWorking(this) && cons != null
139 && conservation != null && quality != null)
141 alignViewport.setConservation(cons);
142 cons.completeAnnotations(conservation, quality, 0, aWidth);
147 public void updateAnnotation()
149 updateResultAnnotation(false);