Response to bug mantis?id=8187 - some quick hacks to read and write david's MSF file...
authorjprocter <Jim Procter>
Fri, 27 May 2005 09:31:14 +0000 (09:31 +0000)
committerjprocter <Jim Procter>
Fri, 27 May 2005 09:31:14 +0000 (09:31 +0000)
src/jalview/io/FormatAdapter.java
src/jalview/io/IdentifyFile.java
src/jalview/io/MSFfile.java

index dba0c61..3e5e250 100755 (executable)
@@ -9,6 +9,7 @@ public class FormatAdapter
   static{\r
     formats.addElement("FASTA");\r
     formats.addElement("MSF");\r
+    formats.addElement("PileUp");\r
     formats.addElement("CLUSTAL");\r
     formats.addElement("BLC");\r
     formats.addElement("PIR");\r
@@ -25,6 +26,8 @@ public class FormatAdapter
         afile = new FastaFile(inFile, type);\r
       else if (format.equals("MSF"))\r
         afile = new MSFfile(inFile, type);\r
+      else if (format.equals("PileUp"))\r
+              afile = new PileUpfile(inFile, type);\r
       else if (format.equals("CLUSTAL"))\r
         afile = new ClustalFile(inFile, type);\r
       else if (format.equals("BLC"))\r
@@ -59,6 +62,8 @@ public class FormatAdapter
         afile = new FastaFile();\r
       else if (format.equals("MSF"))\r
         afile = new MSFfile();\r
+      else if (format.equals("PileUp"))\r
+        afile = new PileUpfile();\r
       else if (format.equals("CLUSTAL"))\r
         afile = new ClustalFile();\r
       else if (format.equals("BLC"))\r
index 55d771b..eebde9b 100755 (executable)
@@ -43,6 +43,12 @@ public class IdentifyFile
 \r
         if(data.indexOf("PILEUP")>-1)\r
         {\r
+          reply = "PileUp";\r
+          break;\r
+        }\r
+        if((data.indexOf("!!")>-1)\r
+           && (data.indexOf("!!")<data.indexOf("_MULTIPLE_ALIGNMENT ")))\r
+        {\r
           reply = "MSF";\r
           break;\r
         }\r
index 9495f82..3c18432 100755 (executable)
@@ -19,8 +19,10 @@ public class MSFfile extends AlignFile {
     super(inFile,type);\r
   }\r
 \r
-  public void parse() {\r
+  private static com.stevesoft.pat.Regex gapre = new com.stevesoft.pat.Regex("\\~","-");\r
+  private static com.stevesoft.pat.Regex re2gap = new com.stevesoft.pat.Regex("["+jalview.util.Comparison.GapChars+"]","\\~");\r
 \r
+  public void parse() {\r
     int       i       = 0;\r
     boolean   seqFlag = false;\r
     String    key     = new String();\r
@@ -106,7 +108,8 @@ public class MSFfile extends AlignFile {
             }\r
           }\r
         }\r
-\r
+        // Replace ~ with a sensible gap character\r
+        seq = gapre.replaceAll(seq);\r
         Sequence newSeq = new Sequence(head,seq,start,end);\r
 \r
         seqs.addElement(newSeq);\r
@@ -195,15 +198,15 @@ public class MSFfile extends AlignFile {
           int end = start + 10;\r
 \r
           if (end < s[j].getSequence().length() && start < s[j].getSequence().length() ) {\r
-            out.append(s[j].getSequence().substring(start,end));\r
+            out.append(re2gap.replaceAll(s[j].getSequence().substring(start,end)));\r
             if (k < 4) {\r
-              out.append(" ");\r
+              // out.append(" ");\r
             } else {\r
               out.append("\n");\r
             }\r
           } else {\r
             if (start < s[j].getSequence().length()) {\r
-              out.append(s[j].getSequence().substring(start));\r
+              out.append(re2gap.replaceAll(s[j].getSequence().substring(start)));\r
               out.append("\n");\r
             } else {\r
               if (k == 0) {\r