JAL-4411 store class of provider in PDBEntry
[jalview.git] / src / jalview / analysis / AlignmentUtils.java
index f470dc6..d88950c 100644 (file)
@@ -37,6 +37,7 @@ import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import jalview.api.AlignCalcWorkerI;
 import jalview.bin.Console;
 import jalview.commands.RemoveGapColCommand;
 import jalview.datamodel.AlignedCodon;
@@ -55,6 +56,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.features.SequenceFeatures;
+import jalview.gui.AlignmentPanel;
 import jalview.io.gff.SequenceOntologyI;
 import jalview.schemes.ResidueProperties;
 import jalview.util.Comparison;
@@ -62,6 +64,7 @@ import jalview.util.DBRefUtils;
 import jalview.util.IntRangeComparator;
 import jalview.util.MapList;
 import jalview.util.MappingUtils;
+import jalview.workers.SecondaryStructureConsensusThread;
 
 /**
  * grab bag of useful alignment manipulation operations Expect these to be
@@ -76,6 +79,17 @@ public class AlignmentUtils
 
   private static final String SEQUENCE_VARIANT = "sequence_variant:";
 
+  
+  private static final Map<String, String> SECONDARY_STRUCTURE_LABELS = new HashMap<>();
+
+  static {
+      SECONDARY_STRUCTURE_LABELS.put("Secondary Structure", "3D Structures");
+      SECONDARY_STRUCTURE_LABELS.put("jnetpred", "JPred");
+      // Add other secondary structure labels here if needed
+  }
+  
+  private static final String SS_ANNOTATION_LABEL = "Secondary Structure";
+
   /*
    * the 'id' attribute is provided for variant features fetched from
    * Ensembl using its REST service with JSON format 
@@ -547,7 +561,8 @@ public class AlignmentUtils
       if (translated == null || !(aaRes == translated.charAt(0)))
       {
         // debug
-        // jalview.bin.Console.outPrintln(("Mismatch at " + i + "/" + aaResidue + ": "
+        // jalview.bin.Console.outPrintln(("Mismatch at " + i + "/" + aaResidue
+        // + ": "
         // + codon + "(" + translated + ") != " + aaRes));
         return false;
       }
@@ -698,7 +713,8 @@ public class AlignmentUtils
          * unmapped position; treat like a gap
          */
         sourceGapMappedLength += ratio;
-        // jalview.bin.Console.errPrintln("Can't align: no codon mapping to residue "
+        // jalview.bin.Console.errPrintln("Can't align: no codon mapping to
+        // residue "
         // + sourceDsPos + "(" + sourceChar + ")");
         // return;
         continue;
@@ -883,7 +899,8 @@ public class AlignmentUtils
   {
     if (protein.isNucleotide() || !dna.isNucleotide())
     {
-      jalview.bin.Console.errPrintln("Wrong alignment type in alignProteinAsDna");
+      jalview.bin.Console
+              .errPrintln("Wrong alignment type in alignProteinAsDna");
       return 0;
     }
     List<SequenceI> unmappedProtein = new ArrayList<>();
@@ -908,7 +925,8 @@ public class AlignmentUtils
   {
     if (protein.isNucleotide() || !dna.isNucleotide())
     {
-      jalview.bin.Console.errPrintln("Wrong alignment type in alignProteinAsDna");
+      jalview.bin.Console
+              .errPrintln("Wrong alignment type in alignProteinAsDna");
       return 0;
     }
     // todo: implement this
@@ -1512,7 +1530,9 @@ public class AlignmentUtils
    * @param alignment
    *          the alignment to add them to
    * @param selectionGroup
-   *          current selection group - may be null, if provided then any added annotation will be trimmed to just those columns in the selection group
+   *          current selection group - may be null, if provided then any added
+   *          annotation will be trimmed to just those columns in the selection
+   *          group
    */
   public static void addReferenceAnnotations(
           Map<SequenceI, List<AlignmentAnnotation>> annotations,
@@ -1526,6 +1546,21 @@ public class AlignmentUtils
       }
     }
   }
+  
+  
+  public static boolean isSSAnnotationPresent( Map<SequenceI, List<AlignmentAnnotation>> annotations) {
+    
+    for (SequenceI seq : annotations.keySet())
+    {
+      for (AlignmentAnnotation ann : annotations.get(seq))
+      {
+        if(ann.getDescription(false).startsWith(SS_ANNOTATION_LABEL)) {                    
+          return true;
+        }       
+      }
+    }
+    return false;
+  }
 
   /**
    * Make a copy of a reference annotation {@code ann} and add it to an
@@ -1536,7 +1571,9 @@ public class AlignmentUtils
    * @param seq
    * @param ann
    * @param selectionGroup
-   *          current selection group - may be null, if provided then any added annotation will be trimmed to just those columns in the selection group
+   *          current selection group - may be null, if provided then any added
+   *          annotation will be trimmed to just those columns in the selection
+   *          group
    * @return annotation added to {@code seq and {@code alignment}
    */
   public static AlignmentAnnotation addReferenceAnnotationTo(
@@ -2770,8 +2807,8 @@ public class AlignmentUtils
                 fromRange[i + 1]);
         if (range == null)
         {
-          jalview.bin.Console.errPrintln("Error in mapping " + seqMap + " from "
-                  + fromSeq.getName());
+          jalview.bin.Console.errPrintln("Error in mapping " + seqMap
+                  + " from " + fromSeq.getName());
           return false;
         }
         int fromCol = fromSeq.findIndex(fromRange[i]);
@@ -2822,4 +2859,41 @@ public class AlignmentUtils
     }
     return true;
   }
+  
+
+  public static List<String> getSecondaryStructureSources(AlignmentAnnotation[] annotations) {
+    
+      List<String> ssSources = new ArrayList<>();
+      Set<String> addedLabels = new HashSet<>(); // to keep track of added labels
+
+      for (AlignmentAnnotation annotation : annotations) {
+          String label = annotation.label;
+          if (SECONDARY_STRUCTURE_LABELS.containsKey(label) && !addedLabels.contains(label)) {
+              ssSources.add(SECONDARY_STRUCTURE_LABELS.get(label));
+              addedLabels.add(label); // Add the label to the set
+          }
+      }
+
+      return ssSources;
+  }
+  
+  public static boolean isSecondaryStructurePresent(AlignmentAnnotation[] annotations)
+  {
+    boolean ssPresent = false;
+    
+    for (AlignmentAnnotation aa : annotations)
+    {
+      if(ssPresent) {
+        break;
+      }     
+
+      if (SECONDARY_STRUCTURE_LABELS.containsKey(aa.label)) {
+          ssPresent = true;
+          break;
+      }
+    }
+    
+    return ssPresent;
+    
+  }
 }