X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fworkers%2FConservationThread.java;h=ac37f463139a70d379435a17fa47d1ac44c3a5c6;hb=4231d40261fef32ce4570a6bbad0d35df44e8baf;hp=32e13f26c429c75e2c8071453f678607cd25378d;hpb=c07eb2c5794833bd0241000d6844d783fe10cb82;p=jalview.git diff --git a/src/jalview/workers/ConservationThread.java b/src/jalview/workers/ConservationThread.java index 32e13f2..ac37f46 100644 --- a/src/jalview/workers/ConservationThread.java +++ b/src/jalview/workers/ConservationThread.java @@ -49,81 +49,89 @@ public class ConservationThread extends AlignCalcWorker implements AlignmentAnnotation conservation, quality; - int alWidth; + @Override + protected void run1(int state) { + 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; + } + List ourAnnot = new ArrayList(); + alignment = alignViewport.getAlignment(); + conservation = alignViewport.getAlignmentConservationAnnotation(); + quality = alignViewport.getAlignmentQualityAnnot(); + ourAnnot.add(conservation); + ourAnnot.add(quality); + ourAnnots = ourAnnot; + ConsPercGaps = alignViewport.getConsPercGaps(); + // AlignViewport.UPDATING_CONSERVATION = true; + + if (alignment == null || (aWidth = alignment.getWidth()) < 0) + { + calcMan.workerComplete(this); + // .updatingConservation = false; + // AlignViewport.UPDATING_CONSERVATION = false; + + return; + } + state = LOOP_CALCULATE; + break; + case LOOP_CALCULATE: + iFirst = iLast; + nPer = aWidth + 1; // for now - one big chunk + iLast = Math.min(iLast + nPer, aWidth); + if (iLast == iFirst) { + state = DONE; + } else { + computeConsensus(); + if (sleepAndReturn(0, state)) + return; + } + break; + case DONE: + updateResultAnnotation(true); + return; + } + } catch (OutOfMemoryError error) { + calcMan.workerCannotRun(this); + ap.raiseOOMWarning("calculating conservation", error); + } catch (Throwable e) { + System.out.println("Error in ConsensusThread: " + e); + e.printStackTrace(); + calcMan.workerComplete(this); + } + } + } + + private void computeConsensus() { + cons = Conservation.calculateConservation("All", + ResidueProperties.propHash, 3, + alignment.getSequences(), 0, aWidth - 1, false, + ConsPercGaps, quality != null); + } - @Override - public void run() - { - try - { - calcMan.notifyStart(this); // updatingConservation = true; - - while (!calcMan.notifyWorking(this)) - { - try - { - if (ap != null) - { - // ap.paintAlignment(false); - } - Thread.sleep(200); - } catch (Exception ex) - { - ex.printStackTrace(); - } - } - if (alignViewport.isClosed()) - { - abortAndDestroy(); - return; - } - List ourAnnot = new ArrayList(); - AlignmentI alignment = alignViewport.getAlignment(); - conservation = alignViewport.getAlignmentConservationAnnotation(); - quality = alignViewport.getAlignmentQualityAnnot(); - ourAnnot.add(conservation); - ourAnnot.add(quality); - ourAnnots = ourAnnot; - ConsPercGaps = alignViewport.getConsPercGaps(); - // AlignViewport.UPDATING_CONSERVATION = true; - - if (alignment == null || (alWidth = alignment.getWidth()) < 0) - { - calcMan.workerComplete(this); - // .updatingConservation = false; - // AlignViewport.UPDATING_CONSERVATION = false; - - return; - } - try - { - cons = Conservation.calculateConservation("All", - ResidueProperties.propHash, 3, - alignment.getSequences(), 0, alWidth - 1, false, - ConsPercGaps, quality != null); - } catch (IndexOutOfBoundsException x) - { - // probable race condition. just finish and return without any fuss. - calcMan.workerComplete(this); - return; - } - updateResultAnnotation(true); - } catch (OutOfMemoryError error) - { - ap.raiseOOMWarning("calculating conservation", error); - calcMan.workerCannotRun(this); - // alignViewport.conservation = null; - // this.alignViewport.quality = null; - - } - calcMan.workerComplete(this); - - if (ap != null) - { - ap.paintAlignment(true); - } - - } private void updateResultAnnotation(boolean b) { @@ -131,7 +139,7 @@ public class ConservationThread extends AlignCalcWorker implements && conservation != null && quality != null) { alignViewport.setConservation(cons); - cons.completeAnnotations(conservation, quality, 0, alWidth); + cons.completeAnnotations(conservation, quality, 0, aWidth); } } @@ -141,4 +149,5 @@ public class ConservationThread extends AlignCalcWorker implements updateResultAnnotation(false); } + }