X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileFormat.java;h=91ce5275d5ff3366296eadf9dc4c55a6e8d8fac3;hb=94ca0419cc7afa75b3c51917a8beaf46a7c05540;hp=d0ce86e23421c6800c3d701d9cab104b81cb35b9;hpb=781218e12641a89d5dd99906369d5b9807c1d203;p=jalview.git
diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java
index d0ce86e..91ce527 100644
--- a/src/jalview/io/FileFormat.java
+++ b/src/jalview/io/FileFormat.java
@@ -1,36 +1,46 @@
+/*
+ * 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 java.io.IOException;
+
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefSource;
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)
+ 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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new FastaFile();
}
@@ -38,21 +48,14 @@ 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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new PfamFile();
}
@@ -60,20 +63,14 @@ public enum FileFormat implements FileFormatI
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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new StockholmFile(al);
}
@@ -83,40 +80,29 @@ 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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new PIRFile();
}
},
- BLC("BLC", "BLC", true, true)
+ 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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new BLCFile();
}
@@ -124,21 +110,14 @@ public enum FileFormat implements FileFormatI
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)
+ public AlignmentFileReaderI getReader(FileParse source)
throws IOException
{
return new AMSAFile(source);
}
@Override
- public AlignmentFileI getAlignmentFile(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new AMSAFile(al);
}
@@ -146,19 +125,14 @@ public enum FileFormat implements FileFormatI
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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new HtmlFile();
}
@@ -173,40 +147,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(AlignmentI al)
+ 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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new JSONFile();
}
@@ -221,19 +185,14 @@ public enum FileFormat implements FileFormatI
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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new PileUpfile();
}
@@ -242,19 +201,14 @@ 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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new MSFfile();
}
@@ -263,19 +217,14 @@ public enum FileFormat implements FileFormatI
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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new ClustalFile();
}
@@ -283,38 +232,53 @@ public enum FileFormat implements FileFormatI
Phylip("PHYLIP", "phy", true, true)
{
@Override
- public AlignmentFileI getAlignmentFile(String inFile,
- DataSourceType sourceType) throws IOException
+ public AlignmentFileReaderI getReader(FileParse source)
+ throws IOException
{
- return new PhylipFile(inFile, sourceType);
+ return new PhylipFile(source);
}
@Override
- public AlignmentFileI getAlignmentFile(FileParse source)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
+ {
+ return new PhylipFile();
+ }
+ },
+ GenBank("GenBank Flatfile", "gb,gbk", true, false)
+ {
+ @Override
+ public AlignmentFileReaderI getReader(FileParse source)
throws IOException
{
- return new PhylipFile(source);
+ return new GenBankFile(source, "GenBank");
}
@Override
- public AlignmentFileI getAlignmentFile(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
- return new PhylipFile();
+ return null;
}
},
- Jnet("JnetFile", "", false, false)
+ Embl("ENA Flatfile", "txt", true, false)
{
@Override
- public AlignmentFileI getAlignmentFile(String inFile,
- DataSourceType sourceType) throws IOException
+ public AlignmentFileReaderI getReader(FileParse source)
+ throws IOException
{
- JPredFile af = new JPredFile(inFile, sourceType);
- af.removeNonSequences();
- return af;
+ // Always assume we import from EMBL for now
+ return new EmblFlatFile(source, DBRefSource.EMBL);
}
@Override
- public AlignmentFileI getAlignmentFile(FileParse source)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
+ {
+ return null;
+ }
+ },
+ Jnet("JnetFile", "", false, false)
+ {
+ @Override
+ public AlignmentFileReaderI getReader(FileParse source)
throws IOException
{
JPredFile af = new JPredFile(source);
@@ -323,7 +287,7 @@ public enum FileFormat implements FileFormatI
}
@Override
- public AlignmentFileI getAlignmentFile(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return null; // todo is this called?
}
@@ -332,75 +296,64 @@ public enum FileFormat implements FileFormatI
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(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new FeaturesFile();
}
},
- PDB("PDB", "pdb,ent", true, false)
+ FeatureSettings("Jalview Feature Settings File","fc",false,false)
{
+ @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)
{
- // 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);
- }
+ return null;
+ }
+ },
+ ScoreMatrix("Substitution matrix", "", false, false)
+ {
+ @Override
+ public AlignmentFileReaderI getReader(FileParse source)
+ throws IOException
+ {
+ 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
.getDefaultStructureFileFormat() != PDBEntry.Type.PDB;
if (isParseWithJMOL)
{
- return new JmolParser(
- StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isProcessSecondaryStructure(),
- StructureImportSettings.isExternalSecondaryStructure(),
- source);
+ return new JmolParser(source);
}
else
{
StructureImportSettings.setShowSeqFeatures(true);
- return new MCview.PDBfile(
+ return new mc_view.PDBfile(
StructureImportSettings.isVisibleChainAnnotation(),
StructureImportSettings.isProcessSecondaryStructure(),
StructureImportSettings.isExternalSecondaryStructure(),
@@ -409,61 +362,49 @@ public enum FileFormat implements FileFormatI
}
@Override
- public AlignmentFileI getAlignmentFile(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new JmolParser(); // todo or null?
}
- },
- MMCif("mmCIF", "cif", true, false)
- {
@Override
- public AlignmentFileI getAlignmentFile(String inFile,
- DataSourceType sourceType) throws IOException
+ public boolean isStructureFile()
{
- return new JmolParser(
- StructureImportSettings.isVisibleChainAnnotation(),
- StructureImportSettings.isProcessSecondaryStructure(),
- 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.isProcessSecondaryStructure(),
- StructureImportSettings.isExternalSecondaryStructure(),
- source);
+ return new JmolParser(source);
}
@Override
- public AlignmentFileI getAlignmentFile(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return new JmolParser(); // todo or null?
}
- },
- Jalview("Jalview", "jar,jvp", true, true)
- {
@Override
- public AlignmentFileI getAlignmentFile(String inFile,
- DataSourceType sourceType) throws IOException
+ public boolean isStructureFile()
{
- return null;
+ return true;
}
-
+ },
+ Jalview("Jalview", "jvp,jar", true, true)
+ {
@Override
- public AlignmentFileI getAlignmentFile(FileParse source)
+ public AlignmentFileReaderI getReader(FileParse source)
throws IOException
{
return null;
}
@Override
- public AlignmentFileI getAlignmentFile(AlignmentI al)
+ public AlignmentFileWriterI getWriter(AlignmentI al)
{
return null;
}
@@ -473,20 +414,13 @@ public enum FileFormat implements FileFormatI
{
return false;
}
- };
- /**
- * 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 isIdentifiable()
{
- names.put(format.toString().toUpperCase(), format);
+ return true;
}
- }
+ };
private boolean writable;
@@ -496,65 +430,12 @@ public enum FileFormat implements FileFormatI
private String name;
- /**
- * Answers a list of writeable file formats (as string, corresponding to the
- * toString() and forName() methods)
- *
- * @return
- */
- public static List getWritableFormats(boolean textOnly)
- {
- List l = new ArrayList();
- for (FileFormatI ff : values())
- {
- if (ff.isWritable() && (!textOnly || ff.isTextFormat()))
- {
- 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;
}
- /**
- * 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()
{
@@ -574,7 +455,10 @@ public enum FileFormat implements FileFormatI
* @param extensions
* comma-separated list of file extensions associated with the format
* @param isReadable
+ * - can be recognised by IdentifyFile and imported with the given
+ * reader
* @param isWritable
+ * - can be exported with the returned writer
*/
private FileFormat(String shortName, String extensions,
boolean isReadable, boolean isWritable)
@@ -591,20 +475,34 @@ 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 toString()
+ public String getName()
{
return name;
}
@Override
- public AlignmentFileI getAlignmentFile()
+ public boolean isTextFormat()
{
- return getAlignmentFile((AlignmentI) null);
+ return true;
}
@Override
- public boolean isTextFormat()
+ 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;
}