2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
24 * <p>Description: </p>
\r
26 * Read and write PileUp style MSF Files.
\r
27 * This used to be the MSFFile class, and was written according to the EBI's idea
\r
28 * of a subset of the MSF alignment format. But, that was updated to reflect current
\r
29 * GCG style IO fashion, as found in Emboss (thanks David Martin!)
\r
34 import jalview.datamodel.*;
\r
35 import jalview.util.*;
\r
37 public class PileUpfile extends MSFfile
\r
41 * Creates a new MSFfile object.
\r
47 * Creates a new MSFfile object.
\r
49 * @param inStr DOCUMENT ME!
\r
51 public PileUpfile(String inStr)
\r
57 * Creates a new MSFfile object.
\r
59 * @param inFile DOCUMENT ME!
\r
60 * @param type DOCUMENT ME!
\r
62 * @throws IOException DOCUMENT ME!
\r
64 public PileUpfile(String inFile, String type) throws IOException
\r
66 super(inFile, type);
\r
71 * @return DOCUMENT ME!
\r
73 public String print()
\r
75 return print(getSeqsAsArray());
\r
79 public String print(SequenceI[] s)
\r
81 StringBuffer out = new StringBuffer("PileUp\n\n");
\r
87 int bigChecksum = 0;
\r
88 int[] checksums = new int[s.length];
\r
89 while (i < s.length)
\r
91 checksums[i] = checkSum(s[i].getSequence());
\r
92 bigChecksum += checksums[i];
\r
96 out.append(" MSF: " + s[0].getSequence().length() +
\r
97 " Type: P Check: " + bigChecksum%10000 + " ..\n\n\n");
\r
100 while ( (i < s.length) && (s[i] != null))
\r
102 String seq = s[i].getSequence();
\r
103 out.append(" Name: " + printId(s[i]) +
\r
105 s[i].getSequence().length() + " Check: " + checksums[i] +
\r
106 " Weight: 1.00\n");
\r
108 if (seq.length() > max)
\r
110 max = seq.length();
\r
113 if (s[i].getName().length() > maxid)
\r
115 maxid = s[i].getName().length();
\r
127 out.append("\n\n//\n\n");
\r
131 int nochunks = (max / len) + 1;
\r
133 if ( (max % len) == 0)
\r
138 for (i = 0; i < nochunks; i++)
\r
142 while ( (j < s.length) && (s[j] != null))
\r
144 String name = printId(s[j]);
\r
146 out.append(new Format("%-" + maxid + "s").form(name + " "));
\r
148 for (int k = 0; k < 5; k++)
\r
150 int start = (i * 50) + (k * 10);
\r
151 int end = start + 10;
\r
153 if ( (end < s[j].getSequence().length()) &&
\r
154 (start < s[j].getSequence().length()))
\r
156 out.append(s[j].getSequence().substring(start, end));
\r
169 if (start < s[j].getSequence().length())
\r
171 out.append(s[j].getSequence().substring(start));
\r
190 return out.toString();
\r