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 jalview.analysis.AAFrequency;
21 import jalview.api.AlignCalcWorkerI;
22 import jalview.api.AlignViewportI;
23 import jalview.api.AlignmentViewPanel;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.Annotation;
27 import jalview.schemes.ColourSchemeI;
29 import java.util.Hashtable;
31 public class ConsensusThread extends AlignCalcWorker implements
34 public ConsensusThread(AlignViewportI alignViewport,
35 AlignmentViewPanel alignPanel)
37 super(alignViewport, alignPanel);
43 if (calcMan.isPending(this))
47 calcMan.notifyStart(this);
48 long started = System.currentTimeMillis();
51 AlignmentAnnotation consensus = alignViewport
52 .getAlignmentConsensusAnnotation();
53 if (consensus == null || calcMan.isPending(this))
55 calcMan.workerComplete(this);
58 while (!calcMan.notifyWorking(this))
60 // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around.");
65 ap.paintAlignment(false);
68 } catch (Exception ex)
73 if (alignViewport.isClosed())
77 AlignmentI alignment = alignViewport.getAlignment();
81 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
83 calcMan.workerComplete(this);
84 // .updatingConservation = false;
85 // AlignViewport.UPDATING_CONSERVATION = false;
89 consensus = alignViewport.getAlignmentConsensusAnnotation();
91 consensus.annotations = null;
92 consensus.annotations = new Annotation[aWidth];
93 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
94 hconsensus = new Hashtable[aWidth];
97 AAFrequency.calculate(alignment.getSequencesArray(), 0,
98 alignment.getWidth(), hconsensus, true);
99 } catch (ArrayIndexOutOfBoundsException x)
101 // this happens due to a race condition -
102 // alignment was edited at same time as calculation was running
104 // calcMan.workerCannotRun(this);
105 calcMan.workerComplete(this);
108 alignViewport.setSequenceConsensusHash(hconsensus);
109 updateResultAnnotation(true);
110 ColourSchemeI globalColourScheme = alignViewport
111 .getGlobalColourScheme();
112 if (globalColourScheme != null)
114 globalColourScheme.setConsensus(hconsensus);
117 } catch (OutOfMemoryError error)
119 calcMan.workerCannotRun(this);
122 // hconsensus = null;
123 ap.raiseOOMWarning("calculating consensus", error);
126 calcMan.workerComplete(this);
129 ap.paintAlignment(true);
134 * update the consensus annotation from the sequence profile data using
135 * current visualization settings.
138 public void updateAnnotation()
140 updateResultAnnotation(false);
143 public void updateResultAnnotation(boolean immediate)
145 AlignmentAnnotation consensus = alignViewport
146 .getAlignmentConsensusAnnotation();
147 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
148 if (immediate || !calcMan.isWorking(this) && consensus != null
149 && hconsensus != null)
151 AAFrequency.completeConsensus(consensus, hconsensus, 0,
152 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
153 alignViewport.isShowSequenceLogo());