2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3 * Copyright (C) 2014 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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.workers;
21 import java.util.ArrayList;
22 import java.util.List;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcWorkerI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.api.AlignViewportI;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
31 public class ConservationThread extends AlignCalcWorker implements
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())
76 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
77 AlignmentI alignment = alignViewport.getAlignment();
78 conservation = alignViewport.getAlignmentConservationAnnotation();
79 quality = alignViewport.getAlignmentQualityAnnot();
80 ourAnnot.add(conservation);
81 ourAnnot.add(quality);
83 ConsPercGaps = alignViewport.getConsPercGaps();
84 // AlignViewport.UPDATING_CONSERVATION = true;
86 if (alignment == null || (alWidth = alignment.getWidth()) < 0)
88 calcMan.workerComplete(this);
89 // .updatingConservation = false;
90 // AlignViewport.UPDATING_CONSERVATION = false;
96 cons = Conservation.calculateConservation("All",
97 jalview.schemes.ResidueProperties.propHash, 3,
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.workerCannotRun(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);