JAL-4159 implement bounds for PASIMAP calculation - from 9 to 20000 sequences.
authorJim Procter <jprocter@dundee.ac.uk>
Tue, 21 May 2024 17:21:05 +0000 (18:21 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Tue, 21 May 2024 17:21:05 +0000 (18:21 +0100)
src/jalview/gui/CalculationChooser.java
src/jalview/gui/PaSiMapPanel.java
src/jalview/gui/PairwiseAlignPanel.java

index 6536358..346e3fa 100644 (file)
@@ -106,7 +106,10 @@ public class CalculationChooser extends JPanel
     
   }
 
-  private static final int MIN_PASIMAP_SELECTION = 8; 
+  /**
+   * minimum number of sequences needed for PASIMAP is 9 (so each has 8 connections)
+   */
+  private static final int MIN_PASIMAP_SELECTION = 9; 
 
   AlignFrame af;
 
index 562605e..bf87dd1 100644 (file)
@@ -29,6 +29,7 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.ImageExporter.ImageWriterI;
 import jalview.gui.JalviewColourChooser.ColourChooserListener;
@@ -69,6 +70,8 @@ public class PaSiMapPanel extends GPaSiMapPanel
 
   private static final int MIN_HEIGHT = 250;
 
+  private static final int MAX_PASIMAP_SEQ = 20000;
+
   private final int GAP_OPEN_COST = 100;
 
   private final int GAP_EXTEND_COST = 5;
@@ -182,7 +185,8 @@ public class PaSiMapPanel extends GPaSiMapPanel
     working = true;
     progId = System.currentTimeMillis();
     progressBar = this;
