JAL-4386 JAL-4411 factored out the test for a particular annotation row being a secon...
authorJim Procter <jprocter@dundee.ac.uk>
Thu, 27 Jun 2024 16:32:24 +0000 (17:32 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Thu, 27 Jun 2024 16:32:24 +0000 (17:32 +0100)
src/jalview/analysis/AlignmentUtils.java

index 3ca5bcb..c2a4c45 100644 (file)
@@ -3113,8 +3113,7 @@ public class AlignmentUtils
           AlignmentAnnotation[] alignAnnotList, String selectedSSSource)
   {
 
-    Map<SequenceI, ArrayList<AlignmentAnnotation>> ssAlignmentAnnotationForSequences 
-             = new HashMap<SequenceI, ArrayList<AlignmentAnnotation>>();
+    Map<SequenceI, ArrayList<AlignmentAnnotation>> ssAlignmentAnnotationForSequences = new HashMap<SequenceI, ArrayList<AlignmentAnnotation>>();
     if (alignAnnotList == null || alignAnnotList.length == 0)
     {
       return ssAlignmentAnnotationForSequences;
@@ -3126,39 +3125,44 @@ public class AlignmentUtils
       {
         continue;
       }
-      
-      for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet())
+
+      if (isSecondaryStructureFrom(selectedSSSource, aa))
       {
+        ssAlignmentAnnotationForSequences
+                .computeIfAbsent(aa.sequenceRef.getDatasetSequence(),
+                        k -> new ArrayList<>())
+                .add(aa);
+      }
+    }
 
-        if (label.equals(aa.label))
-        {
+    return ssAlignmentAnnotationForSequences;
 
-          if (selectedSSSource.equals(MessageManager.getString("option.ss_providers_all")))
-          {
-            ssAlignmentAnnotationForSequences
-                    .computeIfAbsent(aa.sequenceRef.getDatasetSequence(),
-                            k -> new ArrayList<>())
-                    .add(aa);
-            break;
-          }
+  }
 
-          String ssSource = AlignmentUtils
-                  .extractSSSourceFromAnnotationDescription(aa);
-          if (ssSource != null && ssSource.equals(selectedSSSource))
-          {
+  public static boolean isSecondaryStructureFrom(String selectedSSSource,
+          AlignmentAnnotation aa)
+  {
 
-            ssAlignmentAnnotationForSequences
-                    .computeIfAbsent(aa.sequenceRef.getDatasetSequence(),
-                            k -> new ArrayList<>())
-                    .add(aa);
-            break;
-          }
+    for (String label : Constants.SECONDARY_STRUCTURE_LABELS.keySet())
+    {
+
+      if (label.equals(aa.label))
+      {
+
+        if (selectedSSSource.equals(
+                MessageManager.getString("option.ss_providers_all")))
+        {
+          return true;
+        }
+
+        String ssSource = AlignmentUtils
+                .extractSSSourceFromAnnotationDescription(aa);
+        if (ssSource != null && ssSource.equals(selectedSSSource))
+        {
+          return true;
         }
       }
     }
-
-    return ssAlignmentAnnotationForSequences;
-
+    return false;
   }
-  
 }