1 package jalview.workers;
3 import jalview.analysis.AAFrequency;
4 import jalview.api.AlignViewportI;
5 import jalview.api.AlignmentViewPanel;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.AlignmentI;
8 import jalview.datamodel.Annotation;
9 import jalview.datamodel.HiddenMarkovModel;
10 import jalview.datamodel.ProfilesI;
11 import jalview.datamodel.SequenceI;
12 import jalview.renderer.ResidueShaderI;
14 import java.util.List;
16 public class InformationThread extends AlignCalcWorker
19 public InformationThread(AlignViewportI alignViewport,
20 AlignmentViewPanel alignPanel)
22 super(alignViewport, alignPanel);
28 if (calcMan.isPending(this))
32 calcMan.notifyStart(this);
33 long started = System.currentTimeMillis();
35 List<AlignmentAnnotation> information = getInformationAnnotations();
38 if ((information == null) || calcMan.isPending(this))
40 calcMan.workerComplete(this);
43 while (!calcMan.notifyWorking(this))
45 // System.err.println("Thread
46 // (Information"+Thread.currentThread().getName()+") Waiting around.");
51 ap.paintAlignment(false);
54 } catch (Exception ex)
59 if (alignViewport.isClosed())
64 AlignmentI alignment = alignViewport.getAlignment();
68 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
70 calcMan.workerComplete(this);
74 eraseInformation(aWidth);
75 computeInformation(alignment);
76 updateResultAnnotation(true);
80 ap.paintAlignment(true);
82 } catch (OutOfMemoryError error)
84 calcMan.disableWorker(this);
85 ap.raiseOOMWarning("calculating information", error);
88 calcMan.workerComplete(this);
96 * Clear out any existing information annotations
99 * the width (number of columns) of the annotated alignment
101 protected void eraseInformation(int aWidth)
104 List<AlignmentAnnotation> information = getInformationAnnotations();
105 for (AlignmentAnnotation info : information)
107 info.annotations = new Annotation[aWidth];
115 protected void computeInformation(AlignmentI alignment)
118 int width = alignment.getWidth();
119 List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences();
121 for (SequenceI seq : hmmSeqs)
123 HiddenMarkovModel hmm = seq.getHMM();
124 ProfilesI hinformation = AAFrequency.calculateInformation(hmm, width,
125 0, width, true, alignViewport.isIgnoreBelowBackground());
126 alignViewport.setSequenceInformationHash(hinformation, index);
127 // setColourSchemeInformation(hinformation);
135 protected SequenceI[] getSequences()
137 return alignViewport.getAlignment().getSequencesArray();
141 * @param hinformation
143 protected void setColourSchemeInformation(ProfilesI information)
145 ResidueShaderI cs = alignViewport.getResidueShading();
148 cs.setInformation(information);
153 * Get the Information annotation for the alignment
157 protected List<AlignmentAnnotation> getInformationAnnotations()
159 return alignViewport.getInformationAnnotations();
163 * Get the Gap annotation for the alignment
167 protected AlignmentAnnotation getGapAnnotation()
169 return alignViewport.getAlignmentGapAnnotation();
173 * update the information annotation from the sequence profile data using
174 * current visualization settings.
177 public void updateAnnotation()
180 updateResultAnnotation(false);
184 public void updateResultAnnotation(boolean immediate)
186 List<AlignmentAnnotation> annots = getInformationAnnotations();
188 for (AlignmentAnnotation information : annots)
190 ProfilesI hinformation = (ProfilesI) getSequenceInformation(index);
191 if (immediate || !calcMan.isWorking(this) && information != null
192 && hinformation != null)
194 deriveInformation(information, hinformation);
201 * Convert the computed information data into the desired annotation for
204 * @param informationAnnotation
205 * the annotation to be populated
206 * @param hinformation
207 * the computed information data
209 protected void deriveInformation(
210 AlignmentAnnotation informationAnnotation, ProfilesI hinformation)
213 long nseq = getSequences().length;
214 AAFrequency.completeInformation(informationAnnotation, hinformation,
215 hinformation.getStartColumn(), hinformation.getEndColumn() + 1,
216 alignViewport.isIgnoreBelowBackground(),
217 alignViewport.isShowHMMSequenceLogo(), nseq);
223 * Get the information data stored on the viewport.
227 protected Object getSequenceInformation(int index)
229 // TODO convert ComplementInformationThread to use Profile
230 return alignViewport.getSequenceInformationHash(index);