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 import jalview.datamodel.*;
\r
25 import jalview.util.*;
\r
27 public class PfamFile
\r
36 public PfamFile(String inStr)
\r
41 public PfamFile(String inFile, String type)
\r
44 super(inFile, type);
\r
47 public void initData()
\r
59 Hashtable seqhash = new Hashtable();
\r
60 Vector headers = new Vector();
\r
62 while ( (line = nextLine()) != null)
\r
64 if (line.indexOf(" ") != 0)
\r
66 if (line.indexOf("#") != 0)
\r
68 StringTokenizer str = new StringTokenizer(line, " ");
\r
71 if (str.hasMoreTokens())
\r
73 id = str.nextToken();
\r
75 StringBuffer tempseq;
\r
77 if (seqhash.containsKey(id))
\r
79 tempseq = (StringBuffer) seqhash.get(id);
\r
83 tempseq = new StringBuffer();
\r
84 seqhash.put(id, tempseq);
\r
87 if (! (headers.contains(id)))
\r
89 headers.addElement(id);
\r
92 tempseq.append(str.nextToken());
\r
98 this.noSeqs = headers.size();
\r
102 throw new IOException("No sequences found (PFAM input)");
\r
105 for (i = 0; i < headers.size(); i++)
\r
107 if (seqhash.get(headers.elementAt(i)) != null)
\r
109 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
\r
112 maxLength = seqhash.get(headers.elementAt(i)).toString()
\r
116 String head = headers.elementAt(i).toString();
\r
120 if (head.indexOf("/") > 0)
\r
122 StringTokenizer st = new StringTokenizer(head, "/");
\r
124 if (st.countTokens() == 2)
\r
126 ids.addElement(st.nextToken());
\r
128 String tmp = st.nextToken();
\r
129 st = new StringTokenizer(tmp, "-");
\r
131 if (st.countTokens() == 2)
\r
133 start = Integer.valueOf(st.nextToken()).intValue();
\r
134 end = Integer.valueOf(st.nextToken()).intValue();
\r
139 ids.addElement(headers.elementAt(i));
\r
144 ids.addElement(headers.elementAt(i));
\r
147 Sequence newSeq = null;
\r
149 newSeq = new Sequence(ids.elementAt(i).toString(),
\r
150 seqhash.get(headers.elementAt(i).toString())
\r
151 .toString(), start, end);
\r
152 seqs.addElement(newSeq);
\r
155 if (!isValidProteinSequence(newSeq.getSequence()))
\r
157 throw new IOException(
\r
158 "Not a valid protein sequence - (PFAM input)");
\r
163 System.err.println("PFAM File reader: Can't find sequence for " +
\r
164 headers.elementAt(i));
\r
169 public static String print(SequenceI[] s)
\r
171 StringBuffer out = new StringBuffer("");
\r
178 while ( (i < s.length) && (s[i] != null))
\r
180 String tmp = s[i].getName() + "/" + s[i].getStart() + "-" +
\r
183 if (s[i].getSequence().length() > max)
\r
185 max = s[i].getSequence().length();
\r
188 if (tmp.length() > maxid)
\r
190 maxid = tmp.length();
\r
203 while ( (j < s.length) && (s[j] != null))
\r
205 out.append(new Format("%-" + maxid + "s").form(s[j].getName() +
\r
206 "/" + s[j].getStart() + "-" + s[j].getEnd()) + " ");
\r
208 out.append(s[j].getSequence() + "\n");
\r
214 return out.toString();
\r
217 public String print()
\r
219 return print(getSeqsAsArray());
\r