From 2f15cb2f6239cf3a51d2528f5f873273cdcc7936 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 5 Aug 2024 18:40:18 +0100 Subject: [PATCH] JAL-4446 cancellable Pasimap - still need to make the actual pasimap CCA calculation cancellable and report progress --- src/jalview/gui/PaSiMapPanel.java | 43 +++++++++++++++++++++++-------- src/jalview/gui/PairwiseAlignPanel.java | 14 +++++++++- src/jalview/viewmodel/PaSiMapModel.java | 19 ++++++++++++++ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/jalview/gui/PaSiMapPanel.java b/src/jalview/gui/PaSiMapPanel.java index 98a366e..edf7deb 100644 --- a/src/jalview/gui/PaSiMapPanel.java +++ b/src/jalview/gui/PaSiMapPanel.java @@ -212,23 +212,41 @@ public class PaSiMapPanel extends GPaSiMapPanel + MAX_PASIMAP_SEQ); } - PairwiseAlignPanel pap = new PairwiseAlignPanel(av, selGroup, true, + final PairwiseAlignPanel pap = new PairwiseAlignPanel(av, selGroup, true, GAP_OPEN_COST, GAP_EXTEND_COST, false, null); pap.setDiscardAlignments(true); pap.setQuiet(true); System.out.println(pap != null); setPairwiseAlignPanel(pap); - getPasimapModel().calculate(pap); - - xCombobox.setSelectedIndex(0); - yCombobox.setSelectedIndex(1); - zCombobox.setSelectedIndex(2); + progressBar.registerHandler(progId, new IProgressIndicatorHandler() + { + + @Override + public boolean cancelActivity(long id) + { + getPasimapModel().cancel(); + return true; + } + + @Override + public boolean canCancel() + { + return true; + } + }); - getPasimapModel().updateRc(getRotatableCanvas()); - // rc.invalidate(); - setTop(getPasimapModel().getTop()); + getPasimapModel().calculate(pap); + if (!getPasimapModel().isCancelled()) + { + xCombobox.setSelectedIndex(0); + yCombobox.setSelectedIndex(1); + zCombobox.setSelectedIndex(2); + getPasimapModel().updateRc(getRotatableCanvas()); + // rc.invalidate(); + setTop(getPasimapModel().getTop()); + } } catch (OutOfMemoryError er) { new OOMWarning("calculating PaSiMap", er); @@ -236,11 +254,14 @@ public class PaSiMapPanel extends GPaSiMapPanel return; } finally { - progressBar.setProgressBar("", progId); + if (!getPasimapModel().isCancelled()) { + // finish up the progress bar if we weren't cancelled. + progressBar.setProgressBar("", progId); + } } repaint(); - if (getParent() == null) + if (!getPasimapModel().isCancelled() && getParent() == null) { Desktop.addInternalFrame(this, MessageManager.formatMessage("label.calc_title", "PaSiMap", diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index 4c3b30c..ca97aaf 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -70,6 +70,8 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel public static final String PROGRESS = "progress"; + private volatile boolean cancelled; + private int total; private int progress; @@ -151,7 +153,7 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel public void calculate(ScoreMatrix sm) { - + cancelled=false; StringBuilder sb = new StringBuilder(1024); sequences = new Vector(); @@ -206,6 +208,11 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel alignmentScores[i - 1][i - 1] = Float.NaN; for (int j = 0; j < i; j++) { + if (cancelled) + { + alignmentOutput = "Alignment was cancelled."; + return; + } AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j], seqStrings[j], type, GAP_OPEN_COST, GAP_EXTEND_COST); @@ -418,4 +425,9 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel { discardAlignments = discard; } + + public boolean isCancelled() + { + return cancelled; + } } diff --git a/src/jalview/viewmodel/PaSiMapModel.java b/src/jalview/viewmodel/PaSiMapModel.java index 8568af4..ac070e8 100644 --- a/src/jalview/viewmodel/PaSiMapModel.java +++ b/src/jalview/viewmodel/PaSiMapModel.java @@ -86,6 +86,11 @@ public class PaSiMapModel { pasimap = new PaSiMap(inputData, scoreModel, pap); pasimap.run(); // executes in same thread, wait for completion + if (pasimap.isCancelled()) + { + // no more work to do + return; + } // Now find the component coordinates int ii = 0; @@ -262,4 +267,18 @@ public class PaSiMapModel { pasimap = data; } + + public boolean isCancelled() + { + if (pasimap==null || pasimap.isCancelled()) + { + return true; + } + return false; + } + + public void cancel() + { + pasimap.cancel(); + } } -- 1.7.10.2