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
37 public StrucConsensusThread(AlignViewportI alignViewport,
38 AlignmentViewPanel alignPanel)
40 super(alignViewport, alignPanel);
43 AlignmentAnnotation strucConsensus;
45 Hashtable[] hStrucConsensus;
47 private long nseq = -1;
54 if (calcMan.isPending(this))
58 calcMan.notifyStart(this);
59 while (!calcMan.notifyWorking(this))
65 // ap.paintAlignment(false);
69 } catch (Exception ex)
74 if (alignViewport.isClosed())
79 AlignmentI alignment = alignViewport.getAlignment();
83 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
85 calcMan.workerComplete(this);
88 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
89 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
90 strucConsensus.annotations = null;
91 strucConsensus.annotations = new Annotation[aWidth];
93 hStrucConsensus = new Hashtable[aWidth];
95 AlignmentAnnotation[] aa = alignViewport.getAlignment()
96 .getAlignmentAnnotation();
97 AlignmentAnnotation rnaStruc = null;
98 // select rna struct to use for calculation
99 for (int i = 0; i < aa.length; i++)
101 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
107 // check to see if its valid
109 if (rnaStruc == null || !rnaStruc.isValidStruc())
111 calcMan.workerComplete(this);
117 final SequenceI[] arr = alignment.getSequencesArray();
119 jalview.analysis.StructureFrequency.calculate(arr, 0,
120 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
121 } catch (ArrayIndexOutOfBoundsException x)
123 calcMan.workerComplete(this);
126 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
127 // TODO AlignmentAnnotation rnaStruc!!!
128 updateResultAnnotation(true);
129 if (alignViewport.getGlobalColourScheme() != null)
131 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
134 } catch (OutOfMemoryError error)
136 calcMan.workerCannotRun(this);
139 // hconsensus = null;
140 ap.raiseOOMWarning("calculating RNA structure consensus", error);
143 calcMan.workerComplete(this);
146 ap.paintAlignment(true);
153 * update the consensus annotation from the sequence profile data using
154 * current visualization settings.
157 public void updateAnnotation()
159 updateResultAnnotation(false);
162 public void updateResultAnnotation(boolean immediate)
164 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
165 && hStrucConsensus != null)
167 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
168 0, hStrucConsensus.length,
169 alignViewport.isIgnoreGapsConsensus(),
170 alignViewport.isShowSequenceLogo(), nseq);