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?
409 public boolean isStructureFile()
414 MMCif("mmCIF", "cif", true, false)
418 public AlignmentFileI getAlignmentFile(String inFile,
419 DataSourceType sourceType) throws IOException
421 return new JmolParser(inFile, sourceType);
425 public AlignmentFileI getAlignmentFile(FileParse source)
428 return new JmolParser(source);
432 public AlignmentFileI getAlignmentFile(AlignmentI al)
434 return new JmolParser(); // todo or null?
438 public boolean isStructureFile()
443 Jalview("Jalview", "jar,jvp", true, true)
447 public AlignmentFileI getAlignmentFile(String inFile,
448 DataSourceType sourceType) throws IOException
454 public AlignmentFileI getAlignmentFile(FileParse source)
461 public AlignmentFileI getAlignmentFile(AlignmentI al)
467 public boolean isTextFormat()
474 * A lookup map of enums by upper-cased name
476 private static Map<String, FileFormat> names;
479 names = new HashMap<String, FileFormat>();
480 for (FileFormat format : FileFormat.values())
482 names.put(format.toString().toUpperCase(), format);
486 private boolean writable;
488 private boolean readable;
490 private String extensions;
495 * Answers a list of writeable file formats (as string, corresponding to the
496 * toString() and forName() methods)
500 public static List<String> getWritableFormats(boolean textOnly)
502 List<String> l = new ArrayList<String>();
503 for (FileFormatI ff : values())
505 if (ff.isWritable() && (!textOnly || ff.isTextFormat()))
507 l.add(ff.toString());
514 * Answers a list of readable file formats (as string, corresponding to the
515 * toString() and forName() methods)
519 public static List<String> getReadableFormats()
521 List<String> l = new ArrayList<String>();
522 for (FileFormatI ff : values())
526 l.add(ff.toString());
533 public boolean isComplexAlignFile()
539 * Returns the file format with the given name, or null if format is null or
540 * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to
541 * writers of javascript.
546 public static FileFormatI forName(String format)
548 // or could store format.getShortDescription().toUpperCase()
549 // in order to decouple 'given name' from enum name
550 return format == null ? null : names.get(format.toUpperCase());
554 public boolean isReadable()
560 public boolean isWritable()
570 * comma-separated list of file extensions associated with the format
574 private FileFormat(String shortName, String extensions,
575 boolean isReadable, boolean isWritable)
577 this.name = shortName;
578 this.extensions = extensions;
579 this.readable = isReadable;
580 this.writable = isWritable;
584 public String getExtensions()
590 public String toString()
596 public AlignmentFileI getAlignmentFile()
598 return getAlignmentFile((AlignmentI) null);
602 public boolean isTextFormat()
608 public boolean isStructureFile()