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 * Constructor for information thread.
21 * @param alignViewport
24 public InformationThread(AlignViewportI alignViewport,
25 AlignmentViewPanel alignPanel)
27 super(alignViewport, alignPanel);
33 if (calcMan.isPending(this))
37 calcMan.notifyStart(this);
38 long started = System.currentTimeMillis();
40 List<AlignmentAnnotation> information = getInformationAnnotations();
43 if ((information == null) || calcMan.isPending(this))
45 calcMan.workerComplete(this);
48 while (!calcMan.notifyWorking(this))
50 // System.err.println("Thread
51 // (Information"+Thread.currentThread().getName()+") Waiting around.");
56 ap.paintAlignment(false);
59 } catch (Exception ex)
64 if (alignViewport.isClosed())
69 AlignmentI alignment = alignViewport.getAlignment();
73 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
75 calcMan.workerComplete(this);
79 eraseInformation(aWidth);
80 computeInformation(alignment);
81 updateResultAnnotation(true);
85 ap.paintAlignment(true);
87 } catch (OutOfMemoryError error)
89 calcMan.disableWorker(this);
90 ap.raiseOOMWarning("calculating information", error);
93 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];
118 * Computes the profiles from a HMM for an alignment.
122 protected void computeInformation(AlignmentI alignment)
125 int width = alignment.getWidth();
126 List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences(false);
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.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()
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)
223 long nseq = getSequences().length;
224 AAFrequency.completeInformation(informationAnnotation, hinformation,
225 hinformation.getStartColumn(), hinformation.getEndColumn() + 1,
226 alignViewport.isIgnoreBelowBackground(),
227 alignViewport.isShowHMMSequenceLogo(), nseq);
233 * Get the information data stored on the viewport.
237 protected Object getSequenceInformation(int index)
239 // TODO convert ComplementInformationThread to use Profile
240 return alignViewport.getSequenceInformationHash(index);