(JAL-1052) basic consensus line parsing to rna structure lines
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 2 Mar 2012 23:00:40 +0000 (23:00 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 2 Mar 2012 23:00:40 +0000 (23:00 +0000)
src/jalview/io/ClustalFile.java

index 1e198c4..710ef4a 100755 (executable)
@@ -49,7 +49,9 @@ public class ClustalFile extends AlignFile
   {
     int i = 0;
     boolean flag = false;
-
+    boolean rna=false;
+    boolean top=false;
+    StringBuffer pssecstr=new StringBuffer(),consstr=new StringBuffer();
     Vector headers = new Vector();
     Hashtable seqhash = new Hashtable();
     StringBuffer tempseq;
@@ -60,6 +62,10 @@ public class ClustalFile extends AlignFile
     {
       while ((line = nextLine()) != null)
       {
+        if (line.length()==0)
+        {
+          top=true;
+        }
         if (line.indexOf(" ") != 0)
         {
           str = new StringTokenizer(line, " ");
@@ -95,6 +101,7 @@ public class ClustalFile extends AlignFile
                 {
                   tempseq.append(str.nextToken());
                 }
+                top=false;
               }
             }
           }
@@ -102,6 +109,16 @@ public class ClustalFile extends AlignFile
           {
             flag = true;
           }
+        } else {
+          if (line.matches("\\s+(-|\\.|\\(|\\[|\\]|\\))+"))
+          {
+            if (top)
+            {
+              pssecstr.append(line.trim());
+            } else {
+              consstr.append(line.trim());
+            }
+          }
         }
       }
     } catch (IOException e)
@@ -139,9 +156,26 @@ public class ClustalFile extends AlignFile
                           + headers.elementAt(i));
         }
       }
+      AlignmentAnnotation lastssa=null;
+      if (pssecstr.length()==maxLength)
+      {
+        Vector ss=new Vector();
+        AlignmentAnnotation ssa=lastssa=StockholmFile.parseAnnotationRow(ss, "secondary structure", pssecstr.toString());
+        ssa.label="Secondary Structure";
+        annotations.addElement(ssa);
+      }
+      if (consstr.length()==maxLength)
+      {
+        Vector ss=new Vector();
+        AlignmentAnnotation ssa=StockholmFile.parseAnnotationRow(ss, "secondary structure", consstr.toString());
+        ssa.label="Consensus Secondary Structure";
+        if (lastssa==null || !lastssa.getRNAStruc().equals(ssa.getRNAStruc().replace('-', '.')))
+        {
+          annotations.addElement(ssa);
+        }
+      }
     }
   }
-
   public String print()
   {
     return print(getSeqsAsArray());