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.AlignViewportI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.Annotation;
29 import jalview.datamodel.SequenceI;
31 import java.util.Hashtable;
33 public class StrucConsensusThread extends AlignCalcWorker
35 public StrucConsensusThread(AlignViewportI alignViewport,
36 AlignmentViewPanel alignPanel)
38 super(alignViewport, alignPanel);
41 AlignmentAnnotation strucConsensus;
43 Hashtable[] hStrucConsensus;
45 private long nseq = -1;
52 if (calcMan.isPending(this))
56 calcMan.notifyStart(this);
57 while (!calcMan.notifyWorking(this))
63 // ap.paintAlignment(false);
67 } catch (Exception ex)
72 if (alignViewport.isClosed())
77 AlignmentI alignment = alignViewport.getAlignment();
81 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
83 calcMan.workerComplete(this);
86 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
87 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
88 strucConsensus.annotations = null;
89 strucConsensus.annotations = new Annotation[aWidth];
91 hStrucConsensus = new Hashtable[aWidth];
93 AlignmentAnnotation[] aa = alignViewport.getAlignment()
94 .getAlignmentAnnotation();
95 AlignmentAnnotation rnaStruc = null;
96 // select rna struct to use for calculation
99 for (int i = 0; i < aa.length; i++)
101 if (aa[i].visible && aa[i].isRNA() && aa[i].isValidStruc())
108 // check to see if its valid
110 if (rnaStruc == null || !rnaStruc.isValidStruc())
112 calcMan.workerComplete(this);
118 final SequenceI[] arr = alignment.getSequencesArray();
120 jalview.analysis.StructureFrequency.calculate(arr, 0,
121 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
122 } catch (ArrayIndexOutOfBoundsException x)
124 calcMan.workerComplete(this);
127 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
128 // TODO AlignmentAnnotation rnaStruc!!!
129 updateResultAnnotation(true);
130 } catch (OutOfMemoryError error)
132 calcMan.disableWorker(this);
135 // hconsensus = null;
136 ap.raiseOOMWarning("calculating RNA structure consensus", error);
139 calcMan.workerComplete(this);
142 ap.paintAlignment(true);
149 * update the consensus annotation from the sequence profile data using
150 * current visualization settings.
153 public void updateAnnotation()
155 updateResultAnnotation(false);
158 public void updateResultAnnotation(boolean immediate)
160 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
161 && hStrucConsensus != null)
163 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
164 0, hStrucConsensus.length,
165 alignViewport.isIgnoreGapsConsensus(),
166 alignViewport.isShowSequenceLogo(), nseq);