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
26 public class FormatAdapter {
\r
27 public static Vector formats = new Vector();
\r
30 formats.addElement("FASTA");
\r
31 formats.addElement("MSF");
\r
32 formats.addElement("PileUp");
\r
33 formats.addElement("CLUSTAL");
\r
34 formats.addElement("BLC");
\r
35 formats.addElement("PIR");
\r
36 formats.addElement("PFAM");
\r
39 public static SequenceI[] readFile(String inFile, String type, String format) {
\r
41 AlignFile afile = null;
\r
43 if (format.equals("FASTA")) {
\r
44 afile = new FastaFile(inFile, type);
\r
45 } else if (format.equals("MSF")) {
\r
46 afile = new MSFfile(inFile, type);
\r
47 } else if (format.equals("PileUp")) {
\r
48 afile = new PileUpfile(inFile, type);
\r
49 } else if (format.equals("CLUSTAL")) {
\r
50 afile = new ClustalFile(inFile, type);
\r
51 } else if (format.equals("BLC")) {
\r
52 afile = new BLCFile(inFile, type);
\r
53 } else if (format.equals("PIR")) {
\r
54 afile = new PIRFile(inFile, type);
\r
55 } else if (format.equals("PFAM")) {
\r
56 afile = new PfamFile(inFile, type);
\r
59 return afile.getSeqsAsArray();
\r
60 } catch (Exception e) {
\r
61 System.err.println("Failed to read alignment using the '" + format +
\r
63 e.printStackTrace();
\r
69 public static String formatSequences(String format, Vector seqs) {
\r
70 SequenceI[] s = new SequenceI[seqs.size()];
\r
72 for (int i = 0; i < seqs.size(); i++)
\r
73 s[i] = (SequenceI) seqs.elementAt(i);
\r
76 AlignFile afile = null;
\r
78 if (format.equals("FASTA")) {
\r
79 afile = new FastaFile();
\r
80 } else if (format.equals("MSF")) {
\r
81 afile = new MSFfile();
\r
82 } else if (format.equals("PileUp")) {
\r
83 afile = new PileUpfile();
\r
84 } else if (format.equals("CLUSTAL")) {
\r
85 afile = new ClustalFile();
\r
86 } else if (format.equals("BLC")) {
\r
87 afile = new BLCFile();
\r
88 } else if (format.equals("PIR")) {
\r
89 afile = new PIRFile();
\r
90 } else if (format.equals("PFAM")) {
\r
91 afile = new PfamFile();
\r
96 return afile.print();
\r
97 } catch (Exception e) {
\r
98 System.err.println("Failed to write alignment as a '" + format +
\r
100 e.printStackTrace();
\r