2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.workers;
20 import java.util.ArrayList;
21 import java.util.List;
23 import jalview.analysis.Conservation;
24 import jalview.api.AlignCalcWorkerI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.api.AlignViewportI;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
30 public class ConservationThread extends AlignCalcWorker implements
34 private int ConsPercGaps = 25; // JBPNote : This should be a configurable
37 public ConservationThread(AlignViewportI alignViewport,
38 AlignmentViewPanel alignPanel)
40 super(alignViewport, alignPanel);
41 ConsPercGaps = alignViewport.getConsPercGaps();
44 private Conservation cons;
46 AlignmentAnnotation conservation, quality;
55 calcMan.notifyStart(this); // updatingConservation = true;
57 while (!calcMan.notifyWorking(this))
63 // ap.paintAlignment(false);
66 } catch (Exception ex)
71 if (alignViewport.isClosed())
75 List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
76 AlignmentI alignment = alignViewport.getAlignment();
77 conservation = alignViewport.getAlignmentConservationAnnotation();
78 quality = alignViewport.getAlignmentQualityAnnot();
79 ourAnnot.add(conservation);
80 ourAnnot.add(quality);
83 // AlignViewport.UPDATING_CONSERVATION = true;
85 if (alignment == null || (alWidth = alignment.getWidth()) < 0)
87 calcMan.workerComplete(this);
88 // .updatingConservation = false;
89 // AlignViewport.UPDATING_CONSERVATION = false;
95 cons = Conservation.calculateConservation("All",
96 jalview.schemes.ResidueProperties.propHash, 3,
97 alignment.getSequences(), 0, alWidth - 1, false,
98 ConsPercGaps, quality != null);
99 } catch (IndexOutOfBoundsException x)
101 // probable race condition. just finish and return without any fuss.
102 calcMan.workerComplete(this);
105 updateResultAnnotation(true);
106 } catch (OutOfMemoryError error)
108 ap.raiseOOMWarning("calculating conservation", error);
109 calcMan.workerCannotRun(this);
110 // alignViewport.conservation = null;
111 // this.alignViewport.quality = null;
114 calcMan.workerComplete(this);
118 ap.paintAlignment(true);
123 private void updateResultAnnotation(boolean b)
125 if (b || !calcMan.isWorking(this) && cons != null
126 && conservation != null && quality != null)
127 cons.completeAnnotations(conservation, quality, 0, alWidth);
131 public void updateAnnotation()
133 updateResultAnnotation(false);