Clover icon

Coverage Report

  1. Project Clover database Wed Sep 17 2025 10:52:37 BST
  2. Package jalview.io

File FileFormat.java

 

Coverage histogram

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

Code metrics

2
70
61
1
524
429
62
0.89
1.15
61
1.02

Classes

Class Line # Actions
FileFormat 31 70 62
0.5639097756.4%
 

Contributing tests

This file is covered by 301 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  425 toggle @Override
36    public AlignmentFileReaderI getReader(FileParse source)
37    throws IOException
38    {
39  425 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  46 toggle @Override
66    public AlignmentFileReaderI getReader(FileParse source)
67    throws IOException
68    {
69  46 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  500 toggle @Override
413    public boolean isTextFormat()
414    {
415  500 return false;
416    }
417   
 
418  68 toggle @Override
419    public boolean isIdentifiable()
420    {
421  68 return true;
422    }
423    },
424    JalviewAnnotation("Annotation", "ann,annotation", false, false)
425    {
 
426  0 toggle @Override
427    public AlignmentFileReaderI getReader(FileParse source)
428    throws IOException
429    {
430  0 return null;
431    }
432   
 
433  0 toggle @Override
434    public AlignmentFileWriterI getWriter(AlignmentI al)
435    {
436  0 return null;
437    }
438    };
439   
440    private boolean writable;
441   
442    private boolean readable;
443   
444    private String extensions;
445   
446    private String name;
447   
 
448  94 toggle @Override
449    public boolean isComplexAlignFile()
450    {
451  94 return false;
452    }
453   
 
454  9728 toggle @Override
455    public boolean isReadable()
456    {
457  9728 return readable;
458    }
459   
 
460  15864 toggle @Override
461    public boolean isWritable()
462    {
463  15864 return writable;
464    }
465   
466    /**
467    * Constructor
468    *
469    * @param shortName
470    * @param extensions
471    * comma-separated list of file extensions associated with the format
472    * @param isReadable
473    * - can be recognised by IdentifyFile and imported with the given
474    * reader
475    * @param isWritable
476    * - can be exported with the returned writer
477    */
 
478  1242 toggle private FileFormat(String shortName, String extensions,
479    boolean isReadable, boolean isWritable)
480    {
481  1242 this.name = shortName;
482  1242 this.extensions = extensions;
483  1242 this.readable = isReadable;
484  1242 this.writable = isWritable;
485    }
486   
 
487  2079 toggle @Override
488    public String getExtensions()
489    {
490  2079 return extensions;
491    }
492   
493    /**
494    * Answers the display name of the file format (as for example shown in menu
495    * options). This name should not be locale (language) dependent.
496    */
 
497  19512 toggle @Override
498    public String getName()
499    {
500  19512 return name;
501    }
502   
 
503  5499 toggle @Override
504    public boolean isTextFormat()
505    {
506  5499 return true;
507    }
508   
 
509  984 toggle @Override
510    public boolean isStructureFile()
511    {
512  984 return false;
513    }
514   
515    /**
516    * By default, answers true, indicating the format is one that can be
517    * identified by IdentifyFile. Formats that cannot be identified should
518    * override this method to return false.
519    */
 
520  1500 toggle public boolean isIdentifiable()
521    {
522  1500 return true;
523    }
524    }