Merge branch 'feature/JAL-4446_cancellable_pasimap_etal' into feature/JAL-4159_pasima... feature/JAL-4159_pasimap_JAL-4423_alt_msa_source
authorJim Procter <jprocter@dundee.ac.uk>
Mon, 19 Aug 2024 16:49:32 +0000 (17:49 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Mon, 19 Aug 2024 16:49:32 +0000 (17:49 +0100)
 Conflicts:
src/jalview/analysis/PaSiMap.java
src/jalview/gui/PaSiMapPanel.java
src/jalview/viewmodel/PaSiMapModel.java

1  2 
src/jalview/analysis/PaSiMap.java
src/jalview/gui/CalculationChooser.java
src/jalview/gui/PaSiMapPanel.java
src/jalview/viewmodel/PaSiMapModel.java

@@@ -225,37 -231,15 +227,47 @@@ public class PaSiMap implements Runnabl
      try
      {
        // alignment = new PairwiseAlignPanel(seqs, true, 100, 5);
 -      alignment.calculate(scoreMatrix);
 -      if (alignment.isCancelled())
 +      float[][] scores;
 +      SequenceI[] iseqs;
 +      if (!dontRealign && scoreModel instanceof ScoreMatrix)
 +      {
 +        alignment.calculate((ScoreMatrix)scoreModel);
++        if (alignment.isCancelled())
++        {
++          cancel();
++          return;
++        }
 +        iseqs = alignment.getInputSequences();
 +        scores = alignment.getAlignmentScores(); // bigger index first -- eg
 +                                                 // scores[14][13]
 +      }
 +      else
        {
 -        cancel();
 -        return;
 +        AlignmentView alignview = seqs.getAlignmentView(true);
 +        iseqs = alignview.getEditedSequences(seqs.getGapCharacter(), false);
 +        ScoreModelI sm = scoreModel;
 +        if (sm== null)
 +        {
 +          sm = ScoreModels.getInstance().getDefaultModel(!seqs.isNucleotide());
 +        }
 +        MatrixI similarities = sm.findSimilarities(alignview,
 +                SimilarityParams.Jalview);
 +        scores = new float[similarities.height()][similarities.width()];
 +        for (int i = 0; i < scores.length; i++)
 +        {
 +          double[] row = similarities.getRow(i);
 +          for (int j = 0; j < scores[i].length; j++)
 +          {
 +            scores[i][j] = (float) row[j];
 +          }
++          if (alignment.isCancelled())
++          {
++            cancel();
++            return;
++          }
 +        }
        }
 -      float[][] scores = alignment.getAlignmentScores(); // bigger index first
 -                                                         // -- eg scores[14][13]
 -      SequenceI[] iseqs = alignment.getInputSequences();
 +
        Connectivity.getConnectivity(iseqs, scores, dim);
  
        pairwiseScores = new Matrix(scores);
@@@ -92,8 -92,8 +92,10 @@@ public class PaSiMapPanel extends GPaSi
  
    private boolean working;
  
 +  private boolean useObservedAlignment;
 +
+   private String newPasimapTitle;
    /**
     * Constructor given sequence data, a similarity (or distance) score model
     * name, and score calculation parameters
  
      ScoreModelI scoreModel = ScoreModels.getInstance()
              .getScoreModel(modelName, ap);
 -    setPasimapModel(new PaSiMapModel(av, seqs, nucleotide, scoreModel));
 +    setPasimapModel(
 +            new PaSiMapModel(av, seqs, nucleotide, useObservedAlignment, scoreModel));
+     
+     newPasimapTitle = alignPanel.alignFrame.formCalculationTitle(
+             MessageManager.formatMessage("label.calc_title", "PaSiMap",
 -                    scoreModel.getName()),
++                    scoreModel.getName()+(useObservedAlignment ? " (from alignment)":"")),
+             selected, ap.alignFrame.getTitle());
      PaintRefresher.Register(this, av.getSequenceSetId());
  
      setRotatableCanvas(new RotatableCanvas(alignPanel));
  
        System.out.println(pap != null);
        setPairwiseAlignPanel(pap);
-       getPasimapModel().setUseObservedAlignment(useObservedAlignment);
-       getPasimapModel().calculate(pap);
 +
-       xCombobox.setSelectedIndex(0);
-       yCombobox.setSelectedIndex(1);
-       zCombobox.setSelectedIndex(2);
++      getPasimapModel().setUseObservedAlignment(useObservedAlignment);
 +
-       getPasimapModel().updateRc(getRotatableCanvas());
-       // rc.invalidate();
-       setTop(getPasimapModel().getTop());
+       progressBar.registerHandler(progId, new IProgressIndicatorHandler()
+       {
+         
+         @Override
+         public boolean cancelActivity(long id)
+         {
+           getPasimapModel().cancel();
+           return true;
+         }
+         
+         @Override
+         public boolean canCancel()
+         {
+           return true;
+         }
+       });
  
+       getPasimapModel().calculate(pap);
+       if (!getPasimapModel().isCancelled())
+       {
+         // TODO: fix outputAlignment so it uses the compact form if no text report is available
+         outputAlignment.setVisible(!pap.isDiscardAlignments() && !pap.isQuiet());
+         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);
@@@ -88,8 -85,12 +88,13 @@@ public class PaSiMapMode
    public void calculate(PairwiseAlignPanel pap)
    {
      pasimap = new PaSiMap(inputData, scoreModel, pap);
 +    pasimap.setDontRealign(dontRealign);
      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;
      pasimap = data;
    }
  
 +  public void setUseObservedAlignment(boolean useObservedAlignment)
 +  {
 +    dontRealign = useObservedAlignment;
 +  }
++
+   public boolean isCancelled()
+   {
+     if (pasimap==null || pasimap.isCancelled())
+     {
+       return true;
+     }
+     return false;
+   }
+   public void cancel()
+   {
+     pasimap.cancel();    
+   }
  }