Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io

File FileFormat.java

 

Coverage histogram

../../img/srcFileCovDistChart7.png
28% of files have more coverage

Code metrics

2
62
53
1
459
372
54
0.87
1.17
53
1.02

Classes

Class Line # Actions
FileFormat 30 62 54 44
0.6239316562.4%
 

Contributing tests

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