2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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 java.util.Hashtable;
25 import jalview.analysis.StructureFrequency;
26 import jalview.api.AlignCalcWorkerI;
27 import jalview.api.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.datamodel.AlignmentAnnotation;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.SequenceI;
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())
78 AlignmentI alignment = alignViewport.getAlignment();
82 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
84 calcMan.workerComplete(this);
87 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
88 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
89 strucConsensus.annotations = null;
90 strucConsensus.annotations = new Annotation[aWidth];
92 hStrucConsensus = new Hashtable[aWidth];
94 AlignmentAnnotation[] aa = alignViewport.getAlignment()
95 .getAlignmentAnnotation();
96 AlignmentAnnotation rnaStruc = null;
97 // select rna struct to use for calculation
98 for (int i = 0; i < aa.length; i++)
100 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
106 // check to see if its valid
108 if (rnaStruc == null || !rnaStruc.isValidStruc())
110 calcMan.workerComplete(this);
116 final SequenceI[] arr = alignment.getSequencesArray();
118 jalview.analysis.StructureFrequency.calculate(arr, 0,
119 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
120 } catch (ArrayIndexOutOfBoundsException x)
122 calcMan.workerComplete(this);
125 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
126 // TODO AlignmentAnnotation rnaStruc!!!
127 updateResultAnnotation(true);
128 if (alignViewport.getGlobalColourScheme() != null)
130 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
133 } catch (OutOfMemoryError error)
135 calcMan.workerCannotRun(this);
138 // hconsensus = null;
139 ap.raiseOOMWarning("calculating RNA structure consensus", error);
142 calcMan.workerComplete(this);
145 ap.paintAlignment(true);
152 * update the consensus annotation from the sequence profile data using
153 * current visualization settings.
156 public void updateAnnotation()
158 updateResultAnnotation(false);
161 public void updateResultAnnotation(boolean immediate)
163 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
164 && hStrucConsensus != null)
166 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
167 0, hStrucConsensus.length,
168 alignViewport.getIgnoreGapsConsensus(),
169 alignViewport.isShowSequenceLogo(), nseq);