+ @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<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
+ 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);
+ }