3 import jalview.datamodel.AlignmentI;
4 import jalview.datamodel.PDBEntry;
5 import jalview.ext.jmol.JmolParser;
6 import jalview.structure.StructureImportSettings;
8 import java.io.IOException;
9 import java.util.ArrayList;
10 import java.util.HashMap;
11 import java.util.List;
14 public enum FileFormat implements FileFormatI
16 Fasta("Fasta", "fa, fasta, mfa, fastq", true, true)
19 public AlignmentFileI getAlignmentFile(String inFile,
20 DataSourceType sourceType) throws IOException
22 return new FastaFile(inFile, sourceType);
26 public AlignmentFileI getAlignmentFile(FileParse source)
29 return new FastaFile(source);
33 public AlignmentFileI getAlignmentFile(AlignmentI al)
35 return new FastaFile();
38 Pfam("PFAM", "pfam", true, true)
41 public AlignmentFileI getAlignmentFile(String inFile,
42 DataSourceType sourceType) throws IOException
44 return new PfamFile(inFile, sourceType);
48 public AlignmentFileI getAlignmentFile(FileParse source)
51 return new PfamFile(source);
55 public AlignmentFileI getAlignmentFile(AlignmentI al)
57 return new PfamFile();
60 Stockholm("Stockholm", "sto,stk", true, true)
63 public AlignmentFileI getAlignmentFile(String inFile,
64 DataSourceType sourceType) throws IOException
66 return new StockholmFile(inFile, sourceType);
69 public AlignmentFileI getAlignmentFile(FileParse source)
72 return new StockholmFile(source);
76 public AlignmentFileI getAlignmentFile(AlignmentI al)
78 return new StockholmFile(al);
83 PIR("PIR", "pir", true, true)
86 public AlignmentFileI getAlignmentFile(String inFile,
87 DataSourceType sourceType) throws IOException
89 return new PIRFile(inFile, sourceType);
92 public AlignmentFileI getAlignmentFile(FileParse source)
95 return new PIRFile(source);
99 public AlignmentFileI getAlignmentFile(AlignmentI al)
101 return new PIRFile();
104 BLC("BLC", "BLC", true, true)
107 public AlignmentFileI getAlignmentFile(String inFile,
108 DataSourceType sourceType) throws IOException
110 return new BLCFile(inFile, sourceType);
112 public AlignmentFileI getAlignmentFile(FileParse source)
115 return new BLCFile(source);
119 public AlignmentFileI getAlignmentFile(AlignmentI al)
121 return new BLCFile();
124 AMSA("AMSA", "amsa", true, true)
127 public AlignmentFileI getAlignmentFile(String inFile,
128 DataSourceType sourceType) throws IOException
130 return new AMSAFile(inFile, sourceType);
134 public AlignmentFileI getAlignmentFile(FileParse source)
137 return new AMSAFile(source);
141 public AlignmentFileI getAlignmentFile(AlignmentI al)
143 return new AMSAFile(al);
146 Html("HTML", "html", true, false)
149 public AlignmentFileI getAlignmentFile(String inFile,
150 DataSourceType sourceType) throws IOException
152 return new HtmlFile(inFile, sourceType);
154 public AlignmentFileI getAlignmentFile(FileParse source)
157 return new HtmlFile(source);
161 public AlignmentFileI getAlignmentFile(AlignmentI al)
163 return new HtmlFile();
167 public boolean isComplexAlignFile()
173 Rnaml("RNAML", "xml,rnaml", true, false)
176 public AlignmentFileI getAlignmentFile(String inFile,
177 DataSourceType sourceType) throws IOException
179 return new RnamlFile(inFile, sourceType);
181 public AlignmentFileI getAlignmentFile(FileParse source)
184 return new RnamlFile(source);
188 public AlignmentFileI getAlignmentFile(AlignmentI al)
190 return new RnamlFile();
194 Json("JSON","json", true, true)
197 public AlignmentFileI getAlignmentFile(String inFile,
198 DataSourceType sourceType) throws IOException
200 return new JSONFile(inFile, sourceType);
202 public AlignmentFileI getAlignmentFile(FileParse source)
205 return new JSONFile(source);
209 public AlignmentFileI getAlignmentFile(AlignmentI al)
211 return new JSONFile();
215 public boolean isComplexAlignFile()
221 Pileup("PileUp", "pileup", false, true)
224 public AlignmentFileI getAlignmentFile(String inFile,
225 DataSourceType sourceType) throws IOException
227 return new PileUpfile(inFile, sourceType);
229 public AlignmentFileI getAlignmentFile(FileParse source)
232 return new PileUpfile(source);
236 public AlignmentFileI getAlignmentFile(AlignmentI al)
238 return new PileUpfile();
242 MSF("MSF", "msf", true, true)
245 public AlignmentFileI getAlignmentFile(String inFile,
246 DataSourceType sourceType) throws IOException
248 return new MSFfile(inFile, sourceType);
250 public AlignmentFileI getAlignmentFile(FileParse source)
253 return new MSFfile(source);
257 public AlignmentFileI getAlignmentFile(AlignmentI al)
259 return new MSFfile();
263 Clustal("Clustal", "aln", true, true)
266 public AlignmentFileI getAlignmentFile(String inFile,
267 DataSourceType sourceType) throws IOException
269 return new ClustalFile(inFile, sourceType);
271 public AlignmentFileI getAlignmentFile(FileParse source)
274 return new ClustalFile(source);
278 public AlignmentFileI getAlignmentFile(AlignmentI al)
280 return new ClustalFile();
283 Phylip("PHYLIP", "phy", true, true)
286 public AlignmentFileI getAlignmentFile(String inFile,
287 DataSourceType sourceType) throws IOException
289 return new PhylipFile(inFile, sourceType);
293 public AlignmentFileI getAlignmentFile(FileParse source)
296 return new PhylipFile(source);
300 public AlignmentFileI getAlignmentFile(AlignmentI al)
302 return new PhylipFile();
305 Jnet("JnetFile", "", false, false)
308 public AlignmentFileI getAlignmentFile(String inFile,
309 DataSourceType sourceType) throws IOException
311 JPredFile af = new JPredFile(inFile, sourceType);
312 af.removeNonSequences();
317 public AlignmentFileI getAlignmentFile(FileParse source)
320 JPredFile af = new JPredFile(source);
321 af.removeNonSequences();
326 public AlignmentFileI getAlignmentFile(AlignmentI al)
328 return null; // todo is this called?
332 Features("GFF or Jalview features", "gff2,gff3", false, false)
335 public AlignmentFileI getAlignmentFile(String inFile,
336 DataSourceType sourceType) throws IOException
338 return new FeaturesFile(true, inFile, sourceType);
342 public AlignmentFileI getAlignmentFile(FileParse source)
345 return new FeaturesFile(source);
349 public AlignmentFileI getAlignmentFile(AlignmentI al)
351 return new FeaturesFile();
354 PDB("PDB", "", false, false)
358 public AlignmentFileI getAlignmentFile(String inFile,
359 DataSourceType sourceType) throws IOException
361 // TODO obtain config value from preference settings.
362 // Set value to 'true' to test PDB processing with Jmol: JAL-1213
363 boolean isParseWithJMOL = StructureImportSettings
364 .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
367 return new JmolParser(
368 StructureImportSettings.isVisibleChainAnnotation(),
369 StructureImportSettings.isProcessSecondaryStructure(),
370 StructureImportSettings.isExternalSecondaryStructure(),
376 StructureImportSettings.setShowSeqFeatures(true);
377 return new MCview.PDBfile(
378 StructureImportSettings.isVisibleChainAnnotation(),
379 StructureImportSettings.isProcessSecondaryStructure(),
380 StructureImportSettings.isExternalSecondaryStructure(),
387 public AlignmentFileI getAlignmentFile(FileParse source)
390 boolean isParseWithJMOL = StructureImportSettings
391 .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
394 return new JmolParser(
395 StructureImportSettings.isVisibleChainAnnotation(),
396 StructureImportSettings.isProcessSecondaryStructure(),
397 StructureImportSettings.isExternalSecondaryStructure(),
402 StructureImportSettings.setShowSeqFeatures(true);
403 return new MCview.PDBfile(
404 StructureImportSettings.isVisibleChainAnnotation(),
405 StructureImportSettings.isProcessSecondaryStructure(),
406 StructureImportSettings.isExternalSecondaryStructure(),
412 public AlignmentFileI getAlignmentFile(AlignmentI al)
414 return new JmolParser(); // todo or null?
417 MMCif("mmCIF", "cif", false, false)
421 public AlignmentFileI getAlignmentFile(String inFile,
422 DataSourceType sourceType) throws IOException
424 return new JmolParser(
425 StructureImportSettings.isVisibleChainAnnotation(),
426 StructureImportSettings.isProcessSecondaryStructure(),
427 StructureImportSettings.isExternalSecondaryStructure(),
432 public AlignmentFileI getAlignmentFile(FileParse source)
435 return new JmolParser(
436 StructureImportSettings.isVisibleChainAnnotation(),
437 StructureImportSettings.isProcessSecondaryStructure(),
438 StructureImportSettings.isExternalSecondaryStructure(),
443 public AlignmentFileI getAlignmentFile(AlignmentI al)
445 return new JmolParser(); // todo or null?
448 Jalview("Jalview", "jar,jvp", true, false)
452 public AlignmentFileI getAlignmentFile(String inFile,
453 DataSourceType sourceType) throws IOException
459 public AlignmentFileI getAlignmentFile(FileParse source)
466 public AlignmentFileI getAlignmentFile(AlignmentI al)
473 * A lookup map of enums by upper-cased name
475 private static Map<String, FileFormat> names;
478 names = new HashMap<String, FileFormat>();
479 for (FileFormat format : FileFormat.values())
481 names.put(format.toString().toUpperCase(), format);
485 private boolean writable;
487 private boolean readable;
489 private String extensions;
494 * Answers a list of writeable file formats (as string, corresponding to the
495 * toString() and forName() methods)
499 public static List<String> getWritableFormats()
501 List<String> l = new ArrayList<String>();
502 for (FileFormatI ff : values())
506 l.add(ff.toString());
513 * Answers a list of readable file formats (as string, corresponding to the
514 * toString() and forName() methods)
518 public static List<String> getReadableFormats()
520 List<String> l = new ArrayList<String>();
521 for (FileFormatI ff : values())
525 l.add(ff.toString());
532 public boolean isComplexAlignFile()
538 * Returns the file format with the given name, or null if format is null or
539 * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to
540 * writers of javascript.
545 public static FileFormatI forName(String format)
547 // or could store format.getShortDescription().toUpperCase()
548 // in order to decouple 'given name' from enum name
549 return format == null ? null : names.get(format.toUpperCase());
553 public boolean isReadable()
559 public boolean isWritable()
569 * comma-separated list of file extensions associated with the format
573 private FileFormat(String shortName, String extensions,
574 boolean isReadable, boolean isWritable)
576 this.name = shortName;
577 this.extensions = extensions;
578 this.readable = isReadable;
579 this.writable = isWritable;
583 public String getExtensions()
589 public String toString()
595 public AlignmentFileI getAlignmentFile()
597 return getAlignmentFile((AlignmentI) null);