2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.workers;
21 import jalview.analysis.AAFrequency;
22 import jalview.api.AlignCalcWorkerI;
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.Annotation;
28 import jalview.datamodel.SequenceI;
29 import jalview.schemes.ColourSchemeI;
31 import java.util.Hashtable;
33 public class ConsensusThread extends AlignCalcWorker implements
38 public ConsensusThread(AlignViewportI alignViewport,
39 AlignmentViewPanel alignPanel)
41 super(alignViewport, alignPanel);
47 if (calcMan.isPending(this))
51 calcMan.notifyStart(this);
52 long started = System.currentTimeMillis();
55 AlignmentAnnotation consensus = alignViewport
56 .getAlignmentConsensusAnnotation();
57 if (consensus == null || calcMan.isPending(this))
59 calcMan.workerComplete(this);
62 while (!calcMan.notifyWorking(this))
64 // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around.");
69 ap.paintAlignment(false);
72 } catch (Exception ex)
77 if (alignViewport.isClosed())
81 AlignmentI alignment = alignViewport.getAlignment();
85 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
87 calcMan.workerComplete(this);
88 // .updatingConservation = false;
89 // AlignViewport.UPDATING_CONSERVATION = false;
93 consensus = alignViewport.getAlignmentConsensusAnnotation();
95 consensus.annotations = null;
96 consensus.annotations = new Annotation[aWidth];
97 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
98 hconsensus = new Hashtable[aWidth];
101 SequenceI aseqs[] = alignment.getSequencesArray();
103 AAFrequency.calculate(aseqs, 0,
104 alignment.getWidth(), hconsensus, true);
105 } catch (ArrayIndexOutOfBoundsException x)
107 // this happens due to a race condition -
108 // alignment was edited at same time as calculation was running
110 // calcMan.workerCannotRun(this);
111 calcMan.workerComplete(this);
114 alignViewport.setSequenceConsensusHash(hconsensus);
115 updateResultAnnotation(true);
116 ColourSchemeI globalColourScheme = alignViewport
117 .getGlobalColourScheme();
118 if (globalColourScheme != null)
120 globalColourScheme.setConsensus(hconsensus);
123 } catch (OutOfMemoryError error)
125 calcMan.workerCannotRun(this);
128 // hconsensus = null;
129 ap.raiseOOMWarning("calculating consensus", error);
132 calcMan.workerComplete(this);
135 ap.paintAlignment(true);
140 * update the consensus annotation from the sequence profile data using
141 * current visualization settings.
144 public void updateAnnotation()
146 updateResultAnnotation(false);
149 public void updateResultAnnotation(boolean immediate)
151 AlignmentAnnotation consensus = alignViewport
152 .getAlignmentConsensusAnnotation();
153 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
154 if (immediate || !calcMan.isWorking(this) && consensus != null
155 && hconsensus != null)
157 AAFrequency.completeConsensus(consensus, hconsensus, 0,
158 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
159 alignViewport.isShowSequenceLogo(), nseq);