2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.AAFrequency;
24 import jalview.api.AlignCalcWorkerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.SequenceI;
31 import jalview.schemes.ColourSchemeI;
33 import java.util.Hashtable;
35 public class ConsensusThread extends AlignCalcWorker implements
38 private long nseq = -1;
40 public ConsensusThread(AlignViewportI alignViewport,
41 AlignmentViewPanel alignPanel)
43 super(alignViewport, alignPanel);
49 if (calcMan.isPending(this))
53 calcMan.notifyStart(this);
54 long started = System.currentTimeMillis();
57 AlignmentAnnotation consensus = alignViewport
58 .getAlignmentConsensusAnnotation();
59 if (consensus == null || calcMan.isPending(this))
61 calcMan.workerComplete(this);
64 while (!calcMan.notifyWorking(this))
66 // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around.");
71 ap.paintAlignment(false);
74 } catch (Exception ex)
79 if (alignViewport.isClosed())
84 AlignmentI alignment = alignViewport.getAlignment();
88 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
90 calcMan.workerComplete(this);
91 // .updatingConservation = false;
92 // AlignViewport.UPDATING_CONSERVATION = false;
96 consensus = alignViewport.getAlignmentConsensusAnnotation();
98 consensus.annotations = null;
99 consensus.annotations = new Annotation[aWidth];
100 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
101 hconsensus = new Hashtable[aWidth];
104 SequenceI aseqs[] = alignment.getSequencesArray();
106 AAFrequency.calculate(aseqs, 0, alignment.getWidth(), hconsensus,
108 } catch (ArrayIndexOutOfBoundsException x)
110 // this happens due to a race condition -
111 // alignment was edited at same time as calculation was running
113 // calcMan.workerCannotRun(this);
114 calcMan.workerComplete(this);
117 alignViewport.setSequenceConsensusHash(hconsensus);
118 updateResultAnnotation(true);
119 ColourSchemeI globalColourScheme = alignViewport
120 .getGlobalColourScheme();
121 if (globalColourScheme != null)
123 globalColourScheme.setConsensus(hconsensus);
126 } catch (OutOfMemoryError error)
128 calcMan.workerCannotRun(this);
131 // hconsensus = null;
132 ap.raiseOOMWarning("calculating consensus", error);
135 calcMan.workerComplete(this);
138 ap.paintAlignment(true);
143 * update the consensus annotation from the sequence profile data using
144 * current visualization settings.
147 public void updateAnnotation()
149 updateResultAnnotation(false);
152 public void updateResultAnnotation(boolean immediate)
154 AlignmentAnnotation consensus = alignViewport
155 .getAlignmentConsensusAnnotation();
156 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
157 if (immediate || !calcMan.isWorking(this) && consensus != null
158 && hconsensus != null)
160 AAFrequency.completeConsensus(consensus, hconsensus, 0,
161 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
162 alignViewport.isShowSequenceLogo(), nseq);