Merge branch 'develop' into features/hmmer
[jalview.git] / src / jalview / io / StockholmFile.java
index dea0789..dc4fabd 100644 (file)
@@ -163,8 +163,8 @@ public class StockholmFile extends AlignFile
 
       for (int k = 0; k < rna.length(); k++)
       {
-        ann[k] = new Annotation(annot[k], "", Rna.getRNASecStrucState(
-                annot[k]).charAt(0), 0f);
+        ann[k] = new Annotation(annot[k], "",
+                Rna.getRNASecStrucState(annot[k]).charAt(0), 0f);
 
       }
       AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",
@@ -207,9 +207,8 @@ public class StockholmFile extends AlignFile
     r = new Regex("# STOCKHOLM ([\\d\\.]+)");
     if (!r.search(nextLine()))
     {
-      throw new IOException(
-              MessageManager
-                      .getString("exception.stockholm_invalid_format"));
+      throw new IOException(MessageManager
+              .getString("exception.stockholm_invalid_format"));
     }
     else
     {
@@ -439,8 +438,8 @@ public class StockholmFile extends AlignFile
         {
           // logger.error("Could not parse sequence line: " + line);
           throw new IOException(MessageManager.formatMessage(
-                  "exception.couldnt_parse_sequence_line",
-                  new String[] { line }));
+                  "exception.couldnt_parse_sequence_line", new String[]
+                  { line }));
         }
         String ns = seqs.get(x.stringMatched(1));
         if (ns == null)
@@ -671,8 +670,8 @@ public class StockholmFile extends AlignFile
           // }
           else
           {
-            System.err
-                    .println("Warning - couldn't parse sequence annotation row line:\n"
+            System.err.println(
+                    "Warning - couldn't parse sequence annotation row line:\n"
                             + line);
             // throw new IOException("Error parsing " + line);
           }
@@ -680,8 +679,8 @@ public class StockholmFile extends AlignFile
         else
         {
           throw new IOException(MessageManager.formatMessage(
-                  "exception.unknown_annotation_detected", new String[] {
-                      annType, annContent }));
+                  "exception.unknown_annotation_detected", new String[]
+                  { annType, annContent }));
         }
       }
     }
@@ -794,8 +793,10 @@ public class StockholmFile extends AlignFile
     {
       for (DBRefEntry d : dbrs)
       {
-        jalview.util.MapList mp = new jalview.util.MapList(new int[] {
-            seqO.getStart(), seqO.getEnd() }, new int[] { st, en }, 1, 1);
+        jalview.util.MapList mp = new jalview.util.MapList(
+                new int[]
+                { seqO.getStart(), seqO.getEnd() }, new int[] { st, en }, 1,
+                1);
         jalview.datamodel.Mapping mping = new Mapping(mp);
         d.setMap(mping);
       }
@@ -815,8 +816,9 @@ public class StockholmFile extends AlignFile
     String type = label;
     if (label.contains("_cons"))
     {
-      type = (label.indexOf("_cons") == label.length() - 5) ? label
-              .substring(0, label.length() - 5) : label;
+      type = (label.indexOf("_cons") == label.length() - 5)
+              ? label.substring(0, label.length() - 5)
+              : label;
     }
     boolean ss = false, posterior = false;
     type = id2type(type);
@@ -850,14 +852,14 @@ public class StockholmFile extends AlignFile
             ann.secondaryStructure = ResidueProperties.getDssp3state(pos)
                     .charAt(0);
 
-          if (ann.secondaryStructure == pos.charAt(0))
-          {
-            ann.displayCharacter = ""; // null; // " ";
-          }
-          else
-          {
-            ann.displayCharacter = " " + ann.displayCharacter;
-          }
+            if (ann.secondaryStructure == pos.charAt(0))
+            {
+              ann.displayCharacter = ""; // null; // " ";
+            }
+            else
+            {
+              ann.displayCharacter = " " + ann.displayCharacter;
+            }
           }
         }
 
