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
54 public static String FILE = "File";
\r
55 public static String URL = "URL";
\r
56 public static String PASTE = "Paste";
\r
57 public static String CLASSLOADER = "ClassLoader";
\r
59 AlignFile afile = null;
\r
64 * @param inFile DOCUMENT ME!
\r
65 * @param type DOCUMENT ME!
\r
66 * @param format DOCUMENT ME!
\r
68 * @return DOCUMENT ME!
\r
70 public SequenceI[] readFile(String inFile, String type, String format)
\r
71 throws java.io.IOException
\r
75 if (format.equals("FASTA"))
\r
77 afile = new FastaFile(inFile, type);
\r
79 else if (format.equals("MSF"))
\r
81 afile = new MSFfile(inFile, type);
\r
83 else if (format.equals("PileUp"))
\r
85 afile = new PileUpfile(inFile, type);
\r
87 else if (format.equals("CLUSTAL"))
\r
89 afile = new ClustalFile(inFile, type);
\r
91 else if (format.equals("BLC"))
\r
93 afile = new BLCFile(inFile, type);
\r
95 else if (format.equals("PIR"))
\r
97 afile = new PIRFile(inFile, type);
\r
99 else if (format.equals("PFAM"))
\r
101 afile = new PfamFile(inFile, type);
\r
105 return afile.getSeqsAsArray();
\r
107 catch (Exception e)
\r
109 System.err.println("Failed to read alignment using the '" + format +
\r
112 if(e.getMessage()!=null && e.getMessage().startsWith(INVALID_CHARACTERS))
\r
113 throw new java.io.IOException(e.getMessage());
\r
115 // Finally test if the user has pasted just the sequence, no id
\r
116 if(type.equalsIgnoreCase("Paste"))
\r
119 // Possible sequence is just residues with no label
\r
120 afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
\r
121 return afile.getSeqsAsArray();
\r
123 catch(Exception ex)
\r
125 if(ex.toString().startsWith(INVALID_CHARACTERS))
\r
126 throw new java.io.IOException(e.getMessage());
\r
128 ex.printStackTrace();
\r
132 // If we get to this stage, the format was not supported
\r
133 throw new java.io.IOException(SUPPORTED_FORMATS);
\r
141 * @param format DOCUMENT ME!
\r
142 * @param seqs DOCUMENT ME!
\r
144 * @return DOCUMENT ME!
\r
146 public String formatSequences(String format,
\r
150 SequenceI[] s = new SequenceI[seqs.size()];
\r
152 for (int i = 0; i < seqs.size(); i++)
\r
153 s[i] = (SequenceI) seqs.elementAt(i);
\r
157 AlignFile afile = null;
\r
159 if (format.equalsIgnoreCase("FASTA"))
\r
161 afile = new FastaFile();
\r
163 else if (format.equalsIgnoreCase("MSF"))
\r
165 afile = new MSFfile();
\r
167 else if (format.equalsIgnoreCase("PileUp"))
\r
169 afile = new PileUpfile();
\r
171 else if (format.equalsIgnoreCase("CLUSTAL"))
\r
173 afile = new ClustalFile();
\r
175 else if (format.equalsIgnoreCase("BLC"))
\r
177 afile = new BLCFile();
\r
179 else if (format.equalsIgnoreCase("PIR"))
\r
181 afile = new PIRFile();
\r
183 else if (format.equalsIgnoreCase("PFAM"))
\r
185 afile = new PfamFile();
\r
188 afile.addJVSuffix(jvsuffix);
\r
192 return afile.print();
\r
194 catch (Exception e)
\r
196 System.err.println("Failed to write alignment as a '" + format +
\r
198 e.printStackTrace();
\r