OnlyAddPDBEntries
[jalview.git] / src / jalview / io / AppletFormatAdapter.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 AppletFormatAdapter\r
33     {\r
34         /** DOCUMENT ME!! */\r
35         public static final Vector formats = new Vector();\r
36 \r
37         static\r
38         {\r
39             formats.addElement("BLC");\r
40             formats.addElement("CLUSTAL");\r
41             formats.addElement("FASTA");\r
42             formats.addElement("MSF");\r
43             formats.addElement("PileUp");\r
44             formats.addElement("PIR");\r
45             formats.addElement("PFAM");\r
46         }\r
47 \r
48         AlignFile afile = null;\r
49 \r
50         /**\r
51          * DOCUMENT ME!\r
52          *\r
53          * @param inFile DOCUMENT ME!\r
54          * @param type DOCUMENT ME!\r
55          * @param format DOCUMENT ME!\r
56          *\r
57          * @return DOCUMENT ME!\r
58          */\r
59         public SequenceI[] readFile(String inFile, String type, String format)\r
60         {\r
61             try\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         /**\r
106          * DOCUMENT ME!\r
107          *\r
108          * @param format DOCUMENT ME!\r
109          * @param seqs DOCUMENT ME!\r
110          *\r
111          * @return DOCUMENT ME!\r
112          */\r
113         public String formatSequences(String format,\r
114                                       Vector seqs,\r
115                                       boolean dbref,\r
116                                       boolean jvsuffix)\r
117         {\r
118             SequenceI[] s = new SequenceI[seqs.size()];\r
119 \r
120             for (int i = 0; i < seqs.size(); i++)\r
121                 s[i] = (SequenceI) seqs.elementAt(i);\r
122 \r
123             try\r
124             {\r
125                 AlignFile afile = null;\r
126 \r
127                 if (format.equalsIgnoreCase("FASTA"))\r
128                 {\r
129                     afile = new FastaFile();\r
130                 }\r
131                 else if (format.equalsIgnoreCase("MSF"))\r
132                 {\r
133                     afile = new MSFfile();\r
134                 }\r
135                 else if (format.equalsIgnoreCase("PileUp"))\r
136                 {\r
137                     afile = new PileUpfile();\r
138                 }\r
139                 else if (format.equalsIgnoreCase("CLUSTAL"))\r
140                 {\r
141                     afile = new ClustalFile();\r
142                 }\r
143                 else if (format.equalsIgnoreCase("BLC"))\r
144                 {\r
145                     afile = new BLCFile();\r
146                 }\r
147                 else if (format.equalsIgnoreCase("PIR"))\r
148                 {\r
149                     afile = new PIRFile();\r
150                 }\r
151                 else if (format.equalsIgnoreCase("PFAM"))\r
152                 {\r
153                     afile = new PfamFile();\r
154                 }\r
155 \r
156                 afile.addDBPrefix(dbref);\r
157                 afile.addJVSuffix(jvsuffix);\r
158 \r
159                 afile.setSeqs(s);\r
160 \r
161                 return afile.print();\r
162             }\r
163             catch (Exception e)\r
164             {\r
165                 System.err.println("Failed to write alignment as a '" + format +\r
166                     "' file\n");\r
167                 e.printStackTrace();\r
168             }\r
169 \r
170             return null;\r
171         }\r
172     }\r