JAL-3560 Java 11 fix on JAL-3563 moving j11lib set up to top
[jalview.git] / unused / 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   BSML("BSML", "bbb", true, false)
33   {
34     @Override
35     public AlignmentFileReaderI getReader(FileParse source)
36             throws IOException
37     {
38       return new BSMLFile(source);
39     }
40
41     @Override
42     public AlignmentFileWriterI getWriter(AlignmentI al)
43     {
44       return null;
45     }
46   },
47   Fasta("Fasta", "fa, fasta, mfa, fastq", true, true)
48   {
49     @Override
50     public AlignmentFileReaderI getReader(FileParse source)
51             throws IOException
52     {
53       return new FastaFile(source);
54     }
55
56     @Override
57     public AlignmentFileWriterI getWriter(AlignmentI al)
58     {
59       return new FastaFile();
60     }
61   },
62   Pfam("PFAM", "pfam", true, true)
63   {
64     @Override
65     public AlignmentFileReaderI getReader(FileParse source)
66             throws IOException
67     {
68       return new PfamFile(source);
69     }
70
71     @Override
72     public AlignmentFileWriterI getWriter(AlignmentI al)
73     {
74       return new PfamFile();
75     }
76   },
77   Stockholm("Stockholm", "sto,stk", true, true)
78   {
79     @Override
80     public AlignmentFileReaderI getReader(FileParse source)
81             throws IOException
82     {
83       return new StockholmFile(source);
84     }
85
86     @Override
87     public AlignmentFileWriterI getWriter(AlignmentI al)
88     {
89       return new StockholmFile(al);
90     }
91
92   },
93
94   PIR("PIR", "pir", true, true)
95   {
96     @Override
97     public AlignmentFileReaderI getReader(FileParse source)
98             throws IOException
99     {
100       return new PIRFile(source);
101     }
102
103     @Override
104     public AlignmentFileWriterI getWriter(AlignmentI al)
105     {
106       return new PIRFile();
107     }
108   },
109   BLC("BLC", "BLC", true, true)
110   {
111     @Override
112     public AlignmentFileReaderI getReader(FileParse source)
113             throws IOException
114     {
115       return new BLCFile(source);
116     }
117
118     @Override
119     public AlignmentFileWriterI getWriter(AlignmentI al)
120     {
121       return new BLCFile();
122     }
123   },
124   AMSA("AMSA", "amsa", true, true)
125   {
126     @Override
127     public AlignmentFileReaderI getReader(FileParse source)
128             throws IOException
129     {
130       return new AMSAFile(source);
131     }
132
133     @Override
134     public AlignmentFileWriterI getWriter(AlignmentI al)
135     {
136       return new AMSAFile(al);
137     }
138   },
139   Html("HTML", "html", true, false)
140   {
141     @Override
142     public AlignmentFileReaderI getReader(FileParse source)
143             throws IOException
144     {
145       return new HtmlFile(source);
146     }
147
148     @Override
149     public AlignmentFileWriterI getWriter(AlignmentI al)
150     {
151       return new HtmlFile();
152     }
153
154     @Override
155     public boolean isComplexAlignFile()
156     {
157       return true;
158     }
159
160   },
161   Rnaml("RNAML", "xml,rnaml", true, false)
162   {
163     @Override
164     public AlignmentFileReaderI getReader(FileParse source)
165             throws IOException
166     {
167       return new RnamlFile(source);
168     }
169
170     @Override
171     public AlignmentFileWriterI getWriter(AlignmentI al)
172     {
173       return new RnamlFile();
174     }
175
176   },
177   Json("JSON", "json", true, true)
178   {
179     @Override
180     public AlignmentFileReaderI getReader(FileParse source)
181             throws IOException
182     {
183       return new JSONFile(source);
184     }
185
186     @Override
187     public AlignmentFileWriterI getWriter(AlignmentI al)
188     {
189       return new JSONFile();
190     }
191
192     @Override
193     public boolean isComplexAlignFile()
194     {
195       return true;
196     }
197
198   },
199   Pileup("PileUp", "pileup", true, true)
200   {
201     @Override
202     public AlignmentFileReaderI getReader(FileParse source)
203             throws IOException
204     {
205       return new PileUpfile(source);
206     }
207
208     @Override
209     public AlignmentFileWriterI getWriter(AlignmentI al)
210     {
211       return new PileUpfile();
212     }
213
214   },
215   MSF("MSF", "msf", true, true)
216   {
217     @Override
218     public AlignmentFileReaderI getReader(FileParse source)
219             throws IOException
220     {
221       return new MSFfile(source);
222     }
223
224     @Override
225     public AlignmentFileWriterI getWriter(AlignmentI al)
226     {
227       return new MSFfile();
228     }
229
230   },
231   Clustal("Clustal", "aln", true, true)
232   {
233     @Override
234     public AlignmentFileReaderI getReader(FileParse source)
235             throws IOException
236     {
237       return new ClustalFile(source);
238     }
239
240     @Override
241     public AlignmentFileWriterI getWriter(AlignmentI al)
242     {
243       return new ClustalFile();
244     }
245   },
246   Phylip("PHYLIP", "phy", true, true)
247   {
248     @Override
249     public AlignmentFileReaderI getReader(FileParse source)
250             throws IOException
251     {
252       return new PhylipFile(source);
253     }
254
255     @Override
256     public AlignmentFileWriterI getWriter(AlignmentI al)
257     {
258       return new PhylipFile();
259     }
260   },
261   Jnet("JnetFile", "", false, false)
262   {
263     @Override
264     public AlignmentFileReaderI getReader(FileParse source)
265             throws IOException
266     {
267       JPredFile af = new JPredFile(source);
268       af.removeNonSequences();
269       return af;
270     }
271
272     @Override
273     public AlignmentFileWriterI getWriter(AlignmentI al)
274     {
275       return null; // todo is this called?
276     }
277
278   },
279   Features("GFF or Jalview features", "gff2,gff3", true, false)
280   {
281     @Override
282     public AlignmentFileReaderI getReader(FileParse source)
283             throws IOException
284     {
285       return new FeaturesFile(source);
286     }
287
288     @Override
289     public AlignmentFileWriterI getWriter(AlignmentI al)
290     {
291       return new FeaturesFile();
292     }
293   },
294   ScoreMatrix("Substitution matrix", "", false, false)
295   {
296     @Override
297     public AlignmentFileReaderI getReader(FileParse source)
298             throws IOException
299     {
300       return new ScoreMatrixFile(source);
301     }
302
303     @Override
304     public AlignmentFileWriterI getWriter(AlignmentI al)
305     {
306       return null;
307     }
308   },
309   PDB("PDB", "pdb,ent", true, false)
310   {
311     @Override
312     public AlignmentFileReaderI getReader(FileParse source)
313             throws IOException
314     {
315       boolean isParseWithJMOL = StructureImportSettings
316               .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
317       if (isParseWithJMOL)
318       {
319         return new JmolParser(source);
320       }
321       else
322       {
323         StructureImportSettings.setShowSeqFeatures(true);
324         return new mc_view.PDBfile(
325                 StructureImportSettings.isVisibleChainAnnotation(),
326                 StructureImportSettings.isProcessSecondaryStructure(),
327                 StructureImportSettings.isExternalSecondaryStructure(),
328                 source);
329       }
330     }
331
332     @Override
333     public AlignmentFileWriterI getWriter(AlignmentI al)
334     {
335       return new JmolParser(); // todo or null?
336     }
337
338     @Override
339     public boolean isStructureFile()
340     {
341       return true;
342     }
343   },
344   MMCif("mmCIF", "cif", true, false)
345   {
346     @Override
347     public AlignmentFileReaderI getReader(FileParse source)
348             throws IOException
349     {
350       return new JmolParser(source);
351     }
352
353     @Override
354     public AlignmentFileWriterI getWriter(AlignmentI al)
355     {
356       return new JmolParser(); // todo or null?
357     }
358
359     @Override
360     public boolean isStructureFile()
361     {
362       return true;
363     }
364   },
365   Jalview("Jalview", "jvp, jar", true, true)
366   {
367     @Override
368     public AlignmentFileReaderI getReader(FileParse source)
369             throws IOException
370     {
371       return null;
372     }
373
374     @Override
375     public AlignmentFileWriterI getWriter(AlignmentI al)
376     {
377       return null;
378     }
379
380     @Override
381     public boolean isTextFormat()
382     {
383       return false;
384     }
385
386     @Override
387     public boolean isIdentifiable()
388     {
389       return true;
390     }
391   };
392
393   private boolean writable;
394
395   private boolean readable;
396
397   private String extensions;
398
399   private String name;
400
401   @Override
402   public boolean isComplexAlignFile()
403   {
404     return false;
405   }
406
407   @Override
408   public boolean isReadable()
409   {
410     return readable;
411   }
412
413   @Override
414   public boolean isWritable()
415   {
416     return writable;
417   }
418
419   /**
420    * Constructor
421    * 
422    * @param shortName
423    * @param extensions
424    *          comma-separated list of file extensions associated with the format
425    * @param isReadable
426    * @param isWritable
427    */
428   private FileFormat(String shortName, String extensions,
429           boolean isReadable, boolean isWritable)
430   {
431     this.name = shortName;
432     this.extensions = extensions;
433     this.readable = isReadable;
434     this.writable = isWritable;
435   }
436
437   @Override
438   public String getExtensions()
439   {
440     return extensions;
441   }
442
443   /**
444    * Answers the display name of the file format (as for example shown in menu
445    * options). This name should not be locale (language) dependent.
446    */
447   @Override
448   public String getName()
449   {
450     return name;
451   }
452
453   @Override
454   public boolean isTextFormat()
455   {
456     return true;
457   }
458
459   @Override
460   public boolean isStructureFile()
461   {
462     return false;
463   }
464
465   /**
466    * By default, answers true, indicating the format is one that can be
467    * identified by IdentifyFile. Formats that cannot be identified should
468    * override this method to return false.
469    */
470   public boolean isIdentifiable()
471   {
472     return true;
473   }
474 }