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;
30 public class StrucConsensusThread extends AlignCalcWorker implements
33 public StrucConsensusThread(AlignViewportI alignViewport,
34 AlignmentViewPanel alignPanel)
36 super(alignViewport, alignPanel);
39 AlignmentAnnotation strucConsensus;
41 Hashtable[] hStrucConsensus;
48 if (calcMan.isPending(this))
52 calcMan.notifyStart(this);
53 while (!calcMan.notifyWorking(this))
59 // ap.paintAlignment(false);
63 } catch (Exception ex)
68 if (alignViewport.isClosed())
72 AlignmentI alignment = alignViewport.getAlignment();
76 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
78 calcMan.workerComplete(this);
81 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
82 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
83 strucConsensus.annotations = null;
84 strucConsensus.annotations = new Annotation[aWidth];
86 hStrucConsensus = new Hashtable[aWidth];
88 AlignmentAnnotation[] aa = alignViewport.getAlignment()
89 .getAlignmentAnnotation();
90 AlignmentAnnotation rnaStruc = null;
91 // select rna struct to use for calculation
92 for (int i = 0; i < aa.length; i++)
94 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
100 // check to see if its valid
102 if (rnaStruc == null || !rnaStruc.isValidStruc())
104 calcMan.workerComplete(this);
110 jalview.analysis.StructureFrequency.calculate(
111 alignment.getSequencesArray(), 0, alignment.getWidth(),
112 hStrucConsensus, true, rnaStruc);
113 } catch (ArrayIndexOutOfBoundsException x)
115 calcMan.workerComplete(this);
118 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
119 // TODO AlignmentAnnotation rnaStruc!!!
120 updateResultAnnotation(true);
121 if (alignViewport.getGlobalColourScheme() != null)
123 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
126 } catch (OutOfMemoryError error)
128 calcMan.workerCannotRun(this);
131 // hconsensus = null;
132 ap.raiseOOMWarning("calculating RNA structure consensus", error);
135 calcMan.workerComplete(this);
138 ap.paintAlignment(true);
145 * update the consensus annotation from the sequence profile data using
146 * current visualization settings.
149 public void updateAnnotation()
151 updateResultAnnotation(false);
154 public void updateResultAnnotation(boolean immediate)
156 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
157 && hStrucConsensus != null)
159 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
160 0, hStrucConsensus.length,
161 alignViewport.getIgnoreGapsConsensus(),
162 alignViewport.isShowSequenceLogo());