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 AlignCalcWorkerI
16 public ConsensusThread(AlignViewportI alignViewport,
17 AlignmentViewPanel alignPanel)
19 super(alignViewport, alignPanel);
25 if (calcMan.isPending(this))
29 calcMan.notifyStart(this);
30 long started=System.currentTimeMillis();
33 AlignmentAnnotation consensus = alignViewport.getAlignmentConsensusAnnotation();
34 if (consensus==null || calcMan.isPending(this)) {
35 calcMan.workerComplete(this);
38 while (!calcMan.notifyWorking(this))
40 // System.err.println("Thread (Consensus"+Thread.currentThread().getName()+") Waiting around.");
45 ap.paintAlignment(false);
48 } catch (Exception ex)
53 if (alignViewport.isClosed())
57 AlignmentI alignment = alignViewport.getAlignment();
61 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
63 calcMan.workerComplete(this);
64 // .updatingConservation = false;
65 // AlignViewport.UPDATING_CONSERVATION = false;
69 consensus = alignViewport
70 .getAlignmentConsensusAnnotation();
72 consensus.annotations = null;
73 consensus.annotations = new Annotation[aWidth];
74 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
75 hconsensus = new Hashtable[aWidth];
77 AAFrequency.calculate(alignment.getSequencesArray(), 0,
78 alignment.getWidth(), hconsensus, true);
79 } catch (ArrayIndexOutOfBoundsException x){
80 // this happens due to a race condition -
81 // alignment was edited at same time as calculation was running
83 // calcMan.workerCannotRun(this);
84 calcMan.workerComplete(this);
87 alignViewport.setSequenceConsensusHash(hconsensus);
88 updateResultAnnotation(true);
89 ColourSchemeI globalColourScheme = alignViewport
90 .getGlobalColourScheme();
91 if (globalColourScheme != null)
93 globalColourScheme.setConsensus(hconsensus);
96 } catch (OutOfMemoryError error)
98 calcMan.workerCannotRun(this);
101 // hconsensus = null;
102 ap.raiseOOMWarning("calculating consensus", error);
105 calcMan.workerComplete(this);
108 ap.paintAlignment(true);
113 * update the consensus annotation from the sequence profile data using
114 * current visualization settings.
117 public void updateAnnotation()
119 updateResultAnnotation(false);
122 public void updateResultAnnotation(boolean immediate)
124 AlignmentAnnotation consensus = alignViewport
125 .getAlignmentConsensusAnnotation();
126 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
127 if (immediate || !calcMan.isWorking(this) && consensus!=null && hconsensus!=null)
129 AAFrequency.completeConsensus(consensus, hconsensus, 0,
130 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
131 alignViewport.isShowSequenceLogo());