Formatting changes
[jalview.git] / src / jalview / io / FormatAdapter.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\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
9 *\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
14 *\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
18 */\r
19 package jalview.io;\r
20 \r
21 import jalview.datamodel.*;\r
22 \r
23 import java.util.Vector;\r
24 \r
25 \r
26 /**\r
27  * DOCUMENT ME!\r
28  *\r
29  * @author $author$\r
30  * @version $Revision$\r
31  */\r
32 public class FormatAdapter\r
33 {\r
34     /** DOCUMENT ME!! */\r
35     public static Vector formats = new Vector();\r
36 \r
37     static\r
38     {\r
39         formats.addElement("FASTA");\r
40         formats.addElement("MSF");\r
41         formats.addElement("PileUp");\r
42         formats.addElement("CLUSTAL");\r
43         formats.addElement("BLC");\r
44         formats.addElement("PIR");\r
45         formats.addElement("PFAM");\r
46     }\r
47 \r
48     /**\r
49      * DOCUMENT ME!\r
50      *\r
51      * @param inFile DOCUMENT ME!\r
52      * @param type DOCUMENT ME!\r
53      * @param format DOCUMENT ME!\r
54      *\r
55      * @return DOCUMENT ME!\r
56      */\r
57     public static SequenceI[] readFile(String inFile, String type, String format)\r
58     {\r
59         try\r
60         {\r
61             AlignFile afile = null;\r
62 \r
63             if (format.equals("FASTA"))\r
64             {\r
65                 afile = new FastaFile(inFile, type);\r
66             }\r
67             else if (format.equals("MSF"))\r
68             {\r
69                 afile = new MSFfile(inFile, type);\r
70             }\r
71             else if (format.equals("PileUp"))\r
72             {\r
73                 afile = new PileUpfile(inFile, type);\r
74             }\r
75             else if (format.equals("CLUSTAL"))\r
76             {\r
77                 afile = new ClustalFile(inFile, type);\r
78             }\r
79             else if (format.equals("BLC"))\r
80             {\r
81                 afile = new BLCFile(inFile, type);\r
82             }\r
83             else if (format.equals("PIR"))\r
84             {\r
85                 afile = new PIRFile(inFile, type);\r
86             }\r
87             else if (format.equals("PFAM"))\r
88             {\r
89                 afile = new PfamFile(inFile, type);\r
90             }\r
91 \r
92             return afile.getSeqsAsArray();\r
93         }\r
94         catch (Exception e)\r
95         {\r
96             System.err.println("Failed to read alignment using the '" + format +\r
97                 "' reader.");\r
98             e.printStackTrace();\r
99         }\r
100 \r
101         return null;\r
102     }\r
103 \r
104     /**\r
105      * DOCUMENT ME!\r
106      *\r
107      * @param format DOCUMENT ME!\r
108      * @param seqs DOCUMENT ME!\r
109      *\r
110      * @return DOCUMENT ME!\r
111      */\r
112     public static String formatSequences(String format, Vector seqs)\r
113     {\r
114         SequenceI[] s = new SequenceI[seqs.size()];\r
115 \r
116         for (int i = 0; i < seqs.size(); i++)\r
117             s[i] = (SequenceI) seqs.elementAt(i);\r
118 \r
119         try\r
120         {\r
121             AlignFile afile = null;\r
122 \r
123             if (format.equalsIgnoreCase("FASTA"))\r
124             {\r
125                 afile = new FastaFile();\r
126             }\r
127             else if (format.equalsIgnoreCase("MSF"))\r
128             {\r
129                 afile = new MSFfile();\r
130             }\r
131             else if (format.equalsIgnoreCase("PileUp"))\r
132             {\r
133                 afile = new PileUpfile();\r
134             }\r
135             else if (format.equalsIgnoreCase("CLUSTAL"))\r
136             {\r
137                 afile = new ClustalFile();\r
138             }\r
139             else if (format.equalsIgnoreCase("BLC"))\r
140             {\r
141                 afile = new BLCFile();\r
142             }\r
143             else if (format.equalsIgnoreCase("PIR"))\r
144             {\r
145                 afile = new PIRFile();\r
146             }\r
147             else if (format.equalsIgnoreCase("PFAM"))\r
148             {\r
149                 afile = new PfamFile();\r
150             }\r
151 \r
152             afile.setSeqs(s);\r
153 \r
154             return afile.print();\r
155         }\r
156         catch (Exception e)\r
157         {\r
158             System.err.println("Failed to write alignment as a '" + format +\r
159                 "' file\n");\r
160             e.printStackTrace();\r
161         }\r
162 \r
163         return null;\r
164     }\r
165 }\r