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())
83 AlignmentI alignment = alignViewport.getAlignment();
87 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
89 calcMan.workerComplete(this);
90 // .updatingConservation = false;
91 // AlignViewport.UPDATING_CONSERVATION = false;
95 consensus = alignViewport.getAlignmentConsensusAnnotation();
97 consensus.annotations = null;
98 consensus.annotations = new Annotation[aWidth];
99 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
100 hconsensus = new Hashtable[aWidth];
103 SequenceI aseqs[] = alignment.getSequencesArray();
105 AAFrequency.calculate(aseqs, 0, alignment.getWidth(), hconsensus,
107 } catch (ArrayIndexOutOfBoundsException x)
109 // this happens due to a race condition -
110 // alignment was edited at same time as calculation was running
112 // calcMan.workerCannotRun(this);
113 calcMan.workerComplete(this);
116 alignViewport.setSequenceConsensusHash(hconsensus);
117 updateResultAnnotation(true);
118 ColourSchemeI globalColourScheme = alignViewport
119 .getGlobalColourScheme();
120 if (globalColourScheme != null)
122 globalColourScheme.setConsensus(hconsensus);
125 } catch (OutOfMemoryError error)
127 calcMan.workerCannotRun(this);
130 // hconsensus = null;
131 ap.raiseOOMWarning("calculating consensus", error);
134 calcMan.workerComplete(this);
137 ap.paintAlignment(true);
142 * update the consensus annotation from the sequence profile data using
143 * current visualization settings.
146 public void updateAnnotation()
148 updateResultAnnotation(false);
151 public void updateResultAnnotation(boolean immediate)
153 AlignmentAnnotation consensus = alignViewport
154 .getAlignmentConsensusAnnotation();
155 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
156 if (immediate || !calcMan.isWorking(this) && consensus != null
157 && hconsensus != null)
159 AAFrequency.completeConsensus(consensus, hconsensus, 0,
160 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
161 alignViewport.isShowSequenceLogo(), nseq);