FileParse object can be re-used to read different files concatenated together
authorjprocter <Jim Procter>
Tue, 29 Jan 2008 10:15:09 +0000 (10:15 +0000)
committerjprocter <Jim Procter>
Tue, 29 Jan 2008 10:15:09 +0000 (10:15 +0000)
14 files changed:
src/MCview/PDBfile.java
src/jalview/io/AlignFile.java
src/jalview/io/BLCFile.java
src/jalview/io/ClustalFile.java
src/jalview/io/FastaFile.java
src/jalview/io/FeaturesFile.java
src/jalview/io/FileParse.java
src/jalview/io/JPredFile.java
src/jalview/io/MSFfile.java
src/jalview/io/NewickFile.java
src/jalview/io/PIRFile.java
src/jalview/io/PfamFile.java
src/jalview/io/PileUpfile.java
src/jalview/io/StockholmFile.java

index 2c7bd9d..e5ad565 100755 (executable)
@@ -24,6 +24,7 @@ import java.util.*;
 import java.awt.*;
 
 import jalview.datamodel.*;
+import jalview.io.FileParse;
 
 public class PDBfile
     extends jalview.io.AlignFile
@@ -41,6 +42,11 @@ public class PDBfile
     super(inFile, inType);
   }
 
+  public PDBfile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+
   public String print()
   {
     return null;
index da09590..2ad32f0 100755 (executable)
@@ -71,7 +71,17 @@ public abstract class AlignFile
 
     parse();
   }
-
+  /**
+   * Attempt to read from the position where some other parsing process left off.
+   * @param source
+   * @throws IOException
+   */
+  public AlignFile(FileParse source) throws IOException
+  {
+    super(source);
+    initData();
+    parse();
+  }
   /**
    * Return the seqs Vector
    */
index c40e125..fa6f8e2 100755 (executable)
@@ -54,6 +54,10 @@ extends AlignFile
   {
     super(inFile, type);
   }
