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 import jalview.datamodel.*;
25 import jalview.util.*;
35 public PfamFile(String inFile, String type)
40 public PfamFile(FileParse source) throws IOException
44 public void initData()
55 Hashtable seqhash = new Hashtable();
56 Vector headers = new Vector();
58 while ( (line = nextLine()) != null)
60 if (line.indexOf(" ") != 0)
62 if (line.indexOf("#") != 0)
64 StringTokenizer str = new StringTokenizer(line, " ");
67 if (str.hasMoreTokens())
73 if (seqhash.containsKey(id))
75 tempseq = (StringBuffer) seqhash.get(id);
79 tempseq = new StringBuffer();
80 seqhash.put(id, tempseq);
83 if (! (headers.contains(id)))
85 headers.addElement(id);
88 tempseq.append(str.nextToken());
94 this.noSeqs = headers.size();
98 throw new IOException("No sequences found (PFAM input)");
101 for (i = 0; i < headers.size(); i++)
103 if (seqhash.get(headers.elementAt(i)) != null)
105 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
108 maxLength = seqhash.get(headers.elementAt(i)).toString()
112 Sequence newSeq = parseId(headers.elementAt(i).toString());
113 newSeq.setSequence(seqhash.get(headers.elementAt(i).toString()).
115 seqs.addElement(newSeq);
119 System.err.println("PFAM File reader: Can't find sequence for " +
120 headers.elementAt(i));
125 public String print(SequenceI[] s)
127 StringBuffer out = new StringBuffer("");
134 while ( (i < s.length) && (s[i] != null))
136 String tmp = printId(s[i]);
138 if (s[i].getSequence().length > max)
140 max = s[i].getSequence().length;
143 if (tmp.length() > maxid)
145 maxid = tmp.length();
158 while ( (j < s.length) && (s[j] != null))
160 out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));
162 out.append(s[j].getSequenceAsString() + "\n");
168 return out.toString();
171 public String print()
173 return print(getSeqsAsArray());