2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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.schemes.ColourSchemeI;
30 import java.util.Hashtable;
32 public class ConsensusThread extends AlignCalcWorker implements
35 public ConsensusThread(AlignViewportI alignViewport,
36 AlignmentViewPanel alignPanel)
38 super(alignViewport, alignPanel);
44 if (calcMan.isPending(this))
48 calcMan.notifyStart(this);
49 long started = System.currentTimeMillis();
52 AlignmentAnnotation consensus = alignViewport
53 .getAlignmentConsensusAnnotation();
54 if (consensus == null || calcMan.isPending(this))
56 calcMan.workerComplete(this);
59 while (!calcMan.notifyWorking(this))
61 // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around.");
66 ap.paintAlignment(false);
69 } catch (Exception ex)
74 if (alignViewport.isClosed())
78 AlignmentI alignment = alignViewport.getAlignment();
82 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
84 calcMan.workerComplete(this);
85 // .updatingConservation = false;
86 // AlignViewport.UPDATING_CONSERVATION = false;
90 consensus = alignViewport.getAlignmentConsensusAnnotation();
92 consensus.annotations = null;
93 consensus.annotations = new Annotation[aWidth];
94 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
95 hconsensus = new Hashtable[aWidth];
98 AAFrequency.calculate(alignment.getSequencesArray(), 0,
99 alignment.getWidth(), hconsensus, true);
100 } catch (ArrayIndexOutOfBoundsException x)
102 // this happens due to a race condition -
103 // alignment was edited at same time as calculation was running
105 // calcMan.workerCannotRun(this);
106 calcMan.workerComplete(this);
109 alignViewport.setSequenceConsensusHash(hconsensus);
110 updateResultAnnotation(true);
111 ColourSchemeI globalColourScheme = alignViewport
112 .getGlobalColourScheme();
113 if (globalColourScheme != null)
115 globalColourScheme.setConsensus(hconsensus);
118 } catch (OutOfMemoryError error)
120 calcMan.workerCannotRun(this);
123 // hconsensus = null;
124 ap.raiseOOMWarning("calculating consensus", error);
127 calcMan.workerComplete(this);
130 ap.paintAlignment(true);
135 * update the consensus annotation from the sequence profile data using
136 * current visualization settings.
139 public void updateAnnotation()
141 updateResultAnnotation(false);
144 public void updateResultAnnotation(boolean immediate)
146 AlignmentAnnotation consensus = alignViewport
147 .getAlignmentConsensusAnnotation();
148 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
149 if (immediate || !calcMan.isWorking(this) && consensus != null
150 && hconsensus != null)
152 AAFrequency.completeConsensus(consensus, hconsensus, 0,
153 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
154 alignViewport.isShowSequenceLogo());