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
23 import java.util.Vector;
\r
30 * @version $Revision$
\r
32 public class AppletFormatAdapter
\r
34 /** DOCUMENT ME!! */
\r
35 public static final Vector formats = new Vector();
\r
37 public static String INVALID_CHARACTERS = "Contains invalid characters";
\r
39 public static String SUPPORTED_FORMATS = "Formats currently supported are\n" +
\r
40 "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM";
\r
44 formats.addElement("BLC");
\r
45 formats.addElement("CLUSTAL");
\r
46 formats.addElement("FASTA");
\r
47 formats.addElement("MSF");
\r
48 formats.addElement("PileUp");
\r
49 formats.addElement("PIR");
\r
50 formats.addElement("PFAM");
\r
53 AlignFile afile = null;
\r
58 * @param inFile DOCUMENT ME!
\r
59 * @param type DOCUMENT ME!
\r
60 * @param format DOCUMENT ME!
\r
62 * @return DOCUMENT ME!
\r
64 public SequenceI[] readFile(String inFile, String type, String format)
\r
65 throws java.io.IOException
\r
69 if (format.equals("FASTA"))
\r
71 afile = new FastaFile(inFile, type);
\r
73 else if (format.equals("MSF"))
\r
75 afile = new MSFfile(inFile, type);
\r
77 else if (format.equals("PileUp"))
\r
79 afile = new PileUpfile(inFile, type);
\r
81 else if (format.equals("CLUSTAL"))
\r
83 afile = new ClustalFile(inFile, type);
\r
85 else if (format.equals("BLC"))
\r
87 afile = new BLCFile(inFile, type);
\r
89 else if (format.equals("PIR"))
\r
91 afile = new PIRFile(inFile, type);
\r
93 else if (format.equals("PFAM"))
\r
95 afile = new PfamFile(inFile, type);
\r
98 return afile.getSeqsAsArray();
\r
100 catch (Exception e)
\r
102 System.err.println("Failed to read alignment using the '" + format +
\r
105 if(e.getMessage()!=null && e.getMessage().startsWith(INVALID_CHARACTERS))
\r
106 throw new java.io.IOException(e.getMessage());
\r
108 // Finally test if the user has pasted just the sequence, no id
\r
109 if(type.equalsIgnoreCase("Paste"))
\r
112 // Possible sequence is just residues with no label
\r
113 afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
\r
114 return afile.getSeqsAsArray();
\r
116 catch(Exception ex)
\r
118 if(ex.toString().startsWith(INVALID_CHARACTERS))
\r
119 throw new java.io.IOException(e.getMessage());
\r
121 ex.printStackTrace();
\r
125 // If we get to this stage, the format was not supported
\r
126 throw new java.io.IOException(SUPPORTED_FORMATS);
\r
134 * @param format DOCUMENT ME!
\r
135 * @param seqs DOCUMENT ME!
\r
137 * @return DOCUMENT ME!
\r
139 public String formatSequences(String format,
\r
143 SequenceI[] s = new SequenceI[seqs.size()];
\r
145 for (int i = 0; i < seqs.size(); i++)
\r
146 s[i] = (SequenceI) seqs.elementAt(i);
\r
150 AlignFile afile = null;
\r
152 if (format.equalsIgnoreCase("FASTA"))
\r
154 afile = new FastaFile();
\r
156 else if (format.equalsIgnoreCase("MSF"))
\r
158 afile = new MSFfile();
\r
160 else if (format.equalsIgnoreCase("PileUp"))
\r
162 afile = new PileUpfile();
\r
164 else if (format.equalsIgnoreCase("CLUSTAL"))
\r
166 afile = new ClustalFile();
\r
168 else if (format.equalsIgnoreCase("BLC"))
\r
170 afile = new BLCFile();
\r
172 else if (format.equalsIgnoreCase("PIR"))
\r
174 afile = new PIRFile();
\r
176 else if (format.equalsIgnoreCase("PFAM"))
\r
178 afile = new PfamFile();
\r
181 afile.addJVSuffix(jvsuffix);
\r
185 return afile.print();
\r
187 catch (Exception e)
\r
189 System.err.println("Failed to write alignment as a '" + format +
\r
191 e.printStackTrace();
\r