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
22 * Constructor for information thread.
24 * @param alignViewport
27 public InformationThread(AlignViewportI alignViewport,
28 AlignmentViewPanel alignPanel)
30 super(alignViewport, alignPanel);
36 if (calcMan.isPending(this))
40 calcMan.notifyStart(this);
41 long started = System.currentTimeMillis();
43 List<AlignmentAnnotation> information = getInformationAnnotations();
46 if ((information == null) || calcMan.isPending(this))
48 calcMan.workerComplete(this);
51 while (!calcMan.notifyWorking(this))
53 // System.err.println("Thread
54 // (Information"+Thread.currentThread().getName()+") Waiting around.");
59 ap.paintAlignment(false, false);
62 } catch (Exception ex)
67 if (alignViewport.isClosed())
72 AlignmentI alignment = alignViewport.getAlignment();
76 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
78 calcMan.workerComplete(this);
82 eraseInformation(aWidth);
83 computeInformation(alignment);
84 updateResultAnnotation(true);
88 ap.paintAlignment(true, true);
90 } catch (OutOfMemoryError error)
92 calcMan.disableWorker(this);
93 ap.raiseOOMWarning("calculating information", error);
96 calcMan.workerComplete(this);
101 * Clear out any existing information annotations
104 * the width (number of columns) of the annotated alignment
106 protected void eraseInformation(int aWidth)
109 List<AlignmentAnnotation> information = getInformationAnnotations();
110 for (AlignmentAnnotation info : information)
112 info.annotations = new Annotation[aWidth];
117 * Computes the profiles from a HMM for an alignment.
121 protected void computeInformation(AlignmentI alignment)
123 int width = alignment.getWidth();
124 List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences(false);
127 for (SequenceI seq : hmmSeqs)
129 HiddenMarkovModel hmm = seq.getHMM();
130 ProfilesI hinformation = AAFrequency.calculateHMMProfiles(hmm, width,
131 0, width, true, alignViewport.isIgnoreBelowBackground(),
132 alignViewport.isInfoLetterHeight());
133 alignViewport.setSequenceInformationHash(hinformation, index);
134 // setColourSchemeInformation(hinformation);
140 * gets the sequences on the alignment on the viewport.
144 protected SequenceI[] getSequences()
146 return alignViewport.getAlignment().getSequencesArray();
149 protected void setColourSchemeInformation(ProfilesI information)
151 ResidueShaderI cs = alignViewport.getResidueShading();
154 cs.setInformation(information);
159 * Get the Information annotation for the alignment
163 protected List<AlignmentAnnotation> getInformationAnnotations()
165 return alignViewport.getInformationAnnotations();
169 * Get the Gap annotation for the alignment
173 protected AlignmentAnnotation getGapAnnotation()
175 return alignViewport.getAlignmentGapAnnotation();
179 * update the information annotation from the sequence profile data using
180 * current visualization settings.
183 public void updateAnnotation()
185 updateResultAnnotation(false);
189 * Derives the information content for an information annotation.
193 public void updateResultAnnotation(boolean immediate)
195 List<AlignmentAnnotation> annots = getInformationAnnotations();
197 for (AlignmentAnnotation information : annots)
199 ProfilesI hinformation = (ProfilesI) getSequenceInformation(index);
200 if (immediate || !calcMan.isWorking(this) && information != null
201 && hinformation != null)
203 deriveInformation(information, hinformation);
210 * Convert the computed information data into the desired annotation for
213 * @param informationAnnotation
214 * the annotation to be populated
215 * @param hinformation
216 * the computed information data
218 protected void deriveInformation(
219 AlignmentAnnotation informationAnnotation, ProfilesI hinformation)
221 long nseq = getSequences().length;
222 max = AAFrequency.completeInformation(informationAnnotation,
223 hinformation, hinformation.getStartColumn(),
224 hinformation.getEndColumn() + 1, nseq, max);
228 * Get the information data stored on the viewport.
232 protected Object getSequenceInformation(int index)
234 return alignViewport.getSequenceInformationHash(index);