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);
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);
90 } catch (OutOfMemoryError error)
92 calcMan.disableWorker(this);
93 ap.raiseOOMWarning("calculating information", error);
96 calcMan.workerComplete(this);
104 * Clear out any existing information annotations
107 * the width (number of columns) of the annotated alignment
109 protected void eraseInformation(int aWidth)
112 List<AlignmentAnnotation> information = getInformationAnnotations();
113 for (AlignmentAnnotation info : information)
115 info.annotations = new Annotation[aWidth];
121 * Computes the profiles from a HMM for an alignment.
125 protected void computeInformation(AlignmentI alignment)
128 int width = alignment.getWidth();
129 List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences(false);
132 for (SequenceI seq : hmmSeqs)
134 HiddenMarkovModel hmm = seq.getHMM();
135 ProfilesI hinformation = AAFrequency.calculateHMMProfiles(hmm, width,
136 0, width, true, alignViewport.isIgnoreBelowBackground(),
137 alignViewport.isInfoLetterHeight());
138 alignViewport.setSequenceInformationHash(hinformation, index);
139 // setColourSchemeInformation(hinformation);
145 * gets the sequences on the alignment on the viewport.
149 protected SequenceI[] getSequences()
151 return alignViewport.getAlignment().getSequencesArray();
154 protected void setColourSchemeInformation(ProfilesI information)
156 ResidueShaderI cs = alignViewport.getResidueShading();
159 cs.setInformation(information);
164 * Get the Information annotation for the alignment
168 protected List<AlignmentAnnotation> getInformationAnnotations()
170 return alignViewport.getInformationAnnotations();
174 * Get the Gap annotation for the alignment
178 protected AlignmentAnnotation getGapAnnotation()
180 return alignViewport.getAlignmentGapAnnotation();
184 * update the information annotation from the sequence profile data using
185 * current visualization settings.
188 public void updateAnnotation()
191 updateResultAnnotation(false);
195 * Derives the information content for an information annotation.
199 public void updateResultAnnotation(boolean immediate)
201 List<AlignmentAnnotation> annots = getInformationAnnotations();
203 for (AlignmentAnnotation information : annots)
205 ProfilesI hinformation = (ProfilesI) getSequenceInformation(index);
206 if (immediate || !calcMan.isWorking(this) && information != null
207 && hinformation != null)
209 deriveInformation(information, hinformation);
216 * Convert the computed information data into the desired annotation for
219 * @param informationAnnotation
220 * the annotation to be populated
221 * @param hinformation
222 * the computed information data
224 protected void deriveInformation(
225 AlignmentAnnotation informationAnnotation, ProfilesI hinformation)
227 long nseq = getSequences().length;
228 max = AAFrequency.completeInformation(informationAnnotation,
229 hinformation, hinformation.getStartColumn(),
230 hinformation.getEndColumn() + 1, nseq, max);
236 * Get the information data stored on the viewport.
240 protected Object getSequenceInformation(int index)
242 // TODO convert ComplementInformationThread to use Profile
243 return alignViewport.getSequenceInformationHash(index);