2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.
27 import jalview.datamodel.*;
28 import jalview.util.*;
30 public class PfamFile extends AlignFile
37 public PfamFile(String inFile, String type) throws IOException
42 public PfamFile(FileParse source) throws IOException
47 public void initData()
52 public void parse() throws IOException
57 Hashtable seqhash = new Hashtable();
58 Vector headers = new Vector();
60 while ((line = nextLine()) != null)
62 if (line.indexOf(" ") != 0)
64 if (line.indexOf("#") != 0)
66 // TODO: verify pfam format requires spaces and not tab characters -
67 // if not upgrade to use stevesoft regex and look for whitespace.
68 StringTokenizer str = new StringTokenizer(line, " ");
71 if (str.hasMoreTokens())
77 if (seqhash.containsKey(id))
79 tempseq = (StringBuffer) seqhash.get(id);
83 tempseq = new StringBuffer();
84 seqhash.put(id, tempseq);
87 if (!(headers.contains(id)))
89 headers.addElement(id);
91 if (str.hasMoreTokens())
93 tempseq.append(str.nextToken());
100 this.noSeqs = headers.size();
104 throw new IOException("No sequences found (PFAM input)");
107 for (i = 0; i < headers.size(); i++)
109 if (seqhash.get(headers.elementAt(i)) != null)
111 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
114 maxLength = seqhash.get(headers.elementAt(i)).toString().length();
117 Sequence newSeq = parseId(headers.elementAt(i).toString());
118 newSeq.setSequence(seqhash.get(headers.elementAt(i).toString())
120 seqs.addElement(newSeq);
124 System.err.println("PFAM File reader: Can't find sequence for "
125 + headers.elementAt(i));
130 public String print(SequenceI[] s)
132 StringBuffer out = new StringBuffer("");
139 while ((i < s.length) && (s[i] != null))
141 String tmp = printId(s[i]);
143 if (s[i].getSequence().length > max)
145 max = s[i].getSequence().length;
148 if (tmp.length() > maxid)
150 maxid = tmp.length();
163 while ((j < s.length) && (s[j] != null))
165 out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " "));
167 out.append(s[j].getSequenceAsString());
174 return out.toString();
177 public String print()
179 return print(getSeqsAsArray());