2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.workers;
23 import jalview.analysis.StructureFrequency;
24 import jalview.api.AlignCalcWorkerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.Annotation;
30 import jalview.datamodel.SequenceI;
32 import java.util.Hashtable;
34 public class StrucConsensusThread extends AlignCalcWorker implements
38 private AlignmentAnnotation strucConsensus;
40 private Hashtable[] hStrucConsensus;
42 private long nseq = -1;
46 public AlignCalcWorkerI getNewWorker() {
47 return new StrucConsensusThread(alignViewport, ap);
50 public StrucConsensusThread(AlignViewportI alignViewport,
51 AlignmentViewPanel alignPanel)
53 super(alignViewport, alignPanel);
61 if (calcMan.isPending(this))
65 calcMan.notifyStart(this);
66 while (!calcMan.notifyWorking(this))
72 // ap.paintAlignment(false);
76 } catch (Exception ex)
81 if (alignViewport.isClosed())
86 AlignmentI alignment = alignViewport.getAlignment();
90 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
92 calcMan.workerComplete(this);
95 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
96 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
97 strucConsensus.annotations = null;
98 strucConsensus.annotations = new Annotation[aWidth];
100 hStrucConsensus = new Hashtable[aWidth];
102 AlignmentAnnotation[] aa = alignViewport.getAlignment()
103 .getAlignmentAnnotation();
104 AlignmentAnnotation rnaStruc = null;
105 // select rna struct to use for calculation
106 for (int i = 0; i < aa.length; i++)
108 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
114 // check to see if its valid
116 if (rnaStruc == null || !rnaStruc.isValidStruc())
118 calcMan.workerComplete(this);
124 final SequenceI[] arr = alignment.getSequencesArray();
126 StructureFrequency.calculate(arr, 0,
127 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
128 } catch (ArrayIndexOutOfBoundsException x)
130 calcMan.workerComplete(this);
133 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
134 // TODO AlignmentAnnotation rnaStruc!!!
135 updateResultAnnotation(true);
136 if (alignViewport.getGlobalColourScheme() != null)
138 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
141 } catch (OutOfMemoryError error)
143 calcMan.workerCannotRun(this);
146 // hconsensus = null;
147 ap.raiseOOMWarning("calculating RNA structure consensus", error);
150 calcMan.workerComplete(this);
153 ap.paintAlignment(true);
160 * update the consensus annotation from the sequence profile data using
161 * current visualization settings.
164 public void updateAnnotation()
166 updateResultAnnotation(false);
169 public void updateResultAnnotation(boolean immediate)
171 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
172 && hStrucConsensus != null)
174 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
175 0, hStrucConsensus.length,
176 alignViewport.isIgnoreGapsConsensus(),
177 alignViewport.isShowSequenceLogo(), nseq);
182 protected void run1(int state) {
183 // TODO Auto-generated method stub