2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
29 * Read and write PileUp style MSF Files. This used to be the MSFFile class, and
30 * was written according to the EBI's idea of a subset of the MSF alignment
31 * format. But, that was updated to reflect current GCG style IO fashion, as
32 * found in Emboss (thanks David Martin!)
37 import javax.xml.parsers.ParserConfigurationException;
39 import org.xml.sax.SAXException;
41 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
42 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
43 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
45 import jalview.datamodel.*;
46 import jalview.util.*;
48 public class PileUpfile extends MSFfile
52 * Creates a new MSFfile object.
59 * Creates a new MSFfile object.
68 * @throws SAXException
69 * @throws ParserConfigurationException
70 * @throws ExceptionFileFormatOrSyntax
71 * @throws ExceptionLoadingFailed
72 * @throws ExceptionPermissionDenied
74 public PileUpfile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
79 public PileUpfile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
87 * @return DOCUMENT ME!
91 return print(getSeqsAsArray());
94 public String print(SequenceI[] s)
96 StringBuffer out = new StringBuffer("PileUp");
105 int[] checksums = new int[s.length];
108 checksums[i] = checkSum(s[i].getSequenceAsString());
109 bigChecksum += checksums[i];
113 out.append(" MSF: " + s[0].getSequence().length
114 + " Type: P Check: " + bigChecksum % 10000
121 while ((i < s.length) && (s[i] != null))
123 String seq = s[i].getSequenceAsString();
124 out.append(" Name: " + printId(s[i]) + " oo Len: " + seq.length()
125 + " Check: " + checksums[i] + " Weight: 1.00");
128 if (seq.length() > max)
133 if (s[i].getName().length() > maxid)
135 maxid = s[i].getName().length();
147 out.append(newline);out.append(newline);out.append("//");
148 out.append(newline);out.append(newline);
152 int nochunks = (max / len) + 1;
154 if ((max % len) == 0)
159 for (i = 0; i < nochunks; i++)
163 while ((j < s.length) && (s[j] != null))
165 String name = printId(s[j]);
167 out.append(new Format("%-" + maxid + "s").form(name + " "));
169 for (int k = 0; k < 5; k++)
171 int start = (i * 50) + (k * 10);
172 int end = start + 10;
174 if ((end < s[j].getSequence().length)
175 && (start < s[j].getSequence().length))
177 out.append(s[j].getSequence(start, end));
190 if (start < s[j].getSequence().length)
192 out.append(s[j].getSequenceAsString().substring(start));
211 return out.toString();