- @Override
- public void run()
- {
- try
- {
- if (calcMan.isPending(this))
- {
- return;
- }
- calcMan.notifyStart(this);
- while (!calcMan.notifyWorking(this))
- {
- try
- {
- if (ap != null)
- {
- // ap.paintAlignment(false);
- }
-
- Thread.sleep(200);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- if (alignViewport.isClosed())
- {
- abortAndDestroy();
- return;
- }
- AlignmentI alignment = alignViewport.getAlignment();
-
- int aWidth = -1;
-
- if (alignment == null || (aWidth = alignment.getWidth()) < 0)
- {
- calcMan.workerComplete(this);
- return;
- }
- strucConsensus = alignViewport.getAlignmentStrucConsensusAnnotation();
- hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
- strucConsensus.annotations = null;
- strucConsensus.annotations = new Annotation[aWidth];
-
- hStrucConsensus = new Hashtable[aWidth];
-
- AlignmentAnnotation[] aa = alignViewport.getAlignment()
- .getAlignmentAnnotation();
- AlignmentAnnotation rnaStruc = null;
- // 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;
- }
-
- try
- {
- final SequenceI[] arr = alignment.getSequencesArray();
- nseq = arr.length;
- StructureFrequency.calculate(arr, 0,
+ @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,