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
18 public static final String HMM_CALC_ID = "HMM";
20 private float max = 0f;
23 * Constructor for information thread.
25 * @param alignViewport
28 public InformationThread(AlignViewportI alignViewport,
29 AlignmentViewPanel alignPanel)
31 super(alignViewport, alignPanel);
37 if (calcMan.isPending(this))
41 calcMan.notifyStart(this);
42 // long started = System.currentTimeMillis();
44 List<AlignmentAnnotation> information = getInformationAnnotations();
47 if ((information == null) || calcMan.isPending(this))
49 calcMan.workerComplete(this);
52 while (!calcMan.notifyWorking(this))
54 // System.err.println("Thread
55 // (Information"+Thread.currentThread().getName()+") Waiting around.");
60 ap.paintAlignment(false, false);
63 } catch (Exception ex)
68 if (alignViewport.isClosed())
73 AlignmentI alignment = alignViewport.getAlignment();
77 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
79 calcMan.workerComplete(this);
83 eraseInformation(aWidth);
84 computeInformation(alignment);
85 updateResultAnnotation(true);
89 ap.paintAlignment(true, true);
91 } catch (OutOfMemoryError error)
93 calcMan.disableWorker(this);
94 ap.raiseOOMWarning("calculating information", error);
97 calcMan.workerComplete(this);
102 * Clear out any existing information annotations
105 * the width (number of columns) of the annotated alignment
107 protected void eraseInformation(int aWidth)
110 List<AlignmentAnnotation> information = getInformationAnnotations();
111 for (AlignmentAnnotation info : information)
113 info.annotations = new Annotation[aWidth];
118 * Computes the profiles from a HMM for an alignment.
122 protected void computeInformation(AlignmentI alignment)
124 int width = alignment.getWidth();
125 List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences();
128 for (SequenceI seq : hmmSeqs)
130 HiddenMarkovModel hmm = seq.getHMM();
131 ProfilesI hinformation = AAFrequency.calculateHMMProfiles(hmm, width,
132 0, width, true, alignViewport.isIgnoreBelowBackground(),
133 alignViewport.isInfoLetterHeight());
134 alignViewport.setSequenceInformationHash(hinformation, index);
135 // setColourSchemeInformation(hinformation);
141 * gets the sequences on the alignment on the viewport.
145 protected SequenceI[] getSequences()
147 return alignViewport.getAlignment().getSequencesArray();
150 protected void setColourSchemeInformation(ProfilesI information)
152 ResidueShaderI cs = alignViewport.getResidueShading();
155 cs.setInformation(information);
160 * Get the Information annotation for the alignment
164 protected List<AlignmentAnnotation> getInformationAnnotations()
166 return alignViewport.getInformationAnnotations();
170 * Get the Gap annotation for the alignment
174 protected AlignmentAnnotation getGapAnnotation()
176 return alignViewport.getAlignmentGapAnnotation();
180 * update the information annotation from the sequence profile data using
181 * current visualization settings.
184 public void updateAnnotation()
186 updateResultAnnotation(false);
190 * Derives the information content for an information annotation.
194 public void updateResultAnnotation(boolean immediate)
196 List<AlignmentAnnotation> annots = getInformationAnnotations();
198 for (AlignmentAnnotation information : annots)
200 ProfilesI hinformation = (ProfilesI) getSequenceInformation(index);
201 if (immediate || !calcMan.isWorking(this) && information != null
202 && hinformation != null)
204 deriveInformation(information, hinformation);
211 * Convert the computed information data into the desired annotation for
214 * @param informationAnnotation
215 * the annotation to be populated
216 * @param hinformation
217 * the computed information data
219 protected void deriveInformation(
220 AlignmentAnnotation informationAnnotation, ProfilesI hinformation)
222 long nseq = getSequences().length;
223 max = AAFrequency.completeInformation(informationAnnotation,
224 hinformation, hinformation.getStartColumn(),
225 hinformation.getEndColumn() + 1, nseq, max);
229 * Get the information data stored on the viewport.
233 protected Object getSequenceInformation(int index)
235 return alignViewport.getSequenceInformationHash(index);