Merge branch 'bug/JAL-1486_flatfile' into Release_2_8_2_Branch
authorj.procter@dundee.ac.uk <jprocter@carderbee.dyn.lifesci.dundee.ac.uk>
Fri, 12 Sep 2014 16:33:51 +0000 (17:33 +0100)
committerj.procter@dundee.ac.uk <jprocter@carderbee.dyn.lifesci.dundee.ac.uk>
Fri, 12 Sep 2014 16:33:51 +0000 (17:33 +0100)
patch to export of selected area so that start/end numberings are correct. main file export option still needs fixing.

src/jalview/api/AlignViewControllerI.java
src/jalview/api/AlignViewportI.java
src/jalview/appletgui/APopupMenu.java
src/jalview/gui/PopupMenu.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/io/FormatAdapter.java
src/jalview/viewmodel/AlignmentViewport.java

index fadc09e..35f084f 100644 (file)
@@ -27,10 +27,13 @@ package jalview.api;
  * 
  *         All operations should return true if the view has changed as a result
  *         of the operation
- * @param <ViewportI>
+ * 
+ *         The controller holds methods that operate on an alignment view,
+ *         modifying its state in some way that may result in side effects
+ *         reflected in an associated GUI
  * 
  */
-public interface AlignViewControllerI<ViewportI>
+public interface AlignViewControllerI
 {
 
   public boolean makeGroupsFromSelection();
index 567ae83..d8ba30d 100644 (file)
@@ -22,6 +22,7 @@ package jalview.api;
 
 import java.awt.Color;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 
 import jalview.analysis.Conservation;
@@ -191,4 +192,12 @@ public interface AlignViewportI
 
   void setConservation(Conservation cons);
 
+  /**
+   * get a copy of the currently visible alignment annotation
+   * @param selectedOnly if true - trim to selected regions on the alignment
+   * @return an empty list or new alignment annotation objects shown only visible columns trimmed to selected region only
+   */
+  List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
+          boolean selectedOnly);
+
 }
index d98e2aa..58c7703 100644 (file)
@@ -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));
 
   }
 
index 44860a1..0957d28 100644 (file)
  */
 package jalview.gui;
 
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import javax.swing.*;
-
-import jalview.analysis.*;
-import jalview.commands.*;
-import jalview.datamodel.*;
-import jalview.io.*;
-import jalview.schemes.*;
+import jalview.analysis.AAFrequency;
+import jalview.analysis.Conservation;
+import jalview.commands.ChangeCaseCommand;
+import jalview.commands.EditCommand;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceFeature;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.io.FormatAdapter;
+import jalview.io.SequenceAnnotationReport;
+import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.Blosum62ColourScheme;
+import jalview.schemes.BuriedColourScheme;
+import jalview.schemes.ClustalxColourScheme;
+import jalview.schemes.HelixColourScheme;
+import jalview.schemes.HydrophobicColourScheme;
+import jalview.schemes.NucleotideColourScheme;
+import jalview.schemes.PIDColourScheme;
+import jalview.schemes.PurinePyrimidineColourScheme;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.StrandColourScheme;
+import jalview.schemes.TaylorColourScheme;
+import jalview.schemes.TurnColourScheme;
+import jalview.schemes.UserColourScheme;
+import jalview.schemes.ZappoColourScheme;
 import jalview.util.GroupUrlLink;
 import jalview.util.GroupUrlLink.UrlStringTooLongException;
 import jalview.util.MessageManager;
 import jalview.util.UrlLink;
 
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JColorChooser;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButtonMenuItem;
+
 /**
  * DOCUMENT ME!
  * 
@@ -256,8 +291,8 @@ public class PopupMenu extends JPopupMenu
             {
               // TODO re JAL-860: optionally open dialog or provide a menu entry
               // allowing user to open just one structure per sequence
-              //new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
-              //{ pdb })[0], null, ap);
+              // new AppJmol(pdb, ap.av.collateForPDB(new PDBEntry[]
+              // { pdb })[0], null, ap);
               new StructureViewer(ap.getStructureSelectionManager())
                       .viewStructures(pdb,
                               ap.av.collateForPDB(new PDBEntry[]
@@ -522,7 +557,7 @@ public class PopupMenu extends JPopupMenu
       {
         Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence()
                 .getPDBId();
-        if (pes != null && pes.size()>0)
+        if (pes != null && pes.size() > 0)
         {
           reppdb.put(pes.get(0).getId(), pes.get(0));
           for (PDBEntry pe : pes)
@@ -561,7 +596,8 @@ public class PopupMenu extends JPopupMenu
           @Override
           public void actionPerformed(ActionEvent e)
           {
-            new StructureViewer(ap.getStructureSelectionManager()).viewStructures(ap, pe, ap.av.collateForPDB(pe));
+            new StructureViewer(ap.getStructureSelectionManager())
+                    .viewStructures(ap, pe, ap.av.collateForPDB(pe));
           }
         });
         if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
@@ -579,7 +615,8 @@ public class PopupMenu extends JPopupMenu
             @Override
             public void actionPerformed(ActionEvent e)
             {
-              new StructureViewer(ap.getStructureSelectionManager()).viewStructures(ap, pr, ap.av.collateForPDB(pr));
+              new StructureViewer(ap.getStructureSelectionManager())
+                      .viewStructures(ap, pr, ap.av.collateForPDB(pr));
             }
           });
         }
@@ -2071,23 +2108,8 @@ public class PopupMenu extends JPopupMenu
     System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
     // or we simply trust the user wants
     // wysiwig behaviour
-    SequenceGroup sg = ap.av.getSelectionGroup();
-    ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
-    omitHidden = ap.av.getViewAsString(true);
-    Alignment oal = new Alignment(ap.av.getSequenceSelection());
-    AlignmentAnnotation[] nala = ap.av.getAlignment()
-            .getAlignmentAnnotation();
-    if (nala != null)
-    {
-      for (int i = 0; i < nala.length; i++)
-      {
-        AlignmentAnnotation na = nala[i];
-        oal.addAnnotation(na);
-      }
-    }
-    cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
-            oal, omitHidden, csel, sg));
-    oal = null;
+
+    cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(), ap.av, true));
   }
 
   public void pdbFromFile_actionPerformed()
index d7da302..3f9a425 100755 (executable)
@@ -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.*;
 
 /**
@@ -48,7 +50,7 @@ public class AppletFormatAdapter
    * method
    */
   public static final String[] WRITEABLE_FORMATS = new String[]
-  { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA" };
+  { "BLC", "CLUSTAL", "FASTA", "MSF", "PileUp", "PIR", "PFAM", "AMSA", "STH" };
 
   /**
    * List of extensions corresponding to file format types in WRITABLE_FNAMES
@@ -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<AlignmentAnnotation> 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
index 9913428..c2a317a 100755 (executable)
@@ -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);
+  }
+
 }
index 0c8afaa..0fa4a3c 100644 (file)
@@ -1243,6 +1243,28 @@ public abstract class AlignmentViewport implements AlignViewportI
 
   }
 
+  @Override
+  public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
+  {
+    ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
+    AlignmentAnnotation[] aa;
+    if ((aa=alignment.getAlignmentAnnotation())!=null)
+    {
+      for (AlignmentAnnotation annot:aa)
+      {
+        AlignmentAnnotation clone = new AlignmentAnnotation(annot);
+        if (selectedOnly && selectionGroup!=null)
+        {
+          colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
+        } else {
+          colSel.makeVisibleAnnotation(clone);
+        }
+        ala.add(clone);
+      }
+    }
+    return ala;
+  }
+
   /**
    * @return the padGaps
    */