X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fworkers%2FConsensusThread.java;h=dc3bf06fcaea2b36ad23558ae285189ed1cb005b;hb=743dffc0b47bcc06ea8241ee4e36f1a16ace7cf3;hp=335529c71f2395aac83628a51140601cb2d3c98e;hpb=106a3890f956e2aa7780b2985f4326655912a558;p=jalview.git diff --git a/src/jalview/workers/ConsensusThread.java b/src/jalview/workers/ConsensusThread.java index 335529c..dc3bf06 100644 --- a/src/jalview/workers/ConsensusThread.java +++ b/src/jalview/workers/ConsensusThread.java @@ -39,73 +39,41 @@ public class ConsensusThread extends AlignCalcWorker } @Override + public String getCalcName() + { + return "Consensus"; + } + + @Override public void run() { - if (calcMan.isPending(this)) + AlignmentAnnotation consensus = getConsensusAnnotation(); + AlignmentAnnotation gap = getGapAnnotation(); + if ((consensus == null && gap == null)) { return; } - calcMan.notifyStart(this); - long started = System.currentTimeMillis(); - try + if (alignViewport.isClosed()) { - AlignmentAnnotation consensus = getConsensusAnnotation(); - AlignmentAnnotation gap = getGapAnnotation(); - if ((consensus == null && gap == null) || calcMan.isPending(this)) - { - calcMan.workerComplete(this); - return; - } - while (!calcMan.notifyWorking(this)) - { - // System.err.println("Thread - // (Consensus"+Thread.currentThread().getName()+") Waiting around."); - try - { - if (ap != null) - { - ap.paintAlignment(false, false); - } - Thread.sleep(200); - } catch (Exception ex) - { - ex.printStackTrace(); - } - } - if (alignViewport.isClosed()) - { - abortAndDestroy(); - return; - } - AlignmentI alignment = alignViewport.getAlignment(); + abortAndDestroy(); + return; + } + AlignmentI alignment = alignViewport.getAlignment(); - int aWidth = -1; + int aWidth = -1; - if (alignment == null || (aWidth = alignment.getWidth()) < 0) - { - calcMan.workerComplete(this); - return; - } + if (alignment == null || (aWidth = alignment.getWidth()) < 0) + { + return; + } - eraseConsensus(aWidth); - computeConsensus(alignment); - updateResultAnnotation(true); + eraseConsensus(aWidth); + computeConsensus(alignment); + updateResultAnnotation(true); - if (ap != null) - { - ap.paintAlignment(true, true); - } - } catch (OutOfMemoryError error) - { - calcMan.disableWorker(this); - ap.raiseOOMWarning("calculating consensus", error); - } finally + if (ap != null) { - /* - * e.g. ArrayIndexOutOfBoundsException can happen due to a race condition - * - alignment was edited at same time as calculation was running - */ - calcMan.workerComplete(this); + ap.paintAlignment(true, true); } } @@ -118,7 +86,10 @@ public class ConsensusThread extends AlignCalcWorker protected void eraseConsensus(int aWidth) { AlignmentAnnotation consensus = getConsensusAnnotation(); - consensus.annotations = new Annotation[aWidth]; + if (consensus != null) + { + consensus.annotations = new Annotation[aWidth]; + } AlignmentAnnotation gap = getGapAnnotation(); if (gap != null) { @@ -219,7 +190,6 @@ public class ConsensusThread extends AlignCalcWorker protected void deriveConsensus(AlignmentAnnotation consensusAnnotation, ProfilesI hconsensus) { - long nseq = getSequences().length; AAFrequency.completeConsensus(consensusAnnotation, hconsensus, hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1,