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.
23 import jalview.datamodel.Sequence;
24 import jalview.datamodel.SequenceI;
25 import jalview.util.Format;
26 import jalview.util.MessageManager;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.HashMap;
32 public class PfamFile extends AlignFile
39 public PfamFile(String inFile, DataSourceType sourceType)
42 super(inFile, sourceType);
45 public PfamFile(FileParse source) throws IOException
51 public void initData()
57 public void parse() throws IOException
62 HashMap<String, StringBuffer> seqhash = new HashMap<String, StringBuffer>();
63 ArrayList<String> headers = new ArrayList<String>();
64 boolean useTabs = false;
66 while ((line = nextLine()) != null)
68 if (line.indexOf("#") == 0)
73 // locate first space or (if already checked), tab
76 spces = line.indexOf("\t");
80 spces = line.indexOf(" ");
81 // check to see if we ought to split on tabs instead.
82 if (!useTabs && spces == -1)
85 spces = line.indexOf("\t");
90 // no sequence data to split on
93 String id = line.substring(0, spces);
96 if (seqhash.containsKey(id))
98 tempseq = seqhash.get(id);
102 tempseq = new StringBuffer();
103 seqhash.put(id, tempseq);
106 if (!(headers.contains(id)))
110 if (spces + 1 < line.length())
112 tempseq.append(line.substring(spces + 1).trim());
116 this.noSeqs = headers.size();
120 throw new IOException(MessageManager
121 .getString("exception.pfam_no_sequences_found"));
124 for (i = 0; i < headers.size(); i++)
126 if (seqhash.get(headers.get(i)) != null)
128 if (maxLength < seqhash.get(headers.get(i)).toString().length())
130 maxLength = seqhash.get(headers.get(i)).toString().length();
133 Sequence newSeq = parseId(headers.get(i).toString());
135 seqhash.get(headers.get(i).toString()).toString());
136 seqs.addElement(newSeq);
140 System.err.println("PFAM File reader: Can't find sequence for "
147 public String print(SequenceI[] s, boolean jvsuffix)
149 StringBuffer out = new StringBuffer("");
156 while ((i < s.length) && (s[i] != null))
158 String tmp = printId(s[i], jvsuffix);
160 max = Math.max(max, s[i].getLength());
162 if (tmp.length() > maxid)
164 maxid = tmp.length();
177 while ((j < s.length) && (s[j] != null))
179 out.append(new Format("%-" + maxid + "s")
180 .form(printId(s[j], jvsuffix) + " "));
182 out.append(s[j].getSequenceAsString());
189 return out.toString();