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
51 formats.addElement("STH");
\r
52 formats.addElement("PDB");
\r
56 public static String FILE = "File";
\r
57 public static String URL = "URL";
\r
58 public static String PASTE = "Paste";
\r
59 public static String CLASSLOADER = "ClassLoader";
\r
62 AlignFile afile = null;
\r
68 * @param inFile DOCUMENT ME!
\r
69 * @param type DOCUMENT ME!
\r
70 * @param format DOCUMENT ME!
\r
72 * @return DOCUMENT ME!
\r
74 public SequenceI[] readFile(String inFile, String type, String format)
\r
75 throws java.io.IOException
\r
77 this.inFile = inFile;
\r
80 if (format.equals("FASTA"))
\r
82 afile = new FastaFile(inFile, type);
\r
84 else if (format.equals("MSF"))
\r
86 afile = new MSFfile(inFile, type);
\r
88 else if (format.equals("PileUp"))
\r
90 afile = new PileUpfile(inFile, type);
\r
92 else if (format.equals("CLUSTAL"))
\r
94 afile = new ClustalFile(inFile, type);
\r
96 else if (format.equals("BLC"))
\r
98 afile = new BLCFile(inFile, type);
\r
100 else if (format.equals("PIR"))
\r
102 afile = new PIRFile(inFile, type);
\r
104 else if (format.equals("PFAM"))
\r
106 afile = new PfamFile(inFile, type);
\r
108 else if (format.equals("JnetFile"))
\r
110 afile = new JPredFile(inFile, type);
\r
111 ( (JPredFile) afile).removeNonSequences();
\r
113 else if (format.equals("PDB"))
\r
115 afile = new MCview.PDBfile(inFile, type);
\r
117 else if (format.equals("STH"))
\r
119 afile = new StockholmFile(inFile, type);
\r
123 return afile.getSeqsAsArray();
\r
125 catch (Exception e)
\r
127 e.printStackTrace();
\r
128 System.err.println("Failed to read alignment using the '" + format +
\r
131 if(e.getMessage()!=null && e.getMessage().startsWith(INVALID_CHARACTERS))
\r
132 throw new java.io.IOException(e.getMessage());
\r
134 // Finally test if the user has pasted just the sequence, no id
\r
135 if(type.equalsIgnoreCase("Paste"))
\r
138 // Possible sequence is just residues with no label
\r
139 afile = new FastaFile(">UNKNOWN\n" + inFile, "Paste");
\r
140 return afile.getSeqsAsArray();
\r
142 catch(Exception ex)
\r
144 if(ex.toString().startsWith(INVALID_CHARACTERS))
\r
145 throw new java.io.IOException(e.getMessage());
\r
147 ex.printStackTrace();
\r
151 // If we get to this stage, the format was not supported
\r
152 throw new java.io.IOException(SUPPORTED_FORMATS);
\r
160 * @param format DOCUMENT ME!
\r
161 * @param seqs DOCUMENT ME!
\r
163 * @return DOCUMENT ME!
\r
165 public String formatSequences(String format,
\r
169 SequenceI[] s = new SequenceI[seqs.size()];
\r
171 for (int i = 0; i < seqs.size(); i++)
\r
172 s[i] = (SequenceI) seqs.elementAt(i);
\r
176 AlignFile afile = null;
\r
178 if (format.equalsIgnoreCase("FASTA"))
\r
180 afile = new FastaFile();
\r
182 else if (format.equalsIgnoreCase("MSF"))
\r
184 afile = new MSFfile();
\r
186 else if (format.equalsIgnoreCase("PileUp"))
\r
188 afile = new PileUpfile();
\r
190 else if (format.equalsIgnoreCase("CLUSTAL"))
\r
192 afile = new ClustalFile();
\r
194 else if (format.equalsIgnoreCase("BLC"))
\r
196 afile = new BLCFile();
\r
198 else if (format.equalsIgnoreCase("PIR"))
\r
200 afile = new PIRFile();
\r
202 else if (format.equalsIgnoreCase("PFAM"))
\r
204 afile = new PfamFile();
\r
206 else if (format.equalsIgnoreCase("STH"))
\r
208 afile = new StockholmFile();
\r
212 afile.addJVSuffix(jvsuffix);
\r
216 return afile.print();
\r
218 catch (Exception e)
\r
220 System.err.println("Failed to write alignment as a '" + format +
\r
222 e.printStackTrace();
\r