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
42 public AlignCalcWorkerI getNewWorker() {
43 return new ConservationThread(alignViewport, ap);
46 public ConservationThread(AlignViewportI alignViewport,
47 AlignmentViewPanel alignPanel)
49 super(alignViewport, alignPanel);
50 ConsPercGaps = alignViewport.getConsPercGaps();
53 private Conservation cons;
55 AlignmentAnnotation conservation, quality;
58 protected void run1(int state) {
59 while (!interrupted()) {
63 if (calcMan.isPending(this))
65 calcMan.notifyStart(this);
69 while (!calcMan.notifyWorking(this)) {
71 ap.paintAlignment(false);
74 if (sleepAndReturn(200, state))
76 } catch (InterruptedException e) {
81 if (alignViewport.isClosed()) {
86 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
87 alignment = alignViewport.getAlignment();
88 conservation = alignViewport.getAlignmentConservationAnnotation();
89 quality = alignViewport.getAlignmentQualityAnnot();
90 ourAnnot.add(conservation);
91 ourAnnot.add(quality);
93 ConsPercGaps = alignViewport.getConsPercGaps();
94 // AlignViewport.UPDATING_CONSERVATION = true;
96 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
98 calcMan.workerComplete(this);
99 // .updatingConservation = false;
100 // AlignViewport.UPDATING_CONSERVATION = false;
104 state = LOOP_CALCULATE;
108 nPer = aWidth + 1; // for now - one big chunk
109 iLast = Math.min(iLast + nPer, aWidth);
110 if (iLast == iFirst) {
114 if (sleepAndReturn(0, state))
119 updateResultAnnotation(true);
123 } catch (OutOfMemoryError error) {
124 calcMan.workerCannotRun(this);
125 ap.raiseOOMWarning("calculating conservation", error);
126 } catch (Throwable e) {
127 System.out.println("Error in ConsensusThread: " + e);
129 calcMan.workerComplete(this);
134 private void computeConsensus() {
135 cons = Conservation.calculateConservation("All",
136 ResidueProperties.propHash, 3,
137 alignment.getSequences(), 0, aWidth - 1, false,
138 ConsPercGaps, quality != null);
142 private void updateResultAnnotation(boolean b)
144 if (b || !calcMan.isWorking(this) && cons != null
145 && conservation != null && quality != null)
147 alignViewport.setConservation(cons);
148 cons.completeAnnotations(conservation, quality, 0, aWidth);
153 public void updateAnnotation()
155 updateResultAnnotation(false);