updated to jalview 2.1 and begun ArchiveClient/VamsasClient/VamsasStore updates.
[jalview.git] / src / jalview / io / FormatAdapter.java
1 /*
2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 */
19 package jalview.io;
20
21 import jalview.datamodel.*;
22
23
24 /**
25  * DOCUMENT ME!
26  *
27  * @author $author$
28  * @version $Revision$
29  */
30 public class FormatAdapter extends AppletFormatAdapter
31 {
32
33     public String formatSequences(String format,
34                                   SequenceI [] seqs,
35                                   String [] omitHiddenColumns)
36     {
37       if(omitHiddenColumns!=null)
38       {
39         SequenceI [] tmp = new SequenceI[seqs.length];
40         for(int i=0; i<seqs.length; i++)
41           tmp [i] = new Sequence(
42               seqs[i].getName(), omitHiddenColumns[i],
43               seqs[i].getStart(), seqs[i].getEnd());
44
45         seqs = tmp;
46       }
47
48       return formatSequences(format, seqs);
49     }
50
51
52     /**
53      * DOCUMENT ME!
54      *
55      * @param format DOCUMENT ME!
56      * @param seqs DOCUMENT ME!
57      *
58      * @return DOCUMENT ME!
59      */
60     public String formatSequences(String format,
61                                   SequenceI [] seqs)
62     {
63
64         try
65         {
66             AlignFile afile = null;
67
68             if (format.equalsIgnoreCase("FASTA"))
69             {
70                 afile = new FastaFile();
71                 afile.addJVSuffix(
72                     jalview.bin.Cache.getDefault("FASTA_JVSUFFIX", true));
73             }
74             else if (format.equalsIgnoreCase("MSF"))
75             {
76               afile = new MSFfile();
77               afile.addJVSuffix(
78                   jalview.bin.Cache.getDefault("MSF_JVSUFFIX", true));
79             }
80             else if (format.equalsIgnoreCase("PileUp"))
81             {
82                 afile = new PileUpfile();
83                 afile.addJVSuffix(
84                     jalview.bin.Cache.getDefault("PILEUP_JVSUFFIX", true));
85             }
86             else if (format.equalsIgnoreCase("CLUSTAL"))
87             {
88                 afile = new ClustalFile();
89                 afile.addJVSuffix(
90                     jalview.bin.Cache.getDefault("CLUSTAL_JVSUFFIX", true));
91             }
92             else if (format.equalsIgnoreCase("BLC"))
93             {
94                 afile = new BLCFile();
95                 afile.addJVSuffix(
96                     jalview.bin.Cache.getDefault("BLC_JVSUFFIX", true));
97             }
98             else if (format.equalsIgnoreCase("PIR"))
99             {
100                 afile = new PIRFile();
101                 afile.addJVSuffix(
102                     jalview.bin.Cache.getDefault("PIR_JVSUFFIX", true));
103             }
104             else if (format.equalsIgnoreCase("PFAM"))
105             {
106                 afile = new PfamFile();
107                 afile.addJVSuffix(
108                     jalview.bin.Cache.getDefault("PFAM_JVSUFFIX", true));
109             }
110
111             afile.setSeqs(seqs);
112
113             return afile.print();
114         }
115         catch (Exception e)
116         {
117             System.err.println("Failed to write alignment as a '" + format +
118                 "' file\n");
119             e.printStackTrace();
120         }
121
122         return null;
123     }
124 }