2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
25 import jalview.datamodel.*;
26 import jalview.util.*;
28 public class PfamFile extends AlignFile
35 public PfamFile(String inFile, String type) throws IOException
40 public PfamFile(FileParse source) throws IOException
45 public void initData()
50 public void parse() throws IOException
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 // TODO: verify pfam format requires spaces and not tab characters -
65 // if not upgrade to use stevesoft regex and look for whitespace.
66 StringTokenizer str = new StringTokenizer(line, " ");
69 if (str.hasMoreTokens())
75 if (seqhash.containsKey(id))
77 tempseq = (StringBuffer) seqhash.get(id);
81 tempseq = new StringBuffer();
82 seqhash.put(id, tempseq);
85 if (!(headers.contains(id)))
87 headers.addElement(id);
89 if (str.hasMoreTokens())
91 tempseq.append(str.nextToken());
98 this.noSeqs = headers.size();
102 throw new IOException("No sequences found (PFAM input)");
105 for (i = 0; i < headers.size(); i++)
107 if (seqhash.get(headers.elementAt(i)) != null)
109 if (maxLength < seqhash.get(headers.elementAt(i)).toString()
112 maxLength = seqhash.get(headers.elementAt(i)).toString().length();
115 Sequence newSeq = parseId(headers.elementAt(i).toString());
116 newSeq.setSequence(seqhash.get(headers.elementAt(i).toString())
118 seqs.addElement(newSeq);
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].getSequenceAsString());
172 return out.toString();
175 public String print()
177 return print(getSeqsAsArray());