X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileFormat.java;h=21fadd2fe91de4e41fe2ec244f8d2f27a361ef99;hb=4cc3017f070e0bc1b291d9cfaf572b1c9c5e76d3;hp=bca365f62cc972a799be02fc2d4b47ce7b34bd86;hpb=4a5137b64f7ec23db2a09290bfcd392984a52150;p=jalview.git diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index bca365f..21fadd2 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -1,32 +1,45 @@ +/* + * 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; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; public enum FileFormat implements FileFormatI { - Fasta("FASTA", "fa, fasta, mfa, fastq", true, true) + 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(); } @@ -34,44 +47,31 @@ public enum FileFormat implements FileFormatI 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("STH", "sto,stk", true, true) + 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); } }, @@ -79,20 +79,14 @@ public enum FileFormat implements FileFormatI 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new PIRFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PIRFile(); } @@ -100,39 +94,44 @@ public enum FileFormat implements FileFormatI 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) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return new BLCFile(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new BLCFile(); } }, - Html("HTML", "html", true, false) + AMSA("AMSA", "amsa", true, true) { @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { - return new HtmlFile(inFile, sourceType); - } @Override - public AlignmentFileI getAlignmentFile(FileParse source) + 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 AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new HtmlFile(); } @@ -147,40 +146,30 @@ public enum FileFormat implements FileFormatI 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", true, true) + 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(); } @@ -192,22 +181,17 @@ public enum FileFormat implements FileFormatI } }, - Pileup("PileUp", "?", false, false) + 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(); } @@ -216,40 +200,30 @@ public enum FileFormat implements FileFormatI 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", "aln", true, true) + 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(); } @@ -257,21 +231,14 @@ public enum FileFormat implements FileFormatI 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(); } @@ -279,16 +246,7 @@ public enum FileFormat implements FileFormatI 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); @@ -297,164 +255,146 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return null; // todo is this called? } }, - Features("GFF or Jalview features", "gff2,gff3", false, false) + 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("PDB", "", false, false) + 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? } - }, - MMCif("mmCIF", "cif", false, false) - { @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException + public boolean isStructureFile() { - return new JmolParser( - StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), - StructureImportSettings.isExternalSecondaryStructure(), - inFile, sourceType); + return true; } - + }, + MMCif("mmCIF", "cif", true, false) + { @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public AlignmentFileReaderI getReader(FileParse source) throws IOException { - return new JmolParser( - StructureImportSettings.isVisibleChainAnnotation(), - StructureImportSettings.isPredictSecondaryStructure(), - StructureImportSettings.isExternalSecondaryStructure(), - source); + return new JmolParser(source); } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return new JmolParser(); // todo or null? } + + @Override + public boolean isStructureFile() + { + return true; + } }, - Jalview("Jalview", "jar,jvp", true, false) + Bam("bam", "bam", true, true) { + @Override + public AlignmentFileReaderI getReader(FileParse source) + throws IOException + { + return new BamFile(source); + } @Override - public AlignmentFileI getAlignmentFile(String inFile, - DataSourceType sourceType) throws IOException + public AlignmentFileWriterI getWriter(AlignmentI al) { - return null; + return new BamFile(); } @Override - public AlignmentFileI getAlignmentFile(FileParse source) + public boolean isStructureFile() + { + return false; + } + }, + Jalview("Jalview", "jar,jvp", true, true) + { + @Override + public AlignmentFileReaderI getReader(FileParse source) throws IOException { return null; } @Override - public AlignmentFileI getAlignmentFile() + public AlignmentFileWriterI getWriter(AlignmentI al) { return null; } - }; - /** - * A lookup map of enums by upper-cased name - */ - private static Map names; - static - { - names = new HashMap(); - for (FileFormat format : FileFormat.values()) + @Override + public boolean isTextFormat() { - names.put(format.toString().toUpperCase(), format); + return false; } - } + + @Override + public boolean isIdentifiable() + { + return false; + } + }; private boolean writable; @@ -471,27 +411,6 @@ public enum FileFormat implements FileFormatI } @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; @@ -526,4 +445,36 @@ public enum FileFormat implements FileFormatI { 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; + } }