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
22 import jalview.datamodel.*;
\r
23 import java.util.Vector;
\r
24 public class FormatAdapter
\r
27 public static Vector formats = new Vector();
\r
29 formats.addElement("FASTA");
\r
30 formats.addElement("MSF");
\r
31 formats.addElement("PileUp");
\r
32 formats.addElement("CLUSTAL");
\r
33 formats.addElement("BLC");
\r
34 formats.addElement("PIR");
\r
35 formats.addElement("PFAM");
\r
38 public static SequenceI[] readFile(String inFile, String type, String format)
\r
43 AlignFile afile = null;
\r
44 if (format.equals("FASTA"))
\r
45 afile = new FastaFile(inFile, type);
\r
46 else if (format.equals("MSF"))
\r
47 afile = new MSFfile(inFile, type);
\r
48 else if (format.equals("PileUp"))
\r
49 afile = new PileUpfile(inFile, type);
\r
50 else if (format.equals("CLUSTAL"))
\r
51 afile = new ClustalFile(inFile, type);
\r
52 else if (format.equals("BLC"))
\r
53 afile = new BLCFile(inFile, type);
\r
54 else if (format.equals("PIR"))
\r
55 afile = new PIRFile(inFile, type);
\r
56 else if (format.equals("PFAM"))
\r
57 afile = new PfamFile(inFile, type);
\r
59 return afile.getSeqsAsArray();
\r
61 catch (Exception e) {
\r
62 System.err.println("Failed to read alignment using the '"+format+"' reader.");
\r
63 e.printStackTrace();
\r
70 public static String formatSequences(String format, Vector seqs)
\r
72 SequenceI [] s = new SequenceI[seqs.size()];
\r
74 for (int i = 0; i < seqs.size(); i++)
\r
75 s[i] = (SequenceI) seqs.elementAt(i);
\r
79 AlignFile afile = null;
\r
80 if (format.equals("FASTA"))
\r
81 afile = new FastaFile();
\r
82 else if (format.equals("MSF"))
\r
83 afile = new MSFfile();
\r
84 else if (format.equals("PileUp"))
\r
85 afile = new PileUpfile();
\r
86 else if (format.equals("CLUSTAL"))
\r
87 afile = new ClustalFile();
\r
88 else if (format.equals("BLC"))
\r
89 afile = new BLCFile();
\r
90 else if (format.equals("PIR"))
\r
91 afile = new PIRFile();
\r
92 else if (format.equals("PFAM"))
\r
93 afile = new PfamFile();
\r
96 return afile.print();
\r
98 catch (Exception e) {
\r
99 System.err.println("Failed to write alignment as a '"+format+"' file\n");
\r
100 e.printStackTrace();
\r