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
35 public PfamFile(String inStr)
\r
40 public PfamFile(String inFile, String type)
\r
43 super(inFile, type);
\r
46 public void initData()
\r
57 Hashtable seqhash = new Hashtable();
\r
58 Vector headers = new Vector();
\r
60 while ( (line = nextLine()) != null)
\r
62 if (line.indexOf(" ") != 0)
\r
64 if (line.indexOf("#") != 0)
\r
66 StringTokenizer str = new StringTokenizer(line, " ");
\r
69 if (str.hasMoreTokens())
\r
71 id = str.nextToken();
\r
73 StringBuffer tempseq;
\r
75 if (seqhash.containsKey(id))
\r
77 tempseq = (StringBuffer) seqhash.get(id);
\r
81 tempseq = new StringBuffer();
\r
82 seqhash.put(id, tempseq);
\r
85 if (! (headers.contains(id)))
\r
87 headers.addElement(id);
\r
90 tempseq.append(str.nextToken());
\r
96 this.noSeqs = headers.size();
\r
100 throw new IOException("No sequences found (PFAM input)");
\r
103 for (i = 0; i < headers.size(); i++)
\r
105 if (seqhash.get(headers.elementAt(i)) != null)
\r
107 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
\r
110 maxLength = seqhash.get(headers.elementAt(i)).toString()
\r
115 Sequence newSeq = parseId(headers.elementAt(i).toString());
\r
116 newSeq.setSequence( seqhash.get(headers.elementAt(i).toString()).toString());
\r
117 seqs.addElement(newSeq);
\r
119 if (!isValidProteinSequence(newSeq.getSequence()))
\r
121 throw new IOException(
\r
122 "Not a valid protein sequence - (PFAM input)");
\r
127 System.err.println("PFAM File reader: Can't find sequence for " +
\r
128 headers.elementAt(i));
\r
133 public String print(SequenceI[] s)
\r
135 StringBuffer out = new StringBuffer("");
\r
142 while ( (i < s.length) && (s[i] != null))
\r
144 String tmp = printId(s[i]);
\r
146 if (s[i].getSequence().length() > max)
\r
148 max = s[i].getSequence().length();
\r
151 if (tmp.length() > maxid)
\r
153 maxid = tmp.length();
\r
166 while ( (j < s.length) && (s[j] != null))
\r
168 out.append(new Format("%-" + maxid + "s").form( printId(s[j])+" "));
\r
170 out.append(s[j].getSequence() + "\n");
\r
176 return out.toString();
\r
179 public String print()
\r
181 return print(getSeqsAsArray());
\r