FileFormat enum new types
[jalview.git] / src / jalview / io / FileFormat.java
1 package jalview.io;
2
3 import jalview.ext.jmol.JmolParser;
4 import jalview.structure.StructureImportSettings;
5
6 import java.io.IOException;
7
8 public enum FileFormat implements FileFormatI
9 {
10   Fasta
11   {
12     @Override
13     public AlignmentFileI getAlignmentFile(String inFile,
14             DataSourceType sourceType) throws IOException
15     {
16       return new FastaFile(inFile, sourceType);
17     }
18
19     @Override
20     public AlignmentFileI getAlignmentFile(FileParse source)
21             throws IOException
22     {
23       return new FastaFile(source);
24     }
25
26     @Override
27     public AlignmentFileI getAlignmentFile()
28     {
29       return new FastaFile();
30     }
31   },
32   Pfam
33   {
34     @Override
35     public AlignmentFileI getAlignmentFile(String inFile,
36             DataSourceType sourceType) throws IOException
37     {
38       return new PfamFile(inFile, sourceType);
39     }
40
41     @Override
42     public AlignmentFileI getAlignmentFile(FileParse source)
43             throws IOException
44     {
45       return new PfamFile(source);
46     }
47
48     @Override
49     public AlignmentFileI getAlignmentFile()
50     {
51       return new PfamFile();
52     }
53   },
54   Stockholm
55   {
56     @Override
57     public AlignmentFileI getAlignmentFile(String inFile,
58             DataSourceType sourceType) throws IOException
59     {
60       return new StockholmFile(inFile, sourceType);
61     }
62     @Override
63     public AlignmentFileI getAlignmentFile(FileParse source)
64             throws IOException
65     {
66       return new StockholmFile(source);
67     }
68
69     @Override
70     public AlignmentFileI getAlignmentFile()
71     {
72       return new StockholmFile();
73     }
74
75   },
76   SimpleBlast
77   {
78     @Override
79     public AlignmentFileI getAlignmentFile(String inFile,
80             DataSourceType sourceType) throws IOException
81     {
82       return new SimpleBlastFile(inFile, sourceType);
83     }
84
85     @Override
86     public AlignmentFileI getAlignmentFile(FileParse source)
87             throws IOException
88     {
89       return new SimpleBlastFile(source);
90     }
91
92     @Override
93     public AlignmentFileI getAlignmentFile()
94     {
95       return new SimpleBlastFile();
96     }
97   },
98
99   PIR
100   {
101     @Override
102     public AlignmentFileI getAlignmentFile(String inFile,
103             DataSourceType sourceType) throws IOException
104     {
105       return new PIRFile(inFile, sourceType);
106     }
107     @Override
108     public AlignmentFileI getAlignmentFile(FileParse source)
109             throws IOException
110     {
111       return new PIRFile(source);
112     }
113
114     @Override
115     public AlignmentFileI getAlignmentFile()
116     {
117       return new PIRFile();
118     }
119   },
120   BLC
121   {
122     @Override
123     public AlignmentFileI getAlignmentFile(String inFile,
124             DataSourceType sourceType) throws IOException
125     {
126       return new BLCFile(inFile, sourceType);
127     }    @Override
128     public AlignmentFileI getAlignmentFile(FileParse source)
129             throws IOException
130     {
131       return new BLCFile(source);
132     }
133
134     @Override
135     public AlignmentFileI getAlignmentFile()
136     {
137       return new BLCFile();
138     }
139
140   },
141   Html
142   {
143     @Override
144     public AlignmentFileI getAlignmentFile(String inFile,
145             DataSourceType sourceType) throws IOException
146     {
147       return new HtmlFile(inFile, sourceType);
148     }    @Override
149     public AlignmentFileI getAlignmentFile(FileParse source)
150             throws IOException
151     {
152       return new HtmlFile(source);
153     }
154
155     @Override
156     public AlignmentFileI getAlignmentFile()
157     {
158       return new HtmlFile();
159     }
160
161     @Override
162     public boolean isComplexAlignFile()
163     {
164       return true;
165     }
166
167   },
168   Rnaml
169   {
170     @Override
171     public AlignmentFileI getAlignmentFile(String inFile,
172             DataSourceType sourceType) throws IOException
173     {
174       return new RnamlFile(inFile, sourceType);
175     }    @Override
176     public AlignmentFileI getAlignmentFile(FileParse source)
177             throws IOException
178     {
179       return new RnamlFile(source);
180     }
181
182     @Override
183     public AlignmentFileI getAlignmentFile()
184     {
185       return new RnamlFile();
186     }
187
188   },
189   Json
190   {
191     @Override
192     public AlignmentFileI getAlignmentFile(String inFile,
193             DataSourceType sourceType) throws IOException
194     {
195       return new JSONFile(inFile, sourceType);
196     }    @Override
197     public AlignmentFileI getAlignmentFile(FileParse source)
198             throws IOException
199     {
200       return new JSONFile(source);
201     }
202
203     @Override
204     public AlignmentFileI getAlignmentFile()
205     {
206       return new JSONFile();
207     }
208
209     @Override
210     public boolean isComplexAlignFile()
211     {
212       return true;
213     }
214
215   },
216   Pileup
217   {
218     @Override
219     public AlignmentFileI getAlignmentFile(String inFile,
220             DataSourceType sourceType) throws IOException
221     {
222       return new PileUpfile(inFile, sourceType);
223     }    @Override
224     public AlignmentFileI getAlignmentFile(FileParse source)
225             throws IOException
226     {
227       return new PileUpfile(source);
228     }
229
230     @Override
231     public AlignmentFileI getAlignmentFile()
232     {
233       return new PileUpfile();
234     }
235
236   },
237   MSF
238   {
239     @Override
240     public AlignmentFileI getAlignmentFile(String inFile,
241             DataSourceType sourceType) throws IOException
242     {
243       return new MSFfile(inFile, sourceType);
244     }    @Override
245     public AlignmentFileI getAlignmentFile(FileParse source)
246             throws IOException
247     {
248       return new MSFfile(source);
249     }
250
251     @Override
252     public AlignmentFileI getAlignmentFile()
253     {
254       return new MSFfile();
255     }
256
257   },
258   Clustal
259   {
260     @Override
261     public AlignmentFileI getAlignmentFile(String inFile,
262             DataSourceType sourceType) throws IOException
263     {
264       return new ClustalFile(inFile, sourceType);
265     }    @Override
266     public AlignmentFileI getAlignmentFile(FileParse source)
267             throws IOException
268     {
269       return new ClustalFile(source);
270     }
271
272     @Override
273     public AlignmentFileI getAlignmentFile()
274     {
275       return new ClustalFile();
276     }
277
278   },
279   Phylip
280   {
281     @Override
282     public AlignmentFileI getAlignmentFile(String inFile,
283             DataSourceType sourceType) throws IOException
284     {
285       return new PhylipFile(inFile, sourceType);
286     }
287
288     @Override
289     public AlignmentFileI getAlignmentFile(FileParse source)
290             throws IOException
291     {
292       return new PhylipFile(source);
293     }
294
295     @Override
296     public AlignmentFileI getAlignmentFile()
297     {
298       return new PhylipFile();
299     }
300
301   },
302   Jnet
303   {
304     @Override
305     public AlignmentFileI getAlignmentFile(String inFile,
306             DataSourceType sourceType) throws IOException
307     {
308       JPredFile af = new JPredFile(inFile, sourceType);
309       af.removeNonSequences();
310       return af;
311     }
312
313     @Override
314     public AlignmentFileI getAlignmentFile(FileParse source)
315             throws IOException
316     {
317       JPredFile af = new JPredFile(source);
318       af.removeNonSequences();
319       return af;
320     }
321
322     @Override
323     public AlignmentFileI getAlignmentFile()
324     {
325       return null; // todo is this called?
326     }
327
328   },
329   Features
330   {
331     @Override
332     public AlignmentFileI getAlignmentFile(String inFile,
333             DataSourceType sourceType) throws IOException
334     {
335       return new FeaturesFile(true, inFile, sourceType);
336     }
337
338     @Override
339     public AlignmentFileI getAlignmentFile(FileParse source)
340             throws IOException
341     {
342       return new FeaturesFile(source);
343     }
344
345     @Override
346     public AlignmentFileI getAlignmentFile()
347     {
348       return new FeaturesFile();
349     }
350   },
351   PDB
352   {
353
354     @Override
355     public AlignmentFileI getAlignmentFile(String inFile,
356             DataSourceType sourceType) throws IOException
357     {
358       // TODO obtain config value from preference settings.
359       // Set value to 'true' to test PDB processing with Jmol: JAL-1213
360       boolean isParseWithJMOL = !StructureImportSettings
361               .getCurrentDefaultFormat().equalsIgnoreCase("PDB");
362       if (isParseWithJMOL)
363       {
364         return new JmolParser(
365                 StructureImportSettings.isVisibleChainAnnotation(),
366                 StructureImportSettings.isPredictSecondaryStructure(),
367                 StructureImportSettings.isExternalSecondaryStructure(),
368                 inFile,
369                 sourceType);
370       }
371       else
372       {
373         StructureImportSettings.setShowSeqFeatures(true);
374         return new MCview.PDBfile(
375                 StructureImportSettings.isVisibleChainAnnotation(),
376                 StructureImportSettings.isPredictSecondaryStructure(),
377                 StructureImportSettings.isExternalSecondaryStructure(),
378                 inFile,
379                 sourceType);
380       }
381     }
382
383     @Override
384     public AlignmentFileI getAlignmentFile(FileParse source)
385             throws IOException
386     {
387       boolean isParseWithJMOL = !StructureImportSettings
388               .getCurrentDefaultFormat().equalsIgnoreCase("PDB");
389       if (isParseWithJMOL)
390       {
391         return new JmolParser(
392                 StructureImportSettings.isVisibleChainAnnotation(),
393                 StructureImportSettings.isPredictSecondaryStructure(),
394                 StructureImportSettings.isExternalSecondaryStructure(),
395                 source);
396       }
397       else
398       {
399         StructureImportSettings.setShowSeqFeatures(true);
400         return new MCview.PDBfile(
401                 StructureImportSettings.isVisibleChainAnnotation(),
402                 StructureImportSettings.isPredictSecondaryStructure(),
403                 StructureImportSettings.isExternalSecondaryStructure(),
404                 source);
405       }
406     }
407
408     @Override
409     public AlignmentFileI getAlignmentFile()
410     {
411       return new JmolParser(); // todo or null?
412     }
413
414   },
415   MMCif
416   {
417
418     @Override
419     public AlignmentFileI getAlignmentFile(String inFile,
420             DataSourceType sourceType) throws IOException
421     {
422       return new JmolParser(
423               StructureImportSettings.isVisibleChainAnnotation(),
424               StructureImportSettings.isPredictSecondaryStructure(),
425               StructureImportSettings.isExternalSecondaryStructure(),
426               inFile, sourceType);
427     }
428
429     @Override
430     public AlignmentFileI getAlignmentFile(FileParse source)
431             throws IOException
432     {
433       return new JmolParser(
434               StructureImportSettings.isVisibleChainAnnotation(),
435               StructureImportSettings.isPredictSecondaryStructure(),
436               StructureImportSettings.isExternalSecondaryStructure(),
437               source);
438     }
439
440     @Override
441     public AlignmentFileI getAlignmentFile()
442     {
443       return new JmolParser(); // todo or null?
444     }
445   },
446   Jalview
447   {
448
449     @Override
450     public AlignmentFileI getAlignmentFile(String inFile,
451             DataSourceType sourceType) throws IOException
452     {
453       return null;
454     }
455
456     @Override
457     public AlignmentFileI getAlignmentFile(FileParse source)
458             throws IOException
459     {
460       return null;
461     }
462
463     @Override
464     public AlignmentFileI getAlignmentFile()
465     {
466       return null;
467     }
468   };
469
470   @Override
471   public boolean isComplexAlignFile()
472   {
473     return false;
474   }
475
476   @Override
477   public String getShortDescription()
478   {
479     return toString();
480   }
481 }