2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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 import jalview.datamodel.*;
25 import jalview.util.*;
35 public PfamFile(String inFile, String type)
41 public void initData()
46 public void parse() throws IOException
51 Hashtable seqhash = new Hashtable();
52 Vector headers = new Vector();
54 while ( (line = nextLine()) != null)
56 if (line.indexOf(" ") != 0)
58 if (line.indexOf("#") != 0)
60 StringTokenizer str = new StringTokenizer(line, " ");
63 if (str.hasMoreTokens())
69 if (seqhash.containsKey(id))
71 tempseq = (StringBuffer) seqhash.get(id);
75 tempseq = new StringBuffer();
76 seqhash.put(id, tempseq);
79 if (! (headers.contains(id)))
81 headers.addElement(id);
84 tempseq.append(str.nextToken());
90 this.noSeqs = headers.size();
94 throw new IOException("No sequences found (PFAM input)");
97 for (i = 0; i < headers.size(); i++)
99 if (seqhash.get(headers.elementAt(i)) != null)
101 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
104 maxLength = seqhash.get(headers.elementAt(i)).toString()
109 Sequence newSeq = parseId(headers.elementAt(i).toString());
110 newSeq.setSequence( seqhash.get(headers.elementAt(i).toString()).toString());
111 seqs.addElement(newSeq);
113 if (!isValidProteinSequence(newSeq.getSequence()))
115 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS
116 +" : "+ newSeq.getName()
117 +" : "+invalidCharacter);
122 System.err.println("PFAM File reader: Can't find sequence for " +
123 headers.elementAt(i));
128 public String print(SequenceI[] s)
130 StringBuffer out = new StringBuffer("");
137 while ( (i < s.length) && (s[i] != null))
139 String tmp = printId(s[i]);
141 if (s[i].getSequence().length() > max)
143 max = s[i].getSequence().length();
146 if (tmp.length() > maxid)
148 maxid = tmp.length();
161 while ( (j < s.length) && (s[j] != null))
163 out.append(new Format("%-" + maxid + "s").form( printId(s[j])+" "));
165 out.append(s[j].getSequence() + "\n");
171 return out.toString();
174 public String print()
176 return print(getSeqsAsArray());