From 697f55e4ef253fd00f8520e9f43df5e719b8f1b3 Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 23 May 2012 20:19:17 +0100 Subject: [PATCH] JAL-1078 - extend applet cut'n'paste features/annotation to support t-coffee file JAL-1102 - feedback for successful or unsuccessful parsing of annotation files --- src/jalview/appletgui/AlignFrame.java | 31 ++++++------- src/jalview/appletgui/CutAndPasteTransfer.java | 58 ++++++++++++++++++++---- src/jalview/bin/JalviewLite.java | 4 +- src/jalview/javascript/JalviewLiteJsApi.java | 3 +- 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index e03f2f4..842f82d 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -236,9 +236,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis * @param type is protocol for accessing data referred to by file */ - public void parseFeaturesFile(String file, String type) + public boolean parseFeaturesFile(String file, String type) { - parseFeaturesFile(file, type, true); + return parseFeaturesFile(file, type, true); } /** @@ -247,9 +247,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis * @param file file URL, content, or other resolvable path * @param type 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 void parseFeaturesFile(String file, String type, boolean autoenabledisplay) + public boolean parseFeaturesFile(String file, String type, boolean autoenabledisplay) { + // TODO: test if importing a features file onto an alignment which already has features with links overwrites the original links. + Hashtable featureLinks = new Hashtable(); boolean featuresFile = false; try @@ -279,8 +282,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis viewport.featureSettings.refreshTable(); } alignPanel.paintAlignment(true); + statusBar.setText("Successfully added features to alignment."); } - + return featuresFile; } public void keyPressed(KeyEvent evt) @@ -753,9 +757,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis { loadAnnotations(); } - else if( source == loadScores ) { - loadScores(); - } else if (source == outputAnnotations) { outputAnnotations(true); @@ -1104,7 +1105,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis public void loadAnnotations() { CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this); - cap.setText("Paste your features / annotations file here."); + cap.setText("Paste your features / annotations / T-coffee score file here."); cap.setAnnotationImport(); Frame frame = new Frame(); frame.add(cap); @@ -1112,11 +1113,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis } - public void loadScores() { - //TODO - - } - public String outputAnnotations(boolean displayTextbox) { String annotation = new AnnotationFile().printAnnotations( @@ -2288,11 +2284,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis overview.getPreferredSize().height + 50); frame.pack(); + final AlignmentPanel ap=alignPanel; frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { - alignPanel.setOverviewPanel(null); + if (ap!=null) { + ap.setOverviewPanel(null); + } }; }); @@ -2795,8 +2794,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis MenuItem loadAnnotations = new MenuItem("Load Features/Annotations ..."); - MenuItem loadScores = new MenuItem("Load Associated T-Coffee scores ..."); - MenuItem outputFeatures = new MenuItem("Export Features ..."); MenuItem outputAnnotations = new MenuItem("Export Annotations ..."); @@ -3003,7 +3000,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis loadTree.addActionListener(this); loadAnnotations.addActionListener(this); - loadScores.addActionListener(this); outputFeatures.addActionListener(this); outputAnnotations.addActionListener(this); selectAllSequenceMenuItem.addActionListener(this); @@ -3221,7 +3217,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemLis fileMenu.add(inputText); fileMenu.add(loadTree); fileMenu.add(loadAnnotations); - fileMenu.add(loadScores); fileMenu.addSeparator(); fileMenu.add(outputTextboxMenu); diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index 4a29568..ec31b0a 100755 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -22,6 +22,7 @@ import java.awt.event.*; import jalview.datamodel.*; import jalview.io.*; +import jalview.schemes.TCoffeeColourScheme; public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener @@ -157,18 +158,57 @@ public class CutAndPasteTransfer extends Panel implements ActionListener, } else if (annotationImport) { - if (new AnnotationFile().readAnnotationFile( - alignFrame.viewport.getAlignment(), textarea.getText(), - jalview.io.AppletFormatAdapter.PASTE)) + TCoffeeScoreFile tcf = null; + try { - alignFrame.alignPanel.fontChanged(); - alignFrame.alignPanel.setScrollValues(0, 0); - + tcf = new TCoffeeScoreFile(textarea.getText(), + jalview.io.AppletFormatAdapter.PASTE); + if (tcf.isValid()) + { + if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(), + true)) + { + alignFrame.tcoffeeColour.setEnabled(true); + alignFrame.alignPanel.fontChanged(); + alignFrame.changeColour(new TCoffeeColourScheme( + alignFrame.viewport.getAlignment())); + alignFrame.statusBar + .setText("Successfully pasted T-Coffee scores to alignment."); + } + else + { + // file valid but didn't get added to alignment for some reason + alignFrame.statusBar.setText("Failed to add T-Coffee scores: "+(tcf.getWarningMessage()!=null ? tcf.getWarningMessage():"")); + } + } + else + { + tcf = null; + } + } catch (Exception x) + { + tcf = null; } - else + if (tcf == null) { - alignFrame.parseFeaturesFile(textarea.getText(), - jalview.io.AppletFormatAdapter.PASTE); + if (new AnnotationFile().readAnnotationFile( + alignFrame.viewport.getAlignment(), textarea.getText(), + jalview.io.AppletFormatAdapter.PASTE)) + { + alignFrame.alignPanel.fontChanged(); + alignFrame.alignPanel.setScrollValues(0, 0); + alignFrame.statusBar + .setText("Successfully pasted annotation to alignment."); + + } + else + { + if (!alignFrame.parseFeaturesFile(textarea.getText(), + jalview.io.AppletFormatAdapter.PASTE)) + { + alignFrame.statusBar.setText("Couldn't parse pasted text as a valid annotation, feature, GFF, or T-Coffee score file."); + } + } } } else if (alignFrame != null) diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index 3ae1be6..9c23a0a 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -732,9 +732,9 @@ public class JalviewLite extends Applet implements * jalview.bin.JalviewLiteJsApi#loadAnnotationFrom(jalview.appletgui.AlignFrame * , java.lang.String) */ - public void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay) + public boolean loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay) { - alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE, autoenabledisplay); + return alf.parseFeaturesFile(features, AppletFormatAdapter.PASTE, autoenabledisplay); } diff --git a/src/jalview/javascript/JalviewLiteJsApi.java b/src/jalview/javascript/JalviewLiteJsApi.java index de3d29e..f849dc3 100644 --- a/src/jalview/javascript/JalviewLiteJsApi.java +++ b/src/jalview/javascript/JalviewLiteJsApi.java @@ -291,8 +291,9 @@ public interface JalviewLiteJsApi * @param alf * @param features - gff or features file * @param autoenabledisplay - when true, feature display will be enabled if any features can be parsed from the string. + * @return true if data parsed as features */ - public abstract void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay); + public abstract boolean loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay); /** * get the sequence features in the given format (Jalview or GFF) -- 1.7.10.2