1 package jalview.workers;
3 import java.util.Hashtable;
5 import jalview.analysis.StructureFrequency;
6 import jalview.api.AlignCalcWorkerI;
7 import jalview.api.AlignViewportI;
8 import jalview.api.AlignmentViewPanel;
9 import jalview.datamodel.AlignmentAnnotation;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.Annotation;
13 public class StrucConsensusThread extends AlignCalcWorker implements
16 public StrucConsensusThread(AlignViewportI alignViewport,
17 AlignmentViewPanel alignPanel)
19 super(alignViewport, alignPanel);
22 AlignmentAnnotation strucConsensus;
24 Hashtable[] hStrucConsensus;
31 if (calcMan.isPending(this))
35 calcMan.notifyStart(this);
36 while (!calcMan.notifyWorking(this))
42 // ap.paintAlignment(false);
46 } catch (Exception ex)
51 if (alignViewport.isClosed())
55 AlignmentI alignment = alignViewport.getAlignment();
59 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
61 calcMan.workerComplete(this);
64 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
65 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
66 strucConsensus.annotations = null;
67 strucConsensus.annotations = new Annotation[aWidth];
69 hStrucConsensus = new Hashtable[aWidth];
71 AlignmentAnnotation[] aa = alignViewport.getAlignment()
72 .getAlignmentAnnotation();
73 AlignmentAnnotation rnaStruc = null;
74 // select rna struct to use for calculation
75 for (int i = 0; i < aa.length; i++)
77 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
83 // check to see if its valid
85 if (rnaStruc == null || !rnaStruc.isValidStruc())
87 calcMan.workerComplete(this);
92 jalview.analysis.StructureFrequency.calculate(
93 alignment.getSequencesArray(), 0, alignment.getWidth(),
94 hStrucConsensus, true, rnaStruc);
95 } catch (ArrayIndexOutOfBoundsException x)
97 calcMan.workerComplete(this);
100 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
101 // TODO AlignmentAnnotation rnaStruc!!!
102 updateResultAnnotation(true);
103 if (alignViewport.getGlobalColourScheme() != null)
105 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
108 } catch (OutOfMemoryError error)
110 calcMan.workerCannotRun(this);
113 // hconsensus = null;
114 ap.raiseOOMWarning("calculating RNA structure consensus", error);
117 calcMan.workerComplete(this);
120 ap.paintAlignment(true);
127 * update the consensus annotation from the sequence profile data using
128 * current visualization settings.
131 public void updateAnnotation()
133 updateResultAnnotation(false);
136 public void updateResultAnnotation(boolean immediate)
138 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
139 && hStrucConsensus != null)
141 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
142 0, hStrucConsensus.length,
143 alignViewport.getIgnoreGapsConsensus(),
144 alignViewport.isShowSequenceLogo());