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", true, 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", true, 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", "pdb,ent", true, 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", true, 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, true)
452 public AlignmentFileI getAlignmentFile(String inFile,
453 DataSourceType sourceType) throws IOException
459 public AlignmentFileI getAlignmentFile(FileParse source)
466 public AlignmentFileI getAlignmentFile(AlignmentI al)
472 public boolean isTextFormat()
479 * A lookup map of enums by upper-cased name
481 private static Map<String, FileFormat> names;
484 names = new HashMap<String, FileFormat>();
485 for (FileFormat format : FileFormat.values())
487 names.put(format.toString().toUpperCase(), format);
491 private boolean writable;
493 private boolean readable;
495 private String extensions;
500 * Answers a list of writeable file formats (as string, corresponding to the
501 * toString() and forName() methods)
505 public static List<String> getWritableFormats(boolean textOnly)
507 List<String> l = new ArrayList<String>();
508 for (FileFormatI ff : values())
510 if (ff.isWritable() && (!textOnly || ff.isTextFormat()))
512 l.add(ff.toString());
519 * Answers a list of readable file formats (as string, corresponding to the
520 * toString() and forName() methods)
524 public static List<String> getReadableFormats()
526 List<String> l = new ArrayList<String>();
527 for (FileFormatI ff : values())
531 l.add(ff.toString());
538 public boolean isComplexAlignFile()
544 * Returns the file format with the given name, or null if format is null or
545 * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to
546 * writers of javascript.
551 public static FileFormatI forName(String format)
553 // or could store format.getShortDescription().toUpperCase()
554 // in order to decouple 'given name' from enum name
555 return format == null ? null : names.get(format.toUpperCase());
559 public boolean isReadable()
565 public boolean isWritable()
575 * comma-separated list of file extensions associated with the format
579 private FileFormat(String shortName, String extensions,
580 boolean isReadable, boolean isWritable)
582 this.name = shortName;
583 this.extensions = extensions;
584 this.readable = isReadable;
585 this.writable = isWritable;
589 public String getExtensions()
595 public String toString()
601 public AlignmentFileI getAlignmentFile()
603 return getAlignmentFile((AlignmentI) null);
607 public boolean isTextFormat()