X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileFormat.java;h=7a581c194d90a9355465ec354f9c27254075e2e5;hb=b5667f39acdf309cd92881b73edfda591e0acaf4;hp=893a8acf5632aba3db0b4c0c2c0a5969b8f91f2e;hpb=8dd4255a671e95df3fc6d6bc4d5d6b172f682c5d;p=jalview.git diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index 893a8ac..7a581c1 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -1,5 +1,27 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.io; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.PDBEntry; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; @@ -7,153 +29,109 @@ import java.io.IOException; public enum FileFormat implements FileFormatI { - Fasta + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new FastaFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new FastaFile(); } }, - Pfam + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new PfamFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PfamFile(); } }, - Stockholm + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new StockholmFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { - return new StockholmFile(); + return new StockholmFile(al); } }, - SimpleBlast - { - @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException - { - return new SimpleBlastFile(inFile, sourceType); - } + PIR("PIR", "pir", true, true) + { @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { - return new SimpleBlastFile(source); + return new PIRFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { - return new SimpleBlastFile(); + return new PIRFile(); } }, - - PIR + BLC("BLC", "BLC", true, true) { @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException - { - return new PIRFile(inFile, sourceType); - } - @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { - return new PIRFile(source); + return new BLCFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { - return new PIRFile(); + return new BLCFile(); } }, - BLC + AMSA("AMSA", "amsa", true, true) { @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException - { - return new BLCFile(inFile, sourceType); - } @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { - return new BLCFile(source); + return new AMSAFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { - return new BLCFile(); + return new AMSAFile(al); } - }, - Html + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new HtmlFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new HtmlFile(); } @@ -165,43 +143,33 @@ public enum FileFormat implements FileFormatI } }, - Rnaml + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new RnamlFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new RnamlFile(); } }, - Json + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new JSONFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new JSONFile(); } @@ -213,105 +181,72 @@ public enum FileFormat implements FileFormatI } }, - Pileup + Pileup("PileUp", "pileup", true, true) { @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException - { - return new PileUpfile(inFile, sourceType); - } @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new PileUpfile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PileUpfile(); } }, - MSF + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new MSFfile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new MSFfile(); } }, - Clustal + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new ClustalFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new ClustalFile(); } - }, - Phylip + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new PhylipFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PhylipFile(); } - }, - Jnet + 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { JPredFile af = new JPredFile(source); @@ -320,153 +255,150 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return null; // todo is this called? } }, - Features + Features("GFF or Jalview features", "gff2,gff3", true, false) { @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException - { - return new FeaturesFile(true, inFile, sourceType); - } - - @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new FeaturesFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new FeaturesFile(); } }, - PDB + ScoreMatrix("Substitution matrix", "", false, false) { - @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { - // TODO obtain config value from preference settings. - // Set value to 'true' to test PDB processing with Jmol: JAL-1213 - boolean isParseWithJMOL = !StructureImportSettings - .getCurrentDefaultFormat().equalsIgnoreCase("PDB"); - if (isParseWithJMOL) - { - return new JmolParser( - StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), - StructureImportSettings.isExternalSecondaryStructure(), - inFile, - sourceType); - } - else - { - StructureImportSettings.setShowSeqFeatures(true); - return new MCview.PDBfile( - StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), - StructureImportSettings.isExternalSecondaryStructure(), - inFile, - sourceType); - } + return new ScoreMatrixFile(source); } @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public AlignmentFileWriterI getWriter(AlignmentI al) + { + return null; + } + }, + PDB("PDB", "pdb,ent", true, false) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) throws IOException { - boolean isParseWithJMOL = !StructureImportSettings - .getCurrentDefaultFormat().equalsIgnoreCase("PDB"); + boolean isParseWithJMOL = StructureImportSettings + .getDefaultStructureFileFormat() != PDBEntry.Type.PDB; if (isParseWithJMOL) { - return new JmolParser( - StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), - StructureImportSettings.isExternalSecondaryStructure(), - source); + return new JmolParser(source); } else { StructureImportSettings.setShowSeqFeatures(true); return new MCview.PDBfile( StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), + StructureImportSettings.isProcessSecondaryStructure(), StructureImportSettings.isExternalSecondaryStructure(), source); } } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new JmolParser(); // todo or null? } + @Override + public boolean isStructureFile() + { + return true; + } }, - MMCif + MMCif("mmCIF", "cif", true, false) { - @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { - return new JmolParser( - StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), - StructureImportSettings.isExternalSecondaryStructure(), - inFile, sourceType); + return new JmolParser(source); } @Override - public AlignmentFileI getAlignmentFile(FileParse source) - throws IOException + public AlignmentFileWriterI getWriter(AlignmentI al) { - return new JmolParser( - StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), - StructureImportSettings.isExternalSecondaryStructure(), - source); + return new JmolParser(); // todo or null? } @Override - public AlignmentFileI getAlignmentFile() + public boolean isStructureFile() { - return new JmolParser(); // todo or null? + return true; } }, - Jalview + Jalview("Jalview", "jvp, jar", true, true) { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return null; + } @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException + public AlignmentFileWriterI getWriter(AlignmentI al) { return null; } @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public boolean isTextFormat() + { + return false; + } + + @Override + public boolean isIdentifiable() + { + return false; + } + }, + HMMER3("HMMER3", "hmm", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) throws IOException { - return null; + return new HMMFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { - return null; + return new HMMFile(); } }; + + private boolean writable; + + private boolean readable; + + private String extensions; + + private String name; + @Override public boolean isComplexAlignFile() { @@ -474,8 +406,70 @@ public enum FileFormat implements FileFormatI } @Override - public String getShortDescription() + 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 toString(); + return true; } }