From: gmungoc Date: Tue, 30 Aug 2016 11:56:34 +0000 (+0100) Subject: Merge branch 'develop' into features/filetypeEnum X-Git-Tag: Release_2_10_3b1~410 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8b27085fa7fc5f2877e078421284c2636b85b8c6;hp=ddd696878955d609d942c4173dd66a0da9572741;p=jalview.git Merge branch 'develop' into features/filetypeEnum Conflicts: src/jalview/io/AppletFormatAdapter.java src/jalview/io/FormatAdapter.java src/jalview/io/MSFfile.java src/jalview/io/RnamlFile.java src/jalview/io/StockholmFile.java src/jalview/ws/dbsources/Pdb.java test/jalview/ext/jmol/JmolParserTest.java test/jalview/gui/AlignViewportTest.java test/jalview/ws/jabaws/RNAStructExportImport.java --- diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index df98833..1a7e7f5 100644 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -26,6 +26,7 @@ import jalview.appletgui.FeatureRenderer; import jalview.appletgui.SequenceRenderer; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; import jalview.io.StructureFile; import jalview.structure.AtomSpec; import jalview.structure.StructureListener; @@ -145,7 +146,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, StructureSelectionManager ssm; public AppletPDBCanvas(PDBEntry pdbentry, SequenceI[] seq, - String[] chains, AlignmentPanel ap, String protocol) + String[] chains, AlignmentPanel ap, DataSourceType protocol) { this.ap = ap; @@ -159,7 +160,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, { pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol); - if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + if (protocol == DataSourceType.PASTE) { pdbentry.setFile("INLINE" + pdb.getId()); } diff --git a/src/MCview/AppletPDBViewer.java b/src/MCview/AppletPDBViewer.java index 8233ac3..76ee4b0 100644 --- a/src/MCview/AppletPDBViewer.java +++ b/src/MCview/AppletPDBViewer.java @@ -24,6 +24,7 @@ import jalview.appletgui.AlignmentPanel; import jalview.appletgui.EmbmenuFrame; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; import jalview.schemes.BuriedColourScheme; import jalview.schemes.HelixColourScheme; import jalview.schemes.HydrophobicColourScheme; @@ -51,7 +52,7 @@ public class AppletPDBViewer extends EmbmenuFrame implements AppletPDBCanvas pdbcanvas; public AppletPDBViewer(PDBEntry pdbentry, SequenceI[] seq, - String[] chains, AlignmentPanel ap, String protocol) + String[] chains, AlignmentPanel ap, DataSourceType protocol) { try { @@ -73,6 +74,7 @@ public class AppletPDBViewer extends EmbmenuFrame implements } + @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == mapping) @@ -143,6 +145,7 @@ public class AppletPDBViewer extends EmbmenuFrame implements } + @Override public void itemStateChanged(ItemEvent evt) { if (evt.getSource() == allchains) diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index 1c7a1f7..7b4e0f0 100644 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -26,6 +26,7 @@ import jalview.datamodel.SequenceI; import jalview.gui.AlignmentPanel; import jalview.gui.FeatureRenderer; import jalview.gui.SequenceRenderer; +import jalview.io.DataSourceType; import jalview.io.StructureFile; import jalview.structure.AtomSpec; import jalview.structure.StructureListener; @@ -141,7 +142,7 @@ public class PDBCanvas extends JPanel implements MouseListener, String errorMessage; void init(PDBEntry pdbentry, SequenceI[] seq, String[] chains, - AlignmentPanel ap, String protocol) + AlignmentPanel ap, DataSourceType protocol) { this.ap = ap; this.pdbentry = pdbentry; @@ -153,7 +154,7 @@ public class PDBCanvas extends JPanel implements MouseListener, { pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol); - if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + if (protocol.equals(jalview.io.DataSourceType.PASTE)) { pdbentry.setFile("INLINE" + pdb.getId()); } diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index d5f0d0b..39bc4ef 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -26,6 +26,7 @@ import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.gui.OOMWarning; import jalview.gui.UserDefinedColours; +import jalview.io.DataSourceType; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.schemes.BuriedColourScheme; @@ -79,12 +80,12 @@ public class PDBViewer extends JInternalFrame implements Runnable AlignmentPanel ap; - String protocol; + DataSourceType protocol; String tmpPDBFile; public PDBViewer(PDBEntry pdbentry, SequenceI[] seq, String[] chains, - AlignmentPanel ap, String protocol) + AlignmentPanel ap, DataSourceType protocol) { this.pdbentry = pdbentry; this.seq = seq; @@ -113,7 +114,7 @@ public class PDBViewer extends JInternalFrame implements Runnable { tmpPDBFile = pdbentry.getFile(); PDBfile pdbfile = new PDBfile(false, false, false, tmpPDBFile, - jalview.io.AppletFormatAdapter.FILE); + DataSourceType.FILE); pdbcanvas.init(pdbentry, seq, chains, ap, protocol); diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index 2746807..060de45 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -23,6 +23,7 @@ package MCview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.DBRefSource; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.io.StructureFile; import jalview.util.MessageManager; @@ -46,10 +47,11 @@ public class PDBfile extends StructureFile } public PDBfile(boolean addAlignmentAnnotations, boolean predictSecStr, - boolean externalSecStr, String dataObject, String protocol) + boolean externalSecStr, String dataObject, + DataSourceType sourceType) throws IOException { - super(false, dataObject, protocol); + super(false, dataObject, sourceType); addSettings(addAlignmentAnnotations, predictSecStr, externalSecStr); doParse(); } @@ -64,7 +66,7 @@ public class PDBfile extends StructureFile } @Override - public String print() + public String print(SequenceI[] seqs, boolean jvSuffix) { return null; } diff --git a/src/jalview/api/AlignViewControllerI.java b/src/jalview/api/AlignViewControllerI.java index 26966ba..b868ee5 100644 --- a/src/jalview/api/AlignViewControllerI.java +++ b/src/jalview/api/AlignViewControllerI.java @@ -20,6 +20,8 @@ */ package jalview.api; +import jalview.io.DataSourceType; + import java.util.List; /** @@ -88,13 +90,13 @@ public interface AlignViewControllerI * add a features file of some kind to the current view * * @param file - * @param protocol + * @param sourceType * @param relaxedIdMatching * if true, try harder to match up IDs with local sequence data * @return true if parsing resulted in something being imported to the view or * dataset */ - public boolean parseFeaturesFile(String file, String protocol, + public boolean parseFeaturesFile(String file, DataSourceType sourceType, boolean relaxedIdMatching); } diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index ec7cd25..abb6848 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -24,6 +24,7 @@ import jalview.analysis.AAFrequency; import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; import jalview.analysis.Conservation; +import jalview.bin.JalviewLite; import jalview.commands.ChangeCaseCommand; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; @@ -35,6 +36,8 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; import jalview.io.SequenceAnnotationReport; import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.BuriedColourScheme; @@ -824,15 +827,16 @@ public class APopupMenu extends java.awt.PopupMenu implements Frame frame = new Frame(); frame.add(cap); - jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage( + JalviewLite.addFrame(frame, MessageManager.formatMessage( "label.selection_output_command", new Object[] { e.getActionCommand() }), 600, 500); // JBPNote: getSelectionAsNewSequence behaviour has changed - this method // now returns a full copy of sequence data // TODO consider using getSequenceSelection instead here - cap.setText(new jalview.io.AppletFormatAdapter().formatSequences( - e.getActionCommand(), ap.av.getShowJVSuffix(), ap, true)); + FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand()); + cap.setText(new AppletFormatAdapter().formatSequences(fileFormat, + ap.av.getShowJVSuffix(), ap, true)); } @@ -900,12 +904,12 @@ public class APopupMenu extends java.awt.PopupMenu implements if (ap.av.applet.jmolAvailable) { new jalview.appletgui.AppletJmol(entry, new SequenceI[] { seq }, - null, ap, AppletFormatAdapter.URL); + null, ap, DataSourceType.URL); } else { new MCview.AppletPDBViewer(entry, new SequenceI[] { seq }, null, - ap, AppletFormatAdapter.URL); + ap, DataSourceType.URL); } } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 0312015..2ee86f1 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -49,7 +49,9 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.AnnotationFile; import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; import jalview.io.FeaturesFile; +import jalview.io.FileFormat; import jalview.io.TCoffeeScoreFile; import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.BuriedColourScheme; @@ -346,7 +348,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, * is protocol for accessing data referred to by file */ - public boolean parseFeaturesFile(String file, String type) + public boolean parseFeaturesFile(String file, DataSourceType type) { return parseFeaturesFile(file, type, true); } @@ -356,14 +358,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, * * @param file * file URL, content, or other resolvable path - * @param type + * @param paste * is protocol for accessing data referred to by file * @param autoenabledisplay * when true, display features flag will be automatically enabled if * features are loaded * @return true if data parsed as a features file */ - public boolean parseFeaturesFile(String file, String type, + public boolean parseFeaturesFile(String file, DataSourceType paste, boolean autoenabledisplay) { boolean featuresFile = false; @@ -373,7 +375,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, .getFeatureRenderer().getFeatureColours(); boolean relaxedIdMatching = viewport.applet.getDefaultParameter( "relaxedidmatch", false); - featuresFile = new FeaturesFile(file, type).parse( + featuresFile = new FeaturesFile(file, paste).parse( viewport.getAlignment(), colours, true, relaxedIdMatching); } catch (Exception ex) { @@ -1360,13 +1362,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this); Frame frame = new Frame(); frame.add(cap); - jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage( + JalviewLite.addFrame(frame, MessageManager.formatMessage( "label.alignment_output_command", new Object[] { e.getActionCommand() }), 600, 500); - FeatureRenderer fr = this.alignPanel.cloneFeatureRenderer(); + FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand()); cap.setText(new AppletFormatAdapter(alignPanel).formatSequences( - e.getActionCommand(), viewport.getAlignment(), + fileFormat, viewport.getAlignment(), viewport.getShowJVSuffix())); } @@ -4021,7 +4023,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } // resolve data source // TODO: this code should be a refactored to an io package - String protocol = AppletFormatAdapter.resolveProtocol(pdbFile, "PDB"); + DataSourceType protocol = AppletFormatAdapter.resolveProtocol( + pdbFile, FileFormat.PDB); if (protocol == null) { return false; @@ -4031,9 +4034,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // make a note of the access mode and add if (pdbentry.getProperty() == null) { - pdbentry.setProperty(new Hashtable()); + pdbentry.setProperty(new Hashtable()); } - pdbentry.getProperty().put("protocol", protocol); + pdbentry.getProperty().put("protocol", protocol.toString()); toaddpdb.addPDBId(pdbentry); alignPanel.getStructureSelectionManager() .registerPDBEntry(pdbentry); @@ -4070,7 +4073,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } public void newStructureView(JalviewLite applet, PDBEntry pdb, - SequenceI[] seqs, String[] chains, String protocol) + SequenceI[] seqs, String[] chains, DataSourceType protocol) { // Scrub any null sequences from the array Object[] sqch = cleanSeqChainArrays(seqs, chains); @@ -4081,10 +4084,16 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, System.err .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to."); } - if (protocol == null || protocol.trim().length() == 0 - || protocol.equals("null")) + if (protocol == null) { - protocol = (String) pdb.getProperty().get("protocol"); + String sourceType = pdb.getProperty().get("protocol"); + try + { + protocol = DataSourceType.valueOf(sourceType); + } catch (IllegalArgumentException e) + { + // ignore + } if (protocol == null) { System.err.println("Couldn't work out protocol to open structure: " @@ -4107,12 +4116,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { // can only do alignments with Jmol // find the last jmol window assigned to this alignment - jalview.appletgui.AppletJmol ajm = null, tajm; - Vector jmols = applet - .getAppletWindow(jalview.appletgui.AppletJmol.class); + AppletJmol ajm = null, tajm; + Vector jmols = applet.getAppletWindow(AppletJmol.class); for (int i = 0, iSize = jmols.size(); i < iSize; i++) { - tajm = (jalview.appletgui.AppletJmol) jmols.elementAt(i); + tajm = (AppletJmol) jmols.elementAt(i); if (tajm.ap.alignFrame == this) { ajm = tajm; @@ -4131,7 +4139,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // otherwise, create a new window if (applet.jmolAvailable) { - new jalview.appletgui.AppletJmol(pdb, seqs, chains, alignPanel, + new AppletJmol(pdb, seqs, chains, alignPanel, protocol); applet.lastFrameX += 40; applet.lastFrameY += 40; diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 8374721..18e7d1a 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -20,11 +20,12 @@ */ package jalview.appletgui; +import jalview.bin.JalviewLite; import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; import jalview.io.FileParse; +import jalview.io.DataSourceType; import jalview.io.StructureFile; import jalview.schemes.BuriedColourScheme; import jalview.schemes.HelixColourScheme; @@ -176,7 +177,7 @@ public class AppletJmol extends EmbmenuFrame implements } public AppletJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains, - AlignmentPanel ap, String protocol) + AlignmentPanel ap, DataSourceType protocol) { this.ap = ap; jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(), @@ -185,7 +186,7 @@ public class AppletJmol extends EmbmenuFrame implements jmb.setColourBySequence(true); if (pdbentry.getId() == null || pdbentry.getId().length() < 1) { - if (protocol.equals(AppletFormatAdapter.PASTE)) + if (protocol == DataSourceType.PASTE) { pdbentry.setId("PASTED PDB" + (chains == null ? "_" : chains.toString())); @@ -196,7 +197,7 @@ public class AppletJmol extends EmbmenuFrame implements } } - if (jalview.bin.JalviewLite.debug) + if (JalviewLite.debug) { System.err .println("AppletJmol: PDB ID is '" + pdbentry.getId() + "'"); @@ -292,20 +293,20 @@ public class AppletJmol extends EmbmenuFrame implements }); if (pdbentry.getProperty() == null) { - pdbentry.setProperty(new Hashtable()); - pdbentry.getProperty().put("protocol", protocol); + pdbentry.setProperty(new Hashtable()); + pdbentry.getProperty().put("protocol", protocol.toString()); } if (pdbentry.getFile() != null) { // import structure data from pdbentry.getFile based on given protocol - if (protocol.equals(AppletFormatAdapter.PASTE)) + if (protocol == DataSourceType.PASTE) { // TODO: JAL-623 : correctly record file contents for matching up later // pdbentry.getProperty().put("pdbfilehash",""+pdbentry.getFile().hashCode()); loadInline(pdbentry.getFile()); } - else if (protocol.equals(AppletFormatAdapter.FILE) - || protocol.equals(AppletFormatAdapter.URL)) + else if (protocol == DataSourceType.FILE + || protocol == DataSourceType.URL) { jmb.viewer.openFile(pdbentry.getFile()); } diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 6ec5b4d..92dff7b 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -24,6 +24,7 @@ import jalview.api.AlignmentViewPanel; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JalviewJmolBinding; +import jalview.io.DataSourceType; import jalview.structure.StructureSelectionManager; import java.awt.Container; @@ -45,7 +46,7 @@ class AppletJmolBinding extends JalviewJmolBinding public AppletJmolBinding(AppletJmol appletJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry, - SequenceI[][] seq, String[][] chains, String protocol) + SequenceI[][] seq, String[][] chains, DataSourceType protocol) { super(sSm, pdbentry, seq, chains, protocol); appletJmolBinding = appletJmol; @@ -113,12 +114,14 @@ class AppletJmolBinding extends JalviewJmolBinding appletJmolBinding.updateTitleAndMenus(); } + @Override public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; colourBySequence(ap); } + @Override public void showUrl(String url) { try @@ -143,6 +146,7 @@ class AppletJmolBinding extends JalviewJmolBinding // do nothing. } + @Override public void selectionChanged(BS arg0) { // TODO Auto-generated method stub diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index bbaeb68..d50fcef 100644 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -28,9 +28,11 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.io.AlignmentFileI; import jalview.io.AnnotationFile; import jalview.io.AppletFormatAdapter; -import jalview.io.FileParse; +import jalview.io.DataSourceType; +import jalview.io.FileFormatI; import jalview.io.IdentifyFile; import jalview.io.NewickFile; import jalview.io.TCoffeeScoreFile; @@ -51,6 +53,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.io.IOException; public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener @@ -65,7 +68,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, AlignFrame alignFrame; - FileParse source = null; + AlignmentFileI source = null; public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame) { @@ -194,7 +197,8 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, { try { - NewickFile fin = new NewickFile(textarea.getText(), "Paste"); + NewickFile fin = new NewickFile(textarea.getText(), + DataSourceType.PASTE); fin.parse(); if (fin.getTree() != null) @@ -225,17 +229,14 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, { AlignmentI al = null; - String format = new IdentifyFile().identify(text, - AppletFormatAdapter.PASTE); - AppletFormatAdapter afa = new AppletFormatAdapter(alignFrame.alignPanel); try { - al = afa.readFile(text, AppletFormatAdapter.PASTE, format); + FileFormatI format = new IdentifyFile().identify(text, + DataSourceType.PASTE); + AppletFormatAdapter afa = new AppletFormatAdapter( + alignFrame.alignPanel); + al = afa.readFile(text, DataSourceType.PASTE, format); source = afa.getAlignFile(); - } catch (java.io.IOException ex) - { - ex.printStackTrace(); - } if (al != null) { @@ -296,6 +297,10 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, .getString("label.successfully_pasted_alignment_file")); } } + } catch (IOException ex) + { + ex.printStackTrace(); + } } /** @@ -306,7 +311,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, * @param al * @return */ - protected boolean openSplitFrame(AlignmentI al, String format) + protected boolean openSplitFrame(AlignmentI al, FileFormatI format) { final AlignmentI thisAlignment = this.alignFrame.getAlignViewport() .getAlignment(); @@ -376,7 +381,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, try { tcf = new TCoffeeScoreFile(textarea.getText(), - jalview.io.AppletFormatAdapter.PASTE); + jalview.io.DataSourceType.PASTE); if (tcf.isValid()) { if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(), true)) @@ -409,7 +414,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, if (tcf == null) { if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport, - textarea.getText(), jalview.io.AppletFormatAdapter.PASTE)) + textarea.getText(), jalview.io.DataSourceType.PASTE)) { alignFrame.alignPanel.fontChanged(); alignFrame.alignPanel.setScrollValues(0, 0); @@ -421,7 +426,7 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, else { if (!alignFrame.parseFeaturesFile(textarea.getText(), - jalview.io.AppletFormatAdapter.PASTE)) + jalview.io.DataSourceType.PASTE)) { alignFrame.statusBar .setText(MessageManager @@ -445,12 +450,12 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, if (alignFrame.alignPanel.av.applet.jmolAvailable) { new jalview.appletgui.AppletJmol(pdb, new SequenceI[] { seq }, null, - alignFrame.alignPanel, AppletFormatAdapter.PASTE); + alignFrame.alignPanel, DataSourceType.PASTE); } else { new MCview.AppletPDBViewer(pdb, new SequenceI[] { seq }, null, - alignFrame.alignPanel, AppletFormatAdapter.PASTE); + alignFrame.alignPanel, DataSourceType.PASTE); } } diff --git a/src/jalview/appletgui/ExtJmol.java b/src/jalview/appletgui/ExtJmol.java index 929a871..a402ae0 100644 --- a/src/jalview/appletgui/ExtJmol.java +++ b/src/jalview/appletgui/ExtJmol.java @@ -26,6 +26,7 @@ import jalview.api.SequenceRenderer; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JalviewJmolBinding; +import jalview.io.DataSourceType; import java.awt.Container; import java.util.ArrayList; @@ -48,9 +49,9 @@ public class ExtJmol extends JalviewJmolBinding private AlignmentPanel ap; - protected ExtJmol(jalview.appletgui.AlignFrame alframe, + protected ExtJmol(AlignFrame alframe, PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains, - String protocol) + DataSourceType protocol) { super(alframe.alignPanel.getStructureSelectionManager(), pdbentry, seq, chains, protocol); @@ -64,6 +65,7 @@ public class ExtJmol extends JalviewJmolBinding notifyFileLoaded(null, null, null, null, 0); } + @Override public void updateColours(Object source) { @@ -71,6 +73,7 @@ public class ExtJmol extends JalviewJmolBinding } + @Override public void showUrl(String arg0) { showUrl(arg0, "jmol"); @@ -126,6 +129,7 @@ public class ExtJmol extends JalviewJmolBinding // ignore } + @Override public void selectionChanged(BS arg0) { System.out.println(arg0); diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 3294c26..1ab837f 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -28,8 +28,11 @@ import jalview.gui.Desktop; import jalview.gui.PromptUserConfig; import jalview.io.AppletFormatAdapter; import jalview.io.BioJsHTMLOutput; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; import jalview.io.FileLoader; -import jalview.io.FormatAdapter; import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.NewickFile; @@ -344,7 +347,9 @@ public class Jalview BioJsHTMLOutput.updateBioJS(); } - String file = null, protocol = null, format = null, data = null; + String file = null, data = null; + FileFormatI format = null; + DataSourceType protocol = null; FileLoader fileLoader = new FileLoader(!headless); Vector getFeatures = null; // vector of das source nicknames to // fetch @@ -377,13 +382,13 @@ public class Jalview { try { - String viprotocol = AppletFormatAdapter + DataSourceType viprotocol = AppletFormatAdapter .checkProtocol(vamsasImport); - if (viprotocol == jalview.io.FormatAdapter.FILE) + if (viprotocol == DataSourceType.FILE) { inSession = desktop.vamsasImport(new File(vamsasImport)); } - else if (viprotocol == FormatAdapter.URL) + else if (viprotocol == DataSourceType.URL) { inSession = desktop.vamsasImport(new URL(vamsasImport)); } @@ -472,7 +477,13 @@ public class Jalview protocol = AppletFormatAdapter.checkProtocol(file); - format = new IdentifyFile().identify(file, protocol); + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e1) + { + // TODO ? + } AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format); @@ -617,17 +628,17 @@ public class Jalview String imageName = "unnamed.png"; while (aparser.getSize() > 1) { - format = aparser.nextValue(); + String outputFormat = aparser.nextValue(); file = aparser.nextValue(); - if (format.equalsIgnoreCase("png")) + if (outputFormat.equalsIgnoreCase("png")) { af.createPNG(new File(file)); imageName = (new File(file)).getName(); System.out.println("Creating PNG image: " + file); continue; } - else if (format.equalsIgnoreCase("svg")) + else if (outputFormat.equalsIgnoreCase("svg")) { File imageFile = new File(file); imageName = imageFile.getName(); @@ -635,7 +646,7 @@ public class Jalview System.out.println("Creating SVG image: " + file); continue; } - else if (format.equalsIgnoreCase("html")) + else if (outputFormat.equalsIgnoreCase("html")) { File imageFile = new File(file); imageName = imageFile.getName(); @@ -643,13 +654,13 @@ public class Jalview System.out.println("Creating HTML image: " + file); continue; } - else if (format.equalsIgnoreCase("imgMap")) + else if (outputFormat.equalsIgnoreCase("imgMap")) { af.createImageMap(new File(file), imageName); System.out.println("Creating image map: " + file); continue; } - else if (format.equalsIgnoreCase("eps")) + else if (outputFormat.equalsIgnoreCase("eps")) { File outputFile = new File(file); System.out.println("Creating EPS file: " @@ -698,20 +709,26 @@ public class Jalview jalview.bin.Cache.removeProperty("STARTUP_FILE"); } - protocol = "File"; + protocol = DataSourceType.FILE; if (file.indexOf("http:") > -1) { - protocol = "URL"; + protocol = DataSourceType.URL; } if (file.endsWith(".jar")) { - format = "Jalview"; + format = FileFormat.Jalview; } else { - format = new IdentifyFile().identify(file, protocol); + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e) + { + // TODO what? + } } startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol, diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 210a07a..7f15b3e 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -37,6 +37,9 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.AnnotationFile; import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FileParse; import jalview.io.IdentifyFile; import jalview.io.JPredFile; @@ -63,6 +66,7 @@ import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; @@ -513,21 +517,23 @@ public class JalviewLite extends Applet implements { try { + FileFormatI theFormat = FileFormat.valueOf(format); boolean seqlimits = suffix.equalsIgnoreCase(TRUE); if (alf.viewport.getSelectionGroup() != null) { // JBPNote: getSelectionAsNewSequence behaviour has changed - this // method now returns a full copy of sequence data // TODO consider using getSequenceSelection instead here - String reply = new AppletFormatAdapter().formatSequences(format, + String reply = new AppletFormatAdapter().formatSequences(theFormat, new Alignment(alf.viewport.getSelectionAsNewSequence()), seqlimits); return reply; } - } catch (Exception ex) + } catch (IllegalArgumentException ex) { ex.printStackTrace(); - return "Error retrieving alignment in " + format + " format. "; + return "Error retrieving alignment, possibly invalid format specifier: " + + format; } return ""; } @@ -709,13 +715,15 @@ public class JalviewLite extends Applet implements { boolean seqlimits = suffix.equalsIgnoreCase(TRUE); - String reply = new AppletFormatAdapter().formatSequences(format, + FileFormatI theFormat = FileFormat.valueOf(format); + String reply = new AppletFormatAdapter().formatSequences(theFormat, alf.viewport.getAlignment(), seqlimits); return reply; - } catch (Exception ex) + } catch (IllegalArgumentException ex) { ex.printStackTrace(); - return "Error retrieving alignment in " + format + " format. "; + return "Error retrieving alignment, possibly invalid format specifier: " + + format; } } @@ -741,14 +749,14 @@ public class JalviewLite extends Applet implements public void loadAnnotationFrom(AlignFrame alf, String annotation) { if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(), - annotation, AppletFormatAdapter.PASTE)) + annotation, DataSourceType.PASTE)) { alf.alignPanel.fontChanged(); alf.alignPanel.setScrollValues(0, 0); } else { - alf.parseFeaturesFile(annotation, AppletFormatAdapter.PASTE); + alf.parseFeaturesFile(annotation, DataSourceType.PASTE); } } @@ -774,7 +782,7 @@ public class JalviewLite extends Applet implements public boolean loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay) { - return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE, + return alf.parseFeaturesFile(features, DataSourceType.PASTE, autoenabledisplay); } @@ -882,17 +890,17 @@ public class JalviewLite extends Applet implements { AlignmentI al = null; - String format = new IdentifyFile().identify(text, - AppletFormatAdapter.PASTE); try { - al = new AppletFormatAdapter().readFile(text, - AppletFormatAdapter.PASTE, format); + FileFormatI format = new IdentifyFile().identify(text, + DataSourceType.PASTE); + al = new AppletFormatAdapter().readFile(text, DataSourceType.PASTE, + format); if (al.getHeight() > 0) { return new AlignFrame(al, this, title, false); } - } catch (java.io.IOException ex) + } catch (IOException ex) { ex.printStackTrace(); } @@ -1818,7 +1826,7 @@ public class JalviewLite extends Applet implements /** * State variable: protocol for access to file source */ - String protocol; + DataSourceType protocol; String _file; // alignment file or URL spec @@ -1848,7 +1856,7 @@ public class JalviewLite extends Applet implements */ if (path.startsWith("PASTE")) { - protocol = AppletFormatAdapter.PASTE; + protocol = DataSourceType.PASTE; return path.substring(5); } @@ -1857,7 +1865,7 @@ public class JalviewLite extends Applet implements */ if (path.indexOf("://") != -1) { - protocol = AppletFormatAdapter.URL; + protocol = DataSourceType.URL; return path; } @@ -1873,7 +1881,7 @@ public class JalviewLite extends Applet implements System.err.println("Prepended document base '" + documentBase + "' to make: '" + withDocBase + "'"); } - protocol = AppletFormatAdapter.URL; + protocol = DataSourceType.URL; return withDocBase; } @@ -1886,7 +1894,7 @@ public class JalviewLite extends Applet implements if (!withCodeBase.equals(withDocBase) && HttpUtils.isValidUrl(withCodeBase)) { - protocol = AppletFormatAdapter.URL; + protocol = DataSourceType.URL; if (debug) { System.err.println("Prepended codebase '" + codeBase @@ -1901,7 +1909,7 @@ public class JalviewLite extends Applet implements */ if (inArchive(path)) { - protocol = AppletFormatAdapter.CLASSLOADER; + protocol = DataSourceType.CLASSLOADER; } return path; } @@ -2015,11 +2023,12 @@ public class JalviewLite extends Applet implements return null; } String resolvedFile = resolveFileProtocol(fileParam); - String format = new IdentifyFile().identify(resolvedFile, protocol); - dbgMsg("File identified as '" + format + "'"); AlignmentI al = null; try { + FileFormatI format = new IdentifyFile().identify(resolvedFile, + protocol); + dbgMsg("File identified as '" + format + "'"); al = new AppletFormatAdapter().readFile(resolvedFile, protocol, format); if ((al != null) && (al.getHeight() > 0)) @@ -2036,7 +2045,7 @@ public class JalviewLite extends Applet implements // update the focus. currentAlignFrame = newAlignFrame; - if (protocol == AppletFormatAdapter.PASTE) + if (protocol == DataSourceType.PASTE) { newAlignFrame.setTitle(MessageManager.formatMessage( "label.sequences_from", new Object[] { applet @@ -2207,8 +2216,7 @@ public class JalviewLite extends Applet implements } else { - pdbs.addElement(new Object[] { pdb, seqs, chains, - new String(protocol) }); + pdbs.addElement(new Object[] { pdb, seqs, chains, protocol }); } } } diff --git a/src/jalview/bin/JalviewLiteURLRetrieve.java b/src/jalview/bin/JalviewLiteURLRetrieve.java index fd88028..156e146 100644 --- a/src/jalview/bin/JalviewLiteURLRetrieve.java +++ b/src/jalview/bin/JalviewLiteURLRetrieve.java @@ -22,7 +22,11 @@ package jalview.bin; import jalview.datamodel.AlignmentI; import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FileParse; +import jalview.io.IdentifyFile; import java.applet.Applet; import java.io.InputStream; @@ -45,6 +49,7 @@ public class JalviewLiteURLRetrieve extends Applet * * @return void */ + @Override public void init() { this.setSize(300, 200); @@ -55,7 +60,7 @@ public class JalviewLiteURLRetrieve extends Applet .println("Specify a resource to read on the file parameter"); return; } - String protocol = null; + DataSourceType protocol = null; try { System.out.println("Loading thread started with:\n>>file\n" + file @@ -75,7 +80,7 @@ public class JalviewLiteURLRetrieve extends Applet + (rtn ? "" : "not") + " located by classloader."); if (rtn) { - protocol = AppletFormatAdapter.CLASSLOADER; + protocol = DataSourceType.CLASSLOADER; } } catch (Exception ex) @@ -85,12 +90,12 @@ public class JalviewLiteURLRetrieve extends Applet } if (file.indexOf("://") > -1) { - protocol = AppletFormatAdapter.URL; + protocol = DataSourceType.URL; } else { // skipping codebase prepend check. - protocol = AppletFormatAdapter.FILE; + protocol = DataSourceType.FILE; } System.out.println("Trying to get contents of resource:"); @@ -110,10 +115,10 @@ public class JalviewLiteURLRetrieve extends Applet + " cannot be read with protocol==" + protocol); return; } - String format = getParameter("format"); - if (format == null || format.length() == 0) + FileFormatI format = FileFormat.valueOf(getParameter("format")); + if (format == null) { - format = new jalview.io.IdentifyFile().identify(file, protocol); + format = new IdentifyFile().identify(file, protocol); System.out.println("Format is " + format); } else @@ -132,7 +137,7 @@ public class JalviewLiteURLRetrieve extends Applet if (al != null) { System.out.println(new AppletFormatAdapter().formatSequences( - "FASTA", al, false)); + FileFormat.Fasta, al, false)); } } catch (Exception e) { diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index f508bc3..7d60dc8 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -33,6 +33,7 @@ import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; import jalview.io.FeaturesFile; import jalview.util.MessageManager; @@ -349,7 +350,7 @@ public class AlignViewController implements AlignViewControllerI } @Override - public boolean parseFeaturesFile(String file, String protocol, + public boolean parseFeaturesFile(String file, DataSourceType protocol, boolean relaxedIdMatching) { boolean featuresFile = false; diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 32bb761..286e284 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -1742,7 +1742,7 @@ public class Alignment implements AlignmentI @Override public String toString() { - return new FastaFile().print(getSequencesArray()); + return new FastaFile().print(getSequencesArray(), true); } /** diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 1c7df49..37dfdbf 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -34,10 +34,30 @@ public class PDBEntry public enum Type { - PDB, MMCIF, FILE + // TODO is FILE needed; if not is this needed or can we + // use FileFormatI for PDB, MMCIF? + PDB("pdb", "xml"), MMCIF("mmcif", "mmcif"), FILE("?", "?"); + String ext; + + String format; + + private Type(String fmt, String ex) + { + format = fmt; + ext = ex; + } + + public String getFormat() + { + return format; + } + public String getExtension() + { + return ext; + } } - Hashtable properties; + Hashtable properties; /* * (non-Javadoc) @@ -153,7 +173,7 @@ public class PDBEntry this.properties = property; } - public Hashtable getProperty() + public Hashtable getProperty() { return properties; } diff --git a/src/jalview/ext/ensembl/EnsemblRestClient.java b/src/jalview/ext/ensembl/EnsemblRestClient.java index 72efdc1..653d5d5 100644 --- a/src/jalview/ext/ensembl/EnsemblRestClient.java +++ b/src/jalview/ext/ensembl/EnsemblRestClient.java @@ -1,5 +1,6 @@ package jalview.ext.ensembl; +import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.util.StringUtils; @@ -208,7 +209,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher URL url = getUrl(ids); BufferedReader reader = getHttpResponse(url, ids); - FileParse fp = new FileParse(reader, url.toString(), "HTTP_POST"); + FileParse fp = new FileParse(reader, url.toString(), DataSourceType.URL); return fp; } diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 2ccf118..3ee8a34 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -27,7 +27,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; import jalview.io.StructureFile; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; @@ -104,7 +104,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public JalviewJmolBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, - String protocol) + DataSourceType protocol) { super(ssm, pdbentry, sequenceIs, chains, protocol); /* @@ -1140,7 +1140,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // see JAL-623 - need method of matching pasted data up { pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], - pdbfile, AppletFormatAdapter.PASTE); + pdbfile, DataSourceType.PASTE); getPdbEntry(modelnum).setFile("INLINE" + pdb.getId()); matches = true; foundEntry = true; @@ -1158,12 +1158,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // needs // to be tested. See mantis bug // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605 - String protocol = AppletFormatAdapter.URL; + DataSourceType protocol = DataSourceType.URL; try { if (fl.exists()) { - protocol = AppletFormatAdapter.FILE; + protocol = DataSourceType.FILE; } } catch (Exception e) { diff --git a/src/jalview/ext/jmol/JmolParser.java b/src/jalview/ext/jmol/JmolParser.java index 848e7db..858aac7 100644 --- a/src/jalview/ext/jmol/JmolParser.java +++ b/src/jalview/ext/jmol/JmolParser.java @@ -23,6 +23,7 @@ package jalview.ext.jmol; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.io.StructureFile; import jalview.schemes.ResidueProperties; @@ -60,10 +61,10 @@ public class JmolParser extends StructureFile implements JmolStatusListener Viewer viewer = null; public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr, - boolean externalSecStr, String inFile, String type) + boolean externalSecStr, String inFile, DataSourceType sourceType) throws IOException { - super(inFile, type); + super(inFile, sourceType); } public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr, @@ -443,7 +444,7 @@ public class JmolParser extends StructureFile implements JmolStatusListener * Not implemented - returns null */ @Override - public String print() + public String print(SequenceI[] seqs, boolean jvSuffix) { return null; } diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 944ef52..dca7038 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -29,6 +29,7 @@ import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.httpserver.AbstractRequestHandler; +import jalview.io.DataSourceType; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; import jalview.structure.AtomSpec; @@ -197,7 +198,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel */ public JalviewChimeraBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, - String protocol) + DataSourceType protocol) { super(ssm, pdbentry, sequenceIs, chains, protocol); viewer = new ChimeraManager( diff --git a/src/jalview/gui/AlignExportSettings.java b/src/jalview/gui/AlignExportSettings.java index 2a12630..50af20a 100644 --- a/src/jalview/gui/AlignExportSettings.java +++ b/src/jalview/gui/AlignExportSettings.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.api.AlignExportSettingI; import jalview.bin.Jalview; +import jalview.io.FileFormatI; import jalview.jbgui.GAlignExportSettings; import jalview.util.MessageManager; @@ -41,9 +42,9 @@ public class AlignExportSettings extends GAlignExportSettings implements JDialog dialog; public AlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols, - String alignFileFormat) + FileFormatI format) { - super(hasHiddenSeq, hasHiddenCols, alignFileFormat); + super(hasHiddenSeq, hasHiddenCols, format); if (!Jalview.isHeadlessMode() && isShowDialog()) { @@ -53,6 +54,7 @@ public class AlignExportSettings extends GAlignExportSettings implements MessageManager.getString("label.export_settings")); dialog.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { cancelled = true; @@ -66,6 +68,7 @@ public class AlignExportSettings extends GAlignExportSettings implements } } + @Override public void ok_actionPerformed(ActionEvent e) { cancelled = false; @@ -73,6 +76,7 @@ public class AlignExportSettings extends GAlignExportSettings implements dialog.dispose(); } + @Override public void cancel_actionPerformed(ActionEvent e) { cancelled = true; @@ -110,6 +114,7 @@ public class AlignExportSettings extends GAlignExportSettings implements return chkExportGrps.isSelected(); } + @Override public boolean isCancelled() { return cancelled; diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index f6268c0..38223c7 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -65,10 +65,14 @@ import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.AlignmentProperties; import jalview.io.AnnotationFile; import jalview.io.BioJsHTMLOutput; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FileLoader; import jalview.io.FormatAdapter; import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; +import jalview.io.JPredFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.io.JnetAnnotationMaker; @@ -179,7 +183,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Last format used to load or save alignments in this window */ - String currentFileFormat = null; + FileFormatI currentFileFormat = null; /** * Current filename for this alignment @@ -488,7 +492,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param format * format of file */ - public void setFileName(String file, String format) + public void setFileName(String file, FileFormatI format) { fileName = file; setFileFormat(format); @@ -1007,7 +1011,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // originating file's format // TODO: work out how to recover feature settings for correct view(s) when // file is reloaded. - if (currentFileFormat.equals("Jalview")) + if (currentFileFormat == FileFormat.Jalview) { JInternalFrame[] frames = Desktop.desktop.getAllFrames(); for (int i = 0; i < frames.length; i++) @@ -1029,7 +1033,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.instance.closeAssociatedWindows(); FileLoader loader = new FileLoader(); - String protocol = fileName.startsWith("http:") ? "URL" : "File"; + DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL + : DataSourceType.FILE; loader.LoadFile(viewport, fileName, protocol, currentFileFormat); } else @@ -1037,7 +1042,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Rectangle bounds = this.getBounds(); FileLoader loader = new FileLoader(); - String protocol = fileName.startsWith("http:") ? "URL" : "File"; + DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL + : DataSourceType.FILE; AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat); @@ -1081,9 +1087,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void save_actionPerformed(ActionEvent e) { - if (fileName == null - || (currentFileFormat == null || !jalview.io.FormatAdapter - .isValidIOFormat(currentFileFormat, true)) + if (fileName == null || (currentFileFormat == null) || fileName.startsWith("http")) { saveAs_actionPerformed(null); @@ -1103,11 +1107,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void saveAs_actionPerformed(ActionEvent e) { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS, - jalview.io.AppletFormatAdapter.WRITABLE_FNAMES, - currentFileFormat, false); + JalviewFileChooser chooser = JalviewFileChooser.forWrite( + Cache.getProperty("LAST_DIRECTORY"), + // AppletFormatAdapter.WRITABLE_EXTENSIONS, + // AppletFormatAdapter.WRITABLE_FNAMES, + currentFileFormat.toString(), false); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager @@ -1139,24 +1143,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, fileName = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", - currentFileFormat); + Cache.setProperty("DEFAULT_FILE_FORMAT", + currentFileFormat.toString()); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName); - if (currentFileFormat.indexOf(" ") > -1) - { - currentFileFormat = currentFileFormat.substring(0, - currentFileFormat.indexOf(" ")); - } + Cache.setProperty("LAST_DIRECTORY", fileName); saveAlignment(fileName, currentFileFormat); } } - public boolean saveAlignment(String file, String format) + public boolean saveAlignment(String file, FileFormatI format) { boolean success = true; - if (format.equalsIgnoreCase("Jalview")) + if (format == FileFormat.Jalview) { String shortName = title; @@ -1175,16 +1174,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true)) - { - warningMessage("Cannot save file " + fileName + " using format " - + format, "Alignment output format not supported"); - if (!Jalview.isHeadlessMode()) - { - saveAs_actionPerformed(null); - } - return false; - } + // if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true)) + // { + // warningMessage("Cannot save file " + fileName + " using format " + // + format, "Alignment output format not supported"); + // if (!Jalview.isHeadlessMode()) + // { + // saveAs_actionPerformed(null); + // } + // return false; + // } AlignmentExportData exportData = getAlignmentForExport(format, viewport, null); @@ -1264,8 +1263,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void outputText_actionPerformed(ActionEvent e) { + FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand()); AlignmentExportData exportData = getAlignmentForExport( - e.getActionCommand(), viewport, null); +fileFormat, + viewport, null); if (exportData.getSettings().isCancelled()) { return; @@ -1274,8 +1275,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, cap.setForInput(null); try { + FileFormatI format = fileFormat; cap.setText(new FormatAdapter(alignPanel, exportData.getSettings()) - .formatSequences(e.getActionCommand(), + .formatSequences(format, exportData.getAlignment(), exportData.getOmitHidden(), exportData.getStartEndPostions(), @@ -1292,7 +1294,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } public static AlignmentExportData getAlignmentForExport( - String exportFormat, AlignViewportI viewport, + FileFormatI format, AlignViewportI viewport, AlignExportSettingI exportSettings) { AlignmentI alignmentToExport = null; @@ -1308,7 +1310,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (settings == null) { settings = new AlignExportSettings(hasHiddenSeqs, - viewport.hasHiddenColumns(), exportFormat); + viewport.hasHiddenColumns(), format); } // settings.isExportAnnotations(); @@ -1865,7 +1867,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, omitHidden = viewport.getViewAsString(true); } - String output = new FormatAdapter().formatSequences("Fasta", seqs, + String output = new FormatAdapter().formatSequences(FileFormat.Fasta, + seqs, omitHidden, null); StringSelection ss = new StringSelection(output); @@ -1952,7 +1955,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - String str, format; + String str; + FileFormatI format; try { str = (String) contents.getTransferData(DataFlavor.stringFlavor); @@ -1961,7 +1965,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - format = new IdentifyFile().identify(str, "Paste"); + format = new IdentifyFile().identify(str, DataSourceType.PASTE); } catch (OutOfMemoryError er) { @@ -1991,7 +1995,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, else { // parse the clipboard as an alignment. - alignment = new FormatAdapter().readFile(str, "Paste", format); + alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE, + format); sequences = alignment.getSequencesArray(); } @@ -4306,7 +4311,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, jalview.io.NewickFile fin = null; try { - fin = new jalview.io.NewickFile(choice, "File"); + fin = new NewickFile(choice, DataSourceType.FILE); viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree()); } catch (Exception ex) { @@ -4967,11 +4972,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Set the file format * - * @param fileFormat + * @param format */ - public void setFileFormat(String fileFormat) + public void setFileFormat(FileFormatI format) { - this.currentFileFormat = fileFormat; + this.currentFileFormat = format; } /** @@ -4979,14 +4984,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param file * contents or path to retrieve file - * @param type + * @param sourceType * access mode of file (see jalview.io.AlignFile) * @return true if features file was parsed correctly. */ - public boolean parseFeaturesFile(String file, String type) + public boolean parseFeaturesFile(String file, DataSourceType sourceType) { - return avc.parseFeaturesFile(file, type, - jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false)); + return avc.parseFeaturesFile(file, sourceType, + Cache.getDefault("RELAXEDSEQIDMATCHING", false)); } @@ -5028,7 +5033,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void drop(DropTargetDropEvent evt) { Transferable t = evt.getTransferable(); - java.util.List files = new ArrayList(), protocols = new ArrayList(); + List files = new ArrayList(); + List protocols = new ArrayList(); try { @@ -5054,13 +5060,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { String file = files.get(i).toString(); String pdbfn = ""; - String protocol = FormatAdapter.checkProtocol(file); - if (protocol == jalview.io.FormatAdapter.FILE) + DataSourceType protocol = FormatAdapter.checkProtocol(file); + if (protocol == DataSourceType.FILE) { File fl = new File(file); pdbfn = fl.getName(); } - else if (protocol == jalview.io.FormatAdapter.URL) + else if (protocol == DataSourceType.URL) { URL url = new URL(file); pdbfn = url.getFile(); @@ -5084,7 +5090,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (mtch != null) { - String type = null; + FileFormatI type = null; try { type = new IdentifyFile().identify(file, protocol); @@ -5094,7 +5100,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (type != null) { - if (type.equalsIgnoreCase("PDB")) + if (type == FileFormat.PDB) { filesmatched.add(new Object[] { file, protocol, mtch }); continue; @@ -5134,7 +5140,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { PDBEntry pe = new AssociatePdbFileWithSeq() .associatePdbWithSeq((String) fm[0], - (String) fm[1], toassoc, false, + (DataSourceType) fm[1], toassoc, false, Desktop.instance); if (pe != null) { @@ -5193,21 +5199,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param file * either a filename or a URL string. */ - public void loadJalviewDataFile(String file, String protocol, - String format, SequenceI assocSeq) + public void loadJalviewDataFile(String file, DataSourceType sourceType, + FileFormatI format, SequenceI assocSeq) { try { - if (protocol == null) + if (sourceType == null) { - protocol = FormatAdapter.checkProtocol(file); + sourceType = FormatAdapter.checkProtocol(file); } // if the file isn't identified, or not positively identified as some // other filetype (PFAM is default unidentified alignment file type) then // try to parse as annotation. - boolean isAnnotation = (format == null || format - .equalsIgnoreCase("PFAM")) ? new AnnotationFile() - .annotateAlignmentView(viewport, file, protocol) : false; + boolean isAnnotation = (format == null || format == FileFormat.Pfam) ? new AnnotationFile() + .annotateAlignmentView(viewport, file, sourceType) : false; if (!isAnnotation) { @@ -5215,7 +5220,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, TCoffeeScoreFile tcf = null; try { - tcf = new TCoffeeScoreFile(file, protocol); + tcf = new TCoffeeScoreFile(file, sourceType); if (tcf.isValid()) { if (tcf.annotateAlignment(viewport.getAlignment(), true)) @@ -5261,12 +5266,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // try to parse it as a features file if (format == null) { - format = new IdentifyFile().identify(file, protocol); + format = new IdentifyFile().identify(file, sourceType); } - if (format.equalsIgnoreCase("JnetFile")) + if (format == FileFormat.Jnet) { - jalview.io.JPredFile predictions = new jalview.io.JPredFile( - file, protocol); + JPredFile predictions = new JPredFile( + file, sourceType); new JnetAnnotationMaker(); JnetAnnotationMaker.add_annotation(predictions, viewport.getAlignment(), 0, false); @@ -5279,14 +5284,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else if (IdentifyFile.FeaturesFile.equals(format)) { - if (parseFeaturesFile(file, protocol)) + if (parseFeaturesFile(file, sourceType)) { alignPanel.paintAlignment(true); } } else { - new FileLoader().LoadFile(viewport, file, protocol, format); + new FileLoader().LoadFile(viewport, file, sourceType, format); } } } @@ -5311,8 +5316,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } new OOMWarning( "loading data " - + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard." - : "using " + protocol + " from " + file) + + (sourceType != null ? (sourceType == DataSourceType.PASTE ? "from clipboard." + : "using " + sourceType + " from " + file) : ".") + (format != null ? "(parsing as '" + format + "' file)" : ""), oom, Desktop.desktop); diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 62e05d0..d4d2054 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -932,7 +932,7 @@ public class AlignViewport extends AlignmentViewport implements // TODO if we want this (e.g. to enable reload of the alignment from file), // we will need to add parameters to the stack. - // if (!protocol.equals(AppletFormatAdapter.PASTE)) + // if (!protocol.equals(DataSourceType.PASTE)) // { // alignFrame.setFileName(file, format); // } diff --git a/src/jalview/gui/AnnotationChooser.java b/src/jalview/gui/AnnotationChooser.java index 718e0f0..f20d0e6 100644 --- a/src/jalview/gui/AnnotationChooser.java +++ b/src/jalview/gui/AnnotationChooser.java @@ -242,7 +242,7 @@ public class AnnotationChooser extends JPanel * type which are in the application scope (all, selected or unselected * sequences). * - * @param type + * @param dataSourceType */ protected void changeShowHide_actionPerformed() { diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 5b01b9b..d497488 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -27,6 +27,7 @@ import jalview.datamodel.Annotation; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.FileFormat; import jalview.io.FormatAdapter; import jalview.util.MessageManager; @@ -944,8 +945,8 @@ public class AnnotationLabels extends JPanel implements MouseListener, alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex( hiddenCols); } - String output = new FormatAdapter().formatSequences("Fasta", seqs, - omitHidden, alignmentStartEnd); + String output = new FormatAdapter().formatSequences(FileFormat.Fasta, + seqs, omitHidden, alignmentStartEnd); Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(output), Desktop.instance); diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 1c54a5e..6e520e5 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -25,6 +25,7 @@ import jalview.bin.Cache; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JalviewJmolBinding; +import jalview.io.DataSourceType; import jalview.structure.StructureSelectionManager; import java.awt.Container; @@ -42,7 +43,7 @@ public class AppJmolBinding extends JalviewJmolBinding public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, - String protocol) + DataSourceType protocol) { super(sSm, pdbentry, sequenceIs, chains, protocol); appJmolWindow = appJmol; @@ -113,6 +114,7 @@ public class AppJmolBinding extends JalviewJmolBinding // appJmolWindow.repaint(); javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { appJmolWindow.updateTitleAndMenus(); @@ -121,6 +123,7 @@ public class AppJmolBinding extends JalviewJmolBinding }); } + @Override public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; @@ -144,6 +147,7 @@ public class AppJmolBinding extends JalviewJmolBinding // msWalltime); } + @Override public void showUrl(String url) { showUrl(url, "jmol"); diff --git a/src/jalview/gui/AssociatePdbFileWithSeq.java b/src/jalview/gui/AssociatePdbFileWithSeq.java index e2637a9..c380e2f 100644 --- a/src/jalview/gui/AssociatePdbFileWithSeq.java +++ b/src/jalview/gui/AssociatePdbFileWithSeq.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; import jalview.io.StructureFile; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; @@ -44,7 +45,7 @@ public class AssociatePdbFileWithSeq * @param choice * @param sequence */ - public PDBEntry associatePdbWithSeq(String choice, String protocol, + public PDBEntry associatePdbWithSeq(String choice, DataSourceType file, SequenceI sequence, boolean prompt, StructureSelectionManagerProvider ssmp) { @@ -52,7 +53,7 @@ public class AssociatePdbFileWithSeq StructureFile pdbfile = null; pdbfile = StructureSelectionManager.getStructureSelectionManager(ssmp) .setMapping(false, new SequenceI[] { sequence }, null, choice, - protocol); + file); if (pdbfile == null) { // stacktrace already thrown so just return diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index f2244d5..a114f31 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -28,7 +28,7 @@ import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.rbvi.chimera.JalviewChimeraBinding; import jalview.gui.StructureViewer.ViewerType; -import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.schemes.BuriedColourScheme; @@ -660,12 +660,12 @@ public class ChimeraViewFrame extends StructureViewerBase jmb.openFile(pe); jmb.addSequence(pos, jmb.getSequence()[pos]); File fl = new File(pe.getFile()); - String protocol = AppletFormatAdapter.URL; + DataSourceType protocol = DataSourceType.URL; try { if (fl.exists()) { - protocol = AppletFormatAdapter.FILE; + protocol = DataSourceType.FILE; } } catch (Throwable e) { diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 1161340..4e5ef40 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -30,8 +30,11 @@ import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; +import jalview.io.AlignmentFileI; import jalview.io.AppletFormatAdapter; -import jalview.io.FileParse; +import jalview.io.DataSourceType; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; @@ -68,7 +71,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer AlignViewportI viewport; - FileParse source = null; + AlignmentFileI source = null; public CutAndPasteTransfer() { @@ -213,14 +216,21 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer return; } - String format = new IdentifyFile().identify(text, "Paste"); - if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE")) + FileFormatI format = null; + try + { + format = new IdentifyFile().identify(text, DataSourceType.PASTE); + } catch (FileFormatException e1) + { + // leave as null + } + if (format == null) { System.err.println(MessageManager .getString("label.couldnt_read_data")); if (!Jalview.isHeadlessMode()) { - javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop, + JOptionPane.showInternalMessageDialog(Desktop.desktop, AppletFormatAdapter.SUPPORTED_FORMATS, MessageManager.getString("label.couldnt_read_data"), JOptionPane.WARNING_MESSAGE); @@ -231,29 +241,26 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer // TODO: identify feature, annotation or tree file and parse appropriately. AlignmentI al = null; - if (FormatAdapter.isValidFormat(format)) + try { - try - { - FormatAdapter fa = new FormatAdapter(alignpanel); - al = fa.readFile(getText(), "Paste", format); - source = fa.getAlignFile(); + FormatAdapter fa = new FormatAdapter(alignpanel); + al = fa.readFile(getText(), DataSourceType.PASTE, format); + source = fa.getAlignFile(); - } catch (java.io.IOException ex) - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.formatMessage( - "label.couldnt_read_pasted_text", - new String[] { ex.toString() }), MessageManager - .getString("label.error_parsing_text"), - JOptionPane.WARNING_MESSAGE); - } + } catch (java.io.IOException ex) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager + .formatMessage("label.couldnt_read_pasted_text", new String[] + { ex.toString() }), MessageManager + .getString("label.error_parsing_text"), + JOptionPane.WARNING_MESSAGE); } if (al != null && al.hasValidSequence()) { String title = MessageManager.formatMessage( - "label.input_cut_paste_params", new String[] { format }); + "label.input_cut_paste_params", + new String[] { format.getShortDescription() }); FeatureSettingsModelI proxyColourScheme = source .getFeatureColourScheme(); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 7811e41..624054b 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -24,8 +24,11 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.bin.Jalview; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; import jalview.io.FileLoader; -import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; @@ -443,11 +446,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements public void run() { Cache.log.debug("Filechooser init thread started."); - new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS, - jalview.io.AppletFormatAdapter.READABLE_FNAMES, - jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), + // jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS, + // jalview.io.AppletFormatAdapter.READABLE_FNAMES, + fileFormat, true); Cache.log.debug("Filechooser init thread finished."); } }).start(); @@ -667,10 +670,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements String file = (String) contents .getTransferData(DataFlavor.stringFlavor); - String format = new IdentifyFile().identify(file, - FormatAdapter.PASTE); + FileFormatI format = new IdentifyFile().identify(file, + DataSourceType.PASTE); - new FileLoader().LoadFile(file, FormatAdapter.PASTE, format); + new FileLoader().LoadFile(file, DataSourceType.PASTE, format); } } catch (Exception ex) @@ -953,8 +956,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements { boolean success = true; Transferable t = evt.getTransferable(); - java.util.List files = new ArrayList(); - java.util.List protocols = new ArrayList(); + List files = new ArrayList(); + List protocols = new ArrayList(); try { @@ -972,13 +975,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements for (int i = 0; i < files.size(); i++) { String file = files.get(i).toString(); - String protocol = (protocols == null) ? FormatAdapter.FILE - : (String) protocols.get(i); - String format = null; + DataSourceType protocol = (protocols == null) ? DataSourceType.FILE + : protocols.get(i); + FileFormatI format = null; if (file.endsWith(".jar")) { - format = "Jalview"; + format = FileFormat.Jalview; } else @@ -1007,11 +1010,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements @Override public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport) { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS, - jalview.io.AppletFormatAdapter.READABLE_FNAMES, - jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser chooser = JalviewFileChooser.forRead( + Cache.getProperty("LAST_DIRECTORY"), + // AppletFormatAdapter.READABLE_EXTENSIONS, + // AppletFormatAdapter.READABLE_FNAMES, + fileFormat, true); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager @@ -1023,28 +1027,34 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (value == JalviewFileChooser.APPROVE_OPTION) { String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser + Cache.setProperty("LAST_DIRECTORY", chooser .getSelectedFile().getParent()); - String format = null; + FileFormatI format = null; if (chooser.getSelectedFormat() != null - && chooser.getSelectedFormat().equals("Jalview")) + && chooser.getSelectedFormat() == FileFormat.Jalview) { - format = "Jalview"; + format = FileFormat.Jalview; } else { - format = new IdentifyFile().identify(choice, FormatAdapter.FILE); + try + { + format = new IdentifyFile().identify(choice, DataSourceType.FILE); + } catch (FileFormatException e) + { + // format is null + } } if (viewport != null) { - new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, + new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE, format); } else { - new FileLoader().LoadFile(choice, FormatAdapter.FILE, format); + new FileLoader().LoadFile(choice, DataSourceType.FILE, format); } } } @@ -1054,9 +1064,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements * * @param e * DOCUMENT ME! + * @throws FileFormatException */ @Override public void inputURLMenuItem_actionPerformed(AlignViewport viewport) + // throws FileFormatException { // This construct allows us to have a wider textfield // for viewing @@ -1100,19 +1112,28 @@ public class Desktop extends jalview.jbgui.GDesktop implements { if (viewport != null) { - new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, - "Jalview"); + new FileLoader().LoadFile(viewport, url, DataSourceType.URL, + FileFormat.Jalview); } else { - new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview"); + new FileLoader().LoadFile(url, DataSourceType.URL, + FileFormat.Jalview); } } else { - String format = new IdentifyFile().identify(url, FormatAdapter.URL); + FileFormatI format = null; + try + { + format = new IdentifyFile().identify(url, DataSourceType.URL); + } catch (FileFormatException e) + { + // TODO revise error handling, distinguish between + // URL not found and response not valid + } - if (format.equals("URL NOT FOUND")) + if (format == null) { JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager.formatMessage("label.couldnt_locate", @@ -1125,11 +1146,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (viewport != null) { - new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format); + new FileLoader() + .LoadFile(viewport, url, DataSourceType.URL, format); } else { - new FileLoader().LoadFile(url, FormatAdapter.URL, format); + new FileLoader().LoadFile(url, DataSourceType.URL, format); } } } @@ -1512,8 +1534,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements public void saveState_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "jvp" }, new String[] { "Jalview Project" }, + Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project", "Jalview Project"); chooser.setFileView(new JalviewFileView()); @@ -1584,7 +1605,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements public void loadState_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] { + Cache.getProperty("LAST_DIRECTORY"), new String[] { "jvp", "jar" }, new String[] { "Jalview Project", "Jalview Project (old)" }, "Jalview Project"); chooser.setFileView(new JalviewFileView()); @@ -1597,7 +1618,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements final File selectedFile = chooser.getSelectedFile(); setProjectFile(selectedFile); final String choice = selectedFile.getAbsolutePath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", + Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent()); new Thread(new Runnable() { @@ -2168,9 +2189,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (v_client != null) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ - new String[] { "Vamsas Document" }, "Vamsas Document"); + Cache.getProperty("LAST_DIRECTORY"), "vdj", + "Vamsas Document", "Vamsas Document"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager @@ -2184,7 +2204,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements JPanel progpanel = addProgressPanel(MessageManager.formatMessage( "label.saving_vamsas_doc", new Object[] { choice.getName() })); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); + Cache.setProperty("LAST_DIRECTORY", choice.getParent()); String warnmsg = null; String warnttl = null; try @@ -3179,7 +3199,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements } public static void transferFromDropTarget(List files, - List protocols, DropTargetDropEvent evt, Transferable t) + List protocols, DropTargetDropEvent evt, + Transferable t) throws Exception { @@ -3194,7 +3215,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements .getTransferData(DataFlavor.javaFileListFlavor)) { files.add(((File)file).toString()); - protocols.add(FormatAdapter.FILE); + protocols.add(DataSourceType.FILE); } } else @@ -3225,7 +3246,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { Cache.log.debug("Adding missing FILE protocol for " + files.get(protocols.size())); - protocols.add(FormatAdapter.FILE); + protocols.add(DataSourceType.FILE); } for (java.util.StringTokenizer st = new java.util.StringTokenizer( data, "\r\n"); st.hasMoreTokens();) @@ -3240,14 +3261,14 @@ public class Desktop extends jalview.jbgui.GDesktop implements java.net.URI uri = new java.net.URI(s); if (uri.getScheme().toLowerCase().startsWith("http")) { - protocols.add(FormatAdapter.URL); + protocols.add(DataSourceType.URL); files.add(uri.toString()); } else { // otherwise preserve old behaviour: catch all for file objects java.io.File file = new java.io.File(uri); - protocols.add(FormatAdapter.FILE); + protocols.add(DataSourceType.FILE); files.add(file.toString()); } } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 3b8ce37..6dc5cb3 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -750,10 +750,8 @@ public class FeatureSettings extends JPanel implements void load() { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "fc" }, - new String[] { "Sequence Feature Colours" }, - "Sequence Feature Colours"); + Cache.getProperty("LAST_DIRECTORY"), "fc", + "Sequence Feature Colours", "Sequence Feature Colours"); chooser.setFileView(new jalview.io.JalviewFileView()); chooser.setDialogTitle(MessageManager .getString("label.load_feature_colours")); @@ -845,10 +843,8 @@ public class FeatureSettings extends JPanel implements void save() { JalviewFileChooser chooser = new JalviewFileChooser( - Cache.getProperty("LAST_DIRECTORY"), - new String[] { "fc" }, - new String[] { "Sequence Feature Colours" }, - "Sequence Feature Colours"); + Cache.getProperty("LAST_DIRECTORY"), "fc", + "Sequence Feature Colours", "Sequence Feature Colours"); chooser.setFileView(new jalview.io.JalviewFileView()); chooser.setDialogTitle(MessageManager .getString("label.save_feature_colours")); diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 68245b6..35d4685 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -36,6 +36,8 @@ import jalview.datamodel.StructureViewerModel; import jalview.datamodel.StructureViewerModel.StructureData; import jalview.ext.varna.RnaModel; import jalview.gui.StructureViewer.ViewerType; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; import jalview.schemabinding.version2.AlcodMap; import jalview.schemabinding.version2.AlcodonFrame; import jalview.schemabinding.version2.Annotation; @@ -974,14 +976,14 @@ public class Jalview2XML if (entry.getProperty() != null && !entry.getProperty().isEmpty()) { PdbentryItem item = new PdbentryItem(); - Hashtable properties = entry.getProperty(); - Enumeration en2 = properties.keys(); + Hashtable properties = entry.getProperty(); + Enumeration en2 = properties.keys(); while (en2.hasMoreElements()) { Property prop = new Property(); - String key = en2.nextElement().toString(); + String key = en2.nextElement(); prop.setName(key); - prop.setValue(properties.get(key).toString()); + prop.setValue(properties.get(key)); item.addProperty(prop); } pdb.addPdbentryItem(item); @@ -4144,8 +4146,7 @@ public class Jalview2XML StructureData filedat = oldFiles.get(id); String pdbFile = filedat.getFilePath(); SequenceI[] seq = filedat.getSeqList().toArray(new SequenceI[0]); - binding.getSsm().setMapping(seq, null, pdbFile, - jalview.io.AppletFormatAdapter.FILE); + binding.getSsm().setMapping(seq, null, pdbFile, DataSourceType.FILE); binding.addSequenceForStructFile(pdbFile, seq); } // and add the AlignmentPanel's reference to the view panel @@ -4260,7 +4261,7 @@ public class Jalview2XML af = new AlignFrame(al, view.getWidth(), view.getHeight(), uniqueSeqSetId, viewId); - af.setFileName(file, "Jalview"); + af.setFileName(file, FileFormat.Jalview); for (int i = 0; i < JSEQ.length; i++) { diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index 61e20fa..4a582de 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -35,6 +35,7 @@ import jalview.binding.Tree; import jalview.binding.UserColours; import jalview.binding.Viewport; import jalview.datamodel.PDBEntry; +import jalview.io.FileFormat; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; import jalview.schemes.ResidueProperties; @@ -305,7 +306,7 @@ public class Jalview2XML_V1 AlignFrame af = new AlignFrame(al, view.getWidth(), view.getHeight()); - af.setFileName(file, "Jalview"); + af.setFileName(file, FileFormat.Jalview); for (int i = 0; i < JSEQ.length; i++) { diff --git a/src/jalview/gui/JalviewChimeraBindingModel.java b/src/jalview/gui/JalviewChimeraBindingModel.java index 7a54732..76d2703 100644 --- a/src/jalview/gui/JalviewChimeraBindingModel.java +++ b/src/jalview/gui/JalviewChimeraBindingModel.java @@ -24,6 +24,7 @@ import jalview.api.AlignmentViewPanel; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.rbvi.chimera.JalviewChimeraBinding; +import jalview.io.DataSourceType; import jalview.structure.StructureSelectionManager; public class JalviewChimeraBindingModel extends JalviewChimeraBinding @@ -34,7 +35,8 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame, StructureSelectionManager ssm, PDBEntry[] pdbentry, - SequenceI[][] sequenceIs, String[][] chains, String protocol) + SequenceI[][] sequenceIs, String[][] chains, + DataSourceType protocol) { super(ssm, pdbentry, sequenceIs, chains, protocol); cvf = chimeraViewFrame; @@ -72,6 +74,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding { javax.swing.SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { cvf.updateTitleAndMenus(); @@ -80,6 +83,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding }); } + @Override public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; @@ -113,6 +117,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding * Send an asynchronous command to Chimera, in a new thread, optionally with * an 'in progress' message in a progress bar somewhere */ + @Override protected void sendAsynchronousCommand(final String command, final String progressMsg) { diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index d28dc60..52a0d41 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -38,6 +38,8 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FormatAdapter; import jalview.io.SequenceAnnotationReport; import jalview.schemes.AnnotationColourGradient; @@ -2334,8 +2336,8 @@ public class PopupMenu extends JPopupMenu // or we simply trust the user wants // wysiwig behaviour - cap.setText(new FormatAdapter(ap).formatSequences(e.getActionCommand(), - ap, true)); + FileFormatI fileFormat = FileFormat.forName(e.getActionCommand()); + cap.setText(new FormatAdapter(ap).formatSequences(fileFormat, ap, true)); } public void sequenceFeature_actionPerformed() diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index afc93e0..1ac17e4 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -683,12 +683,14 @@ public class Preferences extends GPreferences @Override public void startupFileTextfield_mouseClicked() { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] { - "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", - "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF", - "PIR", "BLC", "Jalview" }, - jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser chooser = JalviewFileChooser.forRead( + Cache.getProperty("LAST_DIRECTORY"), fileFormat, true); + // new String[] { + // "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", + // "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF", + // "PIR", "BLC", "Jalview" }, + // fileFormat); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager .getString("label.select_startup_file")); @@ -697,8 +699,9 @@ public class Preferences extends GPreferences if (value == JalviewFileChooser.APPROVE_OPTION) { - jalview.bin.Cache.applicationProperties.setProperty( - "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat()); + Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT", + chooser + .getSelectedFormat().toString()); startupFileTextfield.setText(chooser.getSelectedFile() .getAbsolutePath()); } diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 828a2aa..fca130b 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -28,6 +28,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.fts.service.pdb.PDBFTSPanel; import jalview.fts.service.uniprot.UniprotFTSPanel; +import jalview.io.FileFormatI; import jalview.io.gff.SequenceOntologyI; import jalview.util.DBRefUtils; import jalview.util.MessageManager; @@ -894,7 +895,7 @@ public class SequenceFetcher extends JPanel implements Runnable } AlignmentI parseResult(AlignmentI al, String title, - String currentFileFormat, + FileFormatI currentFileFormat, FeatureSettingsModelI preferredFeatureColours) { diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 13fa460..3581cf9 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -32,6 +32,7 @@ import jalview.fts.api.FTSRestClientI; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import jalview.fts.service.pdb.PDBFTSRestClient; +import jalview.io.DataSourceType; import jalview.jbgui.GStructureChooser; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; @@ -828,7 +829,7 @@ public class StructureChooser extends GStructureChooser implements } PDBEntry fileEntry = new AssociatePdbFileWithSeq() .associatePdbWithSeq(selectedPdbFileName, - jalview.io.AppletFormatAdapter.FILE, + DataSourceType.FILE, selectedSequence, true, Desktop.instance); launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 7df42fd..e295dfb 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -24,7 +24,7 @@ import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.gui.StructureViewer.ViewerType; import jalview.gui.ViewSelectionMenu.ViewSetProvider; -import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; import jalview.jbgui.GStructureViewer; import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; @@ -152,6 +152,7 @@ public abstract class StructureViewerBase extends GStructureViewer this.ap = alp; } + @Override public AlignmentPanel[] getAllAlignmentPanels() { AlignmentPanel[] t, list = new AlignmentPanel[0]; @@ -291,6 +292,7 @@ public abstract class StructureViewerBase extends GStructureViewer // queue. new Thread(new Runnable() { + @Override public void run() { while (worker != null && worker.isAlive() && _started) @@ -411,7 +413,7 @@ public abstract class StructureViewerBase extends GStructureViewer * create the mappings */ apanel.getStructureSelectionManager().setMapping(seq, chains, - pdbFilename, AppletFormatAdapter.FILE); + pdbFilename, DataSourceType.FILE); /* * alert the FeatureRenderer to show new (PDB RESNUM) features diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index fafa610..af84dbc 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -42,6 +42,7 @@ import jalview.io.JalviewFileView; import jalview.io.NewickFile; import jalview.jbgui.GTreePanel; import jalview.schemes.ResidueProperties; +import jalview.util.ImageMaker; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; @@ -747,24 +748,24 @@ public class TreePanel extends GTreePanel try { - jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "eps" }, new String[] { "Encapsulated Postscript" }, - "Encapsulated Postscript"); - chooser.setFileView(new jalview.io.JalviewFileView()); + JalviewFileChooser chooser = new JalviewFileChooser( + Cache.getProperty("LAST_DIRECTORY"), + ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION, + ImageMaker.EPS_EXTENSION); + chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager .getString("label.create_eps_from_tree")); chooser.setToolTipText(MessageManager.getString("action.save")); int value = chooser.showSaveDialog(this); - if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + if (value != JalviewFileChooser.APPROVE_OPTION) { return; } - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser - .getSelectedFile().getParent()); + Cache.setProperty("LAST_DIRECTORY", chooser.getSelectedFile() + .getParent()); FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, height); @@ -795,10 +796,10 @@ public class TreePanel extends GTreePanel try { - jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "png" }, new String[] { "Portable network graphics" }, - "Portable network graphics"); + JalviewFileChooser chooser = new JalviewFileChooser( + Cache.getProperty("LAST_DIRECTORY"), + ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION, + ImageMaker.PNG_DESCRIPTION); chooser.setFileView(new jalview.io.JalviewFileView()); chooser.setDialogTitle(MessageManager diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index c9c1531..80fd5f6 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.api.structures.JalviewStructureDisplayI; +import jalview.bin.Cache; import jalview.datamodel.SequenceGroup; import jalview.io.JalviewFileChooser; import jalview.jbgui.GUserDefinedColours; @@ -597,9 +598,8 @@ public class UserDefinedColours extends GUserDefinedColours implements lowerCaseButtons = new ArrayList(); JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "jc" }, new String[] { "Jalview User Colours" }, - "Jalview User Colours"); + Cache.getProperty("LAST_DIRECTORY"), "jc", + "Jalview User Colours", "Jalview User Colours"); chooser.setFileView(new jalview.io.JalviewFileView()); chooser.setDialogTitle(MessageManager .getString("label.load_colour_scheme")); @@ -833,9 +833,8 @@ public class UserDefinedColours extends GUserDefinedColours implements userColourSchemes.remove(schemeName.getText()); } JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "jc" }, new String[] { "Jalview User Colours" }, - "Jalview User Colours"); + Cache.getProperty("LAST_DIRECTORY"), "jc", + "Jalview User Colours", "Jalview User Colours"); chooser.setFileView(new jalview.io.JalviewFileView()); chooser.setDialogTitle(MessageManager diff --git a/src/jalview/gui/WsParamSetManager.java b/src/jalview/gui/WsParamSetManager.java index b6a7672..aec79e4 100644 --- a/src/jalview/gui/WsParamSetManager.java +++ b/src/jalview/gui/WsParamSetManager.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.bin.Cache; import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; import jalview.util.MessageManager; import jalview.ws.params.ParamDatastoreI; import jalview.ws.params.ParamManager; @@ -185,11 +186,9 @@ public class WsParamSetManager implements ParamManager if (filename == null) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "wsparams" }, - new String[] { "Web Service Parameter File" }, - "Web Service Parameter File"); - chooser.setFileView(new jalview.io.JalviewFileView()); + Cache.getProperty("LAST_DIRECTORY"), "wsparams", + "Web Service Parameter File", "Web Service Parameter File"); + chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager .getString("label.choose_filename_for_param_file")); chooser.setToolTipText(MessageManager.getString("action.save")); diff --git a/src/jalview/io/AMSAFile.java b/src/jalview/io/AMSAFile.java index f82407e..798249f 100644 --- a/src/jalview/io/AMSAFile.java +++ b/src/jalview/io/AMSAFile.java @@ -22,6 +22,7 @@ package jalview.io; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceI; public class AMSAFile extends jalview.io.FastaFile { @@ -41,9 +42,9 @@ public class AMSAFile extends jalview.io.FastaFile * * @return DOCUMENT ME! */ - public String print() + public String print(SequenceI[] sqs, boolean jvsuffix) { - super.print(getSeqsAsArray()); + super.print(sqs, jvsuffix); AlignmentAnnotation aa; if (al.getAlignmentAnnotation() != null) diff --git a/src/jalview/io/AlignFile.java b/src/jalview/io/AlignFile.java index 5760fbe..d333c64 100755 --- a/src/jalview/io/AlignFile.java +++ b/src/jalview/io/AlignFile.java @@ -40,7 +40,7 @@ import java.util.Vector; * @author $author$ * @version $Revision$ */ -public abstract class AlignFile extends FileParse +public abstract class AlignFile extends FileParse implements AlignmentFileI { int noSeqs = 0; @@ -71,8 +71,6 @@ public abstract class AlignFile extends FileParse long end; - boolean jvSuffix = true; - private boolean parseCalled; /** @@ -86,17 +84,24 @@ public abstract class AlignFile extends FileParse initData(); } + public AlignFile(SequenceI[] seqs) + { + this(); + setSeqs(seqs); + } + /** * Constructor which parses the data from a file of some specified type. * * @param dataObject * Filename, URL or Pasted String to read from. - * @param type + * @param sourceType * What type of file to read from (File, URL, Pasted String) */ - public AlignFile(String dataObject, String type) throws IOException + public AlignFile(String dataObject, DataSourceType sourceType) + throws IOException { - this(true, dataObject, type); + this(true, dataObject, sourceType); } /** @@ -107,14 +112,15 @@ public abstract class AlignFile extends FileParse * if false, need to call 'doParse()' to begin parsing data * @param dataObject * Filename, URL or Pasted String to read from. - * @param type + * @param sourceType * What type of file to read from (File, URL) * @throws IOException */ - public AlignFile(boolean parseImmediately, String dataObject, String type) + public AlignFile(boolean parseImmediately, String dataObject, + DataSourceType sourceType) throws IOException { - super(dataObject, type); + super(dataObject, sourceType); initData(); if (parseImmediately) { @@ -191,6 +197,7 @@ public abstract class AlignFile extends FileParse /** * Return the Sequences in the seqs Vector as an array of Sequences */ + @Override public SequenceI[] getSeqsAsArray() { SequenceI[] s = new SequenceI[seqs.size()]; @@ -209,6 +216,7 @@ public abstract class AlignFile extends FileParse * * @param al */ + @Override public void addAnnotations(AlignmentI al) { addProperties(al); @@ -314,7 +322,8 @@ public abstract class AlignFile extends FileParse * @param s * DOCUMENT ME! */ - protected void setSeqs(SequenceI[] s) + @Override + public void setSeqs(SequenceI[] s) { seqs = new Vector(); @@ -330,16 +339,6 @@ public abstract class AlignFile extends FileParse public abstract void parse() throws IOException; /** - * Print out in alignment file format the Sequences in the seqs Vector. - */ - public abstract String print(); - - public void addJVSuffix(boolean b) - { - jvSuffix = b; - } - - /** * A general parser for ids. * * @String id Id to be parsed @@ -371,14 +370,21 @@ public abstract class AlignFile extends FileParse } /** - * Creates the output id. Adds prefix Uniprot format source|id And suffix - * Jalview /start-end + * Creates the output id. Adds prefix Uniprot format source|id and optionally + * suffix Jalview /start-end + * + * @param jvsuffix * * @String id Id to be parsed */ + String printId(SequenceI seq, boolean jvsuffix) + { + return seq.getDisplayId(jvsuffix); + } + String printId(SequenceI seq) { - return seq.getDisplayId(jvSuffix); + return printId(seq, true); } /** @@ -400,6 +406,7 @@ public abstract class AlignFile extends FileParse return newickStrings == null ? 0 : newickStrings.size(); } + @Override public void addGroups(AlignmentI al) { diff --git a/src/jalview/io/AlignmentFileI.java b/src/jalview/io/AlignmentFileI.java new file mode 100644 index 0000000..1a000a3 --- /dev/null +++ b/src/jalview/io/AlignmentFileI.java @@ -0,0 +1,38 @@ +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 setExportSettings(AlignExportSettingI exportSettings); + + void configureForView(AlignmentViewPanel viewpanel); + + void setSeqs(SequenceI[] sequencesArray); + + String print(SequenceI[] seqs, boolean jvsuffix); + + boolean hasWarningMessage(); + + String getWarningMessage(); + + String getInFile(); + + DataSourceType getDataSourceType(); + + FeatureSettingsModelI getFeatureColourScheme(); + +} diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index d738882..6e121b3 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -661,7 +661,7 @@ public class AnnotationFile String refSeqId = null; public boolean annotateAlignmentView(AlignViewportI viewport, - String file, String protocol) + String file, DataSourceType protocol) { ColumnSelection colSel = viewport.getColumnSelection(); if (colSel == null) @@ -679,31 +679,31 @@ public class AnnotationFile } public boolean readAnnotationFile(AlignmentI al, String file, - String protocol) + DataSourceType sourceType) { - return readAnnotationFile(al, null, file, protocol); + return readAnnotationFile(al, null, file, sourceType); } public boolean readAnnotationFile(AlignmentI al, ColumnSelection colSel, - String file, String protocol) + String file, DataSourceType sourceType) { BufferedReader in = null; try { - if (protocol.equals(AppletFormatAdapter.FILE)) + if (sourceType == DataSourceType.FILE) { in = new BufferedReader(new FileReader(file)); } - else if (protocol.equals(AppletFormatAdapter.URL)) + else if (sourceType == DataSourceType.URL) { URL url = new URL(file); in = new BufferedReader(new InputStreamReader(url.openStream())); } - else if (protocol.equals(AppletFormatAdapter.PASTE)) + else if (sourceType == DataSourceType.PASTE) { in = new BufferedReader(new StringReader(file)); } - else if (protocol.equals(AppletFormatAdapter.CLASSLOADER)) + else if (sourceType == DataSourceType.CLASSLOADER) { java.io.InputStream is = getClass().getResourceAsStream("/" + file); if (is != null) diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 55bb03d..04d68e8 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -27,8 +27,9 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.PDBEntry.Type; +import jalview.datamodel.SequenceI; +import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; -import jalview.util.MessageManager; import java.io.File; import java.io.IOException; @@ -48,14 +49,6 @@ public class AppletFormatAdapter { private AlignmentViewPanel viewpanel; - public static String FILE = "File"; - - public static String URL = "URL"; - - public static String PASTE = "Paste"; - - public static String CLASSLOADER = "ClassLoader"; - /** * add jalview-derived non-secondary structure annotation from PDB structure */ @@ -71,7 +64,7 @@ public class AppletFormatAdapter */ boolean serviceSecondaryStruct = false; - private AlignFile alignFile = null; + private AlignmentFileI alignFile = null; String inFile; @@ -87,7 +80,7 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FORMATS = new String[] { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "STH", "PDB", - "JnetFile", "RNAML", PhylipFile.FILE_DESC, JSONFile.FILE_DESC, + "JnetFile", "RNAML", "PHYLIP", "JSON", IdentifyFile.FeaturesFile, "HTML", "mmCIF" }; /** @@ -96,8 +89,8 @@ public class AppletFormatAdapter */ public static final String[] READABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", "xml,rnaml", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, - ".gff2,gff3", "jar,jvp", HtmlFile.FILE_EXT, "cif" }; + "sto,stk", "xml,rnaml", "phy", "json", + ".gff2,gff3", "jar,jvp", "html", "cif" }; /** * List of readable formats by application in order corresponding to @@ -105,7 +98,7 @@ public class AppletFormatAdapter */ public static final String[] READABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Stockholm", "RNAML", - PhylipFile.FILE_DESC, JSONFile.FILE_DESC, IdentifyFile.FeaturesFile, + "PHYLIP", "JSON", IdentifyFile.FeaturesFile, "Jalview", HtmlFile.FILE_DESC, "mmCIF" }; /** @@ -114,7 +107,7 @@ public class AppletFormatAdapter */ public static final String[] WRITEABLE_FORMATS = new String[] { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA", "STH", - PhylipFile.FILE_DESC, JSONFile.FILE_DESC }; + "PHYLIP", "JSON" }; /** * List of extensions corresponding to file format types in WRITABLE_FNAMES @@ -122,7 +115,7 @@ public class AppletFormatAdapter */ public static final String[] WRITABLE_EXTENSIONS = new String[] { "fa, fasta, mfa, fastq", "aln", "pfam", "msf", "pir", "blc", "amsa", - "sto,stk", PhylipFile.FILE_EXT, JSONFile.FILE_EXT, "jvp" }; + "sto,stk", "phy", "json", "jvp" }; /** * List of writable formats by the application. Order must correspond with the @@ -130,7 +123,7 @@ public class AppletFormatAdapter */ public static final String[] WRITABLE_FNAMES = new String[] { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "STH", - PhylipFile.FILE_DESC, JSONFile.FILE_DESC, "Jalview" }; + "PHYLIP", "JSON", "Jalview" }; public static String INVALID_CHARACTERS = "Contains invalid characters"; @@ -182,102 +175,23 @@ public class AppletFormatAdapter } /** - * check that this format is valid for reading - * - * @param format - * a format string to be compared with READABLE_FORMATS - * @return true if format is readable - */ - public static final boolean isValidFormat(String format) - { - return isValidFormat(format, false); - } - - /** - * validate format is valid for IO - * - * @param format - * a format string to be compared with either READABLE_FORMATS or - * WRITEABLE_FORMATS - * @param forwriting - * when true, format is checked for containment in WRITEABLE_FORMATS - * @return true if format is valid - */ - public static final boolean isValidFormat(String format, - boolean forwriting) - { - if (format == null) - { - return false; - } - boolean valid = false; - String[] format_list = (forwriting) ? WRITEABLE_FORMATS - : READABLE_FORMATS; - for (String element : format_list) - { - if (element.equalsIgnoreCase(format)) - { - return true; - } - } - - return valid; - } - - /** * Constructs the correct filetype parser for a characterised datasource * * @param inFile * data/data location - * @param type + * @param sourceType * type of datasource - * @param format - * File format of data provided by datasource + * @param fileFormat * - * @return DOCUMENT ME! + * @return */ - public AlignmentI readFile(String inFile, String type, String format) - throws java.io.IOException + public AlignmentI readFile(String file, DataSourceType sourceType, + FileFormatI fileFormat) throws IOException { - // TODO: generalise mapping between format string and io. class instances - // using Constructor.invoke reflection - this.inFile = inFile; + this.inFile = file; try { - if (format.equals("FASTA")) - { - alignFile = new FastaFile(inFile, type); - } - else if (format.equals("MSF")) - { - alignFile = new MSFfile(inFile, type); - } - else if (format.equals("PileUp")) - { - alignFile = new PileUpfile(inFile, type); - } - else if (format.equals("CLUSTAL")) - { - alignFile = new ClustalFile(inFile, type); - } - else if (format.equals("BLC")) - { - alignFile = new BLCFile(inFile, type); - } - else if (format.equals("PIR")) - { - alignFile = new PIRFile(inFile, type); - } - else if (format.equals("PFAM")) - { - alignFile = new PfamFile(inFile, type); - } - else if (format.equals("JnetFile")) - { - alignFile = new JPredFile(inFile, type); - ((JPredFile) alignFile).removeNonSequences(); - } - else if (format.equals("PDB")) + if (fileFormat == FileFormat.PDB || fileFormat == FileFormat.MMCif) { // TODO obtain config value from preference settings. // Set value to 'true' to test PDB processing with Jmol: JAL-1213 @@ -289,9 +203,9 @@ public class AppletFormatAdapter { StructureImportSettings.addSettings(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct); - alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, + alignFile = new JmolParser(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct, inFile, - type); + sourceType); } else { @@ -300,85 +214,72 @@ public class AppletFormatAdapter StructureImportSettings.setShowSeqFeatures(true); alignFile = new MCview.PDBfile(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct, inFile, - type); + sourceType); } - ((StructureFile) alignFile).setDbRefType(format); - } - else if (format.equalsIgnoreCase("mmCIF")) - { - StructureImportSettings.addSettings(annotFromStructure, - localSecondaryStruct, serviceSecondaryStruct); - alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, - localSecondaryStruct, serviceSecondaryStruct, inFile, type); - ((StructureFile) alignFile).setDbRefType(format); - } - else if (format.equals("STH")) - { - alignFile = new StockholmFile(inFile, type); + ((StructureFile) alignFile) + .setDbRefType(fileFormat == FileFormat.PDB ? Type.PDB + : Type.MMCIF); } - else if (format.equals("SimpleBLAST")) - { - alignFile = new SimpleBlastFile(inFile, type); - } - else if (format.equals(PhylipFile.FILE_DESC)) - { - alignFile = new PhylipFile(inFile, type); - } - else if (format.equals(JSONFile.FILE_DESC)) - { - alignFile = new JSONFile(inFile, type); - } - else if (format.equals(HtmlFile.FILE_DESC)) - { - alignFile = new HtmlFile(inFile, type); - } - else if (format.equals("RNAML")) - { - alignFile = new RnamlFile(inFile, type); - } - else if (format.equals(IdentifyFile.FeaturesFile)) + else { - alignFile = new FeaturesFile(true, inFile, type); - } - return buildAlignmentFrom(alignFile); + alignFile = fileFormat.getAlignmentFile(inFile, sourceType); + } + // new FastaFile(inFile, sourceType); + // new MSFfile(inFile, sourceType); + // new PileUpfile(inFile, sourceType); + // new ClustalFile(inFile, sourceType); + // new BLCFile(inFile, sourceType); + // new PIRFile(inFile, sourceType); + // new PfamFile(inFile, sourceType); + // alignFile = new JPredFile(inFile, sourceType); + // ((JPredFile) alignFile).removeNonSequences(); + // new StockholmFile(inFile, sourceType); + // new SimpleBlastFile(inFile, sourceType); + // new PhylipFile(inFile, sourceType); + // new JSONFile(inFile, sourceType); + // new HtmlFile(inFile, sourceType); + // new RnamlFile(inFile, sourceType); +// alignFile = new FeaturesFile(true, inFile, sourceType); + return buildAlignmentFromFile(); } catch (Exception e) { e.printStackTrace(); - System.err.println("Failed to read alignment using the '" + format + System.err.println("Failed to read alignment using the '" + + fileFormat + "' reader.\n" + e); if (e.getMessage() != null && e.getMessage().startsWith(INVALID_CHARACTERS)) { - throw new java.io.IOException(e.getMessage()); + throw new IOException(e.getMessage()); } // Finally test if the user has pasted just the sequence, no id - if (type.equalsIgnoreCase("Paste")) + if (sourceType == DataSourceType.PASTE) { try { // Possible sequence is just residues with no label - alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); - return buildAlignmentFrom(alignFile); + alignFile = new FastaFile(">UNKNOWN\n" + inFile, + DataSourceType.PASTE); + return buildAlignmentFromFile(); } catch (Exception ex) { if (ex.toString().startsWith(INVALID_CHARACTERS)) { - throw new java.io.IOException(e.getMessage()); + throw new IOException(e.getMessage()); } ex.printStackTrace(); } } - if (format.equalsIgnoreCase("HTML")) + if (fileFormat == FileFormat.Html) { throw new IOException(e.getMessage()); } - // If we get to this stage, the format was not supported - throw new java.io.IOException(SUPPORTED_FORMATS); } + throw new FileFormatException(SUPPORTED_FORMATS); } /** @@ -389,53 +290,16 @@ public class AppletFormatAdapter * @param format * File format of data that will be provided by datasource * - * @return DOCUMENT ME! + * @return */ - public AlignmentI readFromFile(FileParse source, String format) - throws java.io.IOException + public AlignmentI readFromFile(FileParse source, FileFormatI format) + throws IOException { - // TODO: generalise mapping between format string and io. class instances - // using Constructor.invoke reflection - // This is exactly the same as the readFile method except we substitute - // 'inFile, type' with 'source' this.inFile = source.getInFile(); - String type = source.type; + DataSourceType type = source.dataSourceType; try { - if (format.equals("FASTA")) - { - alignFile = new FastaFile(source); - } - else if (format.equals("MSF")) - { - alignFile = new MSFfile(source); - } - else if (format.equals("PileUp")) - { - alignFile = new PileUpfile(source); - } - else if (format.equals("CLUSTAL")) - { - alignFile = new ClustalFile(source); - } - else if (format.equals("BLC")) - { - alignFile = new BLCFile(source); - } - else if (format.equals("PIR")) - { - alignFile = new PIRFile(source); - } - else if (format.equals("PFAM")) - { - alignFile = new PfamFile(source); - } - else if (format.equals("JnetFile")) - { - alignFile = new JPredFile(source); - ((JPredFile) alignFile).removeNonSequences(); - } - else if (format.equals("PDB")) + if (format == FileFormat.PDB || format == FileFormat.MMCif) { // TODO obtain config value from preference settings boolean isParseWithJMOL = false; @@ -443,7 +307,7 @@ public class AppletFormatAdapter { StructureImportSettings.addSettings(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct); - alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, + alignFile = new JmolParser(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct, source); } else @@ -454,44 +318,12 @@ public class AppletFormatAdapter } ((StructureFile) alignFile).setDbRefType(Type.PDB); } - else if (format.equalsIgnoreCase("mmCIF")) - { - StructureImportSettings.addSettings(annotFromStructure, - localSecondaryStruct, serviceSecondaryStruct); - alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, - localSecondaryStruct, serviceSecondaryStruct, source); - ((StructureFile) alignFile).setDbRefType(Type.MMCIF); - } - else if (format.equals("STH")) - { - alignFile = new StockholmFile(source); - } - else if (format.equals("RNAML")) - { - alignFile = new RnamlFile(source); - } - else if (format.equals("SimpleBLAST")) - { - alignFile = new SimpleBlastFile(source); - } - else if (format.equals(PhylipFile.FILE_DESC)) - { - alignFile = new PhylipFile(source); - } - else if (format.equals(IdentifyFile.FeaturesFile)) - { - alignFile = new FeaturesFile(inFile, type); - } - else if (format.equals(JSONFile.FILE_DESC)) - { - alignFile = new JSONFile(source); - } - else if (format.equals(HtmlFile.FILE_DESC)) + else { - alignFile = new HtmlFile(source); + alignFile = format.getAlignmentFile(source); } - return buildAlignmentFrom(alignFile); + return buildAlignmentFromFile(); } catch (Exception e) { @@ -502,23 +334,24 @@ public class AppletFormatAdapter if (e.getMessage() != null && e.getMessage().startsWith(INVALID_CHARACTERS)) { - throw new java.io.IOException(e.getMessage()); + throw new FileFormatException(e.getMessage()); } // Finally test if the user has pasted just the sequence, no id - if (type.equalsIgnoreCase("Paste")) + if (type == DataSourceType.PASTE) { try { // Possible sequence is just residues with no label - alignFile = new FastaFile(">UNKNOWN\n" + inFile, "Paste"); - return buildAlignmentFrom(alignFile); + alignFile = new FastaFile(">UNKNOWN\n" + inFile, + DataSourceType.PASTE); + return buildAlignmentFromFile(); } catch (Exception ex) { if (ex.toString().startsWith(INVALID_CHARACTERS)) { - throw new java.io.IOException(e.getMessage()); + throw new IOException(e.getMessage()); } ex.printStackTrace(); @@ -526,7 +359,7 @@ public class AppletFormatAdapter } // If we get to this stage, the format was not supported - throw new java.io.IOException(SUPPORTED_FORMATS); + throw new FileFormatException(SUPPORTED_FORMATS); } } @@ -534,10 +367,9 @@ public class AppletFormatAdapter * boilerplate method to handle data from an AlignFile and construct a new * alignment or import to an existing alignment * - * @param alignFile2 * @return AlignmentI instance ready to pass to a UI constructor */ - private AlignmentI buildAlignmentFrom(AlignFile alignFile2) + private AlignmentI buildAlignmentFromFile() { // Standard boilerplate for creating alignment from parser // alignFile.configureForView(viewpanel); @@ -560,7 +392,7 @@ public class AppletFormatAdapter * @param selectedOnly * @return flatfile in a string */ - public String formatSequences(String format, boolean jvsuffix, + public String formatSequences(FileFormatI format, boolean jvsuffix, AlignmentViewPanel ap, boolean selectedOnly) { @@ -596,86 +428,31 @@ public class AppletFormatAdapter * * @return alignment flat file contents */ - public String formatSequences(String format, AlignmentI alignment, + public String formatSequences(FileFormatI format, AlignmentI alignment, boolean jvsuffix) { try { - AlignFile afile = null; - if (format.equalsIgnoreCase("FASTA")) - { - afile = new FastaFile(); - } - else if (format.equalsIgnoreCase("MSF")) - { - afile = new MSFfile(); - } - else if (format.equalsIgnoreCase("PileUp")) - { - afile = new PileUpfile(); - } - else if (format.equalsIgnoreCase("CLUSTAL")) - { - afile = new ClustalFile(); - } - else if (format.equalsIgnoreCase("BLC")) - { - afile = new BLCFile(); - } - else if (format.equalsIgnoreCase("PIR")) - { - afile = new PIRFile(); - } - else if (format.equalsIgnoreCase("PFAM")) - { - afile = new PfamFile(); - } - else if (format.equalsIgnoreCase("STH")) - { - afile = new StockholmFile(alignment); - } - else if (format.equalsIgnoreCase("AMSA")) - { - afile = new AMSAFile(alignment); - } - else if (format.equalsIgnoreCase(PhylipFile.FILE_DESC)) - { - afile = new PhylipFile(); - } - else if (format.equalsIgnoreCase(JSONFile.FILE_DESC)) - { - afile = new JSONFile(); - } - else if (format.equalsIgnoreCase("RNAML")) - { - afile = new RnamlFile(); - } - - else - { - throw new Exception( - MessageManager - .getString("error.implementation_error_unknown_file_format_string")); - } + AlignmentFileI afile = format.getAlignmentFile(); afile.setNewlineString(newline); - afile.addJVSuffix(jvsuffix); afile.setExportSettings(exportSettings); afile.configureForView(viewpanel); // check whether we were given a specific alignment to export, rather than // the one in the viewpanel + SequenceI[] seqs = null; if (viewpanel == null || viewpanel.getAlignment() == null || viewpanel.getAlignment() != alignment) { - afile.setSeqs(alignment.getSequencesArray()); + seqs = alignment.getSequencesArray(); } else { - afile.setSeqs(viewpanel.getAlignment().getSequencesArray()); + seqs = viewpanel.getAlignment().getSequencesArray(); } - String afileresp = afile.print(); + String afileresp = afile.print(seqs, jvsuffix); if (afile.hasWarningMessage()) { System.err.println("Warning raised when writing as " + format @@ -692,14 +469,14 @@ public class AppletFormatAdapter return null; } - public static String checkProtocol(String file) + public static DataSourceType checkProtocol(String file) { - String protocol = FILE; + DataSourceType protocol = DataSourceType.FILE; String ft = file.toLowerCase().trim(); if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0 || ft.indexOf("file:") == 0) { - protocol = URL; + protocol = DataSourceType.URL; } return protocol; } @@ -720,8 +497,10 @@ public class AppletFormatAdapter System.gc(); long memf = -r.totalMemory() + r.freeMemory(); long t1 = -System.currentTimeMillis(); - AlignmentI al = afa.readFile(args[i], FILE, - new IdentifyFile().identify(args[i], FILE)); + AlignmentI al = afa + .readFile(args[i], DataSourceType.FILE, + new IdentifyFile().identify(args[i], + DataSourceType.FILE)); t1 += System.currentTimeMillis(); System.gc(); memf += r.totalMemory() - r.freeMemory(); @@ -732,7 +511,7 @@ public class AppletFormatAdapter try { System.out.println(new AppletFormatAdapter().formatSequences( - "FASTA", al, true)); + FileFormat.Fasta, al, true)); } catch (Exception e) { System.err @@ -771,16 +550,17 @@ public class AppletFormatAdapter * @param format * @return protocol that yields the data parsable as the given type */ - public static String resolveProtocol(String file, String format) + public static DataSourceType resolveProtocol(String file, + FileFormatI format) { return resolveProtocol(file, format, false); } - public static String resolveProtocol(String file, String format, - boolean debug) + public static DataSourceType resolveProtocol(String file, + FileFormatI format, boolean debug) { // TODO: test thoroughly! - String protocol = null; + DataSourceType protocol = null; if (debug) { System.out.println("resolving datasource started with:\n>>file\n" @@ -804,10 +584,9 @@ public class AppletFormatAdapter System.err.println("Resource '" + file + "' was " + (rtn ? "" : "not") + " located by classloader."); } - ; if (rtn) { - protocol = AppletFormatAdapter.CLASSLOADER; + protocol = DataSourceType.CLASSLOADER; } } catch (Exception ex) @@ -818,12 +597,12 @@ public class AppletFormatAdapter if (file.indexOf("://") > -1) { - protocol = AppletFormatAdapter.URL; + protocol = DataSourceType.URL; } else { // skipping codebase prepend check. - protocol = AppletFormatAdapter.FILE; + protocol = DataSourceType.FILE; } FileParse fp = null; try @@ -859,7 +638,7 @@ public class AppletFormatAdapter { System.out.println("Accessing as paste."); } - protocol = AppletFormatAdapter.PASTE; + protocol = DataSourceType.PASTE; fp = null; try { @@ -879,7 +658,7 @@ public class AppletFormatAdapter { return null; } - if (format == null || format.length() == 0) + if (format == null) { return protocol; } @@ -887,7 +666,7 @@ public class AppletFormatAdapter { try { - String idformat = new jalview.io.IdentifyFile().identify(file, + FileFormatI idformat = new IdentifyFile().identify(file, protocol); if (idformat == null) { @@ -927,20 +706,13 @@ public class AppletFormatAdapter System.err.println("File deemed not accessible via " + protocol); e.printStackTrace(); } - ; - } } return null; } - public AlignFile getAlignFile() + public AlignmentFileI getAlignFile() { return alignFile; } - - public void setAlignFile(AlignFile alignFile) - { - this.alignFile = alignFile; - } } diff --git a/src/jalview/io/BLCFile.java b/src/jalview/io/BLCFile.java index a499f75..6317e83 100755 --- a/src/jalview/io/BLCFile.java +++ b/src/jalview/io/BLCFile.java @@ -48,15 +48,16 @@ public class BLCFile extends AlignFile * * @param inFile * DOCUMENT ME! - * @param type + * @param sourceType * DOCUMENT ME! * * @throws IOException * DOCUMENT ME! */ - public BLCFile(String inFile, String type) throws IOException + public BLCFile(String inFile, DataSourceType sourceType) + throws IOException { - super(inFile, type); + super(inFile, sourceType); } public BLCFile(FileParse source) throws IOException @@ -67,6 +68,7 @@ public class BLCFile extends AlignFile /** * DOCUMENT ME! */ + @Override public void initData() { super.initData(); @@ -89,6 +91,7 @@ public class BLCFile extends AlignFile /** * DOCUMENT ME! */ + @Override public void parse() throws IOException { StringBuffer headerLines = new StringBuffer(); @@ -215,22 +218,13 @@ public class BLCFile extends AlignFile /** * DOCUMENT ME! * - * @return DOCUMENT ME! - */ - public String print() - { - return print(getSeqsAsArray()); - } - - /** - * DOCUMENT ME! - * * @param s * DOCUMENT ME! * * @return DOCUMENT ME! */ - public String print(SequenceI[] s) + @Override + public String print(SequenceI[] s, boolean jvsuffix) { StringBuffer out = new StringBuffer(); /** @@ -244,7 +238,7 @@ public class BLCFile extends AlignFile while ((i < s.length) && (s[i] != null)) { - out.append(">" + printId(s[i])); + out.append(">" + printId(s[i], jvsuffix)); if (s[i].getDescription() != null) { out.append(" " + s[i].getDescription()); diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index f8fa1f5..80df097 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -22,12 +22,15 @@ package jalview.io; import jalview.api.AlignExportSettingI; import jalview.api.AlignmentViewPanel; +import jalview.bin.Cache; import jalview.datamodel.AlignmentExportData; import jalview.exceptions.NoFileSelectedException; +import jalview.gui.AlignFrame; import jalview.gui.IProgressIndicator; import jalview.gui.OOMWarning; import jalview.json.binding.biojs.BioJSReleasePojo; import jalview.json.binding.biojs.BioJSRepositoryPojo; +import jalview.util.ImageMaker; import jalview.util.MessageManager; import java.io.BufferedInputStream; @@ -125,11 +128,11 @@ public class BioJsHTMLOutput } }; - AlignmentExportData exportData = jalview.gui.AlignFrame - .getAlignmentForExport(JSONFile.FILE_DESC, + AlignmentExportData exportData = AlignFrame + .getAlignmentForExport(FileFormat.Json, ap.getAlignViewport(), exportSettings); String bioJSON = new FormatAdapter(ap, exportData.getSettings()) - .formatSequences(JSONFile.FILE_DESC, exportData + .formatSequences(FileFormat.Json, exportData .getAlignment(), exportData.getOmitHidden(), exportData.getStartEndPostions(), ap .getAlignViewport().getColumnSelection()); @@ -176,9 +179,8 @@ public class BioJsHTMLOutput } JalviewFileChooser jvFileChooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "html" }, new String[] { "HTML files" }, - "HTML files"); + Cache.getProperty("LAST_DIRECTORY"), ImageMaker.HTML_EXTENSION, + ImageMaker.HTML_EXTENSION, ImageMaker.HTML_EXTENSION); jvFileChooser.setFileView(new JalviewFileView()); jvFileChooser.setDialogTitle(MessageManager @@ -188,7 +190,7 @@ public class BioJsHTMLOutput int fileChooserOpt = jvFileChooser.showSaveDialog(null); if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION) { - jalview.bin.Cache.setProperty("LAST_DIRECTORY", jvFileChooser + Cache.setProperty("LAST_DIRECTORY", jvFileChooser .getSelectedFile().getParent()); selectedFile = jvFileChooser.getSelectedFile().getPath(); } diff --git a/src/jalview/io/ClustalFile.java b/src/jalview/io/ClustalFile.java index f7a45de..5d58d42 100755 --- a/src/jalview/io/ClustalFile.java +++ b/src/jalview/io/ClustalFile.java @@ -37,9 +37,10 @@ public class ClustalFile extends AlignFile { } - public ClustalFile(String inFile, String type) throws IOException + public ClustalFile(String inFile, DataSourceType sourceType) + throws IOException { - super(inFile, type); + super(inFile, sourceType); } public ClustalFile(FileParse source) throws IOException @@ -196,13 +197,7 @@ public class ClustalFile extends AlignFile } @Override - public String print() - { - return print(getSeqsAsArray()); - // TODO: locaRNA style aln output - } - - public String print(SequenceI[] s) + public String print(SequenceI[] s, boolean jvsuffix) { StringBuffer out = new StringBuffer("CLUSTAL" + newline + newline); @@ -213,7 +208,7 @@ public class ClustalFile extends AlignFile while ((i < s.length) && (s[i] != null)) { - String tmp = printId(s[i]); + String tmp = printId(s[i], jvsuffix); if (s[i].getSequence().length > max) { @@ -244,7 +239,8 @@ public class ClustalFile extends AlignFile while ((j < s.length) && (s[j] != null)) { - out.append(new Format("%-" + maxid + "s").form(printId(s[j]) + " ")); + out.append(new Format("%-" + maxid + "s").form(printId(s[j], + jvsuffix) + " ")); int start = i * len; int end = start + len; diff --git a/src/jalview/io/DBRefFile.java b/src/jalview/io/DBRefFile.java index 769f8b9..11cb4bf 100644 --- a/src/jalview/io/DBRefFile.java +++ b/src/jalview/io/DBRefFile.java @@ -20,6 +20,8 @@ */ package jalview.io; +import jalview.datamodel.SequenceI; + import java.io.IOException; /** @@ -32,13 +34,15 @@ import java.io.IOException; public class DBRefFile extends AlignFile { + @Override public void parse() throws IOException { // TODO Auto-generated method stub } - public String print() + @Override + public String print(SequenceI[] sqs, boolean jvsuffix) { // TODO Auto-generated method stub return null; 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/FastaFile.java b/src/jalview/io/FastaFile.java index 4c2265c..9c8cdf6 100755 --- a/src/jalview/io/FastaFile.java +++ b/src/jalview/io/FastaFile.java @@ -55,15 +55,16 @@ public class FastaFile extends AlignFile * * @param inFile * DOCUMENT ME! - * @param type + * @param sourceType * DOCUMENT ME! * * @throws IOException * DOCUMENT ME! */ - public FastaFile(String inFile, String type) throws IOException + public FastaFile(String inFile, DataSourceType sourceType) + throws IOException { - super(inFile, type); + super(inFile, sourceType); } public FastaFile(FileParse source) throws IOException @@ -71,6 +72,11 @@ public class FastaFile extends AlignFile super(source); } + public FastaFile(SequenceI[] seqs) + { + super(seqs); + } + /** * DOCUMENT ME! * @@ -181,28 +187,15 @@ public class FastaFile extends AlignFile } } - /** - * DOCUMENT ME! - * - * @param s - * DOCUMENT ME! - * @param len - * DOCUMENT ME! - * @param gaps - * DOCUMENT ME! - * @param displayId - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public String print(SequenceI[] s) + @Override + public String print(SequenceI[] s, boolean jvsuffix) { out = new StringBuffer(); int i = 0; while ((i < s.length) && (s[i] != null)) { - out.append(">" + printId(s[i])); + out.append(">" + printId(s[i], jvsuffix)); if (s[i].getDescription() != null) { out.append(" " + s[i].getDescription()); @@ -234,15 +227,4 @@ public class FastaFile extends AlignFile return out.toString(); } - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - @Override - public String print() - { - return print(getSeqsAsArray()); - } } diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index aa38540..20c44bc 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -94,12 +94,13 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * Constructor which does not parse the file immediately * * @param inFile - * @param type + * @param paste * @throws IOException */ - public FeaturesFile(String inFile, String type) throws IOException + public FeaturesFile(String inFile, DataSourceType paste) + throws IOException { - super(false, inFile, type); + super(false, inFile, paste); } /** @@ -119,7 +120,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * @param type * @throws IOException */ - public FeaturesFile(boolean parseImmediately, String inFile, String type) + public FeaturesFile(boolean parseImmediately, String inFile, + DataSourceType type) throws IOException { super(parseImmediately, inFile, type); @@ -731,9 +733,10 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * @return error message */ @Override - public String print() + public String print(SequenceI[] sqs, boolean jvsuffix) { - return "Use printGffFormat() or printJalviewFormat()"; + System.out.println("Use printGffFormat() or printJalviewFormat()"); + return null; } /** diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java new file mode 100644 index 0000000..a7113f6 --- /dev/null +++ b/src/jalview/io/FileFormat.java @@ -0,0 +1,530 @@ +package jalview.io; + +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) + { + @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("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) + throws IOException + { + return new PfamFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new PfamFile(); + } + }, + Stockholm("STH", "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) + throws IOException + { + return new StockholmFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new StockholmFile(); + } + + }, + + 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) + throws IOException + { + return new PIRFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new PIRFile(); + } + }, + 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) + throws IOException + { + return new BLCFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new BLCFile(); + } + }, + 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) + throws IOException + { + return new HtmlFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new HtmlFile(); + } + + @Override + public boolean isComplexAlignFile() + { + return true; + } + + }, + 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) + throws IOException + { + return new RnamlFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new RnamlFile(); + } + + }, + 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) + throws IOException + { + return new JSONFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new JSONFile(); + } + + @Override + public boolean isComplexAlignFile() + { + return true; + } + + }, + Pileup("PileUp", "?", false, false) + { + @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("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) + throws IOException + { + return new MSFfile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new MSFfile(); + } + + }, + 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) + throws IOException + { + return new ClustalFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new ClustalFile(); + } + }, + 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) + throws IOException + { + return new PhylipFile(source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new PhylipFile(); + } + }, + 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) + throws IOException + { + JPredFile af = new JPredFile(source); + af.removeNonSequences(); + return af; + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return null; // todo is this called? + } + + }, + Features("GFF or Jalview features", "gff2,gff3", false, false) + { + @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("PDB", "", false, false) + { + + @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 + .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); + } + } + + @Override + public AlignmentFileI getAlignmentFile(FileParse source) + throws IOException + { + boolean isParseWithJMOL = StructureImportSettings + .getDefaultStructureFileFormat() != PDBEntry.Type.PDB; + if (isParseWithJMOL) + { + return new JmolParser( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isProcessSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + source); + } + else + { + StructureImportSettings.setShowSeqFeatures(true); + return new MCview.PDBfile( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isProcessSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + source); + } + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new JmolParser(); // todo or null? + } + }, + MMCif("mmCIF", "cif", false, false) + { + + @Override + public AlignmentFileI getAlignmentFile(String inFile, + DataSourceType sourceType) throws IOException + { + return new JmolParser( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isProcessSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + inFile, sourceType); + } + + @Override + public AlignmentFileI getAlignmentFile(FileParse source) + throws IOException + { + return new JmolParser( + StructureImportSettings.isVisibleChainAnnotation(), + StructureImportSettings.isProcessSecondaryStructure(), + StructureImportSettings.isExternalSecondaryStructure(), + source); + } + + @Override + public AlignmentFileI getAlignmentFile() + { + return new JmolParser(); // todo or null? + } + }, + Jalview("Jalview", "jar,jvp", true, false) + { + + @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; + } + }; + + /** + * A lookup map of enums by upper-cased name + */ + private static Map names; + static + { + names = new HashMap(); + for (FileFormat format : FileFormat.values()) + { + names.put(format.toString().toUpperCase(), format); + } + } + + private boolean writable; + + private boolean readable; + + private String extensions; + + private String name; + + @Override + public boolean isComplexAlignFile() + { + return false; + } + + @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; + } + + @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; + } +} 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..f594a36 --- /dev/null +++ b/src/jalview/io/FileFormatI.java @@ -0,0 +1,30 @@ +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(); + + /** + * Returns a comma-separated list of file extensions associated with the + * format + * + * @return + */ + String getExtensions(); + + boolean isReadable(); + + boolean isWritable(); +} diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index b449d19..88f9ae5 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -24,6 +24,7 @@ import jalview.api.ComplexAlignFile; import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.api.FeaturesSourceI; +import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; @@ -48,11 +49,11 @@ public class FileLoader implements Runnable { String file; - String protocol; + DataSourceType protocol; - String format; + FileFormatI format; - FileParse source = null; // alternative specification of where data comes + AlignmentFileI source = null; // alternative specification of where data comes // from @@ -86,13 +87,14 @@ public class FileLoader implements Runnable } public void LoadFile(AlignViewport viewport, String file, - String protocol, String format) + DataSourceType protocol, FileFormatI format) { this.viewport = viewport; LoadFile(file, protocol, format); } - public void LoadFile(String file, String protocol, String format) + public void LoadFile(String file, DataSourceType protocol, + FileFormatI format) { this.file = file; this.protocol = protocol; @@ -116,7 +118,7 @@ public class FileLoader implements Runnable * @param file * @param protocol */ - public void LoadFile(String file, String protocol) + public void LoadFile(String file, DataSourceType protocol) { LoadFile(file, protocol, null); } @@ -125,27 +127,28 @@ public class FileLoader implements Runnable * Load alignment from (file, protocol) and wait till loaded * * @param file - * @param protocol + * @param sourceType * @return alignFrame constructed from file contents */ - public AlignFrame LoadFileWaitTillLoaded(String file, String protocol) + public AlignFrame LoadFileWaitTillLoaded(String file, + DataSourceType sourceType) { - return LoadFileWaitTillLoaded(file, protocol, null); + return LoadFileWaitTillLoaded(file, sourceType, null); } /** * Load alignment from (file, protocol) of type format and wait till loaded * * @param file - * @param protocol + * @param sourceType * @param format * @return alignFrame constructed from file contents */ - public AlignFrame LoadFileWaitTillLoaded(String file, String protocol, - String format) + public AlignFrame LoadFileWaitTillLoaded(String file, + DataSourceType sourceType, FileFormatI format) { this.file = file; - this.protocol = protocol; + this.protocol = sourceType; this.format = format; return _LoadFileWaitTillLoaded(); } @@ -157,12 +160,13 @@ public class FileLoader implements Runnable * @param format * @return alignFrame constructed from file contents */ - public AlignFrame LoadFileWaitTillLoaded(FileParse source, String format) + public AlignFrame LoadFileWaitTillLoaded(AlignmentFileI source, + FileFormatI format) { this.source = source; file = source.getInFile(); - protocol = source.type; + protocol = source.getDataSourceType(); this.format = format; return _LoadFileWaitTillLoaded(); } @@ -194,13 +198,13 @@ public class FileLoader implements Runnable public void updateRecentlyOpened() { Vector recent = new Vector(); - if (protocol.equals(FormatAdapter.PASTE)) + if (protocol == DataSourceType.PASTE) { // do nothing if the file was pasted in as text... there is no filename to // refer to it as. return; } - String type = protocol.equals(FormatAdapter.FILE) ? "RECENT_FILE" + String type = protocol == DataSourceType.FILE ? "RECENT_FILE" : "RECENT_URL"; String historyItems = jalview.bin.Cache.getProperty(type); @@ -229,18 +233,18 @@ public class FileLoader implements Runnable newHistory.append(recent.elementAt(i)); } - jalview.bin.Cache.setProperty(type, newHistory.toString()); + Cache.setProperty(type, newHistory.toString()); - if (protocol.equals(FormatAdapter.FILE)) + if (protocol == DataSourceType.FILE) { - jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format); + Cache.setProperty("DEFAULT_FILE_FORMAT", format.toString()); } } @Override public void run() { - String title = protocol.equals(AppletFormatAdapter.PASTE) ? "Copied From Clipboard" + String title = protocol == DataSourceType.PASTE ? "Copied From Clipboard" : file; Runtime rt = Runtime.getRuntime(); try @@ -254,10 +258,8 @@ public class FileLoader implements Runnable // just in case the caller didn't identify the file for us if (source != null) { - format = new IdentifyFile().identify(source, false); // identify - // stream and - // rewind rather - // than close + format = new IdentifyFile().identify(source, false); + // identify stream and rewind rather than close } else { @@ -266,7 +268,7 @@ public class FileLoader implements Runnable } - if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE")) + if (format == null) { Desktop.instance.stopLoading(); System.err.println("The input file \"" + file @@ -296,7 +298,7 @@ public class FileLoader implements Runnable loadtime = -System.currentTimeMillis(); AlignmentI al = null; - if (format.equalsIgnoreCase("Jalview")) + if (format == FileFormat.Jalview) { if (source != null) { @@ -310,8 +312,6 @@ public class FileLoader implements Runnable else { String error = AppletFormatAdapter.SUPPORTED_FORMATS; - if (FormatAdapter.isValidFormat(format)) - { try { if (source != null) @@ -332,15 +332,6 @@ public class FileLoader implements Runnable { error = ex.getMessage(); } - } - else - { - if (format != null && format.length() > 7) - { - // ad hoc message in format. - error = format + "\n" + error; - } - } if ((al != null) && (al.getHeight() > 0) && al.hasValidSequence()) { @@ -410,7 +401,7 @@ public class FileLoader implements Runnable } } // add metadata and update ui - if (!protocol.equals(AppletFormatAdapter.PASTE)) + if (!(protocol == DataSourceType.PASTE)) { alignFrame.setFileName(file, format); } diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index fddb565..dc0418f 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -95,7 +95,7 @@ public class FileParse */ protected String suffix = null; - protected String type = null; + protected DataSourceType dataSourceType = null; protected BufferedReader dataIn = null; @@ -139,7 +139,7 @@ public class FileParse suffix = from.suffix; errormessage = from.errormessage; // inherit potential error messages error = false; // reset any error condition. - type = from.type; + dataSourceType = from.dataSourceType; dataIn = from.dataIn; if (dataIn != null) { @@ -279,9 +279,9 @@ public class FileParse * configurable values for the origin and the type of the source */ public FileParse(BufferedReader source, String originString, - String typeString) + DataSourceType sourceType) { - type = typeString; + dataSourceType = sourceType; error = false; inFile = null; dataName = originString; @@ -304,18 +304,18 @@ public class FileParse * * @param fileStr * - datasource locator/content - * @param type + * @param sourceType * - protocol of source * @throws MalformedURLException * @throws IOException */ - public FileParse(String fileStr, String type) + public FileParse(String fileStr, DataSourceType sourceType) throws MalformedURLException, IOException { - this.type = type; + this.dataSourceType = sourceType; error = false; - if (type.equals(AppletFormatAdapter.FILE)) + if (sourceType == DataSourceType.FILE) { if (checkFileSource(fileStr)) { @@ -338,7 +338,7 @@ public class FileParse } } } - else if (type.equals(AppletFormatAdapter.URL)) + else if (sourceType == DataSourceType.URL) { try { @@ -375,13 +375,13 @@ public class FileParse error = true; } } - else if (type.equals(AppletFormatAdapter.PASTE)) + else if (sourceType == DataSourceType.PASTE) { errormessage = "PASTE INACCESSIBLE!"; dataIn = new BufferedReader(new StringReader(fileStr)); dataName = "Paste"; } - else if (type.equals(AppletFormatAdapter.CLASSLOADER)) + else if (sourceType == DataSourceType.CLASSLOADER) { errormessage = "RESOURCE CANNOT BE LOCATED"; java.io.InputStream is = getClass() @@ -407,7 +407,7 @@ public class FileParse else { errormessage = "PROBABLE IMPLEMENTATION ERROR : Datasource Type given as '" - + (type != null ? type : "null") + "'"; + + (sourceType != null ? sourceType : "null") + "'"; error = true; } if (dataIn == null || error) @@ -625,4 +625,9 @@ public class FileParse { return null; } + + public DataSourceType getDataSourceType() + { + return dataSourceType; + } } diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 6d94616..1408cd1 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -22,6 +22,7 @@ package jalview.io; import jalview.api.AlignExportSettingI; import jalview.api.AlignmentViewPanel; +import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; @@ -29,6 +30,9 @@ import jalview.datamodel.ColumnSelection; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.util.Comparison; + +import java.io.IOException; /** * Additional formatting methods used by the application in a number of places. @@ -76,7 +80,7 @@ public class FormatAdapter extends AppletFormatAdapter } } - public String formatSequences(String format, SequenceI[] seqs, + public String formatSequences(FileFormatI format, SequenceI[] seqs, String[] omitHiddenColumns, int[] exportRange) { @@ -112,14 +116,14 @@ public class FormatAdapter extends AppletFormatAdapter startIndex = startEnd[0]; endIndex = startEnd[1]; // get first non-gaped residue start position - while (jalview.util.Comparison.isGap(seqs[i] + while (Comparison.isGap(seqs[i] .getCharAt(startIndex)) && startIndex < endIndex) { startIndex++; } // get last non-gaped residue end position - while (jalview.util.Comparison.isGap(seqs[i].getCharAt(endIndex)) + while (Comparison.isGap(seqs[i].getCharAt(endIndex)) && endIndex > startIndex) { endIndex--; @@ -144,105 +148,101 @@ public class FormatAdapter extends AppletFormatAdapter * * * @param format - * Format string as givien in the AppletFormatAdaptor list (exact - * match to name of class implementing file io for that format) * @param seqs * vector of sequences to write * * @return String containing sequences in desired format */ - public String formatSequences(String format, SequenceI[] seqs) + public String formatSequences(FileFormatI format, SequenceI[] seqs) { + // + // try + // { + boolean withSuffix = getCacheSuffixDefault(format); + return format.getAlignmentFile().print(seqs, withSuffix); + // null; + // + // if (format.equalsIgnoreCase("FASTA")) + // { + // afile = new FastaFile(); + // afile.addJVSuffix(jalview.bin.Cache.getDefault("FASTA_JVSUFFIX", + // true)); + // } + // else if (format.equalsIgnoreCase("MSF")) + // { + // afile = new MSFfile(); + // afile.addJVSuffix(jalview.bin.Cache + // .getDefault("MSF_JVSUFFIX", true)); + // } + // else if (format.equalsIgnoreCase("PileUp")) + // { + // afile = new PileUpfile(); + // afile.addJVSuffix(jalview.bin.Cache.getDefault("PILEUP_JVSUFFIX", + // true)); + // } + // else if (format.equalsIgnoreCase("CLUSTAL")) + // { + // afile = new ClustalFile(); + // afile.addJVSuffix(jalview.bin.Cache.getDefault("CLUSTAL_JVSUFFIX", + // true)); + // } + // else if (format.equalsIgnoreCase("BLC")) + // { + // afile = new BLCFile(); + // afile.addJVSuffix(jalview.bin.Cache + // .getDefault("BLC_JVSUFFIX", true)); + // } + // else if (format.equalsIgnoreCase("PIR")) + // { + // afile = new PIRFile(); + // afile.addJVSuffix(jalview.bin.Cache + // .getDefault("PIR_JVSUFFIX", true)); + // } + // else if (format.equalsIgnoreCase("PFAM")) + // { + // afile = new PfamFile(); + // afile.addJVSuffix(jalview.bin.Cache.getDefault("PFAM_JVSUFFIX", + // true)); + // } + // /* + // * amsa is not supported by this function - it requires an alignment + // * rather than a sequence vector else if + // (format.equalsIgnoreCase("AMSA")) + // * { afile = new AMSAFile(); afile.addJVSuffix( + // * jalview.bin.Cache.getDefault("AMSA_JVSUFFIX", true)); } + // */ - try - { - AlignFile afile = null; - - if (format.equalsIgnoreCase("FASTA")) - { - afile = new FastaFile(); - afile.addJVSuffix(jalview.bin.Cache.getDefault("FASTA_JVSUFFIX", - true)); - } - else if (format.equalsIgnoreCase("MSF")) - { - afile = new MSFfile(); - afile.addJVSuffix(jalview.bin.Cache - .getDefault("MSF_JVSUFFIX", true)); - } - else if (format.equalsIgnoreCase("PileUp")) - { - afile = new PileUpfile(); - afile.addJVSuffix(jalview.bin.Cache.getDefault("PILEUP_JVSUFFIX", - true)); - } - else if (format.equalsIgnoreCase("CLUSTAL")) - { - afile = new ClustalFile(); - afile.addJVSuffix(jalview.bin.Cache.getDefault("CLUSTAL_JVSUFFIX", - true)); - } - else if (format.equalsIgnoreCase("BLC")) - { - afile = new BLCFile(); - afile.addJVSuffix(jalview.bin.Cache - .getDefault("BLC_JVSUFFIX", true)); - } - else if (format.equalsIgnoreCase("PIR")) - { - afile = new PIRFile(); - afile.addJVSuffix(jalview.bin.Cache - .getDefault("PIR_JVSUFFIX", true)); - } - else if (format.equalsIgnoreCase("PFAM")) - { - afile = new PfamFile(); - afile.addJVSuffix(jalview.bin.Cache.getDefault("PFAM_JVSUFFIX", - true)); - } - /* - * amsa is not supported by this function - it requires an alignment - * rather than a sequence vector else if (format.equalsIgnoreCase("AMSA")) - * { afile = new AMSAFile(); afile.addJVSuffix( - * jalview.bin.Cache.getDefault("AMSA_JVSUFFIX", true)); } - */ - - afile.setSeqs(seqs); - String afileresp = afile.print(); - if (afile.hasWarningMessage()) - { - System.err.println("Warning raised when writing as " + format - + " : " + afile.getWarningMessage()); - } - return afileresp; - } catch (Exception e) - { - System.err.println("Failed to write alignment as a '" + format - + "' file\n"); - e.printStackTrace(); - } - - return null; +// afile.setSeqs(seqs); +// String afileresp = afile.print(); +// if (afile.hasWarningMessage()) +// { +// System.err.println("Warning raised when writing as " + format +// + " : " + afile.getWarningMessage()); +// } +// return afileresp; +// } catch (Exception e) +// { +// System.err.println("Failed to write alignment as a '" + format +// + "' file\n"); +// e.printStackTrace(); +// } +// +// return null; } - public boolean getCacheSuffixDefault(String format) + public boolean getCacheSuffixDefault(FileFormatI format) { - if (isValidFormat(format)) - { - return jalview.bin.Cache.getDefault(format.toUpperCase() - + "_JVSUFFIX", true); - } - return false; + return Cache.getDefault(format.toString() + "_JVSUFFIX", true); } - public String formatSequences(String format, AlignmentI alignment, + public String formatSequences(FileFormatI format, AlignmentI alignment, String[] omitHidden, int[] exportRange, ColumnSelection colSel) { return formatSequences(format, alignment, omitHidden, exportRange, getCacheSuffixDefault(format), colSel, null); } - public String formatSequences(String format, AlignmentI alignment, + public String formatSequences(FileFormatI format, AlignmentI alignment, String[] omitHidden, int[] exportRange, ColumnSelection colSel, SequenceGroup sgp) { @@ -262,7 +262,7 @@ public class FormatAdapter extends AppletFormatAdapter * defines hidden columns that are edited out of annotation * @return string representation of the alignment formatted as format */ - public String formatSequences(String format, AlignmentI alignment, + public String formatSequences(FileFormatI format, AlignmentI alignment, String[] omitHidden, int[] exportRange, boolean suffix, ColumnSelection colSel) { @@ -270,9 +270,9 @@ public class FormatAdapter extends AppletFormatAdapter suffix, colSel, null); } - public String formatSequences(String format, AlignmentI alignment, + public String formatSequences(FileFormatI format, AlignmentI alignment, String[] omitHidden, int[] exportRange, boolean suffix, - ColumnSelection colSel, jalview.datamodel.SequenceGroup selgp) + ColumnSelection colSel, SequenceGroup selgp) { if (omitHidden != null) { @@ -305,26 +305,20 @@ public class FormatAdapter extends AppletFormatAdapter return this.formatSequences(format, alignment, suffix); } - /** - * validate format is valid for IO in Application. This is basically the - * AppletFormatAdapter.isValidFormat call with additional checks for - * Application only formats like 'Jalview'. - * - * @param format - * a format string to be compared with list of readable or writable - * formats (READABLE_FORMATS or WRITABLE_FORMATS) - * @param forwriting - * when true, format is checked against list of writable formats. - * @return true if format is valid - */ - public static final boolean isValidIOFormat(String format, - boolean forwriting) + @Override + public AlignmentI readFile(String file, DataSourceType sourceType, + FileFormatI fileFormat) throws IOException { - if (format.equalsIgnoreCase("jalview")) - { - return true; - } - return AppletFormatAdapter.isValidFormat(format, forwriting); + AlignmentI al = super.readFile(file, sourceType, fileFormat); + return al; + } + + @Override + public AlignmentI readFromFile(FileParse source, FileFormatI format) + throws IOException + { + AlignmentI al = super.readFromFile(source, format); + return al; } /** @@ -336,7 +330,7 @@ public class FormatAdapter extends AppletFormatAdapter * alignment panel originating the view * @return String containing flat file */ - public String formatSequences(String format, AlignmentViewPanel ap, + public String formatSequences(FileFormatI format, AlignmentViewPanel ap, boolean selectedOnly) { return formatSequences(format, getCacheSuffixDefault(format), ap, diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index df0dc06..2e4a781 100755 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -20,16 +20,20 @@ */ package jalview.io; +import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.gui.AlignViewport; import jalview.gui.AlignmentPanel; import jalview.gui.FeatureRenderer; import jalview.gui.SequenceRenderer; +import jalview.util.BrowserLauncher; +import jalview.util.ImageMaker; import jalview.util.MessageManager; import java.awt.Color; import java.awt.Font; +import java.io.FileWriter; import java.io.PrintWriter; public class HTMLOutput @@ -52,9 +56,8 @@ public class HTMLOutput fr.transferSettings(fr1); JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "html" }, new String[] { "HTML files" }, - "HTML files"); + Cache.getProperty("LAST_DIRECTORY"), ImageMaker.HTML_EXTENSION, + "HTML files", "HTML files"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.save_as_html")); @@ -65,13 +68,12 @@ public class HTMLOutput if (value == JalviewFileChooser.APPROVE_OPTION) { String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser + Cache.setProperty("LAST_DIRECTORY", chooser .getSelectedFile().getParent()); try { - PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter( - choice)); + PrintWriter out = new PrintWriter(new FileWriter(choice)); out.println(""); out.println("