2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 * <p>Description: </p>
26 * Read and write PileUp style MSF Files.
27 * This used to be the MSFFile class, and was written according to the EBI's idea
28 * of a subset of the MSF alignment format. But, that was updated to reflect current
29 * GCG style IO fashion, as found in Emboss (thanks David Martin!)
34 import jalview.datamodel.*;
35 import jalview.util.*;
37 public class PileUpfile
42 * Creates a new MSFfile object.
49 * Creates a new MSFfile object.
51 * @param inFile DOCUMENT ME!
52 * @param type DOCUMENT ME!
54 * @throws IOException DOCUMENT ME!
56 public PileUpfile(String inFile, String type)
61 public PileUpfile(FileParse source) throws IOException
68 * @return DOCUMENT ME!
72 return print(getSeqsAsArray());
75 public String print(SequenceI[] s)
77 StringBuffer out = new StringBuffer("PileUp\n\n");
84 int[] checksums = new int[s.length];
87 checksums[i] = checkSum(s[i].getSequenceAsString());
88 bigChecksum += checksums[i];
92 out.append(" MSF: " + s[0].getSequence().length +
93 " Type: P Check: " + bigChecksum % 10000 + " ..\n\n\n");
96 while ( (i < s.length) && (s[i] != null))
98 String seq = s[i].getSequenceAsString();
99 out.append(" Name: " + printId(s[i]) +
101 seq.length() + " Check: " + checksums[i] +
104 if (seq.length() > max)
109 if (s[i].getName().length() > maxid)
111 maxid = s[i].getName().length();
123 out.append("\n\n//\n\n");
127 int nochunks = (max / len) + 1;
129 if ( (max % len) == 0)
134 for (i = 0; i < nochunks; i++)
138 while ( (j < s.length) && (s[j] != null))
140 String name = printId(s[j]);
142 out.append(new Format("%-" + maxid + "s").form(name + " "));
144 for (int k = 0; k < 5; k++)
146 int start = (i * 50) + (k * 10);
147 int end = start + 10;
149 if ( (end < s[j].getSequence().length) &&
150 (start < s[j].getSequence().length))
152 out.append(s[j].getSequence(start, end));
165 if (start < s[j].getSequence().length)
167 out.append(s[j].getSequenceAsString().substring(start));
186 return out.toString();