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.api.AlignCalcWorkerI;
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 public class StrucConsensusThread extends AlignCalcWorker implements
34 public StrucConsensusThread(AlignViewportI alignViewport,
35 AlignmentViewPanel alignPanel)
37 super(alignViewport, alignPanel);
40 AlignmentAnnotation strucConsensus;
42 Hashtable[] hStrucConsensus;
51 if (calcMan.isPending(this))
55 calcMan.notifyStart(this);
56 while (!calcMan.notifyWorking(this))
62 // ap.paintAlignment(false);
66 } catch (Exception ex)
71 if (alignViewport.isClosed())
75 AlignmentI alignment = alignViewport.getAlignment();
79 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
81 calcMan.workerComplete(this);
84 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
85 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
86 strucConsensus.annotations = null;
87 strucConsensus.annotations = new Annotation[aWidth];
89 hStrucConsensus = new Hashtable[aWidth];
91 AlignmentAnnotation[] aa = alignViewport.getAlignment()
92 .getAlignmentAnnotation();
93 AlignmentAnnotation rnaStruc = null;
94 // select rna struct to use for calculation
95 for (int i = 0; i < aa.length; i++)
97 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
103 // check to see if its valid
105 if (rnaStruc == null || !rnaStruc.isValidStruc())
107 calcMan.workerComplete(this);
113 final SequenceI[] arr=
114 alignment.getSequencesArray();
116 jalview.analysis.StructureFrequency.calculate(arr, 0, alignment.getWidth(),
117 hStrucConsensus, true, rnaStruc);
118 } catch (ArrayIndexOutOfBoundsException x)
120 calcMan.workerComplete(this);
123 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
124 // TODO AlignmentAnnotation rnaStruc!!!
125 updateResultAnnotation(true);
126 if (alignViewport.getGlobalColourScheme() != null)
128 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
131 } catch (OutOfMemoryError error)
133 calcMan.workerCannotRun(this);
136 // hconsensus = null;
137 ap.raiseOOMWarning("calculating RNA structure consensus", error);
140 calcMan.workerComplete(this);
143 ap.paintAlignment(true);
150 * update the consensus annotation from the sequence profile data using
151 * current visualization settings.
154 public void updateAnnotation()
156 updateResultAnnotation(false);
159 public void updateResultAnnotation(boolean immediate)
161 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
162 && hStrucConsensus != null)
164 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
165 0, hStrucConsensus.length,
166 alignViewport.getIgnoreGapsConsensus(),
167 alignViewport.isShowSequenceLogo(), nseq);