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;
59 calcMan.notifyStart(this); // updatingConservation = true;
61 while (!calcMan.notifyWorking(this))
67 // ap.paintAlignment(false);
70 } catch (Exception ex)
75 if (alignViewport.isClosed())
80 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
81 AlignmentI alignment = alignViewport.getAlignment();
82 conservation = alignViewport.getAlignmentConservationAnnotation();
83 quality = alignViewport.getAlignmentQualityAnnot();
84 ourAnnot.add(conservation);
85 ourAnnot.add(quality);
87 ConsPercGaps = alignViewport.getConsPercGaps();
88 // AlignViewport.UPDATING_CONSERVATION = true;
90 if (alignment == null || (alWidth = alignment.getWidth()) < 0)
92 calcMan.workerComplete(this);
93 // .updatingConservation = false;
94 // AlignViewport.UPDATING_CONSERVATION = false;
100 cons = Conservation.calculateConservation("All",
101 ResidueProperties.propHash, 3,
102 alignment.getSequences(), 0, alWidth - 1, false,
103 ConsPercGaps, quality != null);
104 } catch (IndexOutOfBoundsException x)
106 // probable race condition. just finish and return without any fuss.
107 calcMan.workerComplete(this);
110 updateResultAnnotation(true);
111 } catch (OutOfMemoryError error)
113 ap.raiseOOMWarning("calculating conservation", error);
114 calcMan.workerCannotRun(this);
115 // alignViewport.conservation = null;
116 // this.alignViewport.quality = null;
119 calcMan.workerComplete(this);
123 ap.paintAlignment(true);
128 private void updateResultAnnotation(boolean b)
130 if (b || !calcMan.isWorking(this) && cons != null
131 && conservation != null && quality != null)
133 alignViewport.setConservation(cons);
134 cons.completeAnnotations(conservation, quality, 0, alWidth);
139 public void updateAnnotation()
141 updateResultAnnotation(false);