JAL-3854 patched SeqSeqUtils.deUniquify to not use instanceOf - seems to work
[jalview.git] / src / jalview / analysis / SeqsetUtils.java
index 27b3041..4118124 100755 (executable)
@@ -20,6 +20,8 @@
  */
 package jalview.analysis;
 
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.HiddenMarkovModel;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
@@ -35,7 +37,7 @@ public class SeqsetUtils
 
   /**
    * Store essential properties of a sequence in a hashtable for later recovery
-   * Keys are Name, Start, End, SeqFeatures, PdbId
+   * Keys are Name, Start, End, SeqFeatures, PdbId, HMM
    * 
    * @param seq
    *          SequenceI
@@ -45,14 +47,14 @@ public class SeqsetUtils
   {
     Hashtable sqinfo = new Hashtable();
     sqinfo.put("Name", seq.getName());
-    sqinfo.put("Start", new Integer(seq.getStart()));
-    sqinfo.put("End", new Integer(seq.getEnd()));
+    sqinfo.put("Start", Integer.valueOf(seq.getStart()));
+    sqinfo.put("End", Integer.valueOf(seq.getEnd()));
     if (seq.getDescription() != null)
     {
       sqinfo.put("Description", seq.getDescription());
     }
 
-    Vector<SequenceFeature> sfeat = new Vector<SequenceFeature>();
+    Vector<SequenceFeature> sfeat = new Vector<>();
     List<SequenceFeature> sfs = seq.getFeatures().getAllFeatures();
     sfeat.addAll(sfs);
 
@@ -69,6 +71,16 @@ public class SeqsetUtils
               (seq.getDatasetSequence() != null) ? seq.getDatasetSequence()
                       : new Sequence("THISISAPLACEHOLDER", ""));
     }
+    if (seq.hasHMMProfile())
+    {
+      sqinfo.put("HMM", seq.getHMM());
+    }
+
+    if (seq.getAnnotation("Search Scores") != null)
+    {
+      sqinfo.put("Score", seq.getAnnotation("Search Scores"));
+    }
+
     return sqinfo;
   }
 
@@ -97,6 +109,10 @@ public class SeqsetUtils
     Vector<PDBEntry> pdbid = (Vector<PDBEntry>) sqinfo.get("PdbId");
     String description = (String) sqinfo.get("Description");
     Sequence seqds = (Sequence) sqinfo.get("datasetSequence");
+    HiddenMarkovModel hmm = (HiddenMarkovModel) sqinfo.get("HMM");
+    AlignmentAnnotation[] scores = (AlignmentAnnotation[]) sqinfo
+            .get("Score");
+
     if (oldname == null)
     {
       namePresent = false;
@@ -124,18 +140,29 @@ public class SeqsetUtils
     {
       sq.setDescription(description);
     }
-    if ((seqds != null)
-            && !(seqds.getName().equals("THISISAPLACEHOLDER") && seqds
-                    .getLength() == 0))
+    if ((seqds != null) && !(seqds.getName().equals("THISISAPLACEHOLDER")
+            && seqds.getLength() == 0))
     {
       if (sfeatures != null)
       {
-        System.err
-                .println("Implementation error: setting dataset sequence for a sequence which has sequence features.\n\tDataset sequence features will not be visible.");
+        System.err.println(
+                "Implementation error: setting dataset sequence for a sequence which has sequence features.\n\tDataset sequence features will not be visible.");
       }
       sq.setDatasetSequence(seqds);
     }
 
+    if (hmm != null)
+    {
+      sq.setHMM(new HiddenMarkovModel(hmm, sq));
+    }
+
+    if (scores != null)
+    {
+      for (AlignmentAnnotation score : scores)
+      {
+        sq.addAlignmentAnnotation(score);
+      }
+    }
     return namePresent;
   }
 
@@ -233,8 +260,7 @@ public class SeqsetUtils
     while (keys.hasMoreElements())
     {
       Object key = keys.nextElement();
-      if (key instanceof String)
-      {
+      try {
         if ((msq = matcher.findIdMatch((String) key)) != null)
         {
           Hashtable sqinfo = (Hashtable) map.get(key);
@@ -249,13 +275,19 @@ public class SeqsetUtils
                     + "' in uniquified alignment");
           }
         }
+      } catch (ClassCastException ccastex) {
+        if (!quiet)
+        {
+          System.err.println("Unexpected object in SeqSet map : "+key.getClass());
+        }
       }
     }
     if (unmatched.size() > 0 && !quiet)
     {
       System.err.println("Did not find matches for :");
-      for (Enumeration i = unmatched.elements(); i.hasMoreElements(); System.out
-              .println(((SequenceI) i.nextElement()).getName()))
+      for (Enumeration i = unmatched.elements(); i
+              .hasMoreElements(); System.out
+                      .println(((SequenceI) i.nextElement()).getName()))
       {
         ;
       }