/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.workers; import jalview.analysis.StructureFrequency; import jalview.api.AlignCalcWorkerI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; import jalview.datamodel.SequenceI; import java.util.Hashtable; /** * * untested * * @author Bob Hanson * */ public class StrucConsensusThread extends AlignCalcWorker implements AlignCalcWorkerI { private AlignmentAnnotation rnaStruc = null; private AlignmentAnnotation strucConsensus; private Hashtable[] hStrucConsensus; private long nseq = -1; private AlignmentAnnotation[] aa; private SequenceI[] arr; @Override public AlignCalcWorkerI getNewWorker() { return new StrucConsensusThread(alignViewport, ap); } public StrucConsensusThread(AlignViewportI alignViewport, AlignmentViewPanel alignPanel) { super(alignViewport, alignPanel); } @Override protected void run1(int state) { if (alignViewport.isClosed()) { abortAndDestroy(); return; } while (!interrupted()) { try { switch (state) { case INIT: if (calcMan.isPending(this)) return; calcMan.notifyStart(this); state = LOOP_STANDBY; break; case LOOP_STANDBY: while (!calcMan.notifyWorking(this)) { if (ap != null) { ap.paintAlignment(false); } try { if (sleepAndReturn(200, state)) return; } catch (InterruptedException e) { state = DONE; break; } } if (alignViewport.isClosed()) { abortAndDestroy(); state = DONE; break; } alignment = alignViewport.getAlignment(); aWidth = -1; if (alignment == null || (aWidth = alignment.getWidth()) < 0) { state = DONE; } strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation(); hStrucConsensus = alignViewport.getRnaStructureConsensusHash(); strucConsensus.annotations = null; strucConsensus.annotations = new Annotation[aWidth]; hStrucConsensus = new Hashtable[aWidth]; aa = alignViewport.getAlignment().getAlignmentAnnotation(); // select rna struct to use for calculation for (int i = 0; i < aa.length; i++) { if (aa[i].getRNAStruc() != null && aa[i].isValidStruc()) { rnaStruc = aa[i]; break; } } // check to see if its valid if (rnaStruc == null || !rnaStruc.isValidStruc()) { calcMan.workerComplete(this); return; } arr = alignment.getSequencesArray(); nseq = arr.length; state = LOOP_CALCULATE; break; case LOOP_CALCULATE: iFirst = iLast; iLast = Math.min(iLast + nPer, aWidth); if (iLast == iFirst) { state = DONE; } else { StructureFrequency.calculate(arr, 0, alignment.getWidth(), hStrucConsensus, true, rnaStruc); if (sleepAndReturn(0, state)) return; } break; case DONE: alignViewport.setRnaStructureConsensusHash(hStrucConsensus); // TODO AlignmentAnnotation rnaStruc!!! updateResultAnnotation(true); if (alignViewport.getGlobalColourScheme() != null) { alignViewport.getGlobalColourScheme().setConsensus(hStrucConsensus); } notifyDone(); return; } } catch (OutOfMemoryError error) { calcMan.workerCannotRun(this); ap.raiseOOMWarning("calculating RNA structure consensus", error); } catch (Throwable e) { System.out.println("Error in ConsensusThread: " + e); e.printStackTrace(); calcMan.workerComplete(this); } } } /** * update the consensus annotation from the sequence profile data using * current visualization settings. */ @Override public void updateAnnotation() { updateResultAnnotation(false); } public void updateResultAnnotation(boolean immediate) { if (immediate || !calcMan.isWorking(this) && strucConsensus != null && hStrucConsensus != null) { StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus, 0, hStrucConsensus.length, alignViewport.isIgnoreGapsConsensus(), alignViewport.isShowSequenceLogo(), nseq); } } }