Merge branch 'JAL-686' into Release_2_8_1_Branch
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Wed, 26 Feb 2014 16:20:43 +0000 (16:20 +0000)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Wed, 26 Feb 2014 16:20:43 +0000 (16:20 +0000)
src/jalview/io/FastaFile.java

index 9cc3b55..3a7197f 100755 (executable)
@@ -76,14 +76,14 @@ public class FastaFile extends AlignFile
     StringBuffer sb = new StringBuffer();
     boolean firstLine = true;
 
-    String line;
+    String line,uline;
     Sequence seq = null;
 
     boolean annotation = false;
 
-    while ((line = nextLine()) != null)
+    while ((uline = nextLine()) != null)
     {
-      line = line.trim();
+      line = uline.trim();
       if (line.length() > 0)
       {
         if (line.charAt(0) == '>')
@@ -92,17 +92,7 @@ public class FastaFile extends AlignFile
           {
             if (annotation)
             {
-              Annotation[] anots = new Annotation[sb.length()];
-              String anotString = sb.toString();
-              for (int i = 0; i < sb.length(); i++)
-              {
-                anots[i] = new Annotation(anotString.substring(i, i + 1),
-                        null, ' ', 0);
-              }
-              AlignmentAnnotation aa = new AlignmentAnnotation(seq
-                      .getName().substring(2), seq.getDescription(), anots);
-
-              annotations.addElement(aa);
+              annotations.addElement(makeAnnotation(seq, sb));
             }
           }
           else
@@ -132,24 +122,14 @@ public class FastaFile extends AlignFile
         }
         else
         {
-          sb.append(line);
+          sb.append(annotation ? uline : line);
         }
       }
     }
 
     if (annotation)
     {
-      Annotation[] anots = new Annotation[sb.length()];
-      String anotString = sb.toString();
-      for (int i = 0; i < sb.length(); i++)
-      {
-        anots[i] = new Annotation(anotString.substring(i, i + 1), null,
-                ' ', 0);
-      }
-      AlignmentAnnotation aa = new AlignmentAnnotation(seq.getName()
-              .substring(2), seq.getDescription(), anots);
-
-      annotations.addElement(aa);
+      annotations.addElement(makeAnnotation(seq, sb));
     }
 
     else if (!firstLine)
@@ -158,7 +138,23 @@ public class FastaFile extends AlignFile
       seqs.addElement(seq);
     }
   }
-
+  private AlignmentAnnotation makeAnnotation(SequenceI seq, StringBuffer sb)
+  {
+    Annotation[] anots = new Annotation[sb.length()];
+    char cb;
+    for (int i=0;i<anots.length;i++)
+    {
+      char cn = sb.charAt(i);
+      if (cn != ' ')
+      {
+        anots[i] = new Annotation(""+cn, null,
+              ' ', Float.NaN);
+      }
+    }
+    AlignmentAnnotation aa = new AlignmentAnnotation(seq.getName()
+            .substring(2), seq.getDescription(), anots);
+    return aa;
+  }
   /**
    * called by AppletFormatAdapter to generate an annotated alignment, rather
    * than bare sequences.