X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileFormat.java;fp=src%2Fjalview%2Fio%2FFileFormat.java;h=a11147c069c17570d168b52572df3422763a1070;hb=2595e9d4ee0dbbd3406a98c4e49a61ccde806479;hp=0000000000000000000000000000000000000000;hpb=e20075ba805d744d7cc4976e2b8d5e5840fb0a8d;p=jalview.git diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java new file mode 100644 index 0000000..a11147c --- /dev/null +++ b/src/jalview/io/FileFormat.java @@ -0,0 +1,424 @@ +package jalview.io; + +import jalview.datamodel.AlignmentI; +import jalview.datamodel.PDBEntry; +import jalview.ext.jmol.JmolParser; +import jalview.structure.StructureImportSettings; + +import java.io.IOException; + +public enum FileFormat implements FileFormatI +{ + Fasta("Fasta", "fa, fasta, mfa, fastq", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new FastaFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new FastaFile(); + } + }, + Pfam("PFAM", "pfam", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new PfamFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new PfamFile(); + } + }, + Stockholm("Stockholm", "sto,stk", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new StockholmFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new StockholmFile(al); + } + + }, + + PIR("PIR", "pir", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new PIRFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new PIRFile(); + } + }, + BLC("BLC", "BLC", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new BLCFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new BLCFile(); + } + }, + AMSA("AMSA", "amsa", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new AMSAFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new AMSAFile(al); + } + }, + Html("HTML", "html", true, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new HtmlFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new HtmlFile(); + } + + @Override + public boolean isComplexAlignFile() + { + return true; + } + + }, + Rnaml("RNAML", "xml,rnaml", true, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new RnamlFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new RnamlFile(); + } + + }, + Json("JSON", "json", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new JSONFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new JSONFile(); + } + + @Override + public boolean isComplexAlignFile() + { + return true; + } + + }, + Pileup("PileUp", "pileup", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new PileUpfile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new PileUpfile(); + } + + }, + MSF("MSF", "msf", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new MSFfile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new MSFfile(); + } + + }, + Clustal("Clustal", "aln", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new ClustalFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new ClustalFile(); + } + }, + Phylip("PHYLIP", "phy", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new PhylipFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new PhylipFile(); + } + }, + Jnet("JnetFile", "", false, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + JPredFile af = new JPredFile(source); + af.removeNonSequences(); + return af; + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return null; // todo is this called? + } + + }, + Features("GFF or Jalview features", "gff2,gff3", true, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new FeaturesFile(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new FeaturesFile(); + } + }, + PDB("PDB", "pdb,ent", true, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + boolean isParseWithJMOL = StructureImportSettings + .getDefaultStructureFileFormat() != PDBEntry.Type.PDB; + if (isParseWithJMOL) + { + return new JmolParser(source); + } + else + { + StructureImportSettings.setShowSeqFeatures(true); + return new MCview.PDBfile( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isProcessSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + source); + } + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new JmolParser(); // todo or null? + } + + @Override + public boolean isStructureFile() + { + return true; + } + }, + MMCif("mmCIF", "cif", true, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new JmolParser(source); + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return new JmolParser(); // todo or null? + } + + @Override + public boolean isStructureFile() + { + return true; + } + }, + Jalview("Jalview", "jar,jvp", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return null; + } + + @Override + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return null; + } + + @Override + public boolean isTextFormat() + { + return false; + } + + @Override + public boolean isIdentifiable() + { + return false; + } + }; + + private boolean writable; + + private boolean readable; + + private String extensions; + + private String name; + + @Override + public boolean isComplexAlignFile() + { + return false; + } + + @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; + } + + /** + * Answers the display name of the file format (as for example shown in menu + * options). This name should not be locale (language) dependent. + */ + @Override + public String getName() + { + return name; + } + + @Override + public boolean isTextFormat() + { + return true; + } + + @Override + public boolean isStructureFile() + { + return false; + } + + /** + * By default, answers true, indicating the format is one that can be + * identified by IdentifyFile. Formats that cannot be identified should + * override this method to return false. + */ + public boolean isIdentifiable() + { + return true; + } +}