JAL-3106 use .jvp as default
[jalview.git] / src / jalview / io / FileFormat.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.io;
22
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.PDBEntry;
25 import jalview.ext.jmol.JmolParser;
26 import jalview.structure.StructureImportSettings;
27
28 import java.io.IOException;
29
30 public enum FileFormat implements FileFormatI
31 {
32   Fasta("Fasta", "fa, fasta, mfa, fastq", true, true)
33   {
34     @Override
35     public AlignmentFileReaderI getReader(FileParse source)
36             throws IOException
37     {
38       return new FastaFile(source);
39     }
40
41     @Override
42     public AlignmentFileWriterI getWriter(AlignmentI al)
43     {
44       return new FastaFile();
45     }
46   },
47   Pfam("PFAM", "pfam", true, true)
48   {
49     @Override
50     public AlignmentFileReaderI getReader(FileParse source)
51             throws IOException
52     {
53       return new PfamFile(source);
54     }
55
56     @Override
57     public AlignmentFileWriterI getWriter(AlignmentI al)
58     {
59       return new PfamFile();
60     }
61   },
62   Stockholm("Stockholm", "sto,stk", true, true)
63   {
64     @Override
65     public AlignmentFileReaderI getReader(FileParse source)
66             throws IOException
67     {
68       return new StockholmFile(source);
69     }
70
71     @Override
72     public AlignmentFileWriterI getWriter(AlignmentI al)
73     {
74       return new StockholmFile(al);
75     }
76
77   },
78
79   PIR("PIR", "pir", true, true)
80   {
81     @Override
82     public AlignmentFileReaderI getReader(FileParse source)
83             throws IOException
84     {
85       return new PIRFile(source);
86     }
87
88     @Override
89     public AlignmentFileWriterI getWriter(AlignmentI al)
90     {
91       return new PIRFile();
92     }
93   },
94   BLC("BLC", "BLC", true, true)
95   {
96     @Override
97     public AlignmentFileReaderI getReader(FileParse source)
98             throws IOException
99     {
100       return new BLCFile(source);
101     }
102
103     @Override
104     public AlignmentFileWriterI getWriter(AlignmentI al)
105     {
106       return new BLCFile();
107     }
108   },
109   AMSA("AMSA", "amsa", true, true)
110   {
111     @Override
112     public AlignmentFileReaderI getReader(FileParse source)
113             throws IOException
114     {
115       return new AMSAFile(source);
116     }
117
118     @Override
119     public AlignmentFileWriterI getWriter(AlignmentI al)
120     {
121       return new AMSAFile(al);
122     }
123   },
124   Html("HTML", "html", true, false)
125   {
126     @Override
127     public AlignmentFileReaderI getReader(FileParse source)
128             throws IOException
129     {
130       return new HtmlFile(source);
131     }
132
133     @Override
134     public AlignmentFileWriterI getWriter(AlignmentI al)
135     {
136       return new HtmlFile();
137     }
138
139     @Override
140     public boolean isComplexAlignFile()
141     {
142       return true;
143     }
144
145   },
146   Rnaml("RNAML", "xml,rnaml", true, false)
147   {
148     @Override
149     public AlignmentFileReaderI getReader(FileParse source)
150             throws IOException
151     {
152       return new RnamlFile(source);
153     }
154
155     @Override
156     public AlignmentFileWriterI getWriter(AlignmentI al)
157     {
158       return new RnamlFile();
159     }
160
161   },
162   Json("JSON", "json", true, true)
163   {
164     @Override
165     public AlignmentFileReaderI getReader(FileParse source)
166             throws IOException
167     {
168       return new JSONFile(source);
169     }
170
171     @Override
172     public AlignmentFileWriterI getWriter(AlignmentI al)
173     {
174       return new JSONFile();
175     }
176
177     @Override
178     public boolean isComplexAlignFile()
179     {
180       return true;
181     }
182
183   },
184   Pileup("PileUp", "pileup", true, true)
185   {
186     @Override
187     public AlignmentFileReaderI getReader(FileParse source)
188             throws IOException
189     {
190       return new PileUpfile(source);
191     }
192
193     @Override
194     public AlignmentFileWriterI getWriter(AlignmentI al)
195     {
196       return new PileUpfile();
197     }
198
199   },
200   MSF("MSF", "msf", true, true)
201   {
202     @Override
203     public AlignmentFileReaderI getReader(FileParse source)
204             throws IOException
205     {
206       return new MSFfile(source);
207     }
208
209     @Override
210     public AlignmentFileWriterI getWriter(AlignmentI al)
211     {
212       return new MSFfile();
213     }
214
215   },
216   Clustal("Clustal", "aln", true, true)
217   {
218     @Override
219     public AlignmentFileReaderI getReader(FileParse source)
220             throws IOException
221     {
222       return new ClustalFile(source);
223     }
224
225     @Override
226     public AlignmentFileWriterI getWriter(AlignmentI al)
227     {
228       return new ClustalFile();
229     }
230   },
231   Phylip("PHYLIP", "phy", true, true)
232   {
233     @Override
234     public AlignmentFileReaderI getReader(FileParse source)
235             throws IOException
236     {
237       return new PhylipFile(source);
238     }
239
240     @Override
241     public AlignmentFileWriterI getWriter(AlignmentI al)
242     {
243       return new PhylipFile();
244     }
245   },
246   Jnet("JnetFile", "", false, false)
247   {
248     @Override
249     public AlignmentFileReaderI getReader(FileParse source)
250             throws IOException
251     {
252       JPredFile af = new JPredFile(source);
253       af.removeNonSequences();
254       return af;
255     }
256
257     @Override
258     public AlignmentFileWriterI getWriter(AlignmentI al)
259     {
260       return null; // todo is this called?
261     }
262
263   },
264   Features("GFF or Jalview features", "gff2,gff3", true, false)
265   {
266     @Override
267     public AlignmentFileReaderI getReader(FileParse source)
268             throws IOException
269     {
270       return new FeaturesFile(source);
271     }
272
273     @Override
274     public AlignmentFileWriterI getWriter(AlignmentI al)
275     {
276       return new FeaturesFile();
277     }
278   },
279   ScoreMatrix("Substitution matrix", "", false, false)
280   {
281     @Override
282     public AlignmentFileReaderI getReader(FileParse source)
283             throws IOException
284     {
285       return new ScoreMatrixFile(source);
286     }
287
288     @Override
289     public AlignmentFileWriterI getWriter(AlignmentI al)
290     {
291       return null;
292     }
293   },
294   PDB("PDB", "pdb,ent", true, false)
295   {
296     @Override
297     public AlignmentFileReaderI getReader(FileParse source)
298             throws IOException
299     {
300       boolean isParseWithJMOL = StructureImportSettings
301               .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
302       if (isParseWithJMOL)
303       {
304         return new JmolParser(source);
305       }
306       else
307       {
308         StructureImportSettings.setShowSeqFeatures(true);
309         return new MCview.PDBfile(
310                 StructureImportSettings.isVisibleChainAnnotation(),
311                 StructureImportSettings.isProcessSecondaryStructure(),
312                 StructureImportSettings.isExternalSecondaryStructure(),
313                 source);
314       }
315     }
316
317     @Override
318     public AlignmentFileWriterI getWriter(AlignmentI al)
319     {
320       return new JmolParser(); // todo or null?
321     }
322
323     @Override
324     public boolean isStructureFile()
325     {
326       return true;
327     }
328   },
329   MMCif("mmCIF", "cif", true, false)
330   {
331     @Override
332     public AlignmentFileReaderI getReader(FileParse source)
333             throws IOException
334     {
335       return new JmolParser(source);
336     }
337
338     @Override
339     public AlignmentFileWriterI getWriter(AlignmentI al)
340     {
341       return new JmolParser(); // todo or null?
342     }
343
344     @Override
345     public boolean isStructureFile()
346     {
347       return true;
348     }
349   },
350   Jalview("Jalview", "jvp, jar", true, true)
351   {
352     @Override
353     public AlignmentFileReaderI getReader(FileParse source)
354             throws IOException
355     {
356       return null;
357     }
358
359     @Override
360     public AlignmentFileWriterI getWriter(AlignmentI al)
361     {
362       return null;
363     }
364
365     @Override
366     public boolean isTextFormat()
367     {
368       return false;
369     }
370
371     @Override
372     public boolean isIdentifiable()
373     {
374       return false;
375     }
376   };
377
378   private boolean writable;
379
380   private boolean readable;
381
382   private String extensions;
383
384   private String name;
385
386   @Override
387   public boolean isComplexAlignFile()
388   {
389     return false;
390   }
391
392   @Override
393   public boolean isReadable()
394   {
395     return readable;
396   }
397
398   @Override
399   public boolean isWritable()
400   {
401     return writable;
402   }
403
404   /**
405    * Constructor
406    * 
407    * @param shortName
408    * @param extensions
409    *          comma-separated list of file extensions associated with the format
410    * @param isReadable
411    * @param isWritable
412    */
413   private FileFormat(String shortName, String extensions,
414           boolean isReadable, boolean isWritable)
415   {
416     this.name = shortName;
417     this.extensions = extensions;
418     this.readable = isReadable;
419     this.writable = isWritable;
420   }
421
422   @Override
423   public String getExtensions()
424   {
425     return extensions;
426   }
427
428   /**
429    * Answers the display name of the file format (as for example shown in menu
430    * options). This name should not be locale (language) dependent.
431    */
432   @Override
433   public String getName()
434   {
435     return name;
436   }
437
438   @Override
439   public boolean isTextFormat()
440   {
441     return true;
442   }
443
444   @Override
445   public boolean isStructureFile()
446   {
447     return false;
448   }
449
450   /**
451    * By default, answers true, indicating the format is one that can be
452    * identified by IdentifyFile. Formats that cannot be identified should
453    * override this method to return false.
454    */
455   public boolean isIdentifiable()
456   {
457     return true;
458   }
459 }