+  public BLCFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
 
   /**
    * DOCUMENT ME!
index 5d7be8c..d62d185 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.io;\r
-\r
-import java.io.*;\r
-import java.util.*;\r
-\r
-import jalview.datamodel.*;\r
-import jalview.util.*;\r
-\r
-public class ClustalFile\r
-    extends AlignFile\r
-{\r
-\r
-  public ClustalFile()\r
-  {\r
-  }\r
-\r
-  public ClustalFile(String inFile, String type)\r
-      throws IOException\r
-  {\r
-    super(inFile, type);\r
-  }\r
-\r
-  public void initData()\r
-  {\r
-    super.initData();\r
-  }\r
-\r
-  public void parse()\r
-      throws IOException\r
-  {\r
-    int i = 0;\r
-    boolean flag = false;\r
-\r
-    Vector headers = new Vector();\r
-    Hashtable seqhash = new Hashtable();\r
-    StringBuffer tempseq;\r
-    String line, id;\r
-    StringTokenizer str;\r
-\r
-    try\r
-    {\r
-      while ( (line = nextLine()) != null)\r
-      {\r
-        if (line.indexOf(" ") != 0)\r
-        {\r
-          str = new StringTokenizer(line, " ");\r
-\r
-          if (str.hasMoreTokens())\r
-          {\r
-            id = str.nextToken();\r
-\r
-            if (id.equalsIgnoreCase("CLUSTAL"))\r
-            {\r
-              flag = true;\r
-            }\r
-            else\r
-            {\r
-              if (flag)\r
-              {\r
-                if (seqhash.containsKey(id))\r
-                {\r
-                  tempseq = (StringBuffer) seqhash.get(id);\r
-                }\r
-                else\r
-                {\r
-                  tempseq = new StringBuffer();\r
-                  seqhash.put(id, tempseq);\r
-                }\r
-\r
-                if (! (headers.contains(id)))\r
-                {\r
-                  headers.addElement(id);\r
-                }\r
-\r
-                if (str.hasMoreTokens())\r
-                {\r
-                  tempseq.append(str.nextToken());\r
-                }\r
-              }\r
-            }\r
-          }\r
-          else\r
-          {\r
-            flag = true;\r
-          }\r
-        }\r
-      }\r
-    }\r
-    catch (IOException e)\r
-    {\r
-      System.err.println("Exception parsing clustal file " + e);\r
-      e.printStackTrace();\r
-    }\r
-\r
-    if (flag)\r
-    {\r
-      this.noSeqs = headers.size();\r
-\r
-      //Add sequences to the hash\r
-      for (i = 0; i < headers.size(); i++)\r
-      {\r
-        if (seqhash.get(headers.elementAt(i)) != null)\r
-        {\r
-          if (maxLength < seqhash.get(headers.elementAt(i)).toString()\r
-              .length())\r
-          {\r
-            maxLength = seqhash.get(headers.elementAt(i)).toString()\r
-                .length();\r
-          }\r
-\r
-          Sequence newSeq = parseId(headers.elementAt(i).toString());\r
-          newSeq.setSequence(seqhash.get(headers.elementAt(i).toString()).\r
-                             toString());\r
-\r
-          seqs.addElement(newSeq);\r
-        }\r
-        else\r
-        {\r
-          System.err.println(\r
-              "Clustal File Reader: Can't find sequence for " +\r
-              headers.elementAt(i));\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-  public String print()\r
-  {\r
-    return print(getSeqsAsArray());\r
-  }\r
-\r
-  public String print(SequenceI[] s)\r
-  {\r
-    StringBuffer out = new StringBuffer("CLUSTAL\n\n");\r
-\r
-    int max = 0;\r
-    int maxid = 0;\r
-\r
-    int i = 0;\r
-\r
-    while ( (i < s.length) && (s[i] != null))\r
-    {\r
-      String tmp = printId(s[i]);\r
-\r
-      if (s[i].getSequence().length > max)\r
-      {\r
-        max = s[i].getSequence().length;\r
-      }\r
-\r
-      if (tmp.length() > maxid)\r
-      {\r
-        maxid = tmp.length();\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    if (maxid < 15)\r
-    {\r
-      maxid = 15;\r
-    }\r
-\r
-    maxid++;\r
-\r
-    int len = 60;\r
-    int nochunks = (max / len) + 1;\r
-\r
-    for (i = 0; i < nochunks; i++)\r
-    {\r
-      int j = 0;\r
-\r
-      while ( (j < s.length) && (s[j] != null))\r
-      {\r
-        out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));\r
-\r
-        int start = i * len;\r
-        int end = start + len;\r
-\r
-        if ( (end < s[j].getSequence().length) &&\r
-            (start < s[j].getSequence().length))\r
-        {\r
-          out.append(s[j].getSequenceAsString(start, end));\r
-        }\r
-        else\r
-        {\r
-          if (start < s[j].getSequence().length)\r
-          {\r
-            out.append(s[j].getSequenceAsString().substring(start));\r
-          }\r
-        }\r
-\r
-        out.append("\n");\r
-        j++;\r
-      }\r
-\r
-      out.append("\n");\r
-    }\r
-\r
-    return out.toString();\r
-  }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package jalview.io;
+
+import java.io.*;
+import java.util.*;
+
+import jalview.datamodel.*;
+import jalview.util.*;
+
+public class ClustalFile
+    extends AlignFile
+{
+
+  public ClustalFile()
+  {
+  }
+
+  public ClustalFile(String inFile, String type)
+      throws IOException
+  {
+    super(inFile, type);
+  }
+  public ClustalFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+  public void initData()
+  {
+    super.initData();
+  }
+
+  public void parse()
+      throws IOException
+  {
+    int i = 0;
+    boolean flag = false;
+
+    Vector headers = new Vector();
+    Hashtable seqhash = new Hashtable();
+    StringBuffer tempseq;
+    String line, id;
+    StringTokenizer str;
+
+    try
+    {
+      while ( (line = nextLine()) != null)
+      {
+        if (line.indexOf(" ") != 0)
+        {
+          str = new StringTokenizer(line, " ");
+
+          if (str.hasMoreTokens())
+          {
+            id = str.nextToken();
+
+            if (id.equalsIgnoreCase("CLUSTAL"))
+            {
+              flag = true;
+            }
+            else
+            {
+              if (flag)
+              {
+                if (seqhash.containsKey(id))
+                {
+                  tempseq = (StringBuffer) seqhash.get(id);
+                }
+                else
+                {
+                  tempseq = new StringBuffer();
+                  seqhash.put(id, tempseq);
+                }
+
+                if (! (headers.contains(id)))
+                {
+                  headers.addElement(id);
+                }
+
+                if (str.hasMoreTokens())
+                {
+                  tempseq.append(str.nextToken());
+                }
+              }
+            }
+          }
+          else
+          {
+            flag = true;
+          }
+        }
+      }
+    }
+    catch (IOException e)
+    {
+      System.err.println("Exception parsing clustal file " + e);
+      e.printStackTrace();
+    }
+
+    if (flag)
+    {
+      this.noSeqs = headers.size();
+
+      //Add sequences to the hash
+      for (i = 0; i < headers.size(); i++)
+      {
+        if (seqhash.get(headers.elementAt(i)) != null)
+        {
+          if (maxLength < seqhash.get(headers.elementAt(i)).toString()
+              .length())
+          {
+            maxLength = seqhash.get(headers.elementAt(i)).toString()
+                .length();
+          }
+
+          Sequence newSeq = parseId(headers.elementAt(i).toString());
+          newSeq.setSequence(seqhash.get(headers.elementAt(i).toString()).
+                             toString());
+
+          seqs.addElement(newSeq);
+        }
+        else
+        {
+          System.err.println(
+              "Clustal File Reader: Can't find sequence for " +
+              headers.elementAt(i));
+        }
+      }
+    }
+  }
+
+  public String print()
+  {
+    return print(getSeqsAsArray());
+  }
+
+  public String print(SequenceI[] s)
+  {
+    StringBuffer out = new StringBuffer("CLUSTAL\n\n");
+
+    int max = 0;
+    int maxid = 0;
+
+    int i = 0;
+
+    while ( (i < s.length) && (s[i] != null))
+    {
+      String tmp = printId(s[i]);
+
+      if (s[i].getSequence().length > max)
+      {
+        max = s[i].getSequence().length;
+      }
+
+      if (tmp.length() > maxid)
+      {
+        maxid = tmp.length();
+      }
+
+      i++;
+    }
+
+    if (maxid < 15)
+    {
+      maxid = 15;
+    }
+
+    maxid++;
+
+    int len = 60;
+    int nochunks = (max / len) + 1;
+
+    for (i = 0; i < nochunks; i++)
+    {
+      int j = 0;
+
+      while ( (j < s.length) && (s[j] != null))
+      {
+        out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));
+
+        int start = i * len;
+        int end = start + len;
+
+        if ( (end < s[j].getSequence().length) &&
+            (start < s[j].getSequence().length))
+        {
+          out.append(s[j].getSequenceAsString(start, end));
+        }
+        else
+        {
+          if (start < s[j].getSequence().length)
+          {
+            out.append(s[j].getSequenceAsString().substring(start));
+          }
+        }
+
+        out.append("\n");
+        j++;
+      }
+
+      out.append("\n");
+    }
+
+    return out.toString();
+  }
+}
index 8de469d..1cb016c 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.io;\r
-\r
-import java.io.*;\r
-\r
-import jalview.datamodel.*;\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class FastaFile\r
-    extends AlignFile\r
-{\r
-  /**\r
-   * Length of a sequence line\r
-   */\r
-  int len = 72;\r
-\r
-  StringBuffer out;\r
-\r
-  /**\r
-   * Creates a new FastaFile object.\r
-   */\r
-  public FastaFile()\r
-  {\r
-  }\r
-\r
-  /**\r
-   * Creates a new FastaFile object.\r
-   *\r
-   * @param inFile DOCUMENT ME!\r
-   * @param type DOCUMENT ME!\r
-   *\r
-   * @throws IOException DOCUMENT ME!\r
-   */\r
-  public FastaFile(String inFile, String type)\r
-      throws IOException\r
-  {\r
-    super(inFile, type);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @throws IOException DOCUMENT ME!\r
-   */\r
-  public void parse()\r
-      throws IOException\r
-  {\r
-    StringBuffer sb = new StringBuffer();\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
-        {\r
-          if (line.startsWith(">#_"))\r
-          {\r
-            if (annotation)\r
-            {\r
-              Annotation[] anots = new Annotation[sb.length()];\r
-              String anotString = sb.toString();\r
-              for (int i = 0; i < sb.length(); i++)\r
-              {\r
-                anots[i] = new Annotation(anotString.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.addElement(aa);\r
-            }\r
-          }\r
-          else\r
-          {\r
-            annotation = false;\r
-          }\r
-\r
-          if (!firstLine)\r
-          {\r
-            seq.setSequence(sb.toString());\r
-\r
-            if (!annotation)\r
-            {\r
-              seqs.addElement(seq);\r
-            }\r
-          }\r
-\r
-          seq = parseId(line.substring(1));\r
-          firstLine = false;\r
-\r
-          sb = new StringBuffer();\r
-\r
-          if (line.startsWith(">#_"))\r
-          {\r
-            annotation = true;\r
-          }\r
-        }\r
-        else\r
-        {\r
-          sb.append(line);\r
-        }\r
-      }\r
-    }\r
-\r
-    if (annotation)\r
-    {\r
-      Annotation[] anots = new Annotation[sb.length()];\r
-      String anotString = sb.toString();\r
-      for (int i = 0; i < sb.length(); i++)\r
-      {\r
-        anots[i] = new Annotation(anotString.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.addElement(aa);\r
-    }\r
-\r
-    else if (!firstLine)\r
-    {\r
-      seq.setSequence(sb.toString());\r
-      seqs.addElement(seq);\r
-    }\r
-  }\r
-\r
-  /**\r
-   * called by AppletFormatAdapter to generate\r
-   * an annotated alignment, rather than bare\r
-   * sequences.\r
-   * @param al\r
-   */\r
-  public void addAnnotations(Alignment al)\r
-  {\r
-    addProperties(al);\r
-    for (int i = 0; i < annotations.size(); i++)\r
-    {\r
-      AlignmentAnnotation aa = (AlignmentAnnotation) annotations.elementAt(i);\r
-      aa.setPadGaps(true, al.getGapCharacter());\r
-      al.addAnnotation( aa );\r
-    }\r
-  }\r
-\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param s DOCUMENT ME!\r
-   * @param len DOCUMENT ME!\r
-   * @param gaps DOCUMENT ME!\r
-   * @param displayId DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public String print(SequenceI[] s)\r
-  {\r
-    out = new StringBuffer();\r
-    int i = 0;\r
-\r
-    while ( (i < s.length) && (s[i] != null))\r
-    {\r
-      out.append(">" + printId(s[i]));\r
-      if (s[i].getDescription() != null)\r
-      {\r
-        out.append(" " + s[i].getDescription());\r
-      }\r
-\r
-      out.append("\n");\r
-\r
-      int nochunks = (s[i].getLength() / len) + 1;\r
-\r
-      for (int j = 0; j < nochunks; j++)\r
-      {\r
-        int start = j * len;\r
-        int end = start + len;\r
-\r
-        if (end < s[i].getLength())\r
-        {\r
-          out.append(s[i].getSequenceAsString(start, end) + "\n");\r
-        }\r
-        else if (start < s[i].getLength())\r
-        {\r
-          out.append(s[i].getSequenceAsString(start, s[i].getLength()) + "\n");\r
-        }\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    return out.toString();\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public String print()\r
-  {\r
-    return print(getSeqsAsArray());\r
-  }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package jalview.io;
+
+import java.io.*;
+
+import jalview.datamodel.*;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class FastaFile
+    extends AlignFile
+{
+  /**
+   * Length of a sequence line
+   */
+  int len = 72;
+
+  StringBuffer out;
+
+  /**
+   * Creates a new FastaFile object.
+   */
+  public FastaFile()
+  {
+  }
+
+  /**
+   * Creates a new FastaFile object.
+   *
+   * @param inFile DOCUMENT ME!
+   * @param type DOCUMENT ME!
+   *
+   * @throws IOException DOCUMENT ME!
+   */
+  public FastaFile(String inFile, String type)
+      throws IOException
+  {
+    super(inFile, type);
+  }
+
+  public FastaFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @throws IOException DOCUMENT ME!
+   */
+  public void parse()
+      throws IOException
+  {
+    StringBuffer sb = new StringBuffer();
+    boolean firstLine = true;
+
+    String line;
+    Sequence seq = null;
+
+    boolean annotation = false;
+
+    while ( (line = nextLine()) != null)
+    {
+      line = line.trim();
+      if (line.length() > 0)
+      {
+        if (line.charAt(0) == '>')
+        {
+          if (line.startsWith(">#_"))
+          {
+            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);
+            }
+          }
+          else
+          {
+            annotation = false;
+          }
+
+          if (!firstLine)
+          {
+            seq.setSequence(sb.toString());
+
+            if (!annotation)
+            {
+              seqs.addElement(seq);
+            }
+          }
+
+          seq = parseId(line.substring(1));
+          firstLine = false;
+
+          sb = new StringBuffer();
+
+          if (line.startsWith(">#_"))
+          {
+            annotation = true;
+          }
+        }
+        else
+        {
+          sb.append(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);
+    }
+
+    else if (!firstLine)
+    {
+      seq.setSequence(sb.toString());
+      seqs.addElement(seq);
+    }
+  }
+
+  /**
+   * called by AppletFormatAdapter to generate
+   * an annotated alignment, rather than bare
+   * sequences.
+   * @param al
+   */
+  public void addAnnotations(Alignment al)
+  {
+    addProperties(al);
+    for (int i = 0; i < annotations.size(); i++)
+    {
+      AlignmentAnnotation aa = (AlignmentAnnotation) annotations.elementAt(i);
+      aa.setPadGaps(true, al.getGapCharacter());
+      al.addAnnotation( aa );
+    }
+  }
+
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param s DOCUMENT ME!
+   * @param len DOCUMENT ME!
+   * @param gaps DOCUMENT ME!
+   * @param displayId DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String print(SequenceI[] s)
+  {
+    out = new StringBuffer();
+    int i = 0;
+
+    while ( (i < s.length) && (s[i] != null))
+    {
+      out.append(">" + printId(s[i]));
+      if (s[i].getDescription() != null)
+      {
+        out.append(" " + s[i].getDescription());
+      }
+
+      out.append("\n");
+
+      int nochunks = (s[i].getLength() / len) + 1;
+
+      for (int j = 0; j < nochunks; j++)
+      {
+        int start = j * len;
+        int end = start + len;
+
+        if (end < s[i].getLength())
+        {
+          out.append(s[i].getSequenceAsString(start, end) + "\n");
+        }
+        else if (start < s[i].getLength())
+        {
+          out.append(s[i].getSequenceAsString(start, s[i].getLength()) + "\n");
+        }
+      }
+
+      i++;
+    }
+
+    return out.toString();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String print()
+  {
+    return print(getSeqsAsArray());
+  }
+}
index 9b39d02..e961683 100755 (executable)
@@ -55,6 +55,10 @@ public class FeaturesFile
   {\r
     super(inFile, type);\r
   }\r
+  public FeaturesFile(FileParse source) throws IOException\r
+  {\r
+    super(source);\r
+  }\r
 \r
   /**\r
    * The Application can render HTML, but the applet will\r
index 8a97e39..4c69ce0 100755 (executable)
@@ -27,6 +27,7 @@ import java.net.*;
 public class FileParse
 {
   public File inFile=null;
+  public int index = 1; // sequence counter for FileParse object created from same data source
   protected char suffixSeparator = '#';
   /**
    * '#' separated string tagged on to end of filename 
@@ -46,6 +47,34 @@ public class FileParse
   {
   }
   /**
+   * Create a new FileParse instance reading from the same datasource starting at the current position.
+   * WARNING! Subsequent reads from either object will affect the read position of the other, but not
+   * the error state.
+   * 
+   * @param from
+   */
+  public FileParse(FileParse from) throws IOException
+  {
+    if (from==null)
+    {
+      throw new Error("Implementation error. Null FileParse in copy constructor");
+    }
+    if (from==this)
+      return;
+    index = ++from.index;
+    inFile = from.inFile;
+    suffixSeparator = from.suffixSeparator;
+    suffix = from.suffix;
+    errormessage = from.errormessage; // inherit potential error messages
+    error = false; // reset any error condition.
+    type = from.type;
+    dataIn = from.dataIn;
+    if (dataIn!=null)
+    {
+      mark();
+    }
+  }
+  /**
    * Attempt to open a file as a datasource.
    * Sets error and errormessage if fileStr was invalid.
    * @param fileStr
@@ -183,6 +212,20 @@ public class FileParse
     error=false;
     dataIn.mark(READAHEAD_LIMIT);
   }
+  /**
+   * mark the current position in the source as start
+   * for the purposes of it being analysed by IdentifyFile().identify
+   * @throws IOException
+   */
+  public void mark() throws IOException
+  {
+    if (dataIn!=null)
+    {
+      dataIn.mark(READAHEAD_LIMIT);
+    } else {
+      throw new IOException("Unitialised Source Stream");
+    }
+  }
   public String nextLine()
       throws IOException
   {
@@ -233,4 +276,15 @@ public class FileParse
   public String getWarningMessage() {
     return warningMessage;
   }
+  public String getInFile()
+  {
+    if (inFile!=null)
+    {
+      return inFile.getAbsolutePath()+" ("+index+")";
+    }
+    else
+    {
+      return "From Paste + ("+index+")";
+    }
+  }
 }
index bd57050..dfe1ecf 100755 (executable)
@@ -63,7 +63,10 @@ public class JPredFile
   {
     super(inFile, type);
   }
-
+  public JPredFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
   /**
    * DOCUMENT ME!
    *
index b9a14ba..e2d3704 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.io;\r
-\r
-import java.io.*;\r
-import java.util.*;\r
-\r
-import jalview.datamodel.*;\r
-import jalview.util.*;\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class MSFfile\r
-    extends AlignFile\r
-{\r
-\r
-  /**\r
-   * Creates a new MSFfile object.\r
-   */\r
-  public MSFfile()\r
-  {\r
-  }\r
-\r
-  /**\r
-   * Creates a new MSFfile object.\r
-   *\r
-   * @param inFile DOCUMENT ME!\r
-   * @param type DOCUMENT ME!\r
-   *\r
-   * @throws IOException DOCUMENT ME!\r
-   */\r
-  public MSFfile(String inFile, String type)\r
-      throws IOException\r
-  {\r
-    super(inFile, type);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   */\r
-  public void parse()\r
-      throws IOException\r
-  {\r
-    int i = 0;\r
-    boolean seqFlag = false;\r
-    String key = new String();\r
-    Vector headers = new Vector();\r
-    Hashtable seqhash = new Hashtable();\r
-    String line;\r
-\r
-    try\r
-    {\r
-      while ( (line = nextLine()) != null)\r
-      {\r
-        StringTokenizer str = new StringTokenizer(line);\r
-\r
-        while (str.hasMoreTokens())\r
-        {\r
-          String inStr = str.nextToken();\r
-\r
-          //If line has header information add to the headers vector\r
-          if (inStr.indexOf("Name:") != -1)\r
-          {\r
-            key = str.nextToken();\r
-            headers.addElement(key);\r
-          }\r
-\r
-          //if line has // set SeqFlag to 1 so we know sequences are coming\r
-          if (inStr.indexOf("//") != -1)\r
-          {\r
-            seqFlag = true;\r
-          }\r
-\r
-          //Process lines as sequence lines if seqFlag is set\r
-          if ( (inStr.indexOf("//") == -1) && (seqFlag == true))\r
-          {\r
-            //seqeunce id is the first field\r
-            key = inStr;\r
-\r
-            StringBuffer tempseq;\r
-\r
-            //Get sequence from hash if it exists\r
-            if (seqhash.containsKey(key))\r
-            {\r
-              tempseq = (StringBuffer) seqhash.get(key);\r
-            }\r
-            else\r
-            {\r
-              tempseq = new StringBuffer();\r
-              seqhash.put(key, tempseq);\r
-            }\r
-\r
-            //loop through the rest of the words\r
-            while (str.hasMoreTokens())\r
-            {\r
-              //append the word to the sequence\r
-              tempseq.append(str.nextToken());\r
-            }\r
-          }\r
-        }\r
-      }\r
-    }\r
-    catch (IOException e)\r
-    {\r
-      System.err.println("Exception parsing MSFFile " + e);\r
-      e.printStackTrace();\r
-    }\r
-\r
-    this.noSeqs = headers.size();\r
-\r
-    //Add sequences to the hash\r
-    for (i = 0; i < headers.size(); i++)\r
-    {\r
-      if (seqhash.get(headers.elementAt(i)) != null)\r
-      {\r
-        String head = headers.elementAt(i).toString();\r
-        String seq = seqhash.get(head).toString();\r
-\r
-        if (maxLength < head.length())\r
-        {\r
-          maxLength = head.length();\r
-        }\r
-\r
-        // Replace ~ with a sensible gap character\r
-        seq = seq.replace('~', '-');\r
-\r
-        Sequence newSeq = parseId(head);\r
-\r
-        newSeq.setSequence(seq);\r
-\r
-        seqs.addElement(newSeq);\r
-      }\r
-      else\r
-      {\r
-        System.err.println("MSFFile Parser: Can't find sequence for " +\r
-                           headers.elementAt(i));\r
-      }\r
-    }\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param seq DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public int checkSum(String seq)\r
-  {\r
-    int check = 0;\r
-    String sequence = seq.toUpperCase();\r
-\r
-    for (int i = 0; i < sequence.length(); i++)\r
-    {\r
-      try\r
-      {\r
-\r
-        int value = sequence.charAt(i);\r
-        if (value != -1)\r
-        {\r
-          check += (i % 57 + 1) * value;\r
-        }\r
-      }\r
-      catch (Exception e)\r
-      {\r
-        System.err.println("Exception during MSF Checksum calculation");\r
-        e.printStackTrace();\r
-      }\r
-    }\r
-\r
-    return check % 10000;\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @param s DOCUMENT ME!\r
-   * @param is_NA DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public String print(SequenceI[] seqs)\r
-  {\r
-\r
-    boolean is_NA = jalview.util.Comparison.isNucleotide(seqs);\r
-\r
-    SequenceI[] s = new SequenceI[seqs.length];\r
-\r
-    StringBuffer out = new StringBuffer("!!" + (is_NA ? "NA" : "AA") +\r
-                                        "_MULTIPLE_ALIGNMENT 1.0\n\n"); // TODO: JBPNote : Jalview doesn't remember NA or AA yet.\r
-\r
-    int max = 0;\r
-    int maxid = 0;\r
-    int i = 0;\r
-\r
-    while ( (i < seqs.length) && (seqs[i] != null))\r
-    {\r
-      // Replace all internal gaps with . and external spaces with ~\r
-      s[i] = new Sequence(seqs[i].getName(),\r
-                          seqs[i].getSequenceAsString().replace('-', '.'));\r
-\r
-      StringBuffer sb = new StringBuffer();\r
-      sb.append(s[i].getSequence());\r
-\r
-      for (int ii = 0; ii < sb.length(); ii++)\r
-      {\r
-        if (sb.charAt(ii) == '.')\r
-        {\r
-          sb.setCharAt(ii, '~');\r
-        }\r
-        else\r
-        {\r
-          break;\r
-        }\r
-      }\r
-\r
-      for (int ii = sb.length() - 1; ii > 0; ii--)\r
-      {\r
-        if (sb.charAt(ii) == '.')\r
-        {\r
-          sb.setCharAt(ii, '~');\r
-        }\r
-        else\r
-        {\r
-          break;\r
-        }\r
-      }\r
-\r
-      s[i].setSequence(sb.toString());\r
-\r
-      if (s[i].getSequence().length > max)\r
-      {\r
-        max = s[i].getSequence().length;\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    Format maxLenpad = new Format("%" + (new String("" + max)).length() +\r
-                                  "d");\r
-    Format maxChkpad = new Format("%" + (new String("1" + max)).length() +\r
-                                  "d");\r
-    i = 0;\r
-\r
-    int bigChecksum = 0;\r
-    int[] checksums = new int[s.length];\r
-    while (i < s.length)\r
-    {\r
-      checksums[i] = checkSum(s[i].getSequenceAsString());\r
-      bigChecksum += checksums[i];\r
-      i++;\r
-    }\r
-\r
-    long maxNB = 0;\r
-    out.append("   MSF: " + s[0].getSequence().length + "   Type: " +\r
-               (is_NA ? "N" : "P") + "    Check:  " + (bigChecksum % 10000) +\r
-               "   ..\n\n\n");\r
-\r
-    String[] nameBlock = new String[s.length];\r
-    String[] idBlock = new String[s.length];\r
-\r
-    i = 0;\r
-    while ( (i < s.length) && (s[i] != null))\r
-    {\r
-\r
-      nameBlock[i] = new String("  Name: " + printId(s[i]) + " ");\r
-\r
-      idBlock[i] = new String("Len: " +\r
-                              maxLenpad.form(s[i].getSequence().length) +\r
-                              "  Check: " +\r
-                              maxChkpad.form(checksums[i]) + "  Weight: 1.00\n");\r
-\r
-      if (s[i].getName().length() > maxid)\r
-      {\r
-        maxid = s[i].getName().length();\r
-      }\r
-\r
-      if (nameBlock[i].length() > maxNB)\r
-      {\r
-        maxNB = nameBlock[i].length();\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    if (maxid < 10)\r
-    {\r
-      maxid = 10;\r
-    }\r
-\r
-    if (maxNB < 15)\r
-    {\r
-      maxNB = 15;\r
-    }\r
-\r
-    Format nbFormat = new Format("%-" + maxNB + "s");\r
-\r
-    for (i = 0; (i < s.length) && (s[i] != null); i++)\r
-    {\r
-      out.append(nbFormat.form(nameBlock[i]) + idBlock[i]);\r
-    }\r
-\r
-    maxid++;\r
-    out.append("\n\n//\n\n");\r
-\r
-    int len = 50;\r
-\r
-    int nochunks = (max / len) + 1;\r
-\r
-    if ( (max % len) == 0)\r
-    {\r
-      nochunks--;\r
-    }\r
-\r
-    for (i = 0; i < nochunks; i++)\r
-    {\r
-      int j = 0;\r
-\r
-      while ( (j < s.length) && (s[j] != null))\r
-      {\r
-        String name = printId(s[j]);\r
-\r
-        out.append(new Format("%-" + maxid + "s").form(name + " "));\r
-\r
-        for (int k = 0; k < 5; k++)\r
-        {\r
-          int start = (i * 50) + (k * 10);\r
-          int end = start + 10;\r
-\r
-          if ( (end < s[j].getSequence().length) &&\r
-              (start < s[j].getSequence().length))\r
-          {\r
-            out.append(s[j].getSequence(start, end));\r
-\r
-            if (k < 4)\r
-            {\r
-              out.append(" ");\r
-            }\r
-            else\r
-            {\r
-              out.append("\n");\r
-            }\r
-          }\r
-          else\r
-          {\r
-            if (start < s[j].getSequence().length)\r
-            {\r
-              out.append(s[j].getSequenceAsString().substring(start));\r
-              out.append("\n");\r
-            }\r
-            else\r
-            {\r
-              if (k == 0)\r
-              {\r
-                out.append("\n");\r
-              }\r
-            }\r
-          }\r
-        }\r
-\r
-        j++;\r
-      }\r
-\r
-      out.append("\n");\r
-    }\r
-\r
-    return out.toString();\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public String print()\r
-  {\r
-    return print(getSeqsAsArray());\r
-  }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package jalview.io;
+
+import java.io.*;
+import java.util.*;
+
+import jalview.datamodel.*;
+import jalview.util.*;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class MSFfile
+    extends AlignFile
+{
+
+  /**
+   * Creates a new MSFfile object.
+   */
+  public MSFfile()
+  {
+  }
+
+  /**
+   * Creates a new MSFfile object.
+   *
+   * @param inFile DOCUMENT ME!
+   * @param type DOCUMENT ME!
+   *
+   * @throws IOException DOCUMENT ME!
+   */
+  public MSFfile(String inFile, String type)
+      throws IOException
+  {
+    super(inFile, type);
+  }
+
+  public MSFfile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+{
+    // TODO Auto-generated constructor stub
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void parse()
+      throws IOException
+  {
+    int i = 0;
+    boolean seqFlag = false;
+    String key = new String();
+    Vector headers = new Vector();
+    Hashtable seqhash = new Hashtable();
+    String line;
+
+    try
+    {
+      while ( (line = nextLine()) != null)
+      {
+        StringTokenizer str = new StringTokenizer(line);
+
+        while (str.hasMoreTokens())
+        {
+          String inStr = str.nextToken();
+
+          //If line has header information add to the headers vector
+          if (inStr.indexOf("Name:") != -1)
+          {
+            key = str.nextToken();
+            headers.addElement(key);
+          }
+
+          //if line has // set SeqFlag to 1 so we know sequences are coming
+          if (inStr.indexOf("//") != -1)
+          {
+            seqFlag = true;
+          }
+
+          //Process lines as sequence lines if seqFlag is set
+          if ( (inStr.indexOf("//") == -1) && (seqFlag == true))
+          {
+            //seqeunce id is the first field
+            key = inStr;
+
+            StringBuffer tempseq;
+
+            //Get sequence from hash if it exists
+            if (seqhash.containsKey(key))
+            {
+              tempseq = (StringBuffer) seqhash.get(key);
+            }
+            else
+            {
+              tempseq = new StringBuffer();
+              seqhash.put(key, tempseq);
+            }
+
+            //loop through the rest of the words
+            while (str.hasMoreTokens())
+            {
+              //append the word to the sequence
+              tempseq.append(str.nextToken());
+            }
+          }
+        }
+      }
+    }
+    catch (IOException e)
+    {
+      System.err.println("Exception parsing MSFFile " + e);
+      e.printStackTrace();
+    }
+
+    this.noSeqs = headers.size();
+
+    //Add sequences to the hash
+    for (i = 0; i < headers.size(); i++)
+    {
+      if (seqhash.get(headers.elementAt(i)) != null)
+      {
+        String head = headers.elementAt(i).toString();
+        String seq = seqhash.get(head).toString();
+
+        if (maxLength < head.length())
+        {
+          maxLength = head.length();
+        }
+
+        // Replace ~ with a sensible gap character
+        seq = seq.replace('~', '-');
+
+        Sequence newSeq = parseId(head);
+
+        newSeq.setSequence(seq);
+
+        seqs.addElement(newSeq);
+      }
+      else
+      {
+        System.err.println("MSFFile Parser: Can't find sequence for " +
+                           headers.elementAt(i));
+      }
+    }
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param seq DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public int checkSum(String seq)
+  {
+    int check = 0;
+    String sequence = seq.toUpperCase();
+
+    for (int i = 0; i < sequence.length(); i++)
+    {
+      try
+      {
+
+        int value = sequence.charAt(i);
+        if (value != -1)
+        {
+          check += (i % 57 + 1) * value;
+        }
+      }
+      catch (Exception e)
+      {
+        System.err.println("Exception during MSF Checksum calculation");
+        e.printStackTrace();
+      }
+    }
+
+    return check % 10000;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param s DOCUMENT ME!
+   * @param is_NA DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String print(SequenceI[] seqs)
+  {
+
+    boolean is_NA = jalview.util.Comparison.isNucleotide(seqs);
+
+    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.
+
+    int max = 0;
+    int maxid = 0;
+    int i = 0;
+
+    while ( (i < seqs.length) && (seqs[i] != null))
+    {
+      // Replace all internal gaps with . and external spaces with ~
+      s[i] = new Sequence(seqs[i].getName(),
+                          seqs[i].getSequenceAsString().replace('-', '.'));
+
+      StringBuffer sb = new StringBuffer();
+      sb.append(s[i].getSequence());
+
+      for (int ii = 0; ii < sb.length(); ii++)
+      {
+        if (sb.charAt(ii) == '.')
+        {
+          sb.setCharAt(ii, '~');
+        }
+        else
+        {
+          break;
+        }
+      }
+
+      for (int ii = sb.length() - 1; ii > 0; ii--)
+      {
+        if (sb.charAt(ii) == '.')
+        {
+          sb.setCharAt(ii, '~');
+        }
+        else
+        {
+          break;
+        }
+      }
+
+      s[i].setSequence(sb.toString());
+
+      if (s[i].getSequence().length > max)
+      {
+        max = s[i].getSequence().length;
+      }
+
+      i++;
+    }
+
+    Format maxLenpad = new Format("%" + (new String("" + max)).length() +
+                                  "d");
+    Format maxChkpad = new Format("%" + (new String("1" + max)).length() +
+                                  "d");
+    i = 0;
+
+    int bigChecksum = 0;
+    int[] checksums = new int[s.length];
+    while (i < s.length)
+    {
+      checksums[i] = checkSum(s[i].getSequenceAsString());
+      bigChecksum += checksums[i];
+      i++;
+    }
+
+    long maxNB = 0;
+    out.append("   MSF: " + s[0].getSequence().length + "   Type: " +
+               (is_NA ? "N" : "P") + "    Check:  " + (bigChecksum % 10000) +
+               "   ..\n\n\n");
+
+    String[] nameBlock = new String[s.length];
+    String[] idBlock = new String[s.length];
+
+    i = 0;
+    while ( (i < s.length) && (s[i] != null))
+    {
+
+      nameBlock[i] = new String("  Name: " + printId(s[i]) + " ");
+
+      idBlock[i] = new String("Len: " +
+                              maxLenpad.form(s[i].getSequence().length) +
+                              "  Check: " +
+                              maxChkpad.form(checksums[i]) + "  Weight: 1.00\n");
+
+      if (s[i].getName().length() > maxid)
+      {
+        maxid = s[i].getName().length();
+      }
+
+      if (nameBlock[i].length() > maxNB)
+      {
+        maxNB = nameBlock[i].length();
+      }
+
+      i++;
+    }
+
+    if (maxid < 10)
+    {
+      maxid = 10;
+    }
+
+    if (maxNB < 15)
+    {
+      maxNB = 15;
+    }
+
+    Format nbFormat = new Format("%-" + maxNB + "s");
+
+    for (i = 0; (i < s.length) && (s[i] != null); i++)
+    {
+      out.append(nbFormat.form(nameBlock[i]) + idBlock[i]);
+    }
+
+    maxid++;
+    out.append("\n\n//\n\n");
+
+    int len = 50;
+
+    int nochunks = (max / len) + 1;
+
+    if ( (max % len) == 0)
+    {
+      nochunks--;
+    }
+
+    for (i = 0; i < nochunks; i++)
+    {
+      int j = 0;
+
+      while ( (j < s.length) && (s[j] != null))
+      {
+        String name = printId(s[j]);
+
+        out.append(new Format("%-" + maxid + "s").form(name + " "));
+
+        for (int k = 0; k < 5; k++)
+        {
+          int start = (i * 50) + (k * 10);
+          int end = start + 10;
+
+          if ( (end < s[j].getSequence().length) &&
+              (start < s[j].getSequence().length))
+          {
+            out.append(s[j].getSequence(start, end));
+
+            if (k < 4)
+            {
+              out.append(" ");
+            }
+            else
+            {
+              out.append("\n");
+            }
+          }
+          else
+          {
+            if (start < s[j].getSequence().length)
+            {
+              out.append(s[j].getSequenceAsString().substring(start));
+              out.append("\n");
+            }
+            else
+            {
+              if (k == 0)
+              {
+                out.append("\n");
+              }
+            }
+          }
+        }
+
+        j++;
+      }
+
+      out.append("\n");
+    }
+
+    return out.toString();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String print()
+  {
+    return print(getSeqsAsArray());
+  }
+}
index aa9a129..74612a6 100755 (executable)
@@ -80,7 +80,10 @@ public class NewickFile
   {
     super(inFile, type);
   }
-
+  public NewickFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
   /**
    * Creates a new NewickFile object.
    *
index 910d189..b18b8f4 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.io;\r
-\r
-import java.io.*;\r
-import java.util.*;\r
-\r
-import jalview.datamodel.*;\r
-\r
-public class PIRFile\r
-    extends AlignFile\r
-{\r
-  public static boolean useModellerOutput = false;\r
-\r
-  Vector words = new Vector(); //Stores the words in a line after splitting\r
-\r
-  public PIRFile()\r
-  {\r
-  }\r
-\r
-  public PIRFile(String inFile, String type)\r
-      throws IOException\r
-  {\r
-    super(inFile, type);\r
-  }\r
-\r
-  public void parse()\r
-      throws IOException\r
-  {\r
-    StringBuffer sequence;\r
-    String line = null;\r
-    ModellerDescription md;\r
-\r
-    while ( (line = nextLine()) != null)\r
-    {\r
-      if (line.length() == 0)\r
-      {\r
-        //System.out.println("blank line");\r
-        continue;\r
-      }\r
-      if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)\r
-      {\r
-        continue;\r
-      }\r
-      Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));\r
-\r
-      sequence = new StringBuffer();\r
-\r
-      newSeq.setDescription(nextLine()); // this is the title line\r
-\r
-      boolean starFound = false;\r
-\r
-      while (!starFound)\r
-      {\r
-        line = nextLine();\r
-        sequence.append(line);\r
-\r
-        if (line == null)\r
-        {\r
-          break;\r
-        }\r
-\r
-        if (line.indexOf("*") > -1)\r
-        {\r
-          starFound = true;\r
-        }\r
-      }\r
-\r
-      if (sequence.length() > 0)\r
-      {\r
-        sequence.setLength(sequence.length() - 1);\r
-        newSeq.setSequence(sequence.toString());\r
-\r
-        seqs.addElement(newSeq);\r
-\r
-        md = new ModellerDescription(newSeq.\r
-                                     getDescription());\r
-        md.updateSequenceI(newSeq);\r
-      }\r
-    }\r
-  }\r
-\r
-  public String print()\r
-  {\r
-    return print(getSeqsAsArray());\r
-  }\r
-\r
-  public String print(SequenceI[] s)\r
-  {\r
-    boolean is_NA = jalview.util.Comparison.isNucleotide(s);\r
-    int len = 72;\r
-    StringBuffer out = new StringBuffer();\r
-    int i = 0;\r
-    ModellerDescription md;\r
-\r
-    while ( (i < s.length) && (s[i] != null))\r
-    {\r
-      String seq = s[i].getSequenceAsString();\r
-      seq = seq + "*";\r
-\r
-      if (is_NA)\r
-      {\r
-        // modeller doesn't really do nucleotides, so we don't do anything fancy\r
-        // Official tags area as follows, for now we'll use P1 and DL\r
-        // Protein (complete) P1\r
-        // Protein (fragment) F1\r
-        // DNA (linear) Dl\r
-        // DNA (circular) DC\r
-        // RNA (linear) RL\r
-        // RNA (circular) RC\r
-        // tRNA N3\r
-        // other functional RNA N1\r
-\r
-        out.append(">N1;" + s[i].getName() + "\n");\r
-        if (s[i].getDescription() == null)\r
-        {\r
-          out.append(s[i].getName() + " " +\r
-                     (s[i].getEnd() - s[i].getStart() + 1));\r
-          out.append(is_NA ? " bases\n" : " residues\n");\r
-        }\r
-        else\r
-        {\r
-          out.append(s[i].getDescription() + "\n");\r
-        }\r
-      }\r
-      else\r
-      {\r
-\r
-        if (useModellerOutput)\r
-        {\r
-          out.append(">P1;" + s[i].getName() + "\n");\r
-          md = new ModellerDescription(s[i]);\r
-          out.append(md.getDescriptionLine() + "\n");\r
-        }\r
-        else\r
-        {\r
-          out.append(">P1;" + printId(s[i]) + "\n");\r
-          if (s[i].getDescription() != null)\r
-          {\r
-            out.append(s[i].getDescription() + "\n");\r
-          }\r
-          else\r
-          {\r
-            out.append(s[i].getName() + " "\r
-                       + (s[i].getEnd() - s[i].getStart() + 1)\r
-                       + " residues\n");\r
-          }\r
-        }\r
-      }\r
-      int nochunks = (seq.length() / len) + 1;\r
-\r
-      for (int j = 0; j < nochunks; j++)\r
-      {\r
-        int start = j * len;\r
-        int end = start + len;\r
-\r
-        if (end < seq.length())\r
-        {\r
-          out.append(seq.substring(start, end) + "\n");\r
-        }\r
-        else if (start < seq.length())\r
-        {\r
-          out.append(seq.substring(start) + "\n");\r
-        }\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    return out.toString();\r
-  }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package jalview.io;
+
+import java.io.*;
+import java.util.*;
+
+import jalview.datamodel.*;
+
+public class PIRFile
+    extends AlignFile
+{
+  public static boolean useModellerOutput = false;
+
+  Vector words = new Vector(); //Stores the words in a line after splitting
+
+  public PIRFile()
+  {
+  }
+
+  public PIRFile(String inFile, String type)
+      throws IOException
+  {
+    super(inFile, type);
+  }
+  public PIRFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+  public void parse()
+      throws IOException
+  {
+    StringBuffer sequence;
+    String line = null;
+    ModellerDescription md;
+
+    while ( (line = nextLine()) != null)
+    {
+      if (line.length() == 0)
+      {
+        //System.out.println("blank line");
+        continue;
+      }
+      if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
+      {
+        continue;
+      }
+      Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
+
+      sequence = new StringBuffer();
+
+      newSeq.setDescription(nextLine()); // this is the title line
+
+      boolean starFound = false;
+
+      while (!starFound)
+      {
+        line = nextLine();
+        sequence.append(line);
+
+        if (line == null)
+        {
+          break;
+        }
+
+        if (line.indexOf("*") > -1)
+        {
+          starFound = true;
+        }
+      }
+
+      if (sequence.length() > 0)
+      {
+        sequence.setLength(sequence.length() - 1);
+        newSeq.setSequence(sequence.toString());
+
+        seqs.addElement(newSeq);
+
+        md = new ModellerDescription(newSeq.
+                                     getDescription());
+        md.updateSequenceI(newSeq);
+      }
+    }
+  }
+
+  public String print()
+  {
+    return print(getSeqsAsArray());
+  }
+
+  public String print(SequenceI[] s)
+  {
+    boolean is_NA = jalview.util.Comparison.isNucleotide(s);
+    int len = 72;
+    StringBuffer out = new StringBuffer();
+    int i = 0;
+    ModellerDescription md;
+
+    while ( (i < s.length) && (s[i] != null))
+    {
+      String seq = s[i].getSequenceAsString();
+      seq = seq + "*";
+
+      if (is_NA)
+      {
+        // modeller doesn't really do nucleotides, so we don't do anything fancy
+        // Official tags area as follows, for now we'll use P1 and DL
+        // Protein (complete) P1
+        // Protein (fragment) F1
+        // DNA (linear) Dl
+        // DNA (circular) DC
+        // RNA (linear) RL
+        // RNA (circular) RC
+        // tRNA N3
+        // other functional RNA N1
+
+        out.append(">N1;" + s[i].getName() + "\n");
+        if (s[i].getDescription() == null)
+        {
+          out.append(s[i].getName() + " " +
+                     (s[i].getEnd() - s[i].getStart() + 1));
+          out.append(is_NA ? " bases\n" : " residues\n");
+        }
+        else
+        {
+          out.append(s[i].getDescription() + "\n");
+        }
+      }
+      else
+      {
+
+        if (useModellerOutput)
+        {
+          out.append(">P1;" + s[i].getName() + "\n");
+          md = new ModellerDescription(s[i]);
+          out.append(md.getDescriptionLine() + "\n");
+        }
+        else
+        {
+          out.append(">P1;" + printId(s[i]) + "\n");
+          if (s[i].getDescription() != null)
+          {
+            out.append(s[i].getDescription() + "\n");
+          }
+          else
+          {
+            out.append(s[i].getName() + " "
+                       + (s[i].getEnd() - s[i].getStart() + 1)
+                       + " residues\n");
+          }
+        }
+      }
+      int nochunks = (seq.length() / len) + 1;
+
+      for (int j = 0; j < nochunks; j++)
+      {
+        int start = j * len;
+        int end = start + len;
+
+        if (end < seq.length())
+        {
+          out.append(seq.substring(start, end) + "\n");
+        }
+        else if (start < seq.length())
+        {
+          out.append(seq.substring(start) + "\n");
+        }
+      }
+
+      i++;
+    }
+
+    return out.toString();
+  }
+
+}
index 4c90bca..2b0bf13 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.io;\r
-\r
-import java.io.*;\r
-import java.util.*;\r
-\r
-import jalview.datamodel.*;\r
-import jalview.util.*;\r
-\r
-public class PfamFile\r
-    extends AlignFile\r
-{\r
-\r
-  public PfamFile()\r
-  {\r
-  }\r
-\r
-  public PfamFile(String inFile, String type)\r
-      throws IOException\r
-  {\r
-    super(inFile, type);\r
-  }\r
-\r
-  public void initData()\r
-  {\r
-    super.initData();\r
-  }\r
-\r
-  public void parse()\r
-      throws IOException\r
-  {\r
-    int i = 0;\r
-    String line;\r
-\r
-    Hashtable seqhash = new Hashtable();\r
-    Vector headers = new Vector();\r
-\r
-    while ( (line = nextLine()) != null)\r
-    {\r
-      if (line.indexOf(" ") != 0)\r
-      {\r
-        if (line.indexOf("#") != 0)\r
-        {\r
-          StringTokenizer str = new StringTokenizer(line, " ");\r
-          String id = "";\r
-\r
-          if (str.hasMoreTokens())\r
-          {\r
-            id = str.nextToken();\r
-\r
-            StringBuffer tempseq;\r
-\r
-            if (seqhash.containsKey(id))\r
-            {\r
-              tempseq = (StringBuffer) seqhash.get(id);\r
-            }\r
-            else\r
-            {\r
-              tempseq = new StringBuffer();\r
-              seqhash.put(id, tempseq);\r
-            }\r
-\r
-            if (! (headers.contains(id)))\r
-            {\r
-              headers.addElement(id);\r
-            }\r
-\r
-            tempseq.append(str.nextToken());\r
-          }\r
-        }\r
-      }\r
-    }\r
-\r
-    this.noSeqs = headers.size();\r
-\r
-    if (noSeqs < 1)\r
-    {\r
-      throw new IOException("No sequences found (PFAM input)");\r
-    }\r
-\r
-    for (i = 0; i < headers.size(); i++)\r
-    {\r
-      if (seqhash.get(headers.elementAt(i)) != null)\r
-      {\r
-        if (maxLength < seqhash.get(headers.elementAt(i)).toString()\r
-            .length())\r
-        {\r
-          maxLength = seqhash.get(headers.elementAt(i)).toString()\r
-              .length();\r
-        }\r
-\r
-        Sequence newSeq = parseId(headers.elementAt(i).toString());\r
-        newSeq.setSequence(seqhash.get(headers.elementAt(i).toString()).\r
-                           toString());\r
-        seqs.addElement(newSeq);\r
-      }\r
-      else\r
-      {\r
-        System.err.println("PFAM File reader: Can't find sequence for " +\r
-                           headers.elementAt(i));\r
-      }\r
-    }\r
-  }\r
-\r
-  public String print(SequenceI[] s)\r
-  {\r
-    StringBuffer out = new StringBuffer("");\r
-\r
-    int max = 0;\r
-    int maxid = 0;\r
-\r
-    int i = 0;\r
-\r
-    while ( (i < s.length) && (s[i] != null))\r
-    {\r
-      String tmp = printId(s[i]);\r
-\r
-      if (s[i].getSequence().length > max)\r
-      {\r
-        max = s[i].getSequence().length;\r
-      }\r
-\r
-      if (tmp.length() > maxid)\r
-      {\r
-        maxid = tmp.length();\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    if (maxid < 15)\r
-    {\r
-      maxid = 15;\r
-    }\r
-\r
-    int j = 0;\r
-\r
-    while ( (j < s.length) && (s[j] != null))\r
-    {\r
-      out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));\r
-\r
-      out.append(s[j].getSequenceAsString() + "\n");\r
-      j++;\r
-    }\r
-\r
-    out.append("\n");\r
-\r
-    return out.toString();\r
-  }\r
-\r
-  public String print()\r
-  {\r
-    return print(getSeqsAsArray());\r
-  }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package jalview.io;
+
+import java.io.*;
+import java.util.*;
+
+import jalview.datamodel.*;
+import jalview.util.*;
+
+public class PfamFile
+    extends AlignFile
+{
+
+  public PfamFile()
+  {
+  }
+
+  public PfamFile(String inFile, String type)
+      throws IOException
+  {
+    super(inFile, type);
+  }
+  public PfamFile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+  public void initData()
+  {
+    super.initData();
+  }
+
+  public void parse()
+      throws IOException
+  {
+    int i = 0;
+    String line;
+
+    Hashtable seqhash = new Hashtable();
+    Vector headers = new Vector();
+
+    while ( (line = nextLine()) != null)
+    {
+      if (line.indexOf(" ") != 0)
+      {
+        if (line.indexOf("#") != 0)
+        {
+          StringTokenizer str = new StringTokenizer(line, " ");
+          String id = "";
+
+          if (str.hasMoreTokens())
+          {
+            id = str.nextToken();
+
+            StringBuffer tempseq;
+
+            if (seqhash.containsKey(id))
+            {
+              tempseq = (StringBuffer) seqhash.get(id);
+            }
+            else
+            {
+              tempseq = new StringBuffer();
+              seqhash.put(id, tempseq);
+            }
+
+            if (! (headers.contains(id)))
+            {
+              headers.addElement(id);
+            }
+
+            tempseq.append(str.nextToken());
+          }
+        }
+      }
+    }
+
+    this.noSeqs = headers.size();
+
+    if (noSeqs < 1)
+    {
+      throw new IOException("No sequences found (PFAM input)");
+    }
+
+    for (i = 0; i < headers.size(); i++)
+    {
+      if (seqhash.get(headers.elementAt(i)) != null)
+      {
+        if (maxLength < seqhash.get(headers.elementAt(i)).toString()
+            .length())
+        {
+          maxLength = seqhash.get(headers.elementAt(i)).toString()
+              .length();
+        }
+
+        Sequence newSeq = parseId(headers.elementAt(i).toString());
+        newSeq.setSequence(seqhash.get(headers.elementAt(i).toString()).
+                           toString());
+        seqs.addElement(newSeq);
+      }
+      else
+      {
+        System.err.println("PFAM File reader: Can't find sequence for " +
+                           headers.elementAt(i));
+      }
+    }
+  }
+
+  public String print(SequenceI[] s)
+  {
+    StringBuffer out = new StringBuffer("");
+
+    int max = 0;
+    int maxid = 0;
+
+    int i = 0;
+
+    while ( (i < s.length) && (s[i] != null))
+    {
+      String tmp = printId(s[i]);
+
+      if (s[i].getSequence().length > max)
+      {
+        max = s[i].getSequence().length;
+      }
+
+      if (tmp.length() > maxid)
+      {
+        maxid = tmp.length();
+      }
+
+      i++;
+    }
+
+    if (maxid < 15)
+    {
+      maxid = 15;
+    }
+
+    int j = 0;
+
+    while ( (j < s.length) && (s[j] != null))
+    {
+      out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));
+
+      out.append(s[j].getSequenceAsString() + "\n");
+      j++;
+    }
+
+    out.append("\n");
+
+    return out.toString();
+  }
+
+  public String print()
+  {
+    return print(getSeqsAsArray());
+  }
+}
index 4715d9c..cd46541 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-package jalview.io;\r
-\r
-/**\r
- * <p>Title: </p>\r
- *  PileUpfile\r
- * <p>Description: </p>\r
- *\r
- *  Read and write PileUp style MSF Files.\r
- *  This used to be the MSFFile class, and was written according to the EBI's idea\r
- *  of a subset of the MSF alignment format. But, that was updated to reflect current\r
- *  GCG style IO fashion, as found in Emboss (thanks David Martin!)\r
- *\r
- **/\r
-import java.io.*;\r
-\r
-import jalview.datamodel.*;\r
-import jalview.util.*;\r
-\r
-public class PileUpfile\r
-    extends MSFfile\r
-{\r
-\r
-  /**\r
-   * Creates a new MSFfile object.\r
-   */\r
-  public PileUpfile()\r
-  {\r
-  }\r
-\r
-  /**\r
-   * Creates a new MSFfile object.\r
-   *\r
-   * @param inFile DOCUMENT ME!\r
-   * @param type DOCUMENT ME!\r
-   *\r
-   * @throws IOException DOCUMENT ME!\r
-   */\r
-  public PileUpfile(String inFile, String type)\r
-      throws IOException\r
-  {\r
-    super(inFile, type);\r
-  }\r
-\r
-  /**\r
-   * DOCUMENT ME!\r
-   *\r
-   * @return DOCUMENT ME!\r
-   */\r
-  public String print()\r
-  {\r
-    return print(getSeqsAsArray());\r
-  }\r
-\r
-  public String print(SequenceI[] s)\r
-  {\r
-    StringBuffer out = new StringBuffer("PileUp\n\n");\r
-\r
-    int max = 0;\r
-    int maxid = 0;\r
-\r
-    int i = 0;\r
-    int bigChecksum = 0;\r
-    int[] checksums = new int[s.length];\r
-    while (i < s.length)\r
-    {\r
-      checksums[i] = checkSum(s[i].getSequenceAsString());\r
-      bigChecksum += checksums[i];\r
-      i++;\r
-    }\r
-\r
-    out.append("   MSF: " + s[0].getSequence().length +\r
-               "   Type: P    Check:  " + bigChecksum % 10000 + "   ..\n\n\n");\r
-\r
-    i = 0;\r
-    while ( (i < s.length) && (s[i] != null))\r
-    {\r
-      String seq = s[i].getSequenceAsString();\r
-      out.append(" Name: " + printId(s[i]) +\r
-                 " oo  Len:  " +\r
-                 seq.length() + "  Check:  " + checksums[i] +\r
-                 "  Weight:  1.00\n");\r
-\r
-      if (seq.length() > max)\r
-      {\r
-        max = seq.length();\r
-      }\r
-\r
-      if (s[i].getName().length() > maxid)\r
-      {\r
-        maxid = s[i].getName().length();\r
-      }\r
-\r
-      i++;\r
-    }\r
-\r
-    if (maxid < 10)\r
-    {\r
-      maxid = 10;\r
-    }\r
-\r
-    maxid++;\r
-    out.append("\n\n//\n\n");\r
-\r
-    int len = 50;\r
-\r
-    int nochunks = (max / len) + 1;\r
-\r
-    if ( (max % len) == 0)\r
-    {\r
-      nochunks--;\r
-    }\r
-\r
-    for (i = 0; i < nochunks; i++)\r
-    {\r
-      int j = 0;\r
-\r
-      while ( (j < s.length) && (s[j] != null))\r
-      {\r
-        String name = printId(s[j]);\r
-\r
-        out.append(new Format("%-" + maxid + "s").form(name + " "));\r
-\r
-        for (int k = 0; k < 5; k++)\r
-        {\r
-          int start = (i * 50) + (k * 10);\r
-          int end = start + 10;\r
-\r
-          if ( (end < s[j].getSequence().length) &&\r
-              (start < s[j].getSequence().length))\r
-          {\r
-            out.append(s[j].getSequence(start, end));\r
-\r
-            if (k < 4)\r
-            {\r
-              out.append(" ");\r
-            }\r
-            else\r
-            {\r
-              out.append("\n");\r
-            }\r
-          }\r
-          else\r
-          {\r
-            if (start < s[j].getSequence().length)\r
-            {\r
-              out.append(s[j].getSequenceAsString().substring(start));\r
-              out.append("\n");\r
-            }\r
-            else\r
-            {\r
-              if (k == 0)\r
-              {\r
-                out.append("\n");\r
-              }\r
-            }\r
-          }\r
-        }\r
-\r
-        j++;\r
-      }\r
-\r
-      out.append("\n");\r
-    }\r
-\r
-    return out.toString();\r
-  }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+package jalview.io;
+
+/**
+ * <p>Title: </p>
+ *  PileUpfile
+ * <p>Description: </p>
+ *
+ *  Read and write PileUp style MSF Files.
+ *  This used to be the MSFFile class, and was written according to the EBI's idea
+ *  of a subset of the MSF alignment format. But, that was updated to reflect current
+ *  GCG style IO fashion, as found in Emboss (thanks David Martin!)
+ *
+ **/
+import java.io.*;
+
+import jalview.datamodel.*;
+import jalview.util.*;
+
+public class PileUpfile
+    extends MSFfile
+{
+
+  /**
+   * Creates a new MSFfile object.
+   */
+  public PileUpfile()
+  {
+  }
+
+  /**
+   * Creates a new MSFfile object.
+   *
+   * @param inFile DOCUMENT ME!
+   * @param type DOCUMENT ME!
+   *
+   * @throws IOException DOCUMENT ME!
+   */
+  public PileUpfile(String inFile, String type)
+      throws IOException
+  {
+    super(inFile, type);
+  }
+  public PileUpfile(FileParse source) throws IOException
+  {
+    super(source);
+  }
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String print()
+  {
+    return print(getSeqsAsArray());
+  }
+
+  public String print(SequenceI[] s)
+  {
+    StringBuffer out = new StringBuffer("PileUp\n\n");
+
+    int max = 0;
+    int maxid = 0;
+
+    int i = 0;
+    int bigChecksum = 0;
+    int[] checksums = new int[s.length];
+    while (i < s.length)
+    {
+      checksums[i] = checkSum(s[i].getSequenceAsString());
+      bigChecksum += checksums[i];
+      i++;
+    }
+
+    out.append("   MSF: " + s[0].getSequence().length +
+               "   Type: P    Check:  " + bigChecksum % 10000 + "   ..\n\n\n");
+
+    i = 0;
+    while ( (i < s.length) && (s[i] != null))
+    {
+      String seq = s[i].getSequenceAsString();
+      out.append(" Name: " + printId(s[i]) +
+                 " oo  Len:  " +
+                 seq.length() + "  Check:  " + checksums[i] +
+                 "  Weight:  1.00\n");
+
+      if (seq.length() > max)
+      {
+        max = seq.length();
+      }
+
+      if (s[i].getName().length() > maxid)
+      {
+        maxid = s[i].getName().length();
+      }
+
+      i++;
+    }
+
+    if (maxid < 10)
+    {
+      maxid = 10;
+    }
+
+    maxid++;
+    out.append("\n\n//\n\n");
+
+    int len = 50;
+
+    int nochunks = (max / len) + 1;
+
+    if ( (max % len) == 0)
+    {
+      nochunks--;
+    }
+
+    for (i = 0; i < nochunks; i++)
+    {
+      int j = 0;
+
+      while ( (j < s.length) && (s[j] != null))
+      {
+        String name = printId(s[j]);
+
+        out.append(new Format("%-" + maxid + "s").form(name + " "));
+
+        for (int k = 0; k < 5; k++)
+        {
+          int start = (i * 50) + (k * 10);
+          int end = start + 10;
+
+          if ( (end < s[j].getSequence().length) &&
+              (start < s[j].getSequence().length))
+          {
+            out.append(s[j].getSequence(start, end));
+
+            if (k < 4)
+            {
+              out.append(" ");
+            }
+            else
+            {
+              out.append("\n");
+            }
+          }
+          else
+          {
+            if (start < s[j].getSequence().length)
+            {
+              out.append(s[j].getSequenceAsString().substring(start));
+              out.append("\n");
+            }
+            else
+            {
+              if (k == 0)
+              {
+                out.append("\n");
+              }
+            }
+          }
+        }
+
+        j++;
+      }
+
+      out.append("\n");
+    }
+
+    return out.toString();
+  }
+}
index 945b8c5..d5f3cc2 100644 (file)
@@ -53,7 +53,10 @@ public class StockholmFile extends AlignFile
   {\r
     super(inFile, type);\r
   }\r
-\r
+  public StockholmFile(FileParse source) throws IOException\r
+  {\r
+    super(source);\r
+  }\r
   public void initData()\r
   {\r
     super.initData();\r
@@ -221,6 +224,7 @@ public class StockholmFile extends AlignFile
           // + ": " + seq);\r
           this.seqs.addElement(seqO);\r
         }\r
+        return; // finished parsing this segment of source\r
       }\r
       else if (!r.search(line))\r
       {\r