GPL license added
[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 \r
20 package jalview.io;\r
21 \r
22 import jalview.datamodel.*;\r
23 import java.util.Vector;\r
24 public class FormatAdapter\r
25 {\r
26 \r
27   public static Vector formats = new Vector();\r
28   static{\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
36   }\r
37 \r
38   public static SequenceI[] readFile(String inFile, String type, String format)\r
39   {\r
40 \r
41     try\r
42     {\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
58 \r
59       return afile.getSeqsAsArray();\r
60     }\r
61     catch (Exception e)  {\r
62     System.err.println("Failed to read alignment using the '"+format+"' reader.");\r
63     e.printStackTrace();\r
64     }\r
65 \r
66     return null;\r
67   }\r
68 \r
69 \r
70   public static String formatSequences(String format, Vector seqs)\r
71   {\r
72     SequenceI [] s = new SequenceI[seqs.size()];\r
73 \r
74     for (int i = 0; i < seqs.size(); i++)\r
75       s[i] = (SequenceI) seqs.elementAt(i);\r
76 \r
77     try\r
78     {\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
94 \r
95       afile.setSeqs(s);\r
96       return afile.print();\r
97     }\r
98     catch (Exception e)  {\r
99       System.err.println("Failed to write alignment as a '"+format+"' file\n");\r
100       e.printStackTrace();\r
101     }\r
102 \r
103     return null;\r
104   }\r
105 }\r