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(inFile, sourceType);
371 StructureImportSettings.setShowSeqFeatures(true);
372 return new MCview.PDBfile(
373 StructureImportSettings.isVisibleChainAnnotation(),
374 StructureImportSettings.isProcessSecondaryStructure(),
375 StructureImportSettings.isExternalSecondaryStructure(),
382 public AlignmentFileI getAlignmentFile(FileParse source)
385 boolean isParseWithJMOL = StructureImportSettings
386 .getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
389 return new JmolParser(source);
393 StructureImportSettings.setShowSeqFeatures(true);
394 return new MCview.PDBfile(
395 StructureImportSettings.isVisibleChainAnnotation(),
396 StructureImportSettings.isProcessSecondaryStructure(),
397 StructureImportSettings.isExternalSecondaryStructure(),
403 public AlignmentFileI getAlignmentFile(AlignmentI al)
405 return new JmolParser(); // todo or null?
408 MMCif("mmCIF", "cif", true, false)
412 public AlignmentFileI getAlignmentFile(String inFile,
413 DataSourceType sourceType) throws IOException
415 return new JmolParser(inFile, sourceType);
419 public AlignmentFileI getAlignmentFile(FileParse source)
422 return new JmolParser(source);
426 public AlignmentFileI getAlignmentFile(AlignmentI al)
428 return new JmolParser(); // todo or null?
431 Jalview("Jalview", "jar,jvp", true, true)
435 public AlignmentFileI getAlignmentFile(String inFile,
436 DataSourceType sourceType) throws IOException
442 public AlignmentFileI getAlignmentFile(FileParse source)
449 public AlignmentFileI getAlignmentFile(AlignmentI al)
455 public boolean isTextFormat()
462 * A lookup map of enums by upper-cased name
464 private static Map<String, FileFormat> names;
467 names = new HashMap<String, FileFormat>();
468 for (FileFormat format : FileFormat.values())
470 names.put(format.toString().toUpperCase(), format);
474 private boolean writable;
476 private boolean readable;
478 private String extensions;
483 * Answers a list of writeable file formats (as string, corresponding to the
484 * toString() and forName() methods)
488 public static List<String> getWritableFormats(boolean textOnly)
490 List<String> l = new ArrayList<String>();
491 for (FileFormatI ff : values())
493 if (ff.isWritable() && (!textOnly || ff.isTextFormat()))
495 l.add(ff.toString());
502 * Answers a list of readable file formats (as string, corresponding to the
503 * toString() and forName() methods)
507 public static List<String> getReadableFormats()
509 List<String> l = new ArrayList<String>();
510 for (FileFormatI ff : values())
514 l.add(ff.toString());
521 public boolean isComplexAlignFile()
527 * Returns the file format with the given name, or null if format is null or
528 * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to
529 * writers of javascript.
534 public static FileFormatI forName(String format)
536 // or could store format.getShortDescription().toUpperCase()
537 // in order to decouple 'given name' from enum name
538 return format == null ? null : names.get(format.toUpperCase());
542 public boolean isReadable()
548 public boolean isWritable()
558 * comma-separated list of file extensions associated with the format
562 private FileFormat(String shortName, String extensions,
563 boolean isReadable, boolean isWritable)
565 this.name = shortName;
566 this.extensions = extensions;
567 this.readable = isReadable;
568 this.writable = isWritable;
572 public String getExtensions()
578 public String toString()
584 public AlignmentFileI getAlignmentFile()
586 return getAlignmentFile((AlignmentI) null);
590 public boolean isTextFormat()