Merge branch 'JAL-1372_referenceseq' into feature_29/JAL-1372_referenceseq
authorJim Procter <jprocter@dundee.ac.uk>
Fri, 9 Jan 2015 17:12:04 +0000 (17:12 +0000)
committerJim Procter <jprocter@dundee.ac.uk>
Fri, 9 Jan 2015 17:12:04 +0000 (17:12 +0000)
merge forward to implement support for reference sequences in 2.9
Conflicts:
resources/lang/Messages.properties
src/jalview/appletgui/APopupMenu.java
src/jalview/datamodel/Alignment.java
src/jalview/gui/PopupMenu.java

12 files changed:
resources/lang/Messages.properties
src/jalview/api/AlignViewportI.java
src/jalview/appletgui/APopupMenu.java
src/jalview/appletgui/IdCanvas.java
src/jalview/appletgui/SequenceRenderer.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/SequenceCollectionI.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/IdCanvas.java
src/jalview/gui/PopupMenu.java
src/jalview/gui/SequenceRenderer.java
src/jalview/viewmodel/AlignmentViewport.java

index fce8470..7adae2a 100644 (file)
@@ -57,8 +57,10 @@ action.by_pairwise_id = by Pairwise Identity
 action.by_id = by Id
 action.by_length = by Length
 action.by_group = by Group
+action.unmark_as_reference = Unmark as Reference 
+action.set_as_reference = Set as Reference 
 action.remove = Remove
-action.remove_redundancy = Remove Redundancy
+action.remove_redundancy = Remove Redundancy...
 action.pairwise_alignment = Pairwise Alignments...
 action.by_rna_helixes = by RNA Helices
 action.user_defined = User Defined...
@@ -476,8 +478,8 @@ label.settings_for_type = Settings for {0}
 label.view_full_application = View in Full Application
 label.load_associated_tree = Load Associated Tree ...
 label.load_features_annotations = Load Features/Annotations ...
-label.export_features = Export Features
-label.export_annotations = Export Annotations
+label.export_features = Export Features ...
+label.export_annotations = Export Annotations ...
 label.jalview_copy = Copy (Jalview Only)
 label.jalview_cut = Cut (Jalview Only)
 label.to_upper_case = To Upper Case
@@ -595,7 +597,7 @@ label.figure_id_column_width = Figure ID column width
 label.use_modeller_output = Use Modeller Output
 label.wrap_alignment = Wrap Alignment
 label.right_align_ids = Right Align Ids
-label.sequence_name_italics = Seq Name Italics
+label.sequence_name_italics = Sequence Name Italics
 label.open_overview = Open Overview
 label.default_colour_scheme_for_alignment = Default Colour Scheme for alignment
 label.annotation_shading_default = Annotation Shading Default
index 24ff7a6..1c9d112 100644 (file)
@@ -163,6 +163,29 @@ public interface AlignViewportI
    */
   void updateGroupAnnotationSettings(boolean applyGlobalSettings,
           boolean preserveNewGroupSettings);
+  
+  /**
+   * @return true if a reference sequence is set and should be displayed
+   */
+  public boolean isDisplayReferenceSeq();
+
+  /**
+   * @return set the flag for displaying reference sequences when they are
+   *         available
+   */
+  public void setDisplayReferenceSeq(boolean displayReferenceSeq);
+
+  /**
+   * @return true if colourschemes should render according to reference sequence
+   *         rather than consensus if available
+   */
+  public boolean isColourByReferenceSeq();
+
+  /**
+   * @return true set flag for deciding if colourschemes should render according
+   *         to reference sequence rather than consensus if available
+   */
+  public void setColourByReferenceSeq(boolean colourByReferenceSeq);
 
   void setSequenceColour(SequenceI seq, Color col);
 
index aa1ab21..c58fc5b 100644 (file)
@@ -152,6 +152,8 @@ public class APopupMenu extends java.awt.PopupMenu implements
   MenuItem selSeqDetails = new MenuItem(
           MessageManager.getString("label.sequence_details") + "...");
 
+  MenuItem makeReferenceSeq = new MenuItem();
+  
   Sequence seq;
 
   MenuItem revealAll = new MenuItem();
