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.datamodel.SequenceI;
28 import jalview.schemes.ColourSchemeI;
30 import java.util.Hashtable;
32 public class ConsensusThread extends AlignCalcWorker implements
37 public ConsensusThread(AlignViewportI alignViewport,
38 AlignmentViewPanel alignPanel)
40 super(alignViewport, alignPanel);
46 if (calcMan.isPending(this))
50 calcMan.notifyStart(this);
51 long started = System.currentTimeMillis();
54 AlignmentAnnotation consensus = alignViewport
55 .getAlignmentConsensusAnnotation();
56 if (consensus == null || calcMan.isPending(this))
58 calcMan.workerComplete(this);
61 while (!calcMan.notifyWorking(this))
63 // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around.");
68 ap.paintAlignment(false);
71 } catch (Exception ex)
76 if (alignViewport.isClosed())
80 AlignmentI alignment = alignViewport.getAlignment();
84 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
86 calcMan.workerComplete(this);
87 // .updatingConservation = false;
88 // AlignViewport.UPDATING_CONSERVATION = false;
92 consensus = alignViewport.getAlignmentConsensusAnnotation();
94 consensus.annotations = null;
95 consensus.annotations = new Annotation[aWidth];
96 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
97 hconsensus = new Hashtable[aWidth];
100 SequenceI aseqs[] = alignment.getSequencesArray();
102 AAFrequency.calculate(aseqs, 0,
103 alignment.getWidth(), hconsensus, true);
104 } catch (ArrayIndexOutOfBoundsException x)
106 // this happens due to a race condition -
107 // alignment was edited at same time as calculation was running
109 // calcMan.workerCannotRun(this);
110 calcMan.workerComplete(this);
113 alignViewport.setSequenceConsensusHash(hconsensus);
114 updateResultAnnotation(true);
115 ColourSchemeI globalColourScheme = alignViewport
116 .getGlobalColourScheme();
117 if (globalColourScheme != null)
119 globalColourScheme.setConsensus(hconsensus);
122 } catch (OutOfMemoryError error)
124 calcMan.workerCannotRun(this);
127 // hconsensus = null;
128 ap.raiseOOMWarning("calculating consensus", error);
131 calcMan.workerComplete(this);
134 ap.paintAlignment(true);
139 * update the consensus annotation from the sequence profile data using
140 * current visualization settings.
143 public void updateAnnotation()
145 updateResultAnnotation(false);
148 public void updateResultAnnotation(boolean immediate)
150 AlignmentAnnotation consensus = alignViewport
151 .getAlignmentConsensusAnnotation();
152 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
153 if (immediate || !calcMan.isWorking(this) && consensus != null
154 && hconsensus != null)
156 AAFrequency.completeConsensus(consensus, hconsensus, 0,
157 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
158 alignViewport.isShowSequenceLogo(), nseq);