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