@@ -347,6 +349,17 @@ public class APopupMenu extends java.awt.PopupMenu implements
     if (seq != null)
     {
       seqMenu.setLabel(seq.getName());
+      if (seq == ap.av.getAlignment().getSeqrep())
+      {
+        makeReferenceSeq.setLabel(MessageManager
+                .getString("action.unmark_as_reference"));// Unmark
+                                                          // representative");
+      }
+      else
+      {
+        makeReferenceSeq.setLabel(MessageManager
+                .getString("action.set_as_reference")); // );
+      }
       repGroup.setLabel(MessageManager.formatMessage(
               "label.represent_group_with", new String[]
               { seq.getName() }));
@@ -515,6 +528,10 @@ public class APopupMenu extends java.awt.PopupMenu implements
     {
       editName();
     }
+    else if (source == makeReferenceSeq)
+    {
+      makeReferenceSeq_actionPerformed();
+    }
     else if (source == sequenceDetails)
     {
       showSequenceDetails();
@@ -909,6 +926,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
     toLower.addActionListener(this);
     editMenu.add(toggleCase);
     seqMenu.add(sequenceName);
+    seqMenu.add(makeReferenceSeq);
     // seqMenu.add(sequenceDetails);
 
     if (!ap.av.applet.useXtrnalSviewer)
@@ -928,6 +946,7 @@ public class APopupMenu extends java.awt.PopupMenu implements
     repGroup.addActionListener(this);
     revealAll.addActionListener(this);
     revealSeq.addActionListener(this);
+    makeReferenceSeq.addActionListener(this);
   }
 
   void refresh()
@@ -1117,6 +1136,28 @@ public class APopupMenu extends java.awt.PopupMenu implements
     getGroup().setDisplayText(showText.getState());
     refresh();
   }
+  public void makeReferenceSeq_actionPerformed()
+  {
+    if (!ap.av.getAlignment().hasSeqrep())
+    {
+      // initialise the display flags so the user sees something happen
+      ap.av.setDisplayReferenceSeq(true);
+      ap.av.setColourByReferenceSeq(true);
+      ap.av.getAlignment().setSeqrep(seq);
+    }
+    else
+    {
+      if (ap.av.getAlignment().getSeqrep() == seq)
+      {
+        ap.av.getAlignment().setSeqrep(null);
+      }
+      else
+      {
+        ap.av.getAlignment().setSeqrep(seq);
+      }
+    }
+    refresh();
+  }
 
   public void showNonconserved_itemStateChanged()
   {
index 25aa315..0ac4e55 100755 (executable)
@@ -227,7 +227,7 @@ public class IdCanvas extends Panel
 
           SequenceI s = av.getAlignment().getSequenceAt(i);
           gg.setFont(italic);
-          if (av.hasHiddenRows())
+          if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
           {
             setHiddenFont(s);
           }
@@ -257,7 +257,7 @@ public class IdCanvas extends Panel
         }
         gg.setFont(italic);
         // boolean isrep=false;
-        if (av.hasHiddenRows())
+        if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
         {
           // isrep =
           setHiddenFont(seq);
@@ -366,8 +366,7 @@ public class IdCanvas extends Panel
     Font bold = new Font(av.getFont().getName(), Font.BOLD, av.getFont()
             .getSize());
 
-    if (av.getHiddenRepSequences() != null
-            && av.getHiddenRepSequences().containsKey(seq))
+    if (av.isHiddenRepSequence(seq))
     {
       gg.setFont(bold);
       return true;
index 92d5beb..9badf43 100755 (executable)
@@ -230,7 +230,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     }
 
     char s = ' ';
-
+    boolean srep = av.isDisplayReferenceSeq();
     for (int i = start; i <= end; i++)
     {
       graphics.setColor(Color.black);
@@ -255,9 +255,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
         }
         if (currentSequenceGroup.getShowNonconserved())
         {
-          // cheat - use this if we have a consensus for each group: s =
-          // getDisplayChar(currentSequenceGroup.getConsensus(), i, s, '.');
-          s = getDisplayChar(av.getAlignmentConsensusAnnotation(), i, s,
+          s = getDisplayChar(srep, i, s,
                   '.');
         }
       }
@@ -282,7 +280,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
         }
         if (av.getShowUnconserved())
         {
-          s = getDisplayChar(av.getAlignmentConsensusAnnotation(), i, s,
+          s = getDisplayChar(srep, i, s,
                   '.');
 
         }
@@ -315,10 +313,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
 
   }
 
