File Parsing returns Alignments, not Sequence[]
[jalview.git] / src / jalview / io / FastaFile.java
index f257c6c..75915c1 100755 (executable)
@@ -22,6 +22,8 @@ import jalview.datamodel.*;
 \r
 import java.io.*;\r
 \r
+import java.util.*;\r
+\r
 \r
 /**\r
  * DOCUMENT ME!\r
@@ -59,21 +61,45 @@ public class FastaFile extends AlignFile
     public void parse() throws IOException\r
     {\r
         StringBuffer sb = new StringBuffer();\r
-        int count = 0;\r
+        boolean firstLine = true;\r
 \r
         String line;\r
         Sequence seq = null;\r
 \r
+        boolean annotation = false;\r
+\r
         while ((line = nextLine()) != null)\r
         {\r
             line = line.trim();\r
             if (line.length() > 0)\r
             {\r
-                if (line.charAt(0)=='>')\r
+              if (line.charAt(0)=='>')\r
                 {\r
-                    if (count != 0)\r
+                  if (line.startsWith(">#_"))\r
+                  {\r
+                    if (annotation)\r
                     {\r
-                      if (!isValidProteinSequence(sb.toString().toCharArray()))\r
+                      Annotation[] anots = new Annotation[sb.length()];\r
+                      for (int i = 0; i < sb.length(); i++)\r
+                      {\r
+                        anots[i] = new Annotation(sb.substring(i, i+1),\r
+                                                  null,\r
+                                                  ' ', 0);\r
+                      }\r
+                      AlignmentAnnotation aa = new AlignmentAnnotation(\r
+                          seq.getName().substring(2), seq.getDescription(),\r
+                          anots);\r
+\r
+                      annotations.add(aa);\r
+                    }\r
+                    annotation = true;\r
+                  }\r
+                  else\r
+                    annotation = false;\r
+\r
+                    if (!firstLine)\r
+                    {\r
+                      if (!annotation && !isValidProteinSequence(sb.toString().toCharArray()))\r
                       {\r
                         throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
                                               +" : "+seq.getName()\r
@@ -81,12 +107,14 @@ public class FastaFile extends AlignFile
                       }\r
 \r
                        seq.setSequence(sb.toString());\r
-                       seqs.addElement(seq);\r
+\r
+                       if (!annotation)\r
+                         seqs.addElement(seq);\r
                     }\r
 \r
                     seq = parseId(line.substring(1));\r
+                    firstLine = false;\r
 \r
-                    count++;\r
                     sb = new StringBuffer();\r
                 }\r
                 else\r
@@ -96,8 +124,25 @@ public class FastaFile extends AlignFile
             }\r
         }\r
 \r
-        if (count > 0)\r
+        if (annotation)\r
+        {\r
+          Annotation[] anots = new Annotation[sb.length()];\r
+          for (int i = 0; i < sb.length(); i++)\r
+          {\r
+            anots[i] = new Annotation(sb.substring(i, i + 1),\r
+                                      null,\r
+                                      ' ', 0);\r
+          }\r
+          AlignmentAnnotation aa = new AlignmentAnnotation(\r
+              seq.getName().substring(2), seq.getDescription(),\r
+              anots);\r
+\r
+          annotations.add(aa);\r
+        }\r
+\r
+        else if (!firstLine)\r
         {\r
+\r
             if (!isValidProteinSequence(sb.toString().toCharArray()))\r
             {\r
                 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r