3 import jalview.datamodel.PDBEntry;
4 import jalview.ext.jmol.JmolParser;
5 import jalview.structure.StructureImportSettings;
7 import java.io.IOException;
8 import java.util.ArrayList;
9 import java.util.HashMap;
10 import java.util.List;
13 public enum FileFormat implements FileFormatI
15 Fasta("Fasta", "fa, fasta, mfa, fastq", true, true)
18 public AlignmentFileI getAlignmentFile(String inFile,
19 DataSourceType sourceType) throws IOException
21 return new FastaFile(inFile, sourceType);
25 public AlignmentFileI getAlignmentFile(FileParse source)
28 return new FastaFile(source);
32 public AlignmentFileI getAlignmentFile()
34 return new FastaFile();
37 Pfam("PFAM", "pfam", true, true)
40 public AlignmentFileI getAlignmentFile(String inFile,
41 DataSourceType sourceType) throws IOException
43 return new PfamFile(inFile, sourceType);
47 public AlignmentFileI getAlignmentFile(FileParse source)
50 return new PfamFile(source);
54 public AlignmentFileI getAlignmentFile()
56 return new PfamFile();
59 Stockholm("Stockholm", "sto,stk", true, true)
62 public AlignmentFileI getAlignmentFile(String inFile,
63 DataSourceType sourceType) throws IOException
65 return new StockholmFile(inFile, sourceType);
68 public AlignmentFileI getAlignmentFile(FileParse source)
71 return new StockholmFile(source);
75 public AlignmentFileI getAlignmentFile()
77 return new StockholmFile();
82 PIR("PIR", "pir", true, true)
85 public AlignmentFileI getAlignmentFile(String inFile,
86 DataSourceType sourceType) throws IOException
88 return new PIRFile(inFile, sourceType);
91 public AlignmentFileI getAlignmentFile(FileParse source)
94 return new PIRFile(source);
98 public AlignmentFileI getAlignmentFile()
100 return new PIRFile();
103 BLC("BLC", "BLC", true, true)
106 public AlignmentFileI getAlignmentFile(String inFile,
107 DataSourceType sourceType) throws IOException
109 return new BLCFile(inFile, sourceType);
111 public AlignmentFileI getAlignmentFile(FileParse source)
114 return new BLCFile(source);
118 public AlignmentFileI getAlignmentFile()
120 return new BLCFile();
123 AMSA("AMSA", "amsa", true, true)
126 public AlignmentFileI getAlignmentFile(String inFile,
127 DataSourceType sourceType) throws IOException
129 return new AMSAFile(inFile, sourceType);
133 public AlignmentFileI getAlignmentFile(FileParse source)
136 return new AMSAFile(source);
140 public AlignmentFileI getAlignmentFile()
142 return new BLCFile();
145 Html("HTML", "html", true, false)
148 public AlignmentFileI getAlignmentFile(String inFile,
149 DataSourceType sourceType) throws IOException
151 return new HtmlFile(inFile, sourceType);
153 public AlignmentFileI getAlignmentFile(FileParse source)
156 return new HtmlFile(source);
160 public AlignmentFileI getAlignmentFile()
162 return new HtmlFile();
166 public boolean isComplexAlignFile()
172 Rnaml("RNAML", "xml,rnaml", true, false)
175 public AlignmentFileI getAlignmentFile(String inFile,
176 DataSourceType sourceType) throws IOException
178 return new RnamlFile(inFile, sourceType);
180 public AlignmentFileI getAlignmentFile(FileParse source)
183 return new RnamlFile(source);
187 public AlignmentFileI getAlignmentFile()
189 return new RnamlFile();
193 Json("JSON","json", true, true)
196 public AlignmentFileI getAlignmentFile(String inFile,
197 DataSourceType sourceType) throws IOException
199 return new JSONFile(inFile, sourceType);
201 public AlignmentFileI getAlignmentFile(FileParse source)
204 return new JSONFile(source);
208 public AlignmentFileI getAlignmentFile()
210 return new JSONFile();
214 public boolean isComplexAlignFile()
220 Pileup("PileUp", "pileup", false, true)
223 public AlignmentFileI getAlignmentFile(String inFile,
224 DataSourceType sourceType) throws IOException
226 return new PileUpfile(inFile, sourceType);
228 public AlignmentFileI getAlignmentFile(FileParse source)
231 return new PileUpfile(source);
235 public AlignmentFileI getAlignmentFile()
237 return new PileUpfile();
241 MSF("MSF", "msf", true, true)
244 public AlignmentFileI getAlignmentFile(String inFile,
245 DataSourceType sourceType) throws IOException
247 return new MSFfile(inFile, sourceType);
249 public AlignmentFileI getAlignmentFile(FileParse source)
252 return new MSFfile(source);
256 public AlignmentFileI getAlignmentFile()
258 return new MSFfile();
262 Clustal("Clustal", "aln", true, true)
265 public AlignmentFileI getAlignmentFile(String inFile,
266 DataSourceType sourceType) throws IOException
268 return new ClustalFile(inFile, sourceType);
270 public AlignmentFileI getAlignmentFile(FileParse source)
273 return new ClustalFile(source);
277 public AlignmentFileI getAlignmentFile()
279 return new ClustalFile();
282 Phylip("PHYLIP", "phy", true, true)
285 public AlignmentFileI getAlignmentFile(String inFile,
286 DataSourceType sourceType) throws IOException
288 return new PhylipFile(inFile, sourceType);
292 public AlignmentFileI getAlignmentFile(FileParse source)
295 return new PhylipFile(source);
299 public AlignmentFileI getAlignmentFile()
301 return new PhylipFile();
304 Jnet("JnetFile", "", false, false)
307 public AlignmentFileI getAlignmentFile(String inFile,
308 DataSourceType sourceType) throws IOException
310 JPredFile af = new JPredFile(inFile, sourceType);
311 af.removeNonSequences();
316 public AlignmentFileI getAlignmentFile(FileParse source)
319 JPredFile af = new JPredFile(source);
320 af.removeNonSequences();
325 public AlignmentFileI getAlignmentFile()
327 return null; // todo is this called?
331 Features("GFF or Jalview features", "gff2,gff3", false, false)
334 public AlignmentFileI getAlignmentFile(String inFile,
335 DataSourceType sourceType) throws IOException
337 return new FeaturesFile(true, inFile, sourceType);
341 public AlignmentFileI getAlignmentFile(FileParse source)
344 return new FeaturesFile(source);
348 public AlignmentFileI getAlignmentFile()
350 return new FeaturesFile();
353 PDB("PDB", "", false, false)
357 public AlignmentFileI getAlignmentFile(String inFile,
358 DataSourceType sourceType) throws IOException
360 // TODO obtain config value from preference settings.
361 // Set value to 'true' to test PDB processing with Jmol: JAL-1213
362 boolean isParseWithJMOL = StructureImportSettings
363 .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
366 return new JmolParser(
367 StructureImportSettings.isVisibleChainAnnotation(),
368 StructureImportSettings.isProcessSecondaryStructure(),
369 StructureImportSettings.isExternalSecondaryStructure(),
375 StructureImportSettings.setShowSeqFeatures(true);
376 return new MCview.PDBfile(
377 StructureImportSettings.isVisibleChainAnnotation(),
378 StructureImportSettings.isProcessSecondaryStructure(),
379 StructureImportSettings.isExternalSecondaryStructure(),
386 public AlignmentFileI getAlignmentFile(FileParse source)
389 boolean isParseWithJMOL = StructureImportSettings
390 .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
393 return new JmolParser(
394 StructureImportSettings.isVisibleChainAnnotation(),
395 StructureImportSettings.isProcessSecondaryStructure(),
396 StructureImportSettings.isExternalSecondaryStructure(),
401 StructureImportSettings.setShowSeqFeatures(true);
402 return new MCview.PDBfile(
403 StructureImportSettings.isVisibleChainAnnotation(),
404 StructureImportSettings.isProcessSecondaryStructure(),
405 StructureImportSettings.isExternalSecondaryStructure(),
411 public AlignmentFileI getAlignmentFile()
413 return new JmolParser(); // todo or null?
416 MMCif("mmCIF", "cif", false, false)
420 public AlignmentFileI getAlignmentFile(String inFile,
421 DataSourceType sourceType) throws IOException
423 return new JmolParser(
424 StructureImportSettings.isVisibleChainAnnotation(),
425 StructureImportSettings.isProcessSecondaryStructure(),
426 StructureImportSettings.isExternalSecondaryStructure(),
431 public AlignmentFileI getAlignmentFile(FileParse source)
434 return new JmolParser(
435 StructureImportSettings.isVisibleChainAnnotation(),
436 StructureImportSettings.isProcessSecondaryStructure(),
437 StructureImportSettings.isExternalSecondaryStructure(),
442 public AlignmentFileI getAlignmentFile()
444 return new JmolParser(); // todo or null?
447 Jalview("Jalview", "jar,jvp", true, false)
451 public AlignmentFileI getAlignmentFile(String inFile,
452 DataSourceType sourceType) throws IOException
458 public AlignmentFileI getAlignmentFile(FileParse source)
465 public AlignmentFileI getAlignmentFile()
472 * A lookup map of enums by upper-cased name
474 private static Map<String, FileFormat> names;
477 names = new HashMap<String, FileFormat>();
478 for (FileFormat format : FileFormat.values())
480 names.put(format.toString().toUpperCase(), format);
484 private boolean writable;
486 private boolean readable;
488 private String extensions;
493 * Answers a list of writeable file formats (as string, corresponding to the
494 * toString() and forName() methods)
498 public static List<String> getWritableFormats()
500 List<String> l = new ArrayList<String>();
501 for (FileFormatI ff : values())
505 l.add(ff.toString());
512 * Answers a list of readable file formats (as string, corresponding to the
513 * toString() and forName() methods)
517 public static List<String> getReadableFormats()
519 List<String> l = new ArrayList<String>();
520 for (FileFormatI ff : values())
524 l.add(ff.toString());
531 public boolean isComplexAlignFile()
537 public String getShortDescription()
543 * Returns the file format with the given name, or null if format is null or
544 * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to
545 * writers of javascript.
550 public static FileFormatI forName(String format)
552 // or could store format.getShortDescription().toUpperCase()
553 // in order to decouple 'given name' from enum name
554 return format == null ? null : names.get(format.toUpperCase());
558 public boolean isReadable()
564 public boolean isWritable()
574 * comma-separated list of file extensions associated with the format
578 private FileFormat(String shortName, String extensions,
579 boolean isReadable, boolean isWritable)
581 this.name = shortName;
582 this.extensions = extensions;
583 this.readable = isReadable;
584 this.writable = isWritable;
588 public String getExtensions()
594 public String toString()