2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.workers;
21 import java.util.Hashtable;
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 public class StrucConsensusThread extends AlignCalcWorker implements
35 public StrucConsensusThread(AlignViewportI alignViewport,
36 AlignmentViewPanel alignPanel)
38 super(alignViewport, alignPanel);
41 AlignmentAnnotation strucConsensus;
43 Hashtable[] hStrucConsensus;
52 if (calcMan.isPending(this))
56 calcMan.notifyStart(this);
57 while (!calcMan.notifyWorking(this))
63 // ap.paintAlignment(false);
67 } catch (Exception ex)
72 if (alignViewport.isClosed())
76 AlignmentI alignment = alignViewport.getAlignment();
80 if (alignment == null || (aWidth = alignment.getWidth()) < 0)
82 calcMan.workerComplete(this);
85 strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
86 hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
87 strucConsensus.annotations = null;
88 strucConsensus.annotations = new Annotation[aWidth];
90 hStrucConsensus = new Hashtable[aWidth];
92 AlignmentAnnotation[] aa = alignViewport.getAlignment()
93 .getAlignmentAnnotation();
94 AlignmentAnnotation rnaStruc = null;
95 // select rna struct to use for calculation
96 for (int i = 0; i < aa.length; i++)
98 if (aa[i].getRNAStruc() != null && aa[i].isValidStruc())
104 // check to see if its valid
106 if (rnaStruc == null || !rnaStruc.isValidStruc())
108 calcMan.workerComplete(this);
114 final SequenceI[] arr=
115 alignment.getSequencesArray();
117 jalview.analysis.StructureFrequency.calculate(arr, 0, alignment.getWidth(),
118 hStrucConsensus, true, rnaStruc);
119 } catch (ArrayIndexOutOfBoundsException x)
121 calcMan.workerComplete(this);
124 alignViewport.setRnaStructureConsensusHash(hStrucConsensus);
125 // TODO AlignmentAnnotation rnaStruc!!!
126 updateResultAnnotation(true);
127 if (alignViewport.getGlobalColourScheme() != null)
129 alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus);
132 } catch (OutOfMemoryError error)
134 calcMan.workerCannotRun(this);
137 // hconsensus = null;
138 ap.raiseOOMWarning("calculating RNA structure consensus", error);
141 calcMan.workerComplete(this);
144 ap.paintAlignment(true);
151 * update the consensus annotation from the sequence profile data using
152 * current visualization settings.
155 public void updateAnnotation()
157 updateResultAnnotation(false);
160 public void updateResultAnnotation(boolean immediate)
162 if (immediate || !calcMan.isWorking(this) && strucConsensus != null
163 && hStrucConsensus != null)
165 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
166 0, hStrucConsensus.length,
167 alignViewport.getIgnoreGapsConsensus(),
168 alignViewport.isShowSequenceLogo(), nseq);