From 35ce4609cc8a776b1d85a1f2c2c70aaa106c1a3b Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 11 Jan 2017 16:48:28 +0000 Subject: [PATCH] JAL-2344 separated AlignmentFileI into AlignmentFileReaderI, AlignmentFileWriterI --- examples/groovy/fileFormat.groovy | 1 - src/jalview/appletgui/CutAndPasteTransfer.java | 4 +- src/jalview/gui/CutAndPasteTransfer.java | 4 +- src/jalview/io/AlignFile.java | 3 +- ...ignmentFileI.java => AlignmentFileReaderI.java} | 10 +-- src/jalview/io/AlignmentFileWriterI.java | 24 ++++++ src/jalview/io/AppletFormatAdapter.java | 6 +- src/jalview/io/FileFormat.java | 90 ++++++++++++-------- src/jalview/io/FileFormatI.java | 4 +- src/jalview/io/FileLoader.java | 5 +- src/jalview/io/FormatAdapter.java | 4 +- src/jalview/io/IdentifyFile.java | 2 +- 12 files changed, 96 insertions(+), 61 deletions(-) rename src/jalview/io/{AlignmentFileI.java => AlignmentFileReaderI.java} (69%) create mode 100644 src/jalview/io/AlignmentFileWriterI.java diff --git a/examples/groovy/fileFormat.groovy b/examples/groovy/fileFormat.groovy index 137fec6..c314a6c 100644 --- a/examples/groovy/fileFormat.groovy +++ b/examples/groovy/fileFormat.groovy @@ -3,7 +3,6 @@ import jalview.datamodel.SequenceI import jalview.datamodel.Sequence import jalview.io.FileFormatI import jalview.io.FileFormats -import jalview.io.AlignmentFileI import jalview.io.FileParse import jalview.io.AlignFile diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index d50fcef..c658734 100644 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -28,7 +28,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; -import jalview.io.AlignmentFileI; +import jalview.io.AlignmentFileReaderI; import jalview.io.AnnotationFile; import jalview.io.AppletFormatAdapter; import jalview.io.DataSourceType; @@ -68,7 +68,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, AlignFrame alignFrame; - AlignmentFileI source = null; + AlignmentFileReaderI source = null; public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame) { diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index a81c998..7a0b0af 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -30,7 +30,7 @@ import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; -import jalview.io.AlignmentFileI; +import jalview.io.AlignmentFileReaderI; import jalview.io.AppletFormatAdapter; import jalview.io.DataSourceType; import jalview.io.FileFormatException; @@ -73,7 +73,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer AlignViewportI viewport; - AlignmentFileI source = null; + AlignmentFileReaderI source = null; public CutAndPasteTransfer() { diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index cc5e816..7333075 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -40,7 +40,8 @@ import java.util.Vector; * @author $author$ * @version $Revision$ */ -public abstract class AlignFile extends FileParse implements AlignmentFileI +public abstract class AlignFile extends FileParse implements + AlignmentFileReaderI, AlignmentFileWriterI { int noSeqs = 0; diff --git a/src/jalview/io/AlignmentFileI.java b/src/jalview/io/AlignmentFileReaderI.java similarity index 69% rename from src/jalview/io/AlignmentFileI.java rename to src/jalview/io/AlignmentFileReaderI.java index 1a000a3..77a7643 100644 --- a/src/jalview/io/AlignmentFileI.java +++ b/src/jalview/io/AlignmentFileReaderI.java @@ -6,7 +6,7 @@ import jalview.api.FeatureSettingsModelI; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; -public interface AlignmentFileI +public interface AlignmentFileReaderI { SequenceI[] getSeqsAsArray(); @@ -15,16 +15,8 @@ public interface AlignmentFileI void addGroups(AlignmentI al); - void setNewlineString(String newline); - - void setExportSettings(AlignExportSettingI exportSettings); - - void configureForView(AlignmentViewPanel viewpanel); - void setSeqs(SequenceI[] sequencesArray); - String print(SequenceI[] seqs, boolean jvsuffix); - boolean hasWarningMessage(); String getWarningMessage(); diff --git a/src/jalview/io/AlignmentFileWriterI.java b/src/jalview/io/AlignmentFileWriterI.java new file mode 100644 index 0000000..d8e2dd4 --- /dev/null +++ b/src/jalview/io/AlignmentFileWriterI.java @@ -0,0 +1,24 @@ +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 AlignmentFileWriterI +{ + + void setNewlineString(String newline); + + void setExportSettings(AlignExportSettingI exportSettings); + + void configureForView(AlignmentViewPanel viewpanel); + + String print(SequenceI[] seqs, boolean jvsuffix); + + boolean hasWarningMessage(); + + String getWarningMessage(); + +} diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 1bb7ba3..c5a80e3 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -64,7 +64,7 @@ public class AppletFormatAdapter */ boolean serviceSecondaryStruct = false; - private AlignmentFileI alignFile = null; + private AlignmentFileReaderI alignFile = null; String inFile; @@ -370,7 +370,7 @@ public class AppletFormatAdapter { try { - AlignmentFileI afile = format.getWriter(alignment); + AlignmentFileWriterI afile = format.getWriter(alignment); afile.setNewlineString(newline); afile.setExportSettings(exportSettings); @@ -648,7 +648,7 @@ public class AppletFormatAdapter return null; } - public AlignmentFileI getAlignFile() + public AlignmentFileReaderI getAlignFile() { return alignFile; } diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index 6d7042d..5a95a9e 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -12,13 +12,14 @@ public enum FileFormat implements FileFormatI Fasta("Fasta", "fa, fasta, mfa, fastq", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new FastaFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new FastaFile(); } @@ -26,13 +27,14 @@ public enum FileFormat implements FileFormatI Pfam("PFAM", "pfam", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new PfamFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PfamFile(); } @@ -40,13 +42,14 @@ public enum FileFormat implements FileFormatI Stockholm("Stockholm", "sto,stk", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new StockholmFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new StockholmFile(al); } @@ -56,13 +59,14 @@ public enum FileFormat implements FileFormatI PIR("PIR", "pir", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new PIRFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PIRFile(); } @@ -70,13 +74,14 @@ public enum FileFormat implements FileFormatI BLC("BLC", "BLC", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new BLCFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new BLCFile(); } @@ -84,13 +89,14 @@ public enum FileFormat implements FileFormatI AMSA("AMSA", "amsa", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new AMSAFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new AMSAFile(al); } @@ -98,13 +104,14 @@ public enum FileFormat implements FileFormatI Html("HTML", "html", true, false) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new HtmlFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new HtmlFile(); } @@ -119,13 +126,14 @@ public enum FileFormat implements FileFormatI Rnaml("RNAML", "xml,rnaml", true, false) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new RnamlFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new RnamlFile(); } @@ -134,13 +142,14 @@ public enum FileFormat implements FileFormatI Json("JSON", "json", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new JSONFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new JSONFile(); } @@ -155,13 +164,14 @@ public enum FileFormat implements FileFormatI Pileup("PileUp", "pileup", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new PileUpfile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PileUpfile(); } @@ -170,13 +180,14 @@ public enum FileFormat implements FileFormatI MSF("MSF", "msf", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new MSFfile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new MSFfile(); } @@ -185,13 +196,14 @@ public enum FileFormat implements FileFormatI Clustal("Clustal", "aln", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new ClustalFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new ClustalFile(); } @@ -199,13 +211,14 @@ public enum FileFormat implements FileFormatI Phylip("PHYLIP", "phy", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new PhylipFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new PhylipFile(); } @@ -213,7 +226,8 @@ public enum FileFormat implements FileFormatI Jnet("JnetFile", "", false, false) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { JPredFile af = new JPredFile(source); af.removeNonSequences(); @@ -221,7 +235,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return null; // todo is this called? } @@ -230,13 +244,14 @@ public enum FileFormat implements FileFormatI Features("GFF or Jalview features", "gff2,gff3", true, false) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new FeaturesFile(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new FeaturesFile(); } @@ -244,7 +259,8 @@ public enum FileFormat implements FileFormatI PDB("PDB", "pdb,ent", true, false) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { boolean isParseWithJMOL = StructureImportSettings .getDefaultStructureFileFormat() != PDBEntry.Type.PDB; @@ -264,7 +280,7 @@ public enum FileFormat implements FileFormatI } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new JmolParser(); // todo or null? } @@ -278,13 +294,14 @@ public enum FileFormat implements FileFormatI MMCif("mmCIF", "cif", true, false) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return new JmolParser(source); } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return new JmolParser(); // todo or null? } @@ -298,13 +315,14 @@ public enum FileFormat implements FileFormatI Jalview("Jalview", "jar,jvp", true, true) { @Override - public AlignmentFileI getReader(FileParse source) throws IOException + public AlignmentFileReaderI getReader(FileParse source) + throws IOException { return null; } @Override - public AlignmentFileI getWriter(AlignmentI al) + public AlignmentFileWriterI getWriter(AlignmentI al) { return null; } diff --git a/src/jalview/io/FileFormatI.java b/src/jalview/io/FileFormatI.java index 47b9103..e6f390d 100644 --- a/src/jalview/io/FileFormatI.java +++ b/src/jalview/io/FileFormatI.java @@ -6,9 +6,9 @@ import java.io.IOException; public interface FileFormatI { - AlignmentFileI getReader(FileParse source) throws IOException; + AlignmentFileReaderI getReader(FileParse source) throws IOException; - AlignmentFileI getWriter(AlignmentI al); + AlignmentFileWriterI getWriter(AlignmentI al); boolean isComplexAlignFile(); diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index f137395..4f83ab1 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -53,7 +53,8 @@ public class FileLoader implements Runnable FileFormatI format; - AlignmentFileI source = null; // alternative specification of where data comes + AlignmentFileReaderI source = null; // alternative specification of where data + // comes // from @@ -160,7 +161,7 @@ public class FileLoader implements Runnable * @param format * @return alignFrame constructed from file contents */ - public AlignFrame LoadFileWaitTillLoaded(AlignmentFileI source, + public AlignFrame LoadFileWaitTillLoaded(AlignmentFileReaderI source, FileFormatI format) { this.source = source; diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index ce584f2..d9dd79d 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -258,8 +258,8 @@ public class FormatAdapter extends AppletFormatAdapter selectedOnly); } - public AlignmentI readFromFile(AlignmentFileI source, FileFormatI format) - throws IOException + public AlignmentI readFromFile(AlignmentFileReaderI source, + FileFormatI format) throws IOException { FileParse fp = new FileParse(source.getInFile(), source.getDataSourceType()); diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 72a1155..0556e76 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -72,7 +72,7 @@ public class IdentifyFile // preserves original behaviour prior to version 2.3 } - public FileFormatI identify(AlignmentFileI file, boolean closeSource) + public FileFormatI identify(AlignmentFileReaderI file, boolean closeSource) throws IOException { FileParse fp = new FileParse(file.getInFile(), file.getDataSourceType()); -- 1.7.10.2