JAL-878; Structures associated to a sequence are available via
authorjanengelhardt <engelhardt87@googlemail.com>
Mon, 15 Aug 2011 23:13:38 +0000 (01:13 +0200)
committerjanengelhardt <engelhardt87@googlemail.com>
Mon, 15 Aug 2011 23:13:38 +0000 (01:13 +0200)
Popupmenu;

Change-Id: I20050a77bf494782893d6383f3d2e901cae7d3f1

src/jalview/gui/PopupMenu.java

index 9de51ea..f2f41a3 100644 (file)
@@ -69,10 +69,11 @@ public class PopupMenu extends JPopupMenu
   protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
 
   protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
-  
+
   protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem();
-  
-  //protected JRadioButtonMenuItem covariationColour = new JRadioButtonMenuItem();
+
+  // protected JRadioButtonMenuItem covariationColour = new
+  // JRadioButtonMenuItem();
 
   JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
 
@@ -161,8 +162,8 @@ public class PopupMenu extends JPopupMenu
    * @param links
    * @param groupLinks
    */
-  public PopupMenu(final AlignmentPanel ap, final Sequence seq, final Vector links,
-          final Vector groupLinks)
+  public PopupMenu(final AlignmentPanel ap, final Sequence seq,
+          final Vector links, final Vector groupLinks)
   {
     // /////////////////////////////////////////////////////////
     // If this is activated from the sequence panel, the user may want to
@@ -188,7 +189,7 @@ public class PopupMenu extends JPopupMenu
     colours.add(PIDColour);
     colours.add(BLOSUM62Colour);
     colours.add(purinePyrimidineColour);
-    //colours.add(covariationColour);
+    // colours.add(covariationColour);
 
     for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
     {
@@ -235,8 +236,10 @@ public class PopupMenu extends JPopupMenu
           {
             public void actionPerformed(ActionEvent e)
             {
-               // 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);
+              // 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 PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
             }
 
@@ -253,41 +256,67 @@ public class PopupMenu extends JPopupMenu
         }
       }
       else
-      {        
-         if(ap.av.alignment.isNucleotide()==false){
-                 structureMenu.remove(viewStructureMenu);
-         }
+      {
+        if (ap.av.alignment.isNucleotide() == false)
+        {
+          structureMenu.remove(viewStructureMenu);
+        }
         // structureMenu.remove(colStructureMenu);
       }
-      
-      if(ap.av.alignment.isNucleotide()==true){
-         AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
-         String rnastruc=new String();
-         for(int i=0; i<aa.length;i++){
-                 if(aa[i].getRNAStruc() != null){
-                         rnastruc=aa[i].getRNAStruc();
-                         break;
-                 }
-         }
-
-         AlignmentAnnotation a[] = seq.getAnnotation();
-         
-         //TODO: make rnastrucF a bit more nice
-         final String rnastrucF=rnastruc;
-         menuItem = new JMenuItem();
-         menuItem.setText("RNA structure");
-         menuItem.addActionListener(new java.awt.event.ActionListener()
-         {
-                 public void actionPerformed(ActionEvent e)
-                 {
-                         //System.out.println("Call Varna "+seq.getSequenceAsString()+" "+seq.getName());
-                         //TODO: VARNA does'nt print gaps in the sequence
-                         
-                         new AppVarna(seq.getSequenceAsString(),rnastrucF,seq.getName(),ap);
-                 }
-                       });       
-                       viewStructureMenu.add(menuItem);
-       }
+
+      if (ap.av.alignment.isNucleotide() == true)
+      {
+        AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
+        for (int i = 0; i < aa.length; i++)
+        {
+          if (aa[i].getRNAStruc() != null)
+          {
+            final String rnastruc = aa[i].getRNAStruc();
+            
+            menuItem = new JMenuItem();
+            menuItem.setText("RNA structure - consensus");
+            menuItem.addActionListener(new java.awt.event.ActionListener()
+            {
+              public void actionPerformed(ActionEvent e)
+              {
+                new AppVarna(seq.getSequenceAsString(), rnastruc, seq
+                        .getName(), ap);
+              }
+            });
+            viewStructureMenu.add(menuItem);
+          }
+        }
+
+        // SequenceFeatures[] test = seq.getSequenceFeatures();
+
+        if (seq.getAnnotation() != null)
+        {
+          AlignmentAnnotation seqAnno[] = seq.getAnnotation();
+          for (int i = 0; i < seqAnno.length; i++)
+          {
+            if (seqAnno[i].getRNAStruc() != null)
+            {
+              final String rnastruc = seqAnno[i].getRNAStruc();
+              
+           // TODO: make rnastrucF a bit more nice
+              menuItem = new JMenuItem();
+              menuItem.setText("RNA structure - "+seq.getName());
+              menuItem.addActionListener(new java.awt.event.ActionListener()
+              {
+                public void actionPerformed(ActionEvent e)
+                {
+                  // TODO: VARNA does'nt print gaps in the sequence
+                  new AppVarna(seq.getSequenceAsString(), rnastruc, seq
+                          .getName(), ap);
+                }
+              });
+              viewStructureMenu.add(menuItem);
+            }
+          }
+        }
+
+        
+      }
 
       menuItem = new JMenuItem("Hide Sequences");
       menuItem.addActionListener(new java.awt.event.ActionListener()
@@ -357,7 +386,7 @@ public class PopupMenu extends JPopupMenu
 
     if (sg != null)
     {
-      groupName.setText("Name: "+sg.getName());
+      groupName.setText("Name: " + sg.getName());
       groupName.setText("Edit name and description of current group.");
 
       if (sg.cs instanceof ZappoColourScheme)
@@ -406,12 +435,12 @@ public class PopupMenu extends JPopupMenu
       }
       else if (sg.cs instanceof PurinePyrimidineColourScheme)
       {
-       purinePyrimidineColour.setSelected(true);
+        purinePyrimidineColour.setSelected(true);
       }
-     /* else if (sg.cs instanceof CovariationColourScheme)
-      {
-       covariationColour.setSelected(true);
-      }*/
+      /*
+       * else if (sg.cs instanceof CovariationColourScheme) {
+       * covariationColour.setSelected(true); }
+       */
       else
       {
         noColourmenuItem.setSelected(true);
@@ -431,26 +460,31 @@ public class PopupMenu extends JPopupMenu
         buildGroupURLMenu(sg, groupLinks);
       }
       // Add a 'show all structures' for the current selection
-      Hashtable<String, PDBEntry> pdbe=new Hashtable<String,PDBEntry>();
-      for (SequenceI sq: ap.av.getSequenceSelection())
+      Hashtable<String, PDBEntry> pdbe = new Hashtable<String, PDBEntry>();
+      for (SequenceI sq : ap.av.getSequenceSelection())
       {
-        Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence().getPDBId();
-        if (pes!=null) {
-          for (PDBEntry pe: pes)
+        Vector<PDBEntry> pes = (Vector<PDBEntry>) sq.getDatasetSequence()
+                .getPDBId();
+        if (pes != null)
+        {
+          for (PDBEntry pe : pes)
           {
-            pdbe.put(pe.getId(),  pe);
+            pdbe.put(pe.getId(), pe);
           }
         }
       }
-      if (pdbe.size()>0)
+      if (pdbe.size() > 0)
       {
-        final PDBEntry[] pe = pdbe.values().toArray(new PDBEntry[pdbe.size()]);
+        final PDBEntry[] pe = pdbe.values().toArray(
+                new PDBEntry[pdbe.size()]);
         final JMenuItem gpdbview;
-        structureMenu.add(gpdbview=new JMenuItem("View "+pdbe.size()+" structures."));
-        gpdbview.setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
+        structureMenu.add(gpdbview = new JMenuItem("View " + pdbe.size()
+                + " structures."));
+        gpdbview
+                .setToolTipText("Open a new Jmol view with all structures associated with the current selection and superimpose them using the alignment.");
         gpdbview.addActionListener(new ActionListener()
         {
-          
+
           @Override
           public void actionPerformed(ActionEvent e)
           {
@@ -505,9 +539,9 @@ public class PopupMenu extends JPopupMenu
         {
 
           // collect matching db-refs
-          DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(
-                  seq.getDBRef(), new String[]
-                  { urlLink.getTarget() });
+          DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq
+                  .getDBRef(), new String[]
+          { urlLink.getTarget() });
           // collect id string too
           String id = seq.getName();
           String descr = seq.getDescription();
@@ -610,7 +644,7 @@ public class PopupMenu extends JPopupMenu
     JMenu[] linkMenus = new JMenu[]
     { null, new JMenu("IDS"), new JMenu("Sequences"),
         new JMenu("IDS and Sequences") }; // three types of url that might be
-                                          // created.
+    // created.
     SequenceI[] seqs = ap.av.getSelectionAsNewSequence();
     String[][] idandseqs = GroupUrlLink.formStrings(seqs);
     Hashtable commonDbrefs = new Hashtable();
@@ -658,7 +692,7 @@ public class PopupMenu extends JPopupMenu
     }
     // now create group links for all distinct ID/sequence sets.
     boolean addMenu = false; // indicates if there are any group links to give
-                             // to user
+    // to user
     for (int i = 0; i < groupLinks.size(); i++)
     {
       String link = groupLinks.elementAt(i).toString();
@@ -711,8 +745,8 @@ public class PopupMenu extends JPopupMenu
       Object[] urlset = null;
       try
       {
-        urlset = urlLink.makeUrlStubs(ids, seqstr,
-                "FromJalview" + System.currentTimeMillis(), false);
+        urlset = urlLink.makeUrlStubs(ids, seqstr, "FromJalview"
+                + System.currentTimeMillis(), false);
       } catch (UrlStringTooLongException e)
       {
       }
@@ -795,14 +829,14 @@ public class PopupMenu extends JPopupMenu
     JMenuItem item = new JMenuItem(label);
     item.setToolTipText("open URL (" + urlgenerator.getUrl_prefix()
             + "..) (" + urlgenerator.getNumberInvolved(urlstub) + " seqs)"); // TODO:
-                                                                             // put
-                                                                             // in
-                                                                             // info
-                                                                             // about
-                                                                             // what
-                                                                             // is
-                                                                             // being
-                                                                             // sent.
+    // put
+    // in
+    // info
+    // about
+    // what
+    // is
+    // being
+    // sent.
     item.addActionListener(new java.awt.event.ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -1041,7 +1075,7 @@ public class PopupMenu extends JPopupMenu
     colourMenu.add(buriedColour);
     colourMenu.add(nucleotideMenuItem);
     colourMenu.add(purinePyrimidineColour);
-    //colourMenu.add(covariationColour);
+    // colourMenu.add(covariationColour);
     colourMenu.add(userDefinedColour);
 
     if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
@@ -1194,22 +1228,20 @@ public class PopupMenu extends JPopupMenu
       }
     });
     purinePyrimidineColour.setText("Purine/Pyrimidine");
-    purinePyrimidineColour.addActionListener(new java.awt.event.ActionListener()
-    {
-      public void actionPerformed(ActionEvent e)
-      {
-         purinePyrimidineColour_actionPerformed();
-      }
-    });
-   /* 
-    covariationColour.addActionListener(new java.awt.event.ActionListener()
-    {
-      public void actionPerformed(ActionEvent e)
-      {
-         covariationColour_actionPerformed();
-      }
-    });*/
-    
+    purinePyrimidineColour
+            .addActionListener(new java.awt.event.ActionListener()
+            {
+              public void actionPerformed(ActionEvent e)
+              {
+                purinePyrimidineColour_actionPerformed();
+              }
+            });
+    /*
+     * covariationColour.addActionListener(new java.awt.event.ActionListener() {
+     * public void actionPerformed(ActionEvent e) {
+     * covariationColour_actionPerformed(); } });
+     */
+
     conservationMenuItem.setText("Conservation");
     conservationMenuItem
             .addActionListener(new java.awt.event.ActionListener()
@@ -1247,9 +1279,9 @@ public class PopupMenu extends JPopupMenu
   protected void clustalColour_actionPerformed()
   {
     SequenceGroup sg = getGroup();
-    sg.cs = new ClustalxColourScheme(
-            sg.getSequences(ap.av.hiddenRepSequences),
-            ap.av.alignment.getWidth());
+    sg.cs = new ClustalxColourScheme(sg
+            .getSequences(ap.av.hiddenRepSequences), ap.av.alignment
+            .getWidth());
     refresh();
   }
 
@@ -1348,19 +1380,17 @@ public class PopupMenu extends JPopupMenu
     getGroup().cs = new NucleotideColourScheme();
     refresh();
   }
-  
+
   protected void purinePyrimidineColour_actionPerformed()
   {
     getGroup().cs = new PurinePyrimidineColourScheme();
     refresh();
   }
+
   /*
-  protected void covariationColour_actionPerformed()
-  {
-    getGroup().cs = new CovariationColourScheme(sequence.getAnnotation()[0]);
-    refresh();
-  }
-*/
+   * protected void covariationColour_actionPerformed() { getGroup().cs = new
+   * CovariationColourScheme(sequence.getAnnotation()[0]); refresh(); }
+   */
   /**
    * DOCUMENT ME!
    * 
@@ -1377,9 +1407,9 @@ public class PopupMenu extends JPopupMenu
 
     if (abovePIDColour.isSelected())
     {
-      sg.cs.setConsensus(AAFrequency.calculate(
-              sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
-              sg.getEndRes() + 1));
+      sg.cs.setConsensus(AAFrequency.calculate(sg
+              .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
+              .getEndRes() + 1));
 
       int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
               .getName());
@@ -1431,9 +1461,9 @@ public class PopupMenu extends JPopupMenu
   {
     SequenceGroup sg = getGroup();
     sg.cs = new PIDColourScheme();
-    sg.cs.setConsensus(AAFrequency.calculate(
-            sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
-            sg.getEndRes() + 1));
+    sg.cs.setConsensus(AAFrequency.calculate(sg
+            .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
+            .getEndRes() + 1));
     refresh();
   }
 
@@ -1449,9 +1479,9 @@ public class PopupMenu extends JPopupMenu
 
     sg.cs = new Blosum62ColourScheme();
 
-    sg.cs.setConsensus(AAFrequency.calculate(
-            sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
-            sg.getEndRes() + 1));
+    sg.cs.setConsensus(AAFrequency.calculate(sg
+            .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
+            .getEndRes() + 1));
 
     refresh();
   }
@@ -1485,9 +1515,9 @@ public class PopupMenu extends JPopupMenu
     if (conservationMenuItem.isSelected())
     {
       Conservation c = new Conservation("Group",
-              ResidueProperties.propHash, 3,
-              sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(),
-              sg.getEndRes() + 1);
+              ResidueProperties.propHash, 3, sg
+                      .getSequences(ap.av.hiddenRepSequences), sg
+                      .getStartRes(), sg.getEndRes() + 1);
 
       c.calculate();
       c.verdict(false, ap.av.ConsPercGaps);
@@ -1514,8 +1544,8 @@ public class PopupMenu extends JPopupMenu
       return;
     }
 
-    AnnotationColourGradient acg = new AnnotationColourGradient(
-            sequence.getAnnotation()[0], null,
+    AnnotationColourGradient acg = new AnnotationColourGradient(sequence
+            .getAnnotation()[0], null,
             AnnotationColourGradient.NO_THRESHOLD);
 
     acg.predefinedColours = true;
@@ -1534,10 +1564,9 @@ public class PopupMenu extends JPopupMenu
   {
 
     SequenceGroup sg = getGroup();
-    EditNameDialog dialog = new EditNameDialog(sg.getName(),
-            sg.getDescription(), "       Group Name ",
-            "Group Description ", "Edit Group Name/Description",
-            ap.alignFrame);
+    EditNameDialog dialog = new EditNameDialog(sg.getName(), sg
+            .getDescription(), "       Group Name ", "Group Description ",
+            "Edit Group Name/Description", ap.alignFrame);
 
     if (!dialog.accept)
     {
@@ -1574,8 +1603,8 @@ public class PopupMenu extends JPopupMenu
    */
   void sequenceName_actionPerformed()
   {
-    EditNameDialog dialog = new EditNameDialog(sequence.getName(),
-            sequence.getDescription(), "       Sequence Name ",
+    EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence
+            .getDescription(), "       Sequence Name ",
             "Sequence Description ", "Edit Sequence Name/Description",
             ap.alignFrame);
 
@@ -1767,8 +1796,8 @@ public class PopupMenu extends JPopupMenu
         caseChange = ChangeCaseCommand.TO_LOWER;
       }
 
-      ChangeCaseCommand caseCommand = new ChangeCaseCommand(description,
-              sg.getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
+      ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg
+              .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
               caseChange);
 
       ap.alignFrame.addHistoryItem(caseCommand);
@@ -1783,8 +1812,8 @@ public class PopupMenu extends JPopupMenu
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
     cap.setForInput(null);
-    Desktop.addInternalFrame(cap,
-            "Alignment output - " + e.getActionCommand(), 600, 500);
+    Desktop.addInternalFrame(cap, "Alignment output - "
+            + e.getActionCommand(), 600, 500);
 
     String[] omitHidden = null;
 
@@ -1814,8 +1843,11 @@ public class PopupMenu extends JPopupMenu
     jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
     chooser.setFileView(new jalview.io.JalviewFileView());
-    chooser.setDialogTitle("Select a PDB file for "+sequence.getDisplayId(false));
-    chooser.setToolTipText("Load a PDB file and associate it with sequence '"+sequence.getDisplayId(false)+"'");
+    chooser.setDialogTitle("Select a PDB file for "
+            + sequence.getDisplayId(false));
+    chooser
+            .setToolTipText("Load a PDB file and associate it with sequence '"
+                    + sequence.getDisplayId(false) + "'");
 
     int value = chooser.showOpenDialog(null);
 
@@ -1823,7 +1855,8 @@ public class PopupMenu extends JPopupMenu
     {
       String choice = chooser.getSelectedFile().getPath();
       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-      new AssociatePdbFileWithSeq().associatePdbWithSeq(choice, jalview.io.AppletFormatAdapter.FILE, sequence, true);
+      new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
+              jalview.io.AppletFormatAdapter.FILE, sequence, true);
     }
 
   }
@@ -1909,8 +1942,8 @@ public class PopupMenu extends JPopupMenu
 
   public void colourByStructure(String pdbid)
   {
-    Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure(
-                    sequence, pdbid);
+    Annotation[] anots = ap.av.getStructureSelectionManager()
+            .colourSequenceFromStructure(sequence, pdbid);
 
     AlignmentAnnotation an = new AlignmentAnnotation("Structure",
             "Coloured by " + pdbid, anots);
@@ -1935,18 +1968,17 @@ public class PopupMenu extends JPopupMenu
       if (sequence == null)
         sequence = (Sequence) sg.getSequenceAt(0);
 
-      EditNameDialog dialog = new EditNameDialog(
-              sequence.getSequenceAsString(sg.getStartRes(),
-                      sg.getEndRes() + 1), null, "Edit Sequence ", null,
-              "Edit Sequence", ap.alignFrame);
+      EditNameDialog dialog = new EditNameDialog(sequence
+              .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
+              null, "Edit Sequence ", null, "Edit Sequence", ap.alignFrame);
 
       if (dialog.accept)
       {
         EditCommand editCommand = new EditCommand("Edit Sequences",
                 EditCommand.REPLACE, dialog.getName().replace(' ',
-                        ap.av.getGapCharacter()),
-                sg.getSequencesAsArray(ap.av.hiddenRepSequences),
-                sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
+                        ap.av.getGapCharacter()), sg
+                        .getSequencesAsArray(ap.av.hiddenRepSequences), sg
+                        .getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
 
         ap.alignFrame.addHistoryItem(editCommand);