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);
26 AlignmentAnnotation consensus = alignViewport.getAlignmentConsensusAnnotation();
27 if (consensus==null) { return;
29 calcMan.notifyStart(this);
30 while (!calcMan.notifyWorking(this))
36 ap.paintAlignment(false);
40 } catch (Exception ex)
45 calcMan.notifyWorking(this);
46 if (alignViewport.isClosed())
50 AlignmentI alignment = alignViewport.getAlignment();
54 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
56 calcMan.workerComplete(this);
57 // .updatingConservation = false;
58 // AlignViewport.UPDATING_CONSERVATION = false;
62 consensus = alignViewport
63 .getAlignmentConsensusAnnotation();
65 consensus.annotations = null;
66 consensus.annotations = new Annotation[aWidth];
67 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
68 hconsensus = new Hashtable[aWidth];
69 AAFrequency.calculate(alignment.getSequencesArray(), 0,
70 alignment.getWidth(), hconsensus, true);
71 alignViewport.setSequenceConsensusHash(hconsensus);
72 updateResultAnnotation(true);
73 ColourSchemeI globalColourScheme = alignViewport
74 .getGlobalColourScheme();
75 if (globalColourScheme != null)
77 globalColourScheme.setConsensus(hconsensus);
80 } catch (OutOfMemoryError error)
82 calcMan.workerCannotRun(this);
86 ap.raiseOOMWarning("calculating consensus", error);
89 calcMan.workerComplete(this);
92 ap.paintAlignment(true);
97 * update the consensus annotation from the sequence profile data using
98 * current visualization settings.
100 public void updateAnnotation()
102 updateResultAnnotation(false);
105 public void updateResultAnnotation(boolean immediate)
107 AlignmentAnnotation consensus = alignViewport
108 .getAlignmentConsensusAnnotation();
109 Hashtable[] hconsensus = alignViewport.getSequenceConsensusHash();
110 if (immediate || !calcMan.isWorking(this) && consensus!=null && hconsensus!=null)
112 AAFrequency.completeConsensus(consensus, hconsensus, 0,
113 hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
114 alignViewport.isShowSequenceLogo());