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.AlignViewportI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
29 import java.util.ArrayList;
30 import java.util.List;
32 public class ConservationThread extends AlignCalcWorker
35 private int ConsPercGaps = 25; // JBPNote : This should be a configurable
38 public ConservationThread(AlignViewportI alignViewport,
39 AlignmentViewPanel alignPanel)
41 super(alignViewport, alignPanel);
42 ConsPercGaps = alignViewport.getConsPercGaps();
45 private Conservation cons;
47 AlignmentAnnotation conservation, quality;
56 calcMan.notifyStart(this); // updatingConservation = true;
58 while (!calcMan.notifyWorking(this))
64 // ap.paintAlignment(false);
67 } catch (Exception ex)
72 if (alignViewport.isClosed())
77 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
78 AlignmentI alignment = alignViewport.getAlignment();
79 conservation = alignViewport.getAlignmentConservationAnnotation();
80 quality = alignViewport.getAlignmentQualityAnnot();
81 ourAnnot.add(conservation);
82 ourAnnot.add(quality);
84 ConsPercGaps = alignViewport.getConsPercGaps();
85 // AlignViewport.UPDATING_CONSERVATION = true;
87 if (alignment == null || (alWidth = alignment.getWidth()) < 0)
89 calcMan.workerComplete(this);
90 // .updatingConservation = false;
91 // AlignViewport.UPDATING_CONSERVATION = false;
97 cons = Conservation.calculateConservation("All",
98 alignment.getSequences(), 0, alWidth - 1, false,
99 ConsPercGaps, quality != null);
100 } catch (IndexOutOfBoundsException x)
102 // probable race condition. just finish and return without any fuss.
103 calcMan.workerComplete(this);
106 updateResultAnnotation(true);
107 } catch (OutOfMemoryError error)
109 ap.raiseOOMWarning("calculating conservation", error);
110 calcMan.disableWorker(this);
111 // alignViewport.conservation = null;
112 // this.alignViewport.quality = null;
115 calcMan.workerComplete(this);
119 ap.paintAlignment(true);
124 private void updateResultAnnotation(boolean b)
126 if (b || !calcMan.isWorking(this) && cons != null
127 && conservation != null && quality != null)
129 alignViewport.setConservation(cons);
130 cons.completeAnnotations(conservation, quality, 0, alWidth);
135 public void updateAnnotation()
137 updateResultAnnotation(false);