1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.io

File FileFormat.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
37% of files have more coverage

Code metrics

2
68
59
1
509
415
60
0.88
1.15
59
1.02

Classes

Class
Line #
Actions
FileFormat 31 68 60
0.581395358.1%
 

Contributing tests

This file is covered by 283 tests. .

Source view

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