2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
3 * Copyright (C) 2015 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].visible && aa[i].isRNA() && 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 } catch (OutOfMemoryError error)
131 calcMan.workerCannotRun(this);
134 // hconsensus = null;
135 ap.raiseOOMWarning("calculating RNA structure consensus", error);
138 calcMan.workerComplete(this);
141 ap.paintAlignment(true);
148 * update the consensus annotation from the sequence profile data using
149 * current visualization settings.
152 public void updateAnnotation()
154 updateResultAnnotation(false);
157 public void updateResultAnnotation(boolean immediate)
159 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
160 && hStrucConsensus != null)
162 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
163 0, hStrucConsensus.length,
164 alignViewport.isIgnoreGapsConsensus(),
165 alignViewport.isShowSequenceLogo(), nseq);