merge from 2_4_Release branch
[jalview.git] / src / jalview / io / StockholmFile.java
index d5f3cc2..2183f2d 100644 (file)
@@ -1,17 +1,17 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
+ * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * \r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
  * as published by the Free Software Foundation; either version 2\r
  * of the License, or (at your option) any later version.\r
- *\r
+ * \r
  * This program is distributed in the hope that it will be useful,\r
  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
  * GNU General Public License for more details.\r
- *\r
+ * \r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
@@ -30,13 +30,13 @@ import jalview.datamodel.*;
 // import org.apache.log4j.*;\r
 \r
 /**\r
- * This class is supposed to parse a Stockholm format file into Jalview\r
- * There are TODOs in this class: we do not know what the database source and\r
- * version is for the file when parsing the #GS= AC tag which associates accessions\r
- * with sequences. \r
- * Database references are also not parsed correctly: a separate reference string\r
- * parser must be added to parse the database reference form into Jalview's local\r
- * representation.\r
+ * This class is supposed to parse a Stockholm format file into Jalview There\r
+ * are TODOs in this class: we do not know what the database source and version\r
+ * is for the file when parsing the #GS= AC tag which associates accessions with\r
+ * sequences. Database references are also not parsed correctly: a separate\r
+ * reference string parser must be added to parse the database reference form\r
+ * into Jalview's local representation.\r
+ * \r
  * @author bsb at sanger.ac.uk\r
  * @version 0.3 + jalview mods\r
  * \r
@@ -53,10 +53,12 @@ public class StockholmFile extends AlignFile
   {\r
     super(inFile, type);\r
   }\r
+\r
   public StockholmFile(FileParse source) throws IOException\r
   {\r
     super(source);\r
   }\r
+\r
   public void initData()\r
   {\r
     super.initData();\r
@@ -67,7 +69,7 @@ public class StockholmFile extends AlignFile
    * be passed at construction time\r
    * \r
    * @throws IOException\r
-   *           If there is an error with the input file\r
+   *                 If there is an error with the input file\r
    */\r
   public void parse() throws IOException\r
   {\r
@@ -99,7 +101,7 @@ public class StockholmFile extends AlignFile
     // We define some Regexes here that will be used regularily later\r
     rend = new Regex("\\/\\/"); // Find the end of an alignment\r
     p = new Regex("(\\S+)\\/(\\d+)\\-(\\d+)"); // split sequence id in\r
-                                                // id/from/to\r
+    // id/from/to\r
     s = new Regex("(\\S+)\\s+(\\S*)\\s+(.*)"); // Parses annotation subtype\r
     r = new Regex("#=(G[FSRC]?)\\s+(.*)"); // Finds any annotation line\r
     x = new Regex("(\\S+)\\s+(\\S+)"); // split id from sequence\r
@@ -168,7 +170,7 @@ public class StockholmFile extends AlignFile
               String src = dbr.substring(0, dbr.indexOf(";"));\r
               String acn = dbr.substring(dbr.indexOf(";") + 1);\r
               jalview.util.DBRefUtils.parseToDbRef(seqO, src, "0", acn);\r
-              //seqO.addDBRef(dbref);\r
+              // seqO.addDBRef(dbref);\r
             }\r
           }\r
           Hashtable features = null;\r
@@ -204,9 +206,15 @@ public class StockholmFile extends AlignFile
                 for (int k = 0; k < byChar.length; k++)\r
                 {\r
                   char c = byChar[k];\r
-                  if (!(c == ' ' || c == '_' || c == '-' || c == '.')) // PFAM uses '.' for feature background\r
+                  if (!(c == ' ' || c == '_' || c == '-' || c == '.')) // PFAM\r
+                                                                        // uses\r
+                                                                        // '.'\r
+                                                                        // for\r
+                                                                        // feature\r
+                                                                        // background\r
                   {\r
-                    int new_pos = posmap[k]; // look up nearest seqeunce position to this column\r
+                    int new_pos = posmap[k]; // look up nearest seqeunce\r
+                                              // position to this column\r
                     SequenceFeature feat = new SequenceFeature(type, desc,\r
                             new_pos, new_pos, 0f, null);\r
 \r
@@ -216,10 +224,10 @@ public class StockholmFile extends AlignFile
               }\r
 \r
             }\r
-            \r
+\r
           }\r
           // garbage collect\r
-          \r
+\r
           // logger.debug("Adding seq " + acc + " from " + start + " to " + end\r
           // + ": " + seq);\r
           this.seqs.addElement(seqO);\r
@@ -379,13 +387,15 @@ public class StockholmFile extends AlignFile
             String seq = new String(s.stringMatched(3));\r
             String description = null;\r
             // Check for additional information about the current annotation\r
-            // We use a simple  string tokenizer here for speed\r
-            StringTokenizer sep = new StringTokenizer(seq," \t");\r
+            // We use a simple string tokenizer here for speed\r
+            StringTokenizer sep = new StringTokenizer(seq, " \t");\r
             description = sep.nextToken();\r
             if (sep.hasMoreTokens())\r
             {\r
               seq = sep.nextToken();\r
-            } else {\r
+            }\r
+            else\r
+            {\r
               seq = description;\r
               description = new String();\r
             }\r
@@ -442,7 +452,9 @@ public class StockholmFile extends AlignFile
           }\r
           else\r
           {\r
-            System.err.println("Warning - couldn't parse sequence annotation row line:\n"+line);\r
+            System.err\r
+                    .println("Warning - couldn't parse sequence annotation row line:\n"\r
+                            + line);\r
             // throw new IOException("Error parsing " + line);\r
           }\r
         }\r
@@ -480,18 +492,19 @@ public class StockholmFile extends AlignFile
     {\r
       String pos = annots.substring(i, i + 1);\r
       Annotation ann;\r
-      ann = new Annotation(pos, "", ' ', Float.NaN);\r
+      ann = new Annotation(pos, "", ' ', 0f); // 0f is 'valid' null - will not\r
+                                              // be written out\r
       if (ss)\r
       {\r
         ann.secondaryStructure = jalview.schemes.ResidueProperties\r
                 .getDssp3state(pos).charAt(0);\r
         if (ann.secondaryStructure == pos.charAt(0) || pos.charAt(0) == 'C')\r
         {\r
-          ann.displayCharacter = "";\r
+          ann.displayCharacter = ""; // null; // " ";\r
         }\r
         else\r
         {\r
-          ann.displayCharacter += " ";\r
+          ann.displayCharacter = " " + ann.displayCharacter;\r
         }\r
       }\r
 \r