Merge branch 'develop' (JAL-4102 2.11.2.6 patch release) into features/r2_11_2_alphaf...
[jalview.git] / src / jalview / analysis / AlignmentUtils.java
index fdc74e2..a1a7fef 100644 (file)
@@ -20,8 +20,6 @@
  */
 package jalview.analysis;
 
-import java.util.Locale;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -31,6 +29,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NoSuchElementException;
@@ -46,6 +45,7 @@ import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ContactMatrixI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.GeneLociI;
 import jalview.datamodel.IncompleteCodonException;
@@ -1471,7 +1471,8 @@ public class AlignmentUtils
          */
         final Iterable<AlignmentAnnotation> matchedAlignmentAnnotations = al
                 .findAnnotations(seq, dsann.getCalcId(), dsann.label);
-        if (!matchedAlignmentAnnotations.iterator().hasNext())
+        if (matchedAlignmentAnnotations == null
+                || !matchedAlignmentAnnotations.iterator().hasNext())
         {
           result.add(dsann);
           if (labelForCalcId != null)
@@ -1517,7 +1518,7 @@ public class AlignmentUtils
           startRes = selectionGroup.getStartRes();
           endRes = selectionGroup.getEndRes();
         }
-        copyAnn.restrict(startRes, endRes);
+        copyAnn.restrict(startRes, endRes + 0);
 
         /*
          * Add to the sequence (sets copyAnn.datasetSequence), unless the
@@ -1525,6 +1526,12 @@ public class AlignmentUtils
          */
         if (!seq.hasAnnotation(ann))
         {
+          ContactMatrixI cm = seq.getDatasetSequence()
+                  .getContactMatrixFor(ann);
+          if (cm != null)
+          {
+            seq.addContactListFor(copyAnn, cm);
+          }
           seq.addAlignmentAnnotation(copyAnn);
         }
         // adjust for gaps
@@ -1534,6 +1541,7 @@ public class AlignmentUtils
         copyAnn.visible = true;
       }
     }
+
   }
 
   /**