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
21 import jalview.datamodel.*;
\r
32 * @version $Revision$
\r
34 public abstract class AlignFile extends FileParse
\r
42 boolean dbPrefix = false;
\r
43 boolean jvSuffix = true;
\r
46 * Creates a new AlignFile object.
\r
53 * Creates a new AlignFile object.
\r
55 * @param inStr DOCUMENT ME!
\r
57 public AlignFile(String inStr)
\r
60 System.out.println("is this ever called??");
\r
66 catch (Exception ex)
\r
72 * Constructor which parses the data from a file of some specified type.
\r
73 * @param inFile Filename to read from.
\r
74 * @param type What type of file to read from (File, URL)
\r
76 public AlignFile(String inFile, String type) throws IOException
\r
78 super(inFile, type);
\r
86 * Return the seqs Vector
\r
88 public Vector getSeqs()
\r
94 * Return the Sequences in the seqs Vector as an array of Sequences
\r
96 public SequenceI[] getSeqsAsArray()
\r
98 SequenceI[] s = new SequenceI[seqs.size()];
\r
100 for (int i = 0; i < seqs.size(); i++)
\r
102 s[i] = (SequenceI) seqs.elementAt(i);
\r
109 * Initialise objects to store sequence data in.
\r
111 protected void initData()
\r
113 seqs = new Vector();
\r
114 headers = new Vector();
\r
120 * @param s DOCUMENT ME!
\r
122 protected void setSeqs(SequenceI[] s)
\r
124 seqs = new Vector();
\r
126 for (int i = 0; i < s.length; i++)
\r
128 seqs.addElement(s[i]);
\r
132 // Checks whether sequence is valid aa characters
\r
133 protected boolean isValidProteinSequence(String sequence)
\r
135 for (int i = 0; i < sequence.length(); i++)
\r
136 if (!jalview.schemes.ResidueProperties.aaHash.containsKey(
\r
137 String.valueOf(sequence.charAt(i))))
\r
146 * This method must be implemented to parse the contents of the file.
\r
148 public abstract void parse() throws IOException;
\r
151 * Print out in alignment file format the Sequences in the seqs Vector.
\r
153 public abstract String print();
\r
155 public void addDBPrefix(boolean b)
\r
160 public void addJVSuffix(boolean b)
\r
166 * A general parser for ids. Will look for dbrefs in
\r
167 * Uniprot format source|id
\r
168 * And also Jalview /start-end
\r
170 * @String id Id to be parsed
\r
172 Sequence parseId(String id)
\r
175 Sequence seq = new Sequence("","");
\r
176 int space = id.indexOf(" ");
\r
179 seq.setDescription(id.substring(space+1));
\r
180 id = id.substring(0, space);
\r
183 // Read in any DB refs first
\r
184 StringTokenizer st;
\r
185 st = new StringTokenizer(id, "|");
\r
187 while (st.countTokens()>1)
\r
189 String a = st.nextToken();
\r
190 String b = st.nextToken();
\r
191 seq.addDBRef( new DBRefEntry( a, "0", b));
\r
194 if(st.hasMoreTokens())
\r
195 id = st.nextToken();
\r
198 // Remove /start-end from sequence
\r
199 if (id.indexOf("/") > 0)
\r
201 st = new StringTokenizer(id, "/");
\r
202 String limits=null;
\r
204 if (st.countTokens() == 2)
\r
206 id = st.nextToken();
\r
208 limits = st.nextToken();
\r
210 st = new StringTokenizer(limits, "-");
\r
212 if (st.countTokens() == 2)
\r
214 seq.setStart(Integer.valueOf(st.nextToken()).intValue());
\r
215 seq.setEnd(Integer.valueOf(st.nextToken()).intValue());
\r
218 }catch(NumberFormatException ex)
\r
220 // Problem parsing sequence limits. Just add it back to the
\r
221 // Id so we dont lose this info
\r
222 id += "/" + limits;
\r
230 * Creates the output id.
\r
231 * Adds prefix Uniprot format source|id
\r
232 * And suffix Jalview /start-end
\r
234 * @String id Id to be parsed
\r
236 String printId(SequenceI seq)
\r
238 StringBuffer result = new StringBuffer();
\r
239 if(dbPrefix && seq.getDBRef()!=null)
\r
241 Vector dbrefs = seq.getDBRef();
\r
242 for(int i=0; i<dbrefs.size(); i++)
\r
244 DBRefEntry entry = (DBRefEntry)dbrefs.elementAt(i);
\r
245 result.append(entry.getSource()+"|"+entry.getAccessionId()+"|");
\r
249 result.append(seq.getName());
\r
253 result.append("/"+seq.getStart()+"-"+seq.getEnd());
\r
256 return result.toString();
\r