2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.workers;
20 import java.util.Hashtable;
22 import jalview.analysis.StructureFrequency;
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;
31 public class StrucConsensusThread extends AlignCalcWorker implements
34 public StrucConsensusThread(AlignViewportI alignViewport,
35 AlignmentViewPanel alignPanel)
37 super(alignViewport, alignPanel);
40 AlignmentAnnotation strucConsensus;
42 Hashtable[] hStrucConsensus;
49 if (calcMan.isPending(this))
53 calcMan.notifyStart(this);
54 while (!calcMan.notifyWorking(this))
60 // ap.paintAlignment(false);
64 } catch (Exception ex)
69 if (alignViewport.isClosed())
73 AlignmentI alignment = alignViewport.getAlignment();
77 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
79 calcMan.workerComplete(this);
82 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
83 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
84 strucConsensus.annotations = null;
85 strucConsensus.annotations = new Annotation[aWidth];
87 hStrucConsensus = new Hashtable[aWidth];
89 AlignmentAnnotation[] aa = alignViewport.getAlignment()
90 .getAlignmentAnnotation();
91 AlignmentAnnotation rnaStruc = null;
92 // select rna struct to use for calculation
93 for (int i = 0; i < aa.length; i++)
95 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
101 // check to see if its valid
103 if (rnaStruc == null || !rnaStruc.isValidStruc())
105 calcMan.workerComplete(this);
111 jalview.analysis.StructureFrequency.calculate(
112 alignment.getSequencesArray(), 0, alignment.getWidth(),
113 hStrucConsensus, true, rnaStruc);
114 } catch (ArrayIndexOutOfBoundsException x)
116 calcMan.workerComplete(this);
119 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
120 // TODO AlignmentAnnotation rnaStruc!!!
121 updateResultAnnotation(true);
122 if (alignViewport.getGlobalColourScheme() != null)
124 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
127 } catch (OutOfMemoryError error)
129 calcMan.workerCannotRun(this);
132 // hconsensus = null;
133 ap.raiseOOMWarning("calculating RNA structure consensus", error);
136 calcMan.workerComplete(this);
139 ap.paintAlignment(true);
146 * update the consensus annotation from the sequence profile data using
147 * current visualization settings.
150 public void updateAnnotation()
152 updateResultAnnotation(false);
155 public void updateResultAnnotation(boolean immediate)
157 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
158 && hStrucConsensus != null)
160 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
161 0, hStrucConsensus.length,
162 alignViewport.getIgnoreGapsConsensus(),
163 alignViewport.isShowSequenceLogo());