-    String message = MessageManager.getString("label.pasimap_recalculating");
+    String message = MessageManager
+            .getString("label.pasimap_recalculating");
     if (getParent() == null)
     {
       progressBar = ap.alignFrame;
@@ -191,18 +195,27 @@ public class PaSiMapPanel extends GPaSiMapPanel
     progressBar.setProgressBar(message, progId);
     try
     {
-      //&! remove big seqs
-      for (SequenceI seq : av.getAlignment().getSequencesArray())
+      SequenceGroup selGroup=av.getSelectionGroup();
+      
+      if (selGroup==null)
       {
-       if (seq.getLength() > 20000)
-       {
-         //TODO add warning dialog
-         av.getAlignment().deleteSequence(seq);
-       }
+        selGroup = new SequenceGroup(av.getAlignment().getSequences());
+        selGroup.setStartRes(0);
+        selGroup.setEndRes(av.getAlignment().getWidth()-1);
       }
-
-      PairwiseAlignPanel pap = new PairwiseAlignPanel(av, true, GAP_OPEN_COST, GAP_EXTEND_COST, false);
-System.out.println(pap != null);
+      
+      if (selGroup.getSize()>MAX_PASIMAP_SEQ)
+      {
+        int start = selGroup.getStartRes(),end=selGroup.getEndRes();
+          selGroup = new SequenceGroup(selGroup.getSequences().subList(0, MAX_PASIMAP_SEQ));
+          selGroup.setStartRes(start);
+          selGroup.setEndRes(end);
+          Console.warn("Truncated input sequences for PASIMAP analysis to "+MAX_PASIMAP_SEQ);
+      }
+      
+      PairwiseAlignPanel pap = new PairwiseAlignPanel(av, selGroup, true,
+              GAP_OPEN_COST, GAP_EXTEND_COST, false);
+      System.out.println(pap != null);
       setPairwiseAlignPanel(pap);
       getPasimapModel().calculate(pap);
 
@@ -227,9 +240,9 @@ System.out.println(pap != null);
     repaint();
     if (getParent() == null)
     {
-      Desktop.addInternalFrame(this,
-              MessageManager.formatMessage("label.calc_title", "PaSiMap",
-                      getPasimapModel().getScoreModelName()),
+      Desktop.addInternalFrame(
+              this, MessageManager.formatMessage("label.calc_title",
+                      "PaSiMap", getPasimapModel().getScoreModelName()),
               475, 450);
       this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
     }
@@ -666,6 +679,10 @@ System.out.println(pap != null);
   public void updateProgressBar(int lengthOfTask, int progress)
   {
     JProgressBar pBar = progressBar.getProgressBar(progId);
+    if (pBar==null)
+    {
+      return;
+    }
     if (pBar.isIndeterminate())
     {
       pBar.setMaximum(lengthOfTask);
@@ -677,6 +694,12 @@ System.out.println(pap != null);
   public void updateProgressBar(int progress)
   {
     JProgressBar pBar = progressBar.getProgressBar(progId);
+    
+    if (pBar==null)
+    {
+      return;
+    }
+    
     pBar.setValue(progress);
     pBar.repaint();
   }
index e737e52..6800b0c 100755 (executable)
@@ -75,6 +75,12 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel
 
   private int progress;
 
+  private SequenceGroup selection;
+  /**
+   * input sequences
+   */
+  private SequenceI[] seqs=null;
+
   /**
    * Creates a new PairwiseAlignPanel object.
    * 
@@ -84,52 +90,67 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel
    */
   public PairwiseAlignPanel(AlignmentViewport viewport)
   {
-    this(viewport, false, 120, 20, true);      // default penalties used in AlignSeq
+    this(viewport, null, false, 120, 20, true);        // default penalties used in AlignSeq
   }
   public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost)
   {
-    this(viewport, endGaps, gapOpenCost, gapExtendCost, true);
+    this(viewport, null, endGaps, gapOpenCost, gapExtendCost, true);
   }
-  public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost, boolean run)
+
+  public PairwiseAlignPanel(AlignmentViewport viewport, SequenceGroup selection, boolean  endGaps,
+          int gapOpenCost, int gapExtendCost, boolean run)
   {
     super();
     this.av = viewport;
     this.GAP_OPEN_COST = gapOpenCost;
     this.GAP_EXTEND_COST = gapExtendCost;
     this.endGaps = endGaps;
+    this.selection = selection;
     this.total = MiscMath.combinations(av.getAlignment().getHeight(), 2);
-    
+
     if (run)
       calculate();
-System.out.println("Creating pap");
+    System.out.println("Creating pap");
   }
-
+  
   public void calculate()
   {
 
-    SequenceGroup selectionGroup = av.getSelectionGroup();
     StringBuilder sb = new StringBuilder(1024);
 
     sequences = new Vector<SequenceI>();
+    String[] seqStrings;
+    seqs=null;
 
-    boolean isSelection = selectionGroup != null
-            && selectionGroup.getSize() > 0;
-    AlignmentView view = av.getAlignmentView(isSelection);
-    // String[] seqStrings = av.getViewAsString(true);
-    String[] seqStrings = view
-            .getSequenceStrings(av.getGapCharacter());
-
-    SequenceI[] seqs;
-    if (isSelection)
+    if (selection != null)
     {
-      seqs = (SequenceI[]) view
-              .getAlignmentAndHiddenColumns(av.getGapCharacter())[0];
+      // given a set of sequences to compare
+      seqs = selection.getSelectionAsNewSequences(av.getAlignment());
+      seqStrings = new String[seqs.length];
+      int s = 0;
+      for (SequenceI seq : seqs)
+      {
+        seqStrings[s++] = seq.getSequenceAsString();
+      }
     }
     else
     {
-      seqs = av.getAlignment().getSequencesArray();
+      SequenceGroup selectionGroup = av.getSelectionGroup();
+      boolean isSelection = selectionGroup != null
+              && selectionGroup.getSize() > 0;
+      AlignmentView view = av.getAlignmentView(isSelection);
+      seqStrings = view.getSequenceStrings(av.getGapCharacter());
+      if (isSelection)
+      {
+        seqs = (SequenceI[]) view
+                .getAlignmentAndHiddenColumns(av.getGapCharacter())[0];
+      }
+      else
+      {
+        seqs = av.getAlignment().getSequencesArray();
+      }
     }
-
+    
     String type = (av.getAlignment().isNucleotide()) ? AlignSeq.DNA
             : AlignSeq.PEP;
 
@@ -304,4 +325,8 @@ System.out.println("Creating pap");
   {
     return progress;
   }
+  public SequenceI[] getInputSequences()
+  {
+    return seqs;
+  }
 }