fix for JAL-2509 - don’t replace all bracket types with ()
[jalview.git] / src / jalview / io / StockholmFile.java
index 27be358..a47e1ea 100644 (file)
@@ -97,7 +97,8 @@ public class StockholmFile extends AlignFile
     this.al = al;
   }
 
-  public StockholmFile(String inFile, String type) throws IOException
+  public StockholmFile(String inFile, DataSourceType type)
+          throws IOException
   {
     super(inFile, type);
   }
@@ -799,9 +800,9 @@ public class StockholmFile extends AlignFile
   {
     String convert1, convert2 = null;
 
-    convert1 = OPEN_PAREN.replaceAll(annots);
-    convert2 = CLOSE_PAREN.replaceAll(convert1);
-    annots = convert2;
+    // convert1 = OPEN_PAREN.replaceAll(annots);
+    // convert2 = CLOSE_PAREN.replaceAll(convert1);
+    // annots = convert2;
 
     String type = label;
     if (label.contains("_cons"))
@@ -880,8 +881,13 @@ public class StockholmFile extends AlignFile
     return annot;
   }
 
-  public String print(SequenceI[] s)
+  @Override
+  public String print(SequenceI[] s, boolean jvSuffix)
   {
+    out = new StringBuffer();
+    out.append("# STOCKHOLM 1.0");
+    out.append(newline);
+
     // find max length of id
     int max = 0;
     int maxid = 0;
@@ -889,7 +895,7 @@ public class StockholmFile extends AlignFile
     Hashtable dataRef = null;
     while ((in < s.length) && (s[in] != null))
     {
-      String tmp = printId(s[in]);
+      String tmp = printId(s[in], jvSuffix);
       if (s[in].getSequence().length > max)
       {
         max = s[in].getSequence().length;
@@ -972,23 +978,26 @@ public class StockholmFile extends AlignFile
         {
           for (int j = 0; j < alAnot.length; j++)
           {
-            if (ds.getSequenceFeatures() != null)
+
+            String key = type2id(alAnot[j].label);
+            boolean isrna = alAnot[j].isValidStruc();
+
+            if (isrna)
             {
-              feature = ds.getSequenceFeatures()[0].type;
+              // hardwire to secondary structure if there is RNA secondary
+              // structure on the annotation
+              key = "SS";
             }
-            // ?bug - feature may still have previous loop value
-            String key = type2id(feature);
-
             if (key == null)
             {
+
               continue;
             }
 
             // out.append("#=GR ");
             out.append(new Format("%-" + maxid + "s").form("#=GR "
-                    + printId(s[i]) + " " + key + " "));
+                    + printId(s[i], jvSuffix) + " " + key + " "));
             ann = alAnot[j].annotations;
-            boolean isrna = alAnot[j].isValidStruc();
             String seq = "";
             for (int k = 0; k < ann.length; k++)
             {
@@ -1000,7 +1009,8 @@ public class StockholmFile extends AlignFile
         }
       }
 
-      out.append(new Format("%-" + maxid + "s").form(printId(s[i]) + " "));
+      out.append(new Format("%-" + maxid + "s")
+              .form(printId(s[i], jvSuffix) + " "));
       out.append(s[i].getSequenceAsString());
       out.append(newline);
       i++;
@@ -1053,6 +1063,10 @@ public class StockholmFile extends AlignFile
         out.append(newline);
       }
     }
+
+    out.append("//");
+    out.append(newline);
+
     return out.toString();
   }
 
@@ -1105,13 +1119,12 @@ public class StockholmFile extends AlignFile
     return seq;
   }
 
-  @Override
   public String print()
   {
     out = new StringBuffer();
     out.append("# STOCKHOLM 1.0");
     out.append(newline);
-    print(getSeqsAsArray());
+    print(getSeqsAsArray(), false);
 
     out.append("//");
     out.append(newline);