JAL-1152 prototype of new Annotations menu with sort options
[jalview.git] / src / jalview / analysis / AlignmentUtils.java
index 2feeb91..929a855 100644 (file)
  */
 package jalview.analysis;
 
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import jalview.datamodel.SequenceI;
-import jalview.datamodel.AlignmentI;
-
 /**
  * grab bag of useful alignment manipulation operations Expect these to be
  * refactored elsewhere at some point.
@@ -124,4 +124,28 @@ public class AlignmentUtils
     newAl.setDataset(core.getDataset());
     return newAl;
   }
+
+  /**
+   * Returns the index (zero-based position) of a sequence in an alignment, or
+   * -1 if not found.
+   * 
+   * @param al
+   * @param seq
+   * @return
+   */
+  public static int getSequenceIndex(AlignmentI al, SequenceI seq)
+  {
+    int result = -1;
+    int pos = 0;
+    for (SequenceI alSeq : al.getSequences())
+    {
+      if (alSeq == seq)
+      {
+        result = pos;
+        break;
+      }
+      pos++;
+    }
+    return result;
+  }
 }