package jalview.io; import jalview.datamodel.PDBEntry; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public enum FileFormat implements FileFormatI { Fasta("Fasta", "fa, fasta, mfa, fastq", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new FastaFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new FastaFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new FastaFile(); } }, Pfam("PFAM", "pfam", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new PfamFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new PfamFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new PfamFile(); } }, Stockholm("Stockholm", "sto,stk", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new StockholmFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new StockholmFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new StockholmFile(); } }, PIR("PIR", "pir", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new PIRFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new PIRFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new PIRFile(); } }, BLC("BLC", "BLC", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new BLCFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new BLCFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new BLCFile(); } }, AMSA("AMSA", "amsa", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new AMSAFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new AMSAFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new BLCFile(); } }, Html("HTML", "html", true, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new HtmlFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new HtmlFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new HtmlFile(); } @Override public boolean isComplexAlignFile() { return true; } }, Rnaml("RNAML", "xml,rnaml", true, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new RnamlFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new RnamlFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new RnamlFile(); } }, Json("JSON","json", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new JSONFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new JSONFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new JSONFile(); } @Override public boolean isComplexAlignFile() { return true; } }, Pileup("PileUp", "pileup", false, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new PileUpfile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new PileUpfile(source); } @Override public AlignmentFileI getAlignmentFile() { return new PileUpfile(); } }, MSF("MSF", "msf", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new MSFfile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new MSFfile(source); } @Override public AlignmentFileI getAlignmentFile() { return new MSFfile(); } }, Clustal("Clustal", "aln", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new ClustalFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new ClustalFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new ClustalFile(); } }, Phylip("PHYLIP", "phy", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new PhylipFile(inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new PhylipFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new PhylipFile(); } }, Jnet("JnetFile", "", false, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { JPredFile af = new JPredFile(inFile, sourceType); af.removeNonSequences(); return af; } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { JPredFile af = new JPredFile(source); af.removeNonSequences(); return af; } @Override public AlignmentFileI getAlignmentFile() { return null; // todo is this called? } }, Features("GFF or Jalview features", "gff2,gff3", false, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new FeaturesFile(true, inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new FeaturesFile(source); } @Override public AlignmentFileI getAlignmentFile() { return new FeaturesFile(); } }, PDB("PDB", "", false, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { // TODO obtain config value from preference settings. // Set value to 'true' to test PDB processing with Jmol: JAL-1213 boolean isParseWithJMOL = StructureImportSettings .getDefaultStructureFileFormat() != PDBEntry.Type.PDB; if (isParseWithJMOL) { return new JmolParser( StructureImportSettings.isVisibleChainAnnotation(), StructureImportSettings.isProcessSecondaryStructure(), StructureImportSettings.isExternalSecondaryStructure(), inFile, sourceType); } else { StructureImportSettings.setShowSeqFeatures(true); return new MCview.PDBfile( StructureImportSettings.isVisibleChainAnnotation(), StructureImportSettings.isProcessSecondaryStructure(), StructureImportSettings.isExternalSecondaryStructure(), inFile, sourceType); } } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { boolean isParseWithJMOL = StructureImportSettings .getDefaultStructureFileFormat() != PDBEntry.Type.PDB; if (isParseWithJMOL) { return new JmolParser( StructureImportSettings.isVisibleChainAnnotation(), StructureImportSettings.isProcessSecondaryStructure(), StructureImportSettings.isExternalSecondaryStructure(), source); } else { StructureImportSettings.setShowSeqFeatures(true); return new MCview.PDBfile( StructureImportSettings.isVisibleChainAnnotation(), StructureImportSettings.isProcessSecondaryStructure(), StructureImportSettings.isExternalSecondaryStructure(), source); } } @Override public AlignmentFileI getAlignmentFile() { return new JmolParser(); // todo or null? } }, MMCif("mmCIF", "cif", false, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return new JmolParser( StructureImportSettings.isVisibleChainAnnotation(), StructureImportSettings.isProcessSecondaryStructure(), StructureImportSettings.isExternalSecondaryStructure(), inFile, sourceType); } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return new JmolParser( StructureImportSettings.isVisibleChainAnnotation(), StructureImportSettings.isProcessSecondaryStructure(), StructureImportSettings.isExternalSecondaryStructure(), source); } @Override public AlignmentFileI getAlignmentFile() { return new JmolParser(); // todo or null? } }, Jalview("Jalview", "jar,jvp", true, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException { return null; } @Override public AlignmentFileI getAlignmentFile(FileParse source) throws IOException { return null; } @Override public AlignmentFileI getAlignmentFile() { return null; } }; /** * A lookup map of enums by upper-cased name */ private static Map names; static { names = new HashMap(); for (FileFormat format : FileFormat.values()) { names.put(format.toString().toUpperCase(), format); } } private boolean writable; private boolean readable; private String extensions; private String name; /** * Answers a list of writeable file formats (as string, corresponding to the * toString() and forName() methods) * * @return */ public static List getWritableFormats() { List l = new ArrayList(); for (FileFormatI ff : values()) { if (ff.isWritable()) { l.add(ff.toString()); } } return l; } /** * Answers a list of readable file formats (as string, corresponding to the * toString() and forName() methods) * * @return */ public static List getReadableFormats() { List l = new ArrayList(); for (FileFormatI ff : values()) { if (ff.isReadable()) { l.add(ff.toString()); } } return l; } @Override public boolean isComplexAlignFile() { return false; } @Override public String getShortDescription() { return toString(); } /** * Returns the file format with the given name, or null if format is null or * invalid. Unlike valueOf(), this is not case-sensitive, to be kind to * writers of javascript. * * @param format * @return */ public static FileFormatI forName(String format) { // or could store format.getShortDescription().toUpperCase() // in order to decouple 'given name' from enum name return format == null ? null : names.get(format.toUpperCase()); } @Override public boolean isReadable() { return readable; } @Override public boolean isWritable() { return writable; } /** * Constructor * * @param shortName * @param extensions * comma-separated list of file extensions associated with the format * @param isReadable * @param isWritable */ private FileFormat(String shortName, String extensions, boolean isReadable, boolean isWritable) { this.name = shortName; this.extensions = extensions; this.readable = isReadable; this.writable = isWritable; } @Override public String getExtensions() { return extensions; } @Override public String toString() { return name; } }