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.ScoreModels;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
30 import java.util.ArrayList;
31 import java.util.List;
33 public class ConservationThread extends AlignCalcWorker
36 private int ConsPercGaps = 25; // JBPNote : This should be a configurable
39 public ConservationThread(AlignViewportI alignViewport,
40 AlignmentViewPanel alignPanel)
42 super(alignViewport, alignPanel);
43 ConsPercGaps = alignViewport.getConsPercGaps();
46 private Conservation cons;
48 AlignmentAnnotation conservation, quality;
57 calcMan.notifyStart(this); // updatingConservation = true;
59 while ((calcMan != null) && (!calcMan.notifyWorking(this)))
65 // ap.paintAlignment(false);
68 } catch (Exception ex)
73 if ((alignViewport == null) || (calcMan == null)
74 || (alignViewport.isClosed()))
79 List<AlignmentAnnotation> ourAnnot = new ArrayList<>();
80 AlignmentI alignment = alignViewport.getAlignment();
81 conservation = alignViewport.getAlignmentConservationAnnotation();
82 quality = alignViewport.getAlignmentQualityAnnot();
83 ourAnnot.add(conservation);
84 ourAnnot.add(quality);
86 ConsPercGaps = alignViewport.getConsPercGaps();
87 // AlignViewport.UPDATING_CONSERVATION = true;
89 if (alignment == null || (alWidth = alignment.getWidth()) < 0)
91 calcMan.workerComplete(this);
92 // .updatingConservation = false;
93 // AlignViewport.UPDATING_CONSERVATION = false;
99 // TODO - TDI is there a conservation measure ?
100 cons = Conservation.calculateConservation("All",
101 alignment.getSequences(), 0, alWidth - 1, false,
102 ConsPercGaps, quality != null, alignViewport.is3di() ? ScoreModels.getInstance().getFOLDSEEK3DI():ScoreModels.getInstance().getDefaultModel(true));
103 } catch (IndexOutOfBoundsException x)
105 // probable race condition. just finish and return without any fuss.
106 calcMan.workerComplete(this);
109 updateResultAnnotation(true);
110 } catch (OutOfMemoryError error)
112 ap.raiseOOMWarning("calculating conservation", error);
113 calcMan.disableWorker(this);
114 // alignViewport.conservation = null;
115 // this.alignViewport.quality = null;
118 calcMan.workerComplete(this);
120 if ((alignViewport == null) || (calcMan == null)
121 || (alignViewport.isClosed()))
128 ap.paintAlignment(true, true);
133 private void updateResultAnnotation(boolean b)
135 if (b || !calcMan.isWorking(this) && cons != null
136 && conservation != null && quality != null)
138 alignViewport.setConservation(cons);
139 cons.completeAnnotations(conservation, quality, 0, alWidth);
144 public void updateAnnotation()
146 updateResultAnnotation(false);