2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
26 import jalview.datamodel.*;
27 import jalview.util.*;
29 public class PfamFile extends AlignFile
36 public PfamFile(String inFile, String type) throws IOException
41 public PfamFile(FileParse source) throws IOException
46 public void initData()
51 public void parse() throws IOException
56 Hashtable seqhash = new Hashtable();
57 Vector headers = new Vector();
59 while ((line = nextLine()) != null)
61 if (line.indexOf(" ") != 0)
63 if (line.indexOf("#") != 0)
65 // TODO: verify pfam format requires spaces and not tab characters -
66 // if not upgrade to use stevesoft regex and look for whitespace.
67 StringTokenizer str = new StringTokenizer(line, " ");
70 if (str.hasMoreTokens())
76 if (seqhash.containsKey(id))
78 tempseq = (StringBuffer) seqhash.get(id);
82 tempseq = new StringBuffer();
83 seqhash.put(id, tempseq);
86 if (!(headers.contains(id)))
88 headers.addElement(id);
90 if (str.hasMoreTokens())
92 tempseq.append(str.nextToken());
99 this.noSeqs = headers.size();
103 throw new IOException(MessageManager.getString("exception.pfam_no_sequences_found"));
106 for (i = 0; i < headers.size(); i++)
108 if (seqhash.get(headers.elementAt(i)) != null)
110 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
113 maxLength = seqhash.get(headers.elementAt(i)).toString().length();
116 Sequence newSeq = parseId(headers.elementAt(i).toString());
117 newSeq.setSequence(seqhash.get(headers.elementAt(i).toString())
119 seqs.addElement(newSeq);
123 System.err.println("PFAM File reader: Can't find sequence for "
124 + headers.elementAt(i));
129 public String print(SequenceI[] s)
131 StringBuffer out = new StringBuffer("");
138 while ((i < s.length) && (s[i] != null))
140 String tmp = printId(s[i]);
142 if (s[i].getSequence().length > max)
144 max = s[i].getSequence().length;
147 if (tmp.length() > maxid)
149 maxid = tmp.length();
162 while ((j < s.length) && (s[j] != null))
164 out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));
166 out.append(s[j].getSequenceAsString());
173 return out.toString();
176 public String print()
178 return print(getSeqsAsArray());