From 4b8e37b39d6599396ea8538e1737b65eb869aa21 Mon Sep 17 00:00:00 2001 From: "j.procter@dundee.ac.uk" Date: Fri, 12 Sep 2014 17:27:47 +0100 Subject: [PATCH] JAL-1486 JAL-1543 pushed alignment viewport->view->flat file logic into jalview.io to unify applet and application selected region export method --- src/jalview/appletgui/APopupMenu.java | 5 ++--- src/jalview/gui/PopupMenu.java | 15 +-------------- src/jalview/io/AppletFormatAdapter.java | 31 +++++++++++++++++++++++++++++++ src/jalview/io/FormatAdapter.java | 13 +++++++++++++ 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index d98e2aa..58c7703 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -672,9 +672,8 @@ public class APopupMenu extends java.awt.PopupMenu implements // TODO consider using getSequenceSelection instead here cap.setText(new jalview.io.AppletFormatAdapter().formatSequences( - e.getActionCommand(), - new Alignment(ap.av.getSelectionAsNewSequence()), - ap.av.showJVSuffix)); + e.getActionCommand(), + ap.av.showJVSuffix, ap.av, true)); } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index e84a799..0957d28 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -2109,20 +2109,7 @@ public class PopupMenu extends JPopupMenu // or we simply trust the user wants // wysiwig behaviour - AlignmentView selvew = ap.av.getAlignmentView(true, false); - AlignmentI aselview = selvew.getVisibleAlignment(ap.av - .getGapCharacter()); - List ala = (ap.av - .getVisibleAlignmentAnnotation(true)); - if (ala != null) - { - for (AlignmentAnnotation aa : ala) - { - aselview.addAnnotation(aa); - } - } - cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(), - aselview, null, null, null)); + cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(), ap.av, true)); } public void pdbFromFile_actionPerformed() diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 26fa854..3f9a425 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -22,7 +22,9 @@ package jalview.io; import java.io.File; import java.io.InputStream; +import java.util.List; +import jalview.api.AlignViewportI; import jalview.datamodel.*; /** @@ -405,6 +407,35 @@ public class AppletFormatAdapter } } + + /** + * create an alignment flatfile from a Jalview alignment view + * @param format + * @param jvsuffix + * @param av + * @param selectedOnly + * @return flatfile in a string + */ + public String formatSequences(String format, boolean jvsuffix, + AlignViewportI av, boolean selectedOnly) + { + + AlignmentView selvew = av.getAlignmentView(selectedOnly, false); + AlignmentI aselview = selvew.getVisibleAlignment(av + .getGapCharacter()); + List ala = (av + .getVisibleAlignmentAnnotation(selectedOnly)); + if (ala != null) + { + for (AlignmentAnnotation aa : ala) + { + aselview.addAnnotation(aa); + } + } + + return formatSequences(format, aselview, jvsuffix); + } + /** * Construct an output class for an alignment in a particular filetype TODO: * allow caller to detect errors and warnings encountered when generating diff --git a/src/jalview/io/FormatAdapter.java b/src/jalview/io/FormatAdapter.java index 9913428..c2a317a 100755 --- a/src/jalview/io/FormatAdapter.java +++ b/src/jalview/io/FormatAdapter.java @@ -20,6 +20,7 @@ */ package jalview.io; +import jalview.api.AlignViewportI; import jalview.datamodel.*; /** @@ -247,4 +248,16 @@ public class FormatAdapter extends AppletFormatAdapter } return AppletFormatAdapter.isValidFormat(format, forwriting); } + + /** + * Create a flat file representation of a given view or selected region of a view + * @param format + * @param av + * @return String containing flat file + */ + public String formatSequences(String format, AlignViewportI av, boolean selectedOnly) + { + return formatSequences(format, getCacheSuffixDefault(format), av, selectedOnly); + } + } -- 1.7.10.2