1 package jalview.workers;
3 import java.util.Hashtable;
5 import jalview.analysis.AAFrequency;
6 import jalview.analysis.StructureFrequency;
7 import jalview.api.AlignCalcWorkerI;
8 import jalview.api.AlignViewportI;
9 import jalview.api.AlignmentViewPanel;
10 import jalview.datamodel.AlignmentAnnotation;
11 import jalview.datamodel.AlignmentI;
12 import jalview.datamodel.Annotation;
14 public class StrucConsensusThread extends AlignCalcWorker implements
17 public StrucConsensusThread(AlignViewportI alignViewport,
18 AlignmentViewPanel alignPanel)
20 super(alignViewport, alignPanel);
23 AlignmentAnnotation strucConsensus;
25 Hashtable[] hStrucConsensus;
32 calcMan.notifyStart(this);
33 while (!calcMan.notifyWorking(this))
39 ap.paintAlignment(false);
43 } catch (Exception ex)
48 if (alignViewport.isClosed())
52 AlignmentI alignment = alignViewport.getAlignment();
56 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
58 calcMan.workerComplete(this);
61 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
62 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
63 strucConsensus.annotations = null;
64 strucConsensus.annotations = new Annotation[aWidth];
66 hStrucConsensus = new Hashtable[aWidth];
68 AlignmentAnnotation[] aa = alignViewport.getAlignment()
69 .getAlignmentAnnotation();
70 AlignmentAnnotation rnaStruc = null;
71 // select rna struct to use for calculation
72 for (int i = 0; i < aa.length; i++)
74 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
80 // check to see if its valid
82 if (rnaStruc == null || !rnaStruc.isValidStruc())
84 calcMan.workerComplete(this);
88 jalview.analysis.StructureFrequency.calculate(
89 alignment.getSequencesArray(), 0, alignment.getWidth(),
90 hStrucConsensus, true, rnaStruc);
91 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
92 // TODO AlignmentAnnotation rnaStruc!!!
93 updateResultAnnotation(true);
94 if (alignViewport.getGlobalColourScheme() != null)
96 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
99 } catch (OutOfMemoryError error)
101 calcMan.workerCannotRun(this);
104 // hconsensus = null;
105 ap.raiseOOMWarning("calculating RNA structure consensus", error);
108 calcMan.workerComplete(this);
111 ap.paintAlignment(true);
117 * update the consensus annotation from the sequence profile data using
118 * current visualization settings.
121 public void updateAnnotation()
123 updateResultAnnotation(false);
126 public void updateResultAnnotation(boolean immediate)
128 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
129 && hStrucConsensus != null)
131 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
132 0, hStrucConsensus.length,
133 alignViewport.getIgnoreGapsConsensus(),
134 alignViewport.isShowSequenceLogo());