Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.io

File FileFormat.java

 

Coverage histogram

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

Code metrics

2
76
67
1
569
470
68
0.89
1.13
67
1.01

Classes

Class Line # Actions
FileFormat 31 76 68
0.558620755.9%
 

Contributing tests

This file is covered by 401 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  411 toggle @Override
36    public AlignmentFileReaderI getReader(FileParse source)
37    throws IOException
38    {
39  411 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  47 toggle @Override
66    public AlignmentFileReaderI getReader(FileParse source)
67    throws IOException
68    {
69  47 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    A3M("A3M (HHSuite)", "a3m", true, false)
126    {
 
127  1 toggle @Override
128    public AlignmentFileReaderI getReader(FileParse source)
129    throws IOException
130    {
131  1 return new A3mFile(source);
132    }
133   
 
134  0 toggle @Override
135    public AlignmentFileWriterI getWriter(AlignmentI al)
136    {
137  0 throw new Error("Not Implemented.");
138    }
139    },
140    Html("HTML", "html", true, false)
141    {
 
142  0 toggle @Override
143    public AlignmentFileReaderI getReader(FileParse source)
144    throws IOException
145    {
146  0 return new HtmlFile(source);
147    }
148   
 
149  0 toggle @Override
150    public AlignmentFileWriterI getWriter(AlignmentI al)
151    {
152  0 return new HtmlFile();
153    }
154   
 
155  0 toggle @Override
156    public boolean isComplexAlignFile()
157    {
158  0 return true;
159    }
160   
161    },
162    Rnaml("RNAML", "xml,rnaml", true, false)
163    {
 
164  1 toggle @Override
165    public AlignmentFileReaderI getReader(FileParse source)
166    throws IOException
167    {
168  1 return new RnamlFile(source);
169    }
170   
 
171  0 toggle @Override
172    public AlignmentFileWriterI getWriter(AlignmentI al)
173    {
174  0 return new RnamlFile();
175    }
176   
177    },
178    Json("JSON", "json", true, true)
179    {
 
180  12 toggle @Override
181    public AlignmentFileReaderI getReader(FileParse source)
182    throws IOException
183    {
184  12 return new JSONFile(source);
185    }
186   
 
187  8 toggle @Override
188    public AlignmentFileWriterI getWriter(AlignmentI al)
189    {
190  8 return new JSONFile();
191    }
192   
 
193  0 toggle @Override
194    public boolean isComplexAlignFile()
195    {
196  0 return true;
197    }
198   
199    },
200    Pileup("PileUp", "pileup", true, true)
201    {
 
202  1 toggle @Override
203    public AlignmentFileReaderI getReader(FileParse source)
204    throws IOException
205    {
206  1 return new PileUpfile(source);
207    }
208   
 
209  2 toggle @Override
210    public AlignmentFileWriterI getWriter(AlignmentI al)
211    {
212  2 return new PileUpfile();
213    }
214   
215    },
216    MSF("MSF", "msf", true, true)
217    {
 
218  1 toggle @Override
219    public AlignmentFileReaderI getReader(FileParse source)
220    throws IOException
221    {
222  1 return new MSFfile(source);
223    }
224   
 
225  3 toggle @Override
226    public AlignmentFileWriterI getWriter(AlignmentI al)
227    {
228  3 return new MSFfile();
229    }
230   
231    },
232    Clustal("Clustal", "aln", true, true)
233    {
 
234  1 toggle @Override
235    public AlignmentFileReaderI getReader(FileParse source)
236    throws IOException
237    {
238  1 return new ClustalFile(source);
239    }
240   
 
241  37 toggle @Override
242    public AlignmentFileWriterI getWriter(AlignmentI al)
243    {
244  37 return new ClustalFile();
245    }
246    },
247    Phylip("PHYLIP", "phy", true, true)
248    {
 
249  7 toggle @Override
250    public AlignmentFileReaderI getReader(FileParse source)
251    throws IOException
252    {
253  7 return new PhylipFile(source);
254    }
255   
 
256  3 toggle @Override
257    public AlignmentFileWriterI getWriter(AlignmentI al)
258    {
259  3 return new PhylipFile();
260    }
261    },
262    GenBank("GenBank Flatfile", "gb,gbk", true, false)
263    {
 
264  0 toggle @Override
265    public AlignmentFileReaderI getReader(FileParse source)
266    throws IOException
267    {
268  0 return new GenBankFile(source, "GenBank");
269    }
270   
 
271  0 toggle @Override
272    public AlignmentFileWriterI getWriter(AlignmentI al)
273    {
274  0 return null;
275    }
276    },
277    Embl("ENA Flatfile", "txt", true, false)
278    {
 
279  0 toggle @Override
280    public AlignmentFileReaderI getReader(FileParse source)
281    throws IOException
282    {
283    // Always assume we import from EMBL for now
284  0 return new EmblFlatFile(source, DBRefSource.EMBL);
285    }
286   
 
287  0 toggle @Override
288    public AlignmentFileWriterI getWriter(AlignmentI al)
289    {
290  0 return null;
291    }
292    },
293    Jnet("JnetFile", "", false, false)
294    {
 
295  0 toggle @Override
296    public AlignmentFileReaderI getReader(FileParse source)
297    throws IOException
298    {
299  0 JPredFile af = new JPredFile(source);
300  0 af.removeNonSequences();
301  0 return af;
302    }
303   
 
304  0 toggle @Override
305    public AlignmentFileWriterI getWriter(AlignmentI al)
306    {
307  0 return null; // todo is this called?
308    }
309   
310    },
311    Features("GFF or Jalview features", "gff2,gff3", true, false)
312    {
 
313  1 toggle @Override
314    public AlignmentFileReaderI getReader(FileParse source)
315    throws IOException
316    {
317  1 return new FeaturesFile(source);
318    }
319   
 
320  0 toggle @Override
321    public AlignmentFileWriterI getWriter(AlignmentI al)
322    {
323  0 return new FeaturesFile();
324    }
325    },
326    FeatureSettings("Jalview Feature Settings File", "fc", false, false)
327    {
 
328  0 toggle @Override
329    public AlignmentFileReaderI getReader(FileParse source)
330    throws IOException
331    {
332  0 return null;
333    }
334   
 
335  0 toggle @Override
336    public AlignmentFileWriterI getWriter(AlignmentI al)
337    {
338  0 return null;
339    }
340    },
341    ScoreMatrix("Substitution matrix", "", false, false)
342    {
 
343  0 toggle @Override
344    public AlignmentFileReaderI getReader(FileParse source)
345    throws IOException
346    {
347  0 return new ScoreMatrixFile(source);
348    }
349   
 
350  0 toggle @Override
351    public AlignmentFileWriterI getWriter(AlignmentI al)
352    {
353  0 return null;
354    }
355    },
356    PDB("PDB", "pdb,ent", true, false)
357    {
 
358  0 toggle @Override
359    public AlignmentFileReaderI getReader(FileParse source)
360    throws IOException
361    {
362  0 boolean isParseWithJMOL = StructureImportSettings
363    .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
364  0 if (isParseWithJMOL)
365    {
366  0 return new JmolParser(source);
367    }
368    else
369    {
370  0 StructureImportSettings.setShowSeqFeatures(true);
371  0 return new mc_view.PDBfile(
372    StructureImportSettings.isVisibleChainAnnotation(),
373    StructureImportSettings.isProcessSecondaryStructure(),
374    StructureImportSettings.isExternalSecondaryStructure(),
375    source);
376    }
377    }
378   
 
379  0 toggle @Override
380    public AlignmentFileWriterI getWriter(AlignmentI al)
381    {
382  0 return new JmolParser(); // todo or null?
383    }
384   
 
385  27 toggle @Override
386    public boolean isStructureFile()
387    {
388  27 return true;
389    }
390    },
391    MMCif("mmCIF", "cif", true, false)
392    {
 
393  0 toggle @Override
394    public AlignmentFileReaderI getReader(FileParse source)
395    throws IOException
396    {
397  0 return new JmolParser(source);
398    }
399   
 
400  0 toggle @Override
401    public AlignmentFileWriterI getWriter(AlignmentI al)
402    {
403  0 return new JmolParser(); // todo or null?
404    }
405   
 
406  0 toggle @Override
407    public boolean isStructureFile()
408    {
409  0 return true;
410    }
411    },
412    Jalview("Jalview", "jvp,jar", true, true)
413    {
 
414  0 toggle @Override
415    public AlignmentFileReaderI getReader(FileParse source)
416    throws IOException
417    {
418  0 return null;
419    }
420   
 
421  0 toggle @Override
422    public AlignmentFileWriterI getWriter(AlignmentI al)
423    {
424  0 return null;
425    }
426   
 
427  512 toggle @Override
428    public boolean isTextFormat()
429    {
430  512 return false;
431    }
432   
 
433  68 toggle @Override
434    public boolean isIdentifiable()
435    {
436  68 return true;
437    }
438    },
439    JalviewAnnotation("Annotation", "ann,annotation", false, false)
440    {
 
441  0 toggle @Override
442    public AlignmentFileReaderI getReader(FileParse source)
443    throws IOException
444    {
445  0 return null;
446    }
447   
 
448  0 toggle @Override
449    public AlignmentFileWriterI getWriter(AlignmentI al)
450    {
451  0 return null;
452    }
453    },
454    HMMER3("HMMER3", "hmm", true, true)
455    {
 
456  3 toggle @Override
457    public AlignmentFileReaderI getReader(FileParse source)
458    throws IOException
459    {
460  3 return new HMMFile(source);
461    }
462   
 
463  1 toggle @Override
464    public AlignmentFileWriterI getWriter(AlignmentI al)
465    {
466  1 return new HMMFile();
467    }
468    }, BSML("BSML", "bbb", true, false)
469    {
 
470  0 toggle @Override
471    public AlignmentFileReaderI getReader(FileParse source)
472    throws IOException
473    {
474  0 return new BSMLFile(source);
475    }
476   
 
477  0 toggle @Override
478    public AlignmentFileWriterI getWriter(AlignmentI al)
479    {
480  0 return null;
481    }
482    };
483   
484   
485    private boolean writable;
486   
487    private boolean readable;
488   
489    private String extensions;
490   
491    private String name;
492   
 
493  94 toggle @Override
494    public boolean isComplexAlignFile()
495    {
496  94 return false;
497    }
498   
 
499  8553 toggle @Override
500    public boolean isReadable()
501    {
502  8553 return readable;
503    }
504   
 
505  23396 toggle @Override
506    public boolean isWritable()
507    {
508  23396 return writable;
509    }
510   
511    /**
512    * Constructor
513    *
514    * @param shortName
515    * @param extensions
516    * comma-separated list of file extensions associated with the format
517    * @param isReadable
518    * - can be recognised by IdentifyFile and imported with the given
519    * reader
520    * @param isWritable
521    * - can be exported with the returned writer
522    */
 
523  1404 toggle private FileFormat(String shortName, String extensions,
524    boolean isReadable, boolean isWritable)
525    {
526  1404 this.name = shortName;
527  1404 this.extensions = extensions;
528  1404 this.readable = isReadable;
529  1404 this.writable = isWritable;
530    }
531   
 
532  664 toggle @Override
533    public String getExtensions()
534    {
535  664 return extensions;
536    }
537   
538    /**
539    * Answers the display name of the file format (as for example shown in menu
540    * options). This name should not be locale (language) dependent.
541    */
 
542  25191 toggle @Override
543    public String getName()
544    {
545  25191 return name;
546    }
547   
 
548  6143 toggle @Override
549    public boolean isTextFormat()
550    {
551  6143 return true;
552    }
553   
 
554  952 toggle @Override
555    public boolean isStructureFile()
556    {
557  952 return false;
558    }
559   
560    /**
561    * By default, answers true, indicating the format is one that can be
562    * identified by IdentifyFile. Formats that cannot be identified should
563    * override this method to return false.
564    */
 
565  1704 toggle public boolean isIdentifiable()
566    {
567  1704 return true;
568    }
569    }