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.analysis.scoremodels.ScoreMatrix;
25 import jalview.analysis.scoremodels.ScoreModels;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.util.MessageManager;
32 import java.util.ArrayList;
33 import java.util.List;
35 public class ConservationThread extends AlignCalcWorker
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();
46 setScoreModel(ScoreModels.getInstance().getBlosum62());
49 private Conservation cons;
51 AlignmentAnnotation conservation, quality;
55 private ScoreMatrix scoreModel;
62 calcMan.notifyStart(this); // updatingConservation = true;
64 while ((calcMan != null) && (!calcMan.notifyWorking(this)))
70 // ap.paintAlignment(false);
73 } catch (Exception ex)
78 if ((alignViewport == null) || (calcMan == null)
79 || (alignViewport.isClosed()))
84 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
85 AlignmentI alignment = alignViewport.getAlignment();
86 conservation = alignViewport.getAlignmentConservationAnnotation();
87 quality = alignViewport.getAlignmentQualityAnnot();
88 ourAnnot.add(conservation);
89 ourAnnot.add(quality);
91 ConsPercGaps = alignViewport.getConsPercGaps();
92 // AlignViewport.UPDATING_CONSERVATION = true;
94 if (alignment == null || (alWidth = alignment.getWidth()) < 0)
96 calcMan.workerComplete(this);
97 // .updatingConservation = false;
98 // AlignViewport.UPDATING_CONSERVATION = false;
104 cons = Conservation.calculateConservation("All",
105 alignment.getSequences(), 0, alWidth - 1, false,
106 ConsPercGaps, quality != null, scoreModel);
107 } catch (IndexOutOfBoundsException x)
109 // probable race condition. just finish and return without any fuss.
110 calcMan.workerComplete(this);
113 updateResultAnnotation(true);
114 } catch (OutOfMemoryError error)
116 ap.raiseOOMWarning("calculating conservation", error);
117 calcMan.disableWorker(this);
118 // alignViewport.conservation = null;
119 // this.alignViewport.quality = null;
122 calcMan.workerComplete(this);
124 if ((alignViewport == null) || (calcMan == null)
125 || (alignViewport.isClosed()))
132 ap.paintAlignment(true);
137 private void updateResultAnnotation(boolean b)
139 if (b || !calcMan.isWorking(this) && cons != null
140 && conservation != null && quality != null)
142 alignViewport.setConservation(cons);
143 cons.completeAnnotations(conservation, quality, 0, alWidth);
148 public void updateAnnotation()
150 updateResultAnnotation(false);
155 * Sets the substitution matrix to be used in the Quality calculation. This
156 * method is not thread-safe.
160 public void setScoreModel(ScoreMatrix model)
165 quality.description = MessageManager.formatMessage(
166 "label.quality_label", model.getName());
170 public ScoreMatrix getScoreModel()