X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fworkers%2FConsensusThread.java;h=b97c4c58ecfb6b787b040140b71a74a375cc1758;hb=747167089ecf8d6afc70d417f5a20352e029bd95;hp=d6a4488ad25a637db7c9e8271f47929609ba2ba2;hpb=4389a166735bf1203894abdf3cf7dd57c4856dbc;p=jalview.git diff --git a/src/jalview/workers/ConsensusThread.java b/src/jalview/workers/ConsensusThread.java index d6a4488..b97c4c5 100644 --- a/src/jalview/workers/ConsensusThread.java +++ b/src/jalview/workers/ConsensusThread.java @@ -41,71 +41,33 @@ public class ConsensusThread extends AlignCalcWorker @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 = getOccupancyAnnotation(); - 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,8 +80,11 @@ public class ConsensusThread extends AlignCalcWorker protected void eraseConsensus(int aWidth) { AlignmentAnnotation consensus = getConsensusAnnotation(); - consensus.annotations = new Annotation[aWidth]; - AlignmentAnnotation gap = getOccupancyAnnotation(); + if (consensus != null) + { + consensus.annotations = new Annotation[aWidth]; + } + AlignmentAnnotation gap = getGapAnnotation(); if (gap != null) { gap.annotations = new Annotation[aWidth]; @@ -137,7 +102,7 @@ public class ConsensusThread extends AlignCalcWorker ProfilesI hconsensus = AAFrequency.calculate(aseqs, width, 0, width, true); - alignViewport.setConsensusProfiles(hconsensus); + alignViewport.setSequenceConsensusHash(hconsensus); setColourSchemeConsensus(hconsensus); } @@ -176,9 +141,9 @@ public class ConsensusThread extends AlignCalcWorker * * @return */ - protected AlignmentAnnotation getOccupancyAnnotation() + protected AlignmentAnnotation getGapAnnotation() { - return alignViewport.getOccupancyAnnotation(); + return alignViewport.getAlignmentGapAnnotation(); } /** @@ -199,10 +164,10 @@ public class ConsensusThread extends AlignCalcWorker && hconsensus != null) { deriveConsensus(consensus, hconsensus); - AlignmentAnnotation occupancy = getOccupancyAnnotation(); - if (occupancy != null) + AlignmentAnnotation gap = getGapAnnotation(); + if (gap != null) { - deriveOccupancy(occupancy, hconsensus); + deriveGap(gap, hconsensus); } } } @@ -234,11 +199,11 @@ public class ConsensusThread extends AlignCalcWorker * @param hconsensus * the computed consensus data */ - protected void deriveOccupancy(AlignmentAnnotation gapAnnotation, + protected void deriveGap(AlignmentAnnotation gapAnnotation, ProfilesI hconsensus) { long nseq = getSequences().length; - AAFrequency.completeOccupancyAnnot(gapAnnotation, hconsensus, + AAFrequency.completeGapAnnot(gapAnnotation, hconsensus, hconsensus.getStartColumn(), hconsensus.getEndColumn() + 1, nseq); } @@ -251,6 +216,6 @@ public class ConsensusThread extends AlignCalcWorker protected Object getViewportConsensus() { // TODO convert ComplementConsensusThread to use Profile - return alignViewport.getConsensusProfiles(); + return alignViewport.getSequenceConsensusHash(); } }