JAL-2349 JAL-3855 helper method to make it easy to transfer a single ‘reference annot...
[jalview.git] / src / jalview / analysis / AlignmentUtils.java
index 0906872..403991a 100644 (file)
@@ -1503,7 +1503,7 @@ public class AlignmentUtils
 
   /**
    * Adds annotations to the top of the alignment annotations, in the same order
-   * as their related sequences.
+   * as their related sequences. If you already have an annotation and want to add it to a sequence in an alignment use {@code addReferenceAnnotationTo}
    * 
    * @param annotations
    *          the annotations to add
@@ -1520,6 +1520,20 @@ public class AlignmentUtils
     {
       for (AlignmentAnnotation ann : annotations.get(seq))
       {
+        addReferenceAnnotationTo(alignment, seq,ann,selectionGroup);
+      }
+    }
+  }
+  /**
+   * Make a copy of a reference annotation {@code ann} and add it to an alignment sequence {@code seq} in {@code alignment}, optionally limited to the extent of {@code selectionGroup}
+   * @param alignment
+   * @param seq
+   * @param ann
+   * @param selectionGroup - may be null
+   * @return annotation added to {@code seq and {@code alignment}
+   */
+  public static AlignmentAnnotation addReferenceAnnotationTo(final AlignmentI alignment, final SequenceI seq,final AlignmentAnnotation ann,final SequenceGroup selectionGroup)
+  {
         AlignmentAnnotation copyAnn = new AlignmentAnnotation(ann);
         int startRes = 0;
         int endRes = ann.annotations.length;
@@ -1549,9 +1563,8 @@ public class AlignmentUtils
         // add to the alignment and set visible
         alignment.addAnnotation(copyAnn);
         copyAnn.visible = true;
-      }
-    }
-
+      
+        return copyAnn;
   }
 
   /**