-  private char getDisplayChar(AlignmentAnnotation consensus, int position,
+  private char getDisplayChar(final boolean usesrep, int position,
           char s, char c)
   {
-    char conschar = consensus.annotations[position].displayCharacter
+    // TODO - use currentSequenceGroup rather than alignemnt 
+    // currentSequenceGroup.getConsensus()
+    char conschar = (usesrep) ? av.getAlignment().getSeqrep().getCharAt(position) : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter
             .charAt(0);
     if (conschar != '-' && s == conschar)
     {
index 9c5914f..01d3d8d 100755 (executable)
@@ -1571,6 +1571,39 @@ public class Alignment implements AlignmentI
     }
   }
 
+
+ private SequenceI seqrep=null;
+
+ /**
+  * 
+  * @return the representative sequence for this group
+  */
+ public SequenceI getSeqrep()
+ {
+   return seqrep;
+ }
+
+ /**
+  * set the representative sequence for this group. Note - this affects the
+  * interpretation of the Hidereps attribute.
+  * 
+  * @param seqrep
+  *          the seqrep to set (null means no sequence representative)
+  */
+ public void setSeqrep(SequenceI seqrep)
+ {
+   this.seqrep = seqrep;
+ }
+
+ /**
+  * 
+  * @return true if group has a sequence representative
+  */
+ public boolean hasSeqrep()
+ {
+   return seqrep != null;
+ }
+
   @Override
   public int getEndRes()
   {
index 3af441b..ee216a4 100644 (file)
@@ -29,8 +29,23 @@ public interface SequenceCollectionI
 
   List<SequenceI> getSequences(
           Map<SequenceI, SequenceCollectionI> hiddenReps);
-
   int getWidth();
+  /**
+   * 
+   * @return true if getSeqrep doesn't return null
+   */
+  boolean hasSeqrep();
+  /**
+   * get the reference or representative sequence within this collection
+   * @return null or the current reference sequence
+   */
+  SequenceI getSeqrep();
+  /**
+   * set the reference or representative sequence for this collection. 
+   * Reference is assumed to be present within the collection.
+   * @return
+   */
+  void setSeqrep(SequenceI refseq);
 
   /**
    * @return the first column included in this collection. Runs from 0<=i<N_cols
index 015b95b..269e103 100644 (file)
@@ -5753,6 +5753,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       alignPanel.paintAlignment(true);
     }
   }
+  public void clearAlignmentSeqRep()
+  {
+    // TODO refactor alignmentseqrep to controller
+    if (viewport.getAlignment().hasSeqrep()) {
+      viewport.getAlignment().setSeqrep(null);
+      PaintRefresher.Refresh(this, viewport.getSequenceSetId());
+      alignPanel.updateAnnotation();
+      alignPanel.paintAlignment(true);
+    }
+  }
 
   @Override
   protected void createGroup_actionPerformed(ActionEvent e)
index 6810fed..3bc3168 100755 (executable)
@@ -310,7 +310,7 @@ public class IdCanvas extends JPanel
         for (int i = starty; i < alheight; i++)
         {
           SequenceI s = av.getAlignment().getSequenceAt(i);
-          if (av.hasHiddenRows())
+          if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
           {
             setHiddenFont(s);
           }
@@ -350,7 +350,7 @@ public class IdCanvas extends JPanel
           continue;
         }
 
-        if (av.hasHiddenRows())
+        if (av.isDisplayReferenceSeq() || av.hasHiddenRows())
         {
           setHiddenFont(sequence);
         }
index 3ea689f..41cb6b1 100644 (file)
@@ -140,6 +140,8 @@ public class PopupMenu extends JPopupMenu
   JMenuItem sequenceDetails = new JMenuItem();
 
   JMenuItem sequenceSelDetails = new JMenuItem();
+  
+  JMenuItem makeReferenceSeq = new JMenuItem();
 
   JMenuItem chooseAnnotations = new JMenuItem();
 
@@ -322,6 +324,12 @@ public class PopupMenu extends JPopupMenu
     if (seq != null)
     {
       sequenceMenu.setText(sequence.getName());
+      if (seq == ap.av.getAlignment().getSeqrep())
+      {
+        makeReferenceSeq.setText("Unmark representative");
+      } else {
+        makeReferenceSeq.setText("Mark as representative");
+      }
 
       if (seq.getDatasetSequence().getPDBId() != null
               && seq.getDatasetSequence().getPDBId().size() > 0)
@@ -369,7 +377,6 @@ public class PopupMenu extends JPopupMenu
         }
         // structureMenu.remove(colStructureMenu);
       }
-
       if (ap.av.getAlignment().isNucleotide() == true)
       {
         AlignmentAnnotation[] aa = ap.av.getAlignment()
@@ -441,7 +448,6 @@ public class PopupMenu extends JPopupMenu
             }
           }
         }
-
       }
 
       menuItem = new JMenuItem(
@@ -1507,7 +1513,17 @@ public class PopupMenu extends JPopupMenu
         editSequence_actionPerformed(actionEvent);
       }
     });
-
+    makeReferenceSeq.setText("Mark as representative");
+    makeReferenceSeq.addActionListener(new ActionListener()
+    {
+      
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        makeReferenceSeq_actionPerformed(actionEvent);
+        
+      }
+    });
     /*
      * annotationMenuItem.setText("By Annotation");
      * annotationMenuItem.addActionListener(new ActionListener() { public void
@@ -1539,6 +1555,7 @@ public class PopupMenu extends JPopupMenu
     groupMenu.add(jMenu1);
     sequenceMenu.add(sequenceName);
     sequenceMenu.add(sequenceDetails);
+    sequenceMenu.add(makeReferenceSeq);
     colourMenu.add(textColour);
     colourMenu.add(noColourmenuItem);
     colourMenu.add(clustalColour);
@@ -1912,6 +1929,28 @@ public class PopupMenu extends JPopupMenu
     }
     refresh();
   }
+protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
+{
+  if (!ap.av.getAlignment().hasSeqrep())
+  {
+    // initialise the display flags so the user sees something happen
+    ap.av.setDisplayReferenceSeq(true);
+    ap.av.setColourByReferenceSeq(true);
+    ap.av.getAlignment().setSeqrep(sequence);
+  }
+  else
+  {
+    if (ap.av.getAlignment().getSeqrep() == sequence)
+    {
+      ap.av.getAlignment().setSeqrep(null);
+    }
+    else
+    {
+      ap.av.getAlignment().setSeqrep(sequence);
+    }
+  }
+  refresh();
+}
 
   protected void sequenceSelectionDetails_actionPerformed()
   {
index 177fc83..438ef00 100755 (executable)
@@ -319,6 +319,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     }
     else
     {
+      boolean srep = av.isDisplayReferenceSeq();
       boolean getboxColour = false;
       for (int i = start; i <= end; i++)
       {
@@ -364,7 +365,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
           if (currentSequenceGroup.getShowNonconserved()) // todo optimize
           {
             // todo - use sequence group consensus
-            s = getDisplayChar(av.getAlignmentConsensusAnnotation(), i, s,
+            s = getDisplayChar(srep, i, s,
                     '.');
 
           }
@@ -407,7 +408,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
           }
           if (av.getShowUnconserved())
           {
-            s = getDisplayChar(av.getAlignmentConsensusAnnotation(), i, s,
+            s = getDisplayChar(srep, i, s,
                     '.');
 
           }
@@ -422,10 +423,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     }
   }
 
-  private char getDisplayChar(AlignmentAnnotation consensus, int position,
+  private char getDisplayChar(final boolean usesrep, int position,
           char s, char c)
   {
-    char conschar = consensus.annotations[position].displayCharacter
+    // TODO - use currentSequenceGroup rather than alignemnt 
+    // currentSequenceGroup.getConsensus()
+    char conschar = (usesrep) ? av.getAlignment().getSeqrep().getCharAt(position) : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter
             .charAt(0);
     if (conschar != '-' && s == conschar)
     {
index a2da591..72cd316 100644 (file)
@@ -1031,8 +1031,8 @@ public abstract class AlignmentViewport implements AlignViewportI
 
   public boolean isHiddenRepSequence(SequenceI seq)
   {
-    return hiddenRepSequences != null
-            && hiddenRepSequences.containsKey(seq);
+    return alignment.getSeqrep()==seq || (hiddenRepSequences != null
+            && hiddenRepSequences.containsKey(seq));
   }
 
   public SequenceGroup getRepresentedSequences(SequenceI seq)
@@ -1603,6 +1603,34 @@ public abstract class AlignmentViewport implements AlignViewportI
     }
     oldrfs.clear();
   }
+  /**
+   * show the reference sequence in the alignment view
+   */
+  private boolean displayReferenceSeq=false;
+  /**
+   * colour according to the reference sequence defined on the alignment
+   */
+  private boolean colourByReferenceSeq=false;
+
+  public boolean isDisplayReferenceSeq()
+  {
+    return alignment.hasSeqrep() && displayReferenceSeq;
+  }
+
+  public void setDisplayReferenceSeq(boolean displayReferenceSeq)
+  {
+    this.displayReferenceSeq = displayReferenceSeq;
+  }
+
+  public boolean isColourByReferenceSeq()
+  {
+    return alignment.hasSeqrep() && colourByReferenceSeq;
+  }
+
+  public void setColourByReferenceSeq(boolean colourByReferenceSeq)
+  {
+    this.colourByReferenceSeq = colourByReferenceSeq;
+  }
 
   @Override
   public Color getSequenceColour(SequenceI seq)