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
21 import jalview.datamodel.*;
\r
23 import jalview.util.*;
\r
30 public class PfamFile extends AlignFile {
\r
36 public PfamFile(String inStr) {
\r
40 public PfamFile(String inFile, String type) throws IOException {
\r
41 super(inFile, type);
\r
44 public void initData() {
\r
49 public void parse() throws IOException {
\r
53 Hashtable seqhash = new Hashtable();
\r
54 Vector headers = new Vector();
\r
56 while ((line = nextLine()) != null) {
\r
57 if (line.indexOf(" ") != 0) {
\r
58 if (line.indexOf("#") != 0) {
\r
59 StringTokenizer str = new StringTokenizer(line, " ");
\r
62 if (str.hasMoreTokens()) {
\r
63 id = str.nextToken();
\r
65 StringBuffer tempseq;
\r
67 if (seqhash.containsKey(id)) {
\r
68 tempseq = (StringBuffer) seqhash.get(id);
\r
70 tempseq = new StringBuffer();
\r
71 seqhash.put(id, tempseq);
\r
74 if (!(headers.contains(id))) {
\r
75 headers.addElement(id);
\r
78 tempseq.append(str.nextToken());
\r
84 this.noSeqs = headers.size();
\r
87 throw new IOException("No sequences found (PFAM input)");
\r
90 for (i = 0; i < headers.size(); i++) {
\r
91 if (seqhash.get(headers.elementAt(i)) != null) {
\r
92 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
\r
94 maxLength = seqhash.get(headers.elementAt(i)).toString()
\r
98 String head = headers.elementAt(i).toString();
\r
100 int end = seqhash.get(headers.elementAt(i)).toString().length();
\r
102 if (head.indexOf("/") > 0) {
\r
103 StringTokenizer st = new StringTokenizer(head, "/");
\r
105 if (st.countTokens() == 2) {
\r
106 ids.addElement(st.nextToken());
\r
108 String tmp = st.nextToken();
\r
109 st = new StringTokenizer(tmp, "-");
\r
111 if (st.countTokens() == 2) {
\r
112 start = Integer.valueOf(st.nextToken()).intValue();
\r
113 end = Integer.valueOf(st.nextToken()).intValue();
\r
119 ids.addElement(headers.elementAt(i));
\r
122 ids.addElement(headers.elementAt(i));
\r
125 Sequence newSeq = null;
\r
127 if ((start != -1) && (end != -1)) {
\r
128 newSeq = new Sequence(ids.elementAt(i).toString(),
\r
129 seqhash.get(headers.elementAt(i).toString())
\r
130 .toString(), start, end);
\r
131 seqs.addElement(newSeq);
\r
133 newSeq = new Sequence(ids.elementAt(i).toString(),
\r
134 seqhash.get(headers.elementAt(i).toString())
\r
136 seqhash.get(headers.elementAt(i).toString())
\r
137 .toString().length());
\r
138 seqs.addElement(newSeq);
\r
141 if (!isValidProteinSequence(newSeq.getSequence())) {
\r
142 throw new IOException(
\r
143 "Not a valid protein sequence - (PFAM input)");
\r
146 System.err.println("PFAM File reader: Can't find sequence for " +
\r
147 headers.elementAt(i));
\r
152 public static String print(SequenceI[] s) {
\r
153 StringBuffer out = new StringBuffer("");
\r
160 while ((i < s.length) && (s[i] != null)) {
\r
161 String tmp = s[i].getName() + "/" + s[i].getStart() + "-" +
\r
164 if (s[i].getSequence().length() > max) {
\r
165 max = s[i].getSequence().length();
\r
168 if (tmp.length() > maxid) {
\r
169 maxid = tmp.length();
\r
181 while ((j < s.length) && (s[j] != null)) {
\r
182 out.append(new Format("%-" + maxid + "s").form(s[j].getName() +
\r
183 "/" + s[j].getStart() + "-" + s[j].getEnd()) + " ");
\r
185 out.append(s[j].getSequence() + "\n");
\r
191 return out.toString();
\r
194 public String print() {
\r
195 return print(getSeqsAsArray());
\r