1 package jalview.workers;
3 import jalview.analysis.AAFrequency;
4 import jalview.api.AlignCalcWorkerI;
5 import jalview.api.AlignViewportI;
6 import jalview.api.AlignmentViewPanel;
7 import jalview.datamodel.AlignmentAnnotation;
8 import jalview.datamodel.AlignmentI;
9 import jalview.datamodel.Annotation;
10 import jalview.schemes.ColourSchemeI;
12 import java.util.Hashtable;
14 public class ConsensusThread extends AlignCalcWorker implements
17 public ConsensusThread(AlignViewportI alignViewport,
18 AlignmentViewPanel alignPanel)
20 super(alignViewport, alignPanel);
26 if (calcMan.isPending(this))
30 calcMan.notifyStart(this);
31 long started = System.currentTimeMillis();
34 AlignmentAnnotation consensus = alignViewport
35 .getAlignmentConsensusAnnotation();
36 if (consensus == null || calcMan.isPending(this))
38 calcMan.workerComplete(this);
41 while (!calcMan.notifyWorking(this))
43 // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around.");
48 ap.paintAlignment(false);
51 } catch (Exception ex)
56 if (alignViewport.isClosed())
60 AlignmentI alignment = alignViewport.getAlignment();
64 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
66 calcMan.workerComplete(this);
67 // .updatingConservation = false;
68 // AlignViewport.UPDATING_CONSERVATION = false;
72 consensus = alignViewport.getAlignmentConsensusAnnotation();
74 consensus.annotations = null;
75 consensus.annotations = new Annotation[aWidth];
76 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
77 hconsensus = new Hashtable[aWidth];
80 AAFrequency.calculate(alignment.getSequencesArray(), 0,
81 alignment.getWidth(), hconsensus, true);
82 } catch (ArrayIndexOutOfBoundsException x)
84 // this happens due to a race condition -
85 // alignment was edited at same time as calculation was running
87 // calcMan.workerCannotRun(this);
88 calcMan.workerComplete(this);
91 alignViewport.setSequenceConsensusHash(hconsensus);
92 updateResultAnnotation(true);
93 ColourSchemeI globalColourScheme = alignViewport
94 .getGlobalColourScheme();
95 if (globalColourScheme != null)
97 globalColourScheme.setConsensus(hconsensus);
100 } catch (OutOfMemoryError error)
102 calcMan.workerCannotRun(this);
105 // hconsensus = null;
106 ap.raiseOOMWarning("calculating consensus", error);
109 calcMan.workerComplete(this);
112 ap.paintAlignment(true);
117 * update the consensus annotation from the sequence profile data using
118 * current visualization settings.
121 public void updateAnnotation()
123 updateResultAnnotation(false);
126 public void updateResultAnnotation(boolean immediate)
128 AlignmentAnnotation consensus = alignViewport
129 .getAlignmentConsensusAnnotation();
130 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
131 if (immediate || !calcMan.isWorking(this) && consensus != null
132 && hconsensus != null)
134 AAFrequency.completeConsensus(consensus, hconsensus, 0,
135 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
136 alignViewport.isShowSequenceLogo());