From: gmungoc Date: Tue, 12 Jul 2016 20:55:14 +0000 (+0100) Subject: FileFormat enum new types X-Git-Tag: Release_2_10_3b1~412 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8dd4255a671e95df3fc6d6bc4d5d6b172f682c5d;p=jalview.git FileFormat enum new types --- diff --git a/src/jalview/io/AlignmentFileI.java b/src/jalview/io/AlignmentFileI.java new file mode 100644 index 0000000..bee36f6 --- /dev/null +++ b/src/jalview/io/AlignmentFileI.java @@ -0,0 +1,40 @@ +package jalview.io; + +import jalview.api.AlignExportSettingI; +import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureSettingsModelI; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceI; + +public interface AlignmentFileI +{ + + SequenceI[] getSeqsAsArray(); + + void addAnnotations(AlignmentI al); + + void addGroups(AlignmentI al); + + void setNewlineString(String newline); + + void addJVSuffix(boolean jvsuffix); + + void setExportSettings(AlignExportSettingI exportSettings); + + void configureForView(AlignmentViewPanel viewpanel); + + void setSeqs(SequenceI[] sequencesArray); + + String print(); + + boolean hasWarningMessage(); + + String getWarningMessage(); + + String getInFile(); + + DataSourceType getDataSourceType(); + + FeatureSettingsModelI getFeatureColourScheme(); + +} diff --git a/src/jalview/io/DataSourceType.java b/src/jalview/io/DataSourceType.java new file mode 100644 index 0000000..e2808e8 --- /dev/null +++ b/src/jalview/io/DataSourceType.java @@ -0,0 +1,6 @@ +package jalview.io; + +public enum DataSourceType +{ + FILE, URL, PASTE, CLASSLOADER; +} diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java new file mode 100644 index 0000000..893a8ac --- /dev/null +++ b/src/jalview/io/FileFormat.java @@ -0,0 +1,481 @@ +package jalview.io; + +import jalview.ext.jmol.JmolParser; +import jalview.structure.StructureImportSettings; + +import java.io.IOException; + +public enum FileFormat implements FileFormatI +{ + Fasta + { + @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 + { + @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 + { + @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(); + } + + }, + SimpleBlast + { + @Override + public AlignmentFileI getAlignmentFile(String inFile, + DataSourceType sourceType) throws IOException + { + return new SimpleBlastFile(inFile, sourceType); + } + + @Override + public AlignmentFileI getAlignmentFile(FileParse source) + throws IOException + { + return new SimpleBlastFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new SimpleBlastFile(); + } + }, + + PIR + { + @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 + { + @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(); + } + + }, + Html + { + @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 + { + @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 + { + @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 + { + @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 + { + @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 + { + @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 + { + @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 + { + @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 + { + @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 + { + + @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 + .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); + } + } + + @Override + public AlignmentFileI getAlignmentFile(FileParse source) + throws IOException + { + boolean isParseWithJMOL = !StructureImportSettings + .getCurrentDefaultFormat().equalsIgnoreCase("PDB"); + if (isParseWithJMOL) + { + return new JmolParser( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isPredictSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + source); + } + else + { + StructureImportSettings.setShowSeqFeatures(true); + return new MCview.PDBfile( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isPredictSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + source); + } + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new JmolParser(); // todo or null? + } + + }, + MMCif + { + + @Override + public AlignmentFileI getAlignmentFile(String inFile, + DataSourceType sourceType) throws IOException + { + return new JmolParser( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isPredictSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + inFile, sourceType); + } + + @Override + public AlignmentFileI getAlignmentFile(FileParse source) + throws IOException + { + return new JmolParser( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isPredictSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new JmolParser(); // todo or null? + } + }, + Jalview + { + + @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; + } + }; + + @Override + public boolean isComplexAlignFile() + { + return false; + } + + @Override + public String getShortDescription() + { + return toString(); + } +} diff --git a/src/jalview/io/FileFormatException.java b/src/jalview/io/FileFormatException.java new file mode 100644 index 0000000..c037cf2 --- /dev/null +++ b/src/jalview/io/FileFormatException.java @@ -0,0 +1,13 @@ +package jalview.io; + +import java.io.IOException; + +public class FileFormatException extends IOException +{ + + public FileFormatException(String msg) + { + super(msg); + } + +} diff --git a/src/jalview/io/FileFormatI.java b/src/jalview/io/FileFormatI.java new file mode 100644 index 0000000..c9d56ae --- /dev/null +++ b/src/jalview/io/FileFormatI.java @@ -0,0 +1,19 @@ +package jalview.io; + +import java.io.IOException; + +public interface FileFormatI +{ + + AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) + throws IOException; + + AlignmentFileI getAlignmentFile(FileParse source) throws IOException; + + AlignmentFileI getAlignmentFile(); + + boolean isComplexAlignFile(); + + String getShortDescription(); + +}