JAL-4159 connectivity should be computed for the sequences analysed with PAsiMap...
authorJim Procter <jprocter@dundee.ac.uk>
Tue, 21 May 2024 17:18:20 +0000 (18:18 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Tue, 21 May 2024 17:18:20 +0000 (18:18 +0100)
src/jalview/analysis/Connectivity.java
src/jalview/analysis/PaSiMap.java
src/jalview/viewmodel/AlignmentViewport.java

index a4cbc3a..c65c170 100644 (file)
  */
 package jalview.analysis;
 
-//import jalview.datamodel.AlignmentView;
-import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
 import jalview.viewmodel.AlignmentViewport;
 
-import java.util.Comparator;
 import java.util.Hashtable;
-import java.util.HashSet;
-import java.util.TreeSet;
 
 /**
  * @Author MorellThomas
@@ -38,27 +33,40 @@ import java.util.TreeSet;
 
 public class Connectivity
 {
-
-  /**
-   * Returns the number of unique connections for each sequence
-   * only connections with a score of above 0 count
-   * 
-   * @param av sequences
-   * @param scores alignment scores
-   *
-   * @return connectivity
-   */
-  public static Hashtable<SequenceI, Integer> getConnectivity(AlignmentViewport av, float[][] scores, byte dim) throws RuntimeException
+  public static Hashtable<SequenceI, Integer> getConnectivityForAlignmentView(
+          AlignmentViewport av, float[][] scores, byte dim)
   {
-    boolean isSelection = av.getSelectionGroup() != null && av.getSelectionGroup().getSize() > 0;
+    boolean isSelection = av.getSelectionGroup() != null
+            && av.getSelectionGroup().getSize() > 0;
     SequenceI[] sequences;
     if (isSelection)
     {
-      sequences = (SequenceI[]) av.getAlignmentView(isSelection).getAlignmentAndHiddenColumns(av.getGapCharacter())[0];
-    } else {
+      sequences = (SequenceI[]) av.getAlignmentView(isSelection)
+              .getAlignmentAndHiddenColumns(av.getGapCharacter())[0];
+    }
+    else
+    {
       sequences = av.getAlignment().getSequencesArray();
     }
 
+    return Connectivity.getConnectivity(sequences, scores, dim);
+  }
+
+  /**
+   * Returns the number of unique connections for each sequence only connections
+   * with a score of above 0 count
+   * 
+   * @param av
+   *          sequences
+   * @param scores
+   *          alignment scores
+   *
+   * @return connectivity
+   */
+  public static Hashtable<SequenceI, Integer> getConnectivity(
+          SequenceI[] sequences, float[][] scores, byte dim)
+          throws RuntimeException
+  {
     Hashtable<SequenceI, Integer> connectivity = new Hashtable<SequenceI, Integer>();
     // for each unique connection
     for (int i = 0; i < sequences.length; i++)
@@ -67,28 +75,34 @@ public class Connectivity
       for (int j = 0; j < i; j++)
       {
         connectivity.putIfAbsent(sequences[j], 0);
-       int iOld = connectivity.get(sequences[i]);
-       int jOld = connectivity.get(sequences[j]); 
+        int iOld = connectivity.get(sequences[i]);
+        int jOld = connectivity.get(sequences[j]);
         // count the connection if its score is not NaN
-//System.out.println(String.format("%s - %s : %f", sequences[i].getName(), sequences[j].getName(), scores[i][j]));
-       if (!Float.isNaN(scores[i][j]))
-       {
-         connectivity.put(sequences[i], ++iOld);
-         connectivity.put(sequences[j], ++jOld);
-       }
+        // System.out.println(String.format("%s - %s : %f",
+        // sequences[i].getName(), sequences[j].getName(), scores[i][j]));
+        if (!Float.isNaN(scores[i][j]))
+        {
+          connectivity.put(sequences[i], ++iOld);
+          connectivity.put(sequences[j], ++jOld);
+        }
       }
     }
 
     // if a sequence has too few connections, abort
-    connectivity.forEach((sequence, connection) ->
-    {
-      System.out.println(String.format("%s: %d", sequence.getName(), connection));
+    connectivity.forEach((sequence, connection) -> {
+      System.out.println(
+              String.format("%s: %d", sequence.getName(), connection));
       if (connection < dim)
       {
-       JvOptionPane.showInternalMessageDialog(Desktop.desktop, String.format("Insufficient number of connections for %s (%d, should be %d or more)", sequence.getName(), connection, dim), "Connectivity Error", JvOptionPane.WARNING_MESSAGE);
-       throw new ConnectivityException(sequence.getName(), connection, dim);
+        JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+                String.format(
+                        "Insufficient number of connections for %s (%d, should be %d or more)",
+                        sequence.getName(), connection, dim),
+                "Connectivity Error", JvOptionPane.WARNING_MESSAGE);
+        throw new ConnectivityException(sequence.getName(), connection,
+                dim);
       }
-    } );
+    });
 
     return connectivity;
   }
index 7c1c24a..86888ee 100755 (executable)
@@ -205,8 +205,8 @@ public class PaSiMap implements Runnable
       //alignment = new PairwiseAlignPanel(seqs, true, 100, 5);
       alignment.calculate();
       float[][] scores = alignment.getAlignmentScores();       //bigger index first -- eg scores[14][13]
-
-      seqs.calculateConnectivity(scores, dim);
+      SequenceI[] iseqs = alignment.getInputSequences();
+      Connectivity.getConnectivity(iseqs, scores, dim);
 
       pairwiseScores = new Matrix(scores);
       pairwiseScores.fillDiagonal();
index 4708888..d26f023 100644 (file)
@@ -3294,9 +3294,4 @@ public abstract class AlignmentViewport
             + savedUpToDate);
     return savedUpToDate;
   }
-
-  public Hashtable<SequenceI, Integer> calculateConnectivity(float[][] scores, byte dim)
-  {
-    return Connectivity.getConnectivity(this, scores, dim);
-  }
 }