last version stay many bugs ..
[jalview.git] / src / jalview / io / MSFfile.java
index 3e8f336..161634c 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
@@ -20,6 +20,15 @@ package jalview.io;
 import java.io.*;
 import java.util.*;
 
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.SAXException;
+
+import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
+import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
+import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
+import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
+
 import jalview.datamodel.*;
 import jalview.util.*;
 
@@ -49,13 +58,20 @@ public class MSFfile extends AlignFile
    * 
    * @throws IOException
    *           DOCUMENT ME!
+ * @throws SAXException 
+ * @throws ParserConfigurationException 
+ * @throws ExceptionFileFormatOrSyntax 
+ * @throws ExceptionLoadingFailed 
+ * @throws ExceptionPermissionDenied 
+ * @throws InterruptedException 
+ * @throws ExceptionUnmatchedClosingParentheses 
    */
-  public MSFfile(String inFile, String type) throws IOException
+  public MSFfile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
   {
     super(inFile, type);
   }
 
-  public MSFfile(FileParse source) throws IOException
+  public MSFfile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
   {
     super(source);
   }
@@ -216,9 +232,10 @@ public class MSFfile extends AlignFile
     SequenceI[] s = new SequenceI[seqs.length];
 
     StringBuffer out = new StringBuffer("!!" + (is_NA ? "NA" : "AA")
-            + "_MULTIPLE_ALIGNMENT 1.0\n\n"); // TODO: JBPNote : Jalview doesn't
-    // remember NA or AA yet.
-
+            + "_MULTIPLE_ALIGNMENT 1.0");
+     // TODO: JBPNote : Jalview doesn't remember NA or AA yet.
+    out.append(newline);
+    out.append(newline);
     int max = 0;
     int maxid = 0;
     int i = 0;
@@ -227,7 +244,7 @@ public class MSFfile extends AlignFile
     {
       // Replace all internal gaps with . and external spaces with ~
       s[i] = new Sequence(seqs[i].getName(), seqs[i].getSequenceAsString()
-              .replace('-', '.'));
+              .replace('-', '.'), seqs[i].getStart(),seqs[i].getEnd());
 
       StringBuffer sb = new StringBuffer();
       sb.append(s[i].getSequence());
@@ -284,7 +301,10 @@ public class MSFfile extends AlignFile
     long maxNB = 0;
     out.append("   MSF: " + s[0].getSequence().length + "   Type: "
             + (is_NA ? "N" : "P") + "    Check:  " + (bigChecksum % 10000)
-            + "   ..\n\n\n");
+            + "   ..");
+    out.append(newline);
+    out.append(newline);
+    out.append(newline);
 
     String[] nameBlock = new String[s.length];
     String[] idBlock = new String[s.length];
@@ -297,7 +317,7 @@ public class MSFfile extends AlignFile
 
       idBlock[i] = new String("Len: "
               + maxLenpad.form(s[i].getSequence().length) + "  Check: "
-              + maxChkpad.form(checksums[i]) + "  Weight: 1.00\n");
+              + maxChkpad.form(checksums[i]) + "  Weight: 1.00"+newline);
 
       if (s[i].getName().length() > maxid)
       {
@@ -330,8 +350,10 @@ public class MSFfile extends AlignFile
     }
 
     maxid++;
-    out.append("\n\n//\n\n");
-
+    out.append(newline);
+    out.append(newline);out.append("//");
+    out.append(newline);
+    out.append(newline);
     int len = 50;
 
     int nochunks = (max / len) + 1;
@@ -367,7 +389,7 @@ public class MSFfile extends AlignFile
             }
             else
             {
-              out.append("\n");
+              out.append(newline);
             }
           }
           else
@@ -375,13 +397,13 @@ public class MSFfile extends AlignFile
             if (start < s[j].getSequence().length)
             {
               out.append(s[j].getSequenceAsString().substring(start));
-              out.append("\n");
+              out.append(newline);
             }
             else
             {
               if (k == 0)
               {
-                out.append("\n");
+                out.append(newline);
               }
             }
           }
@@ -390,7 +412,7 @@ public class MSFfile extends AlignFile
         j++;
       }
 
-      out.append("\n");
+      out.append(newline);
     }
 
     return out.toString();