Reinstated 'create tree from selected region only' with better indication that only...
authorjprocter <Jim Procter>
Fri, 3 Jun 2005 13:16:56 +0000 (13:16 +0000)
committerjprocter <Jim Procter>
Fri, 3 Jun 2005 13:16:56 +0000 (13:16 +0000)
src/jalview/analysis/NJTree.java
src/jalview/gui/AlignFrame.java
src/jalview/util/Comparison.java

index d56464c..85749a1 100755 (executable)
@@ -412,7 +412,7 @@ public class NJTree {
           if (j==i) {\r
             distance[i][i] = 0;\r
           } else {\r
-            distance[i][j] = 100-Comparison.PID(sequence[i], sequence[j]);\r
+            distance[i][j] = 100-Comparison.PID(sequence[i], sequence[j], start, end);\r
             distance[j][i] = distance[i][j];\r
           }\r
         }\r
@@ -423,7 +423,7 @@ public class NJTree {
       for (int i = 0; i < noseqs-1; i++) {\r
         for (int j = i; j < noseqs; j++) {\r
           int score = 0;\r
-          for (int k=0; k < sequence[i].getLength(); k++) {\r
+          for (int k=start; k < end; k++) {\r
             try{\r
               score +=\r
                   ResidueProperties.getBLOSUM62(sequence[i].getSequence(k,\r
index afb1f0c..4d97f49 100755 (executable)
@@ -1068,34 +1068,51 @@ public class AlignFrame extends GAlignFrame
 
   void NewTreePanel(String type, String pwType, String title)
   {
-    //are the sequences aligned?
-    if(!viewport.alignment.isAligned())
-    {
-      JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
-                                   +"Try using the Pad function in the edit menu,\n"
-                                  +"or one of the multiple sequence alignment web services.",
-                                    "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
-      return;
-    }
-
+    String ltitle;
     final TreePanel tp;
     if (viewport.getSelectionGroup() != null &&
         viewport.getSelectionGroup().getSize() > 3)
     {
+      int s=0;
+      SequenceGroup sg = viewport.getSelectionGroup();
+
+      /* Decide if the selection is a column region */
+      while (s<sg.sequences.size()) {
+        if (((SequenceI) sg.sequences.elementAt(s++)).getLength()<sg.getEndRes()) {
+          JOptionPane.showMessageDialog(Desktop.desktop,
+                                        "The selected region to create a tree may\nonly contain residues or gaps.\n"
+                                       +"Try using the Pad function in the edit menu,\n"
+                                      +"or one of the multiple sequence alignment web services.",
+                                        "Sequences in selection are not aligned", JOptionPane.WARNING_MESSAGE);
+          return;
+        }
+
+      }
+      title=title+" on region";
       tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
                          pwType,
-                         0, viewport.alignment.getWidth());
+                         sg.getStartRes(), sg.getEndRes());
     }
     else
     {
-      tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
-                         type, pwType, 0, viewport.alignment.getWidth());
-    }
+
+     //are the sequences aligned?
+     if(!viewport.alignment.isAligned())
+     {
+       JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
+                                     +"Try using the Pad function in the edit menu,\n"
+                                     +"or one of the multiple sequence alignment web services.",
+                                     "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
+       return;
+     }
+     tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
+                        type, pwType, 0, viewport.alignment.getWidth());
+   }
 
    addTreeMenuItem(tp, title);
    viewport.setCurrentTree(tp.getTree());
 
-   Desktop.addInternalFrame(tp, title, 600, 500);
+   Desktop.addInternalFrame(tp, title+" from "+this.title, 600, 500);
   }
 
   public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
index 03abd0c..181dea5 100755 (executable)
@@ -105,6 +105,55 @@ public class Comparison {
 \r
     return (float)100*(len-bad)/len;\r
   }\r
+\r
+  // Another pid with region specification\r
+\r
+  public static float PID(SequenceI s1 , SequenceI s2, int start, int end)\r
+  {\r
+    int len;\r
+\r
+    if (s1.getSequence().length() > s2.getSequence().length())\r
+      len = s1.getSequence().length();\r
+    else\r
+      len = s2.getSequence().length();\r
+\r
+    if (end<len)\r
+      len=end;\r
+\r
+    if (len<start) {\r
+      start = len - 1; // we just use a single residue for the difference\r
+    }\r
+\r
+    int bad = 0;\r
+\r
+    for (int i = start; i < len; i++)\r
+    {\r
+      char chr1;\r
+      char chr2;\r
+\r
+      if (i < s1.getSequence().length())\r
+        chr1 = s1.getSequence().charAt(i);\r
+      else\r
+        chr1 = '.';\r
+\r
+\r
+      if (i < s2.getSequence().length())\r
+        chr2 = s2.getSequence().charAt(i);\r
+      else\r
+        chr2 = '.';\r
+\r
+\r
+      if (!(jalview.util.Comparison.isGap( chr1 ))  &&  !(jalview.util.Comparison.isGap( chr2 )))\r
+      {\r
+        if (chr1!=chr2)\r
+          bad++;\r
+      }\r
+    }\r
+\r
+    return (float)100*(len-bad)/len;\r
+  }\r
+\r
+\r
   public static String GapChars = " .-";\r
   public static boolean isGap(char c)\r
   {\r