64f33cda30665e59e4cff014c49b619a6c2f5e53
[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 extends AppletFormatAdapter\r
33 {\r
34     /**\r
35      * DOCUMENT ME!\r
36      *\r
37      * @param format DOCUMENT ME!\r
38      * @param seqs DOCUMENT ME!\r
39      *\r
40      * @return DOCUMENT ME!\r
41      */\r
42     public String formatSequences(String format, Vector seqs)\r
43     {\r
44         SequenceI[] s = new SequenceI[seqs.size()];\r
45 \r
46         for (int i = 0; i < seqs.size(); i++)\r
47             s[i] = (SequenceI) seqs.elementAt(i);\r
48 \r
49         try\r
50         {\r
51             AlignFile afile = null;\r
52 \r
53             if (format.equalsIgnoreCase("FASTA"))\r
54             {\r
55                 afile = new FastaFile();\r
56                 afile.addDBPrefix(\r
57                     jalview.bin.Cache.getDefault("FASTA_DBPREFIX", false));\r
58                 afile.addJVSuffix(\r
59                     jalview.bin.Cache.getDefault("FASTA_JVSUFFIX", true));\r
60             }\r
61             else if (format.equalsIgnoreCase("MSF"))\r
62             {\r
63               afile = new MSFfile();\r
64               afile.addDBPrefix(\r
65                   jalview.bin.Cache.getDefault("MSF_DBPREFIX", false));\r
66               afile.addJVSuffix(\r
67                   jalview.bin.Cache.getDefault("MSF_JVSUFFIX", true));\r
68             }\r
69             else if (format.equalsIgnoreCase("PileUp"))\r
70             {\r
71                 afile = new PileUpfile();\r
72                 afile.addDBPrefix(\r
73                     jalview.bin.Cache.getDefault("PILEUP_DBPREFIX", false));\r
74                 afile.addJVSuffix(\r
75                     jalview.bin.Cache.getDefault("PILEUP_JVSUFFIX", true));\r
76             }\r
77             else if (format.equalsIgnoreCase("CLUSTAL"))\r
78             {\r
79                 afile = new ClustalFile();\r
80                 afile.addDBPrefix(\r
81                     jalview.bin.Cache.getDefault("CLUSTAL_DBPREFIX", false));\r
82                 afile.addJVSuffix(\r
83                     jalview.bin.Cache.getDefault("CLUSTAL_JVSUFFIX", true));\r
84             }\r
85             else if (format.equalsIgnoreCase("BLC"))\r
86             {\r
87                 afile = new BLCFile();\r
88                 afile.addDBPrefix(\r
89                     jalview.bin.Cache.getDefault("BLC_DBPREFIX", false));\r
90                 afile.addJVSuffix(\r
91                     jalview.bin.Cache.getDefault("BLC_JVSUFFIX", true));\r
92             }\r
93             else if (format.equalsIgnoreCase("PIR"))\r
94             {\r
95                 afile = new PIRFile();\r
96                 afile.addDBPrefix(\r
97                     jalview.bin.Cache.getDefault("PIR_DBPREFIX", false));\r
98                 afile.addJVSuffix(\r
99                     jalview.bin.Cache.getDefault("PIR_JVSUFFIX", true));\r
100             }\r
101             else if (format.equalsIgnoreCase("PFAM"))\r
102             {\r
103                 afile = new PfamFile();\r
104                 afile.addDBPrefix(\r
105                     jalview.bin.Cache.getDefault("PFAM_DBPREFIX", false));\r
106                 afile.addJVSuffix(\r
107                     jalview.bin.Cache.getDefault("PFAM_JVSUFFIX", true));\r
108             }\r
109 \r
110             afile.setSeqs(s);\r
111 \r
112             return afile.print();\r
113         }\r
114         catch (Exception e)\r
115         {\r
116             System.err.println("Failed to write alignment as a '" + format +\r
117                 "' file\n");\r
118             e.printStackTrace();\r
119         }\r
120 \r
121         return null;\r
122     }\r
123 }\r