@@ -980,8 +982,8 @@ public class StockholmFile extends AlignFile
       {
         Object idd = en.nextElement();
         String type = (String) dataRef.remove(idd);
-        out.append(new Format("%-" + (maxid - 2) + "s").form("#=GS "
-                + idd.toString() + " "));
+        out.append(new Format("%-" + (maxid - 2) + "s")
+                .form("#=GS " + idd.toString() + " "));
         if (type.contains("PFAM") || type.contains("RFAM"))
         {
 
@@ -996,52 +998,52 @@ public class StockholmFile extends AlignFile
     }
 
 
-      // output annotations
-      while (i < s.length && s[i] != null)
-      {
-        AlignmentAnnotation[] alAnot = s[i].getAnnotation();
+    // output annotations
+    while (i < s.length && s[i] != null)
+    {
+      AlignmentAnnotation[] alAnot = s[i].getAnnotation();
       if (alAnot != null)
+      {
+        Annotation[] ann;
+        for (int j = 0; j < alAnot.length; j++)
         {
-          Annotation[] ann;
-          for (int j = 0; j < alAnot.length; j++)
-          {
 
-            String key = type2id(alAnot[j].label);
-            boolean isrna = alAnot[j].isValidStruc();
+          String key = type2id(alAnot[j].label);
+          boolean isrna = alAnot[j].isValidStruc();
+          if (isrna)
+          {
+            // hardwire to secondary structure if there is RNA secondary
+            // structure on the annotation
+            key = "SS";
+          }
+          if (key == null)
+          {
 
-            if (isrna)
-            {
-              // hardwire to secondary structure if there is RNA secondary
-              // structure on the annotation
-              key = "SS";
-            }
-            if (key == null)
-            {
+            continue;
+          }
 
-              continue;
-            }
+          // out.append("#=GR ");
+          out.append(new Format("%-" + maxid + "s").form(
+                  "#=GR " + printId(s[i], jvSuffix) + " " + key + " "));
+          ann = alAnot[j].annotations;
+          String seq = "";
+          for (int k = 0; k < ann.length; k++)
+          {
+            seq += outputCharacter(key, k, isrna, ann, s[i]);
 
-            // out.append("#=GR ");
-            out.append(new Format("%-" + maxid + "s").form(
-                    "#=GR " + printId(s[i], jvSuffix) + " " + key + " "));
-            ann = alAnot[j].annotations;
-            String seq = "";
-            for (int k = 0; k < ann.length; k++)
-            {
-              seq += outputCharacter(key, k, isrna, ann, s[i]);
-            }
-            out.append(seq);
-            out.append(newline);
-          }
         }
-
-        out.append(new Format("%-" + maxid + "s")
-                .form(printId(s[i], jvSuffix) + " "));
-        out.append(s[i].getSequenceAsString());
-        out.append(newline);
-        i++;
+          out.append(seq);
+          out.append(newline);
+        }
       }
 
+      out.append(new Format("%-" + maxid + "s")
+              .form(printId(s[i], jvSuffix) + " "));
+      out.append(s[i].getSequenceAsString());
+      out.append(newline);
+      i++;
+    }
+
     // alignment annotation
     AlignmentAnnotation aa;
     if (al.getAlignmentAnnotation() != null)
@@ -1089,6 +1091,7 @@ public class StockholmFile extends AlignFile
         out.append(newline);
       }
     }
+    
 
 
     out.append("//");
@@ -1112,8 +1115,10 @@ public class StockholmFile extends AlignFile
   {
     char seq = ' ';
     Annotation annot = ann[k];
-    String ch = (annot == null) ? ((sequenceI == null) ? "-" : Character
-            .toString(sequenceI.getCharAt(k))) : annot.displayCharacter;
+    String ch = (annot == null)
+            ? ((sequenceI == null) ? "-"
+                    : Character.toString(sequenceI.getCharAt(k)))
+            : annot.displayCharacter;
     if (key != null && key.equals("SS"))
     {
       if (annot == null)
@@ -1152,7 +1157,8 @@ public class StockholmFile extends AlignFile
     out.append("# STOCKHOLM 1.0");
     out.append(newline);
     print(getSeqsAsArray(), false);
-
+    
+    out.append("//");
     out.append(newline);
     return out.toString();
   }
@@ -1189,8 +1195,8 @@ public class StockholmFile extends AlignFile
     {
       return (String) typeIds.get(id);
     }
-    System.err.println("Warning : Unknown Stockholm annotation type code "
-            + id);
+    System.err.println(
+            "Warning : Unknown Stockholm annotation type code " + id);
     return id;
   }
 
@@ -1211,8 +1217,8 @@ public class StockholmFile extends AlignFile
     {
       return key;
     }
-    System.err.println("Warning : Unknown Stockholm annotation type: "
-            + type);
+    System.err.println(
+            "Warning : Unknown Stockholm annotation type: " + type);
     return key;
   }