Merge branch 'develop' into features/JAL-250_hideredundantseqs
[jalview.git] / src / jalview / controller / AlignViewController.java
index 9451c3b..e71ccfb 100644 (file)
@@ -33,10 +33,12 @@ import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FeaturesFile;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
+import java.util.Arrays;
 import java.util.BitSet;
 import java.util.List;
 
@@ -101,29 +103,36 @@ public class AlignViewController implements AlignViewControllerI
     }
     if (gps != null)
     {
-      viewport.getAlignment().deleteAllGroups();
-      viewport.clearSequenceColours();
-      viewport.setSelectionGroup(null);
-      // set view properties for each group
-      for (int g = 0; g < gps.length; g++)
-      {
-        // gps[g].setShowunconserved(viewport.getShowUnconserved());
-        gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
-        viewport.getAlignment().addGroup(gps[g]);
-        Color col = new Color((int) (Math.random() * 255),
-                (int) (Math.random() * 255), (int) (Math.random() * 255));
-        col = col.brighter();
-        for (SequenceI sq : gps[g].getSequences(null))
-        {
-          viewport.setSequenceColour(sq, col);
-        }
-      }
+      showRandomColoursForGroups(Arrays.asList(gps));
+
       return true;
     }
     return false;
   }
 
   @Override
+  public void showRandomColoursForGroups(List<SequenceGroup> gps)
+  {
+    viewport.getAlignment().deleteAllGroups();
+    viewport.clearSequenceColours();
+    viewport.setSelectionGroup(null);
+    // set view properties for each group
+    for (SequenceGroup sg : gps)
+    {
+      // gps[g].setShowunconserved(viewport.getShowUnconserved());
+      sg.setshowSequenceLogo(viewport.isShowSequenceLogo());
+      viewport.getAlignment().addGroup(sg);
+      Color col = new Color((int) (Math.random() * 255),
+              (int) (Math.random() * 255), (int) (Math.random() * 255));
+      col = col.brighter();
+      for (SequenceI sq : sg.getSequences(null))
+      {
+        viewport.setSequenceColour(sq, col);
+      }
+    }
+  }
+
+  @Override
   public boolean createGroup()
   {
 
@@ -243,10 +252,6 @@ public class AlignViewController implements AlignViewControllerI
         SequenceFeature[] sfs = sq.getSequenceFeatures();
         if (sfs != null)
         {
-          /*
-           * check whether the feature start/end (base 1) 
-           * overlaps the selection start/end
-           */
           int ist = sq.findIndex(sq.getStart());
           int iend = sq.findIndex(sq.getEnd());
           if (iend < startPosition || ist > endPosition)
@@ -264,29 +269,54 @@ public class AlignViewController implements AlignViewControllerI
               // - findIndex wastes time by starting from first character and
               // counting
 
-              int i = sq.findIndex(sf.getBegin());
-              int j = sq.findIndex(sf.getEnd());
-              if (j < startPosition || i > endPosition)
+              int sfStartCol = sq.findIndex(sf.getBegin());
+              int sfEndCol = sq.findIndex(sf.getEnd());
+
+              if (sf.isContactFeature())
+              {
+                /*
+                 * 'contact' feature - check for 'start' or 'end'
+                 * position within the selected region
+                 */
+                if (sfStartCol >= startPosition
+                        && sfStartCol <= endPosition)
+                {
+                  bs.set(sfStartCol - 1);
+                  sequenceHasFeature = true;
+                }
+                if (sfEndCol >= startPosition && sfEndCol <= endPosition)
+                {
+                  bs.set(sfEndCol - 1);
+                  sequenceHasFeature = true;
+                }
+                continue;
+              }
+
+              /*
+               * contiguous feature - select feature positions (if any) 
+               * within the selected region
+               */
+              if (sfStartCol > endPosition || sfEndCol < startPosition)
               {
                 // feature is outside selected region
                 continue;
               }
               sequenceHasFeature = true;
-              if (i < startPosition)
+              if (sfStartCol < startPosition)
               {
-                i = startPosition;
+                sfStartCol = startPosition;
               }
-              if (i < ist)
+              if (sfStartCol < ist)
               {
-                i = ist;
+                sfStartCol = ist;
               }
-              if (j > endPosition)
+              if (sfEndCol > endPosition)
               {
-                j = endPosition;
+                sfEndCol = endPosition;
               }
-              for (; i <= j; i++)
+              for (; sfStartCol <= sfEndCol; sfStartCol++)
               {
-                bs.set(i - 1); // convert to base 0
+                bs.set(sfStartCol - 1); // convert to base 0
               }
             }
           }
@@ -349,7 +379,7 @@ public class AlignViewController implements AlignViewControllerI
   }
 
   @Override
-  public boolean parseFeaturesFile(String file, String protocol,
+  public boolean parseFeaturesFile(String file, DataSourceType protocol,
           boolean relaxedIdMatching)
   {
     boolean featuresFile = false;