Skip to content
Snippets Groups Projects
ViewMenu.java 60 KiB
Newer Older
  • Learn to ignore specific revisions
  • tjc's avatar
    tjc committed
    /* ViewMenu.java
     *
     * created: Tue Dec 29 1998
     *
     * This file is part of Artemis
     *
     * Copyright (C) 1998,1999,2000,2002  Genome Research Limited
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * as published by the Free Software Foundation; either version 2
     * of the License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     *
    
    tjc's avatar
    tjc committed
     * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/ViewMenu.java,v 1.15 2009-04-22 08:50:13 tjc Exp $
    
    tjc's avatar
    tjc committed
     */
    
    package uk.ac.sanger.artemis.components;
    
    import uk.ac.sanger.artemis.*;
    import uk.ac.sanger.artemis.sequence.*;
    
    import uk.ac.sanger.artemis.util.*;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.components.filetree.FileList;
    import uk.ac.sanger.artemis.components.filetree.RemoteFileNode;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.components.genebuilder.GeneUtils;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.io.DocumentEntry;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.io.InvalidRelationException;
    import uk.ac.sanger.artemis.io.Key;
    
    import uk.ac.sanger.artemis.io.Qualifier;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.io.Range;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.j2ssh.FTProgress;
    import uk.ac.sanger.artemis.j2ssh.FileTransferProgressMonitor;
    
    tjc's avatar
    tjc committed
    
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    
    tjc's avatar
    tjc committed
    import com.sshtools.j2ssh.sftp.FileAttributes;
    
    
    tjc's avatar
    tjc committed
    /**
     *  A popup menu with viewing commands.
     *
     *  @author Kim Rutherford
    
    tjc's avatar
    tjc committed
     *  @version $Id: ViewMenu.java,v 1.15 2009-04-22 08:50:13 tjc Exp $
    
    tjc's avatar
    tjc committed
     **/
    
    
    tjc's avatar
    tjc committed
    public class ViewMenu extends SelectionMenu 
    {
      /** */
      private static final long serialVersionUID = 1L;
    
      /**
       *  The EntryGroup that was passed to the constructor.
       **/
      private EntryGroup entry_group = null;
    
      /**
       *  The Selection that was passed to the constructor.
       **/
      private Selection selection = null;
    
      /**
       *  The GotoEventSource that was passed to the constructor.
       **/
      //private GotoEventSource goto_event_source = null;
    
      private BasePlotGroup base_plot_group;
      
    
    tjc's avatar
    tjc committed
      /**
       *  Create a new ViewMenu object.
       *  @param frame The JFrame that owns this JMenu.
       *  @param selection The Selection that the commands in the menu will
       *    operate on.
       *  @param entry_group The EntryGroup object where new features/entries will
       *    be added.
    
    tjc's avatar
    tjc committed
       *  @param goto_event_source The object that we will call makeBaseVisible()
    
    tjc's avatar
    tjc committed
       *    on.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       *  @param menu_name The name of the new menu.
       **/
    
    tjc's avatar
    tjc committed
      public ViewMenu(final JFrame frame,
                      final Selection selection,
                      final GotoEventSource goto_event_source,
                      final EntryGroup entry_group,
                      final BasePlotGroup base_plot_group,
                      final String menu_name) 
      {
        super(frame, menu_name, selection);
    
    tjc's avatar
    tjc committed
    
        this.entry_group = entry_group;
        this.selection = selection;
    
        this.base_plot_group = base_plot_group;
    
    
    tjc's avatar
    tjc committed
        final JMenuItem plot_features_item = new JMenuItem("Feature Plots");
    
    tjc's avatar
    tjc committed
        plot_features_item.setAccelerator(PLOT_FEATURES_KEY);
        plot_features_item.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent event) 
          {
            plotSelectedFeatures(getParentFrame(), getSelection());
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem view_feature_item = new JMenuItem("Selected Features");
    
    tjc's avatar
    tjc committed
        view_feature_item.setAccelerator(VIEW_FEATURES_KEY);
        view_feature_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            viewSelectedFeatures(getParentFrame(), getSelection());
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem view_selection_item = new JMenuItem("Selection");
    
    tjc's avatar
    tjc committed
        view_selection_item.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            new SelectionViewer(getSelection(), entry_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem feature_info_item = new JMenuItem("Feature Statistics");
    
    tjc's avatar
    tjc committed
        feature_info_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            viewSelectedFeatureInfo();
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem view_bases_item = new JMenuItem("Bases Of Selection");
    
    tjc's avatar
    tjc committed
        view_bases_item.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent event) 
          {
            viewSelectedBases(true);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem view_bases_as_fasta_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Bases Of Selection As FASTA");
    
    tjc's avatar
    tjc committed
        view_bases_as_fasta_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            viewSelectedBases(false);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem view_aa_item = new JMenuItem("Amino Acids Of Selection");
    
    tjc's avatar
    tjc committed
        view_aa_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            viewSelectedAminoAcids(true);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem view_aa_as_fasta_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Amino Acids Of Selection As FASTA");
    
    tjc's avatar
    tjc committed
        view_aa_as_fasta_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            viewSelectedAminoAcids(false);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem overview_item = new JMenuItem("Overview");
    
    tjc's avatar
    tjc committed
        overview_item.setAccelerator(OVERVIEW_KEY);
        overview_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            new EntryGroupInfoDisplay(getParentFrame(), entry_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem forward_overview_item = new JMenuItem("Forward Strand Overview");
    
    tjc's avatar
    tjc committed
        forward_overview_item.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent event)
          {
            new EntryGroupInfoDisplay(getParentFrame(), entry_group,
                                      Bases.FORWARD);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem reverse_overview_item = new JMenuItem("Reverse Strand Overview");
    
    tjc's avatar
    tjc committed
        reverse_overview_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event)
          {
            new EntryGroupInfoDisplay(getParentFrame(), entry_group,
                                      Bases.REVERSE);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem view_cds_item = new JMenuItem("CDS Genes And Products");
    
    tjc's avatar
    tjc committed
        if(GeneUtils.isDatabaseEntry(entry_group))
          view_cds_item.setEnabled(false);
    
    tjc's avatar
    tjc committed
        view_cds_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
    
    tjc's avatar
    tjc committed
            final FeaturePredicate feature_predicate =
    
    tjc's avatar
    tjc committed
              new FeatureKeyPredicate(Key.CDS);
    
    tjc's avatar
    tjc committed
    
            final String filter_name =
              "CDS features (filtered from: " +
    
    tjc's avatar
    tjc committed
              getParentFrame().getTitle() + ")";
    
    tjc's avatar
    tjc committed
    
            final FilteredEntryGroup filtered_entry_group =
    
    tjc's avatar
    tjc committed
              new FilteredEntryGroup(entry_group, feature_predicate, filter_name);
    
    tjc's avatar
    tjc committed
    
            final FeatureListFrame feature_list_frame =
    
    tjc's avatar
    tjc committed
              new FeatureListFrame(filter_name,
    
    tjc's avatar
    tjc committed
                                    selection, goto_event_source,
                                    filtered_entry_group,
                                    base_plot_group);
    
    
    tjc's avatar
    tjc committed
            feature_list_frame.getFeatureList().setShowGenes(true);
            feature_list_frame.getFeatureList().setShowProducts(true);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
            feature_list_frame.setVisible(true);
    
    tjc's avatar
    tjc committed
          }
        });
    
        JMenu search_results_menu = null;
    
    
    tjc's avatar
    tjc committed
        search_results_menu = new JMenu("Search Results");
    
    tjc's avatar
    tjc committed
    
        final boolean sanger_options =
    
    tjc's avatar
    tjc committed
          Options.getOptions().getPropertyTruthValue("sanger_options");
    
    tjc's avatar
    tjc committed
    
        final ExternalProgramVector external_programs =
    
    tjc's avatar
    tjc committed
          Options.getOptions().getExternalPrograms();
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final StringVector external_program_names = new StringVector();
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        for(int i = 0 ; i < external_programs.size() ; ++i) 
        {
    
    tjc's avatar
    tjc committed
          final ExternalProgram external_program =
    
    tjc's avatar
    tjc committed
            external_programs.elementAt(i);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
          final String new_name = external_program.getName();
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
          if(!external_program_names.contains(new_name)) 
            external_program_names.add(new_name);
    
    tjc's avatar
    tjc committed
        }
    
    
    tjc's avatar
    tjc committed
        for(int i = 0 ; i < external_program_names.size() ; ++i) 
        {
    
    tjc's avatar
    tjc committed
          final String external_program_name =
    
    tjc's avatar
    tjc committed
            (String)external_program_names.elementAt(i);
    
    tjc's avatar
    tjc committed
    
          final JMenuItem new_menu =
    
    tjc's avatar
    tjc committed
            makeSearchResultsMenu(external_program_name, false, sanger_options);
          search_results_menu.add(new_menu);
    
    tjc's avatar
    tjc committed
        }
    
    
    tjc's avatar
    tjc committed
        if(sanger_options) 
        {
          search_results_menu.addSeparator();
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
          for(int i = 0 ; i < external_program_names.size() ; ++i)
          {
    
    tjc's avatar
    tjc committed
            final String external_program_name =
    
    tjc's avatar
    tjc committed
              (String)external_program_names.elementAt(i);
    
    tjc's avatar
    tjc committed
    
            final JMenuItem new_menu =
    
    tjc's avatar
    tjc committed
              makeSearchResultsMenu(external_program_name, true, sanger_options);
            search_results_menu.add(new_menu);
    
    tjc's avatar
    tjc committed
          }
        }
    
        final int MAX_FILTER_FEATURE_COUNT = 10000;
    
    
    tjc's avatar
    tjc committed
        final JMenu feature_filters_menu = new JMenu("Feature Filters");
    
    tjc's avatar
    tjc committed
    
        final JMenuItem bad_start_codons_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Suspicious Start Codons ...");
        bad_start_codons_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT))
              showBadStartCodons(getParentFrame(), selection, 
                                 entry_group, goto_event_source,
                                 base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
        final JMenuItem bad_stop_codons_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Suspicious Stop Codons ...");
        bad_stop_codons_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT)) 
              showBadStopCodons(getParentFrame(), selection,
                                entry_group, goto_event_source,
                                base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
        final JMenuItem stop_codons_in_translation =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Stop Codons In Translation ...");
        stop_codons_in_translation.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT)) 
              showStopsInTranslation(getParentFrame(), selection,
                                     entry_group, goto_event_source,
                                     base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
        final JMenuItem bad_feature_keys_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Non EMBL Keys ...");
        bad_feature_keys_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT))
              showNonEMBLKeys(getParentFrame(), selection,
                              entry_group, goto_event_source,
                              base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
        final JMenuItem duplicated_keys_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Duplicated Features ...");
        duplicated_keys_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT)) 
              showDuplicatedFeatures(getParentFrame(), selection,
                                     entry_group, goto_event_source,
                                     base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem overlapping_cds_features_item;
        
        if(GeneUtils.isDatabaseEntry(entry_group))
          overlapping_cds_features_item =
            new JMenuItem("Overlapping "+DatabaseDocument.EXONMODEL+" Features ...");
        else
          overlapping_cds_features_item =   
            new JMenuItem("Overlapping CDS Features ...");
    
    tjc's avatar
    tjc committed
        overlapping_cds_features_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT)) 
              showOverlappingCDSs(getParentFrame(), selection,
                                  entry_group, goto_event_source,
                                  base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        final JMenuItem same_stop_cds_features_item;
        if(GeneUtils.isDatabaseEntry(entry_group))
          same_stop_cds_features_item = new JMenuItem(
              DatabaseDocument.EXONMODEL+"s Sharing Stop Codons ...");
        else
          same_stop_cds_features_item = new JMenuItem("CDSs Sharing Stop Codons ...");
    
    tjc's avatar
    tjc committed
        same_stop_cds_features_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT)) 
              showFeaturesWithSameStopCodons(getParentFrame(), 
                                             selection, entry_group,
                                             goto_event_source,
                                             base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
        final JMenuItem missing_qualifier_features_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Features Missing Required Qualifiers ...");
        missing_qualifier_features_item.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT)) 
              showMissingQualifierFeatures(getParentFrame(), selection,
                                           entry_group, goto_event_source,
                                           base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
        final JMenuItem filter_by_key_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Filter By Key ...");
        filter_by_key_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            if(checkEntryGroupSize(MAX_FILTER_FEATURE_COUNT)) 
              showFilterByKey(getParentFrame(), selection,
                              entry_group, goto_event_source,
                              base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    
        final JMenuItem filter_by_multiple_sys_id =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Duplicate Systematic Name Qualifier ...");
    
        filter_by_multiple_sys_id.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            showFilterByMultipleID(getParentFrame(), selection,
                                   entry_group, goto_event_source,
                                   base_plot_group);
          }
        });
        
        
    
    tjc's avatar
    tjc committed
        final JMenuItem filter_by_selection_item =
    
    tjc's avatar
    tjc committed
          new JMenuItem("Selected Features ...");
        filter_by_selection_item.addActionListener(new ActionListener() 
        {
          public void actionPerformed(ActionEvent event) 
          {
            showFilterBySelection(getParentFrame(),
                                  selection, entry_group, goto_event_source,
                                  base_plot_group);
    
    tjc's avatar
    tjc committed
          }
        });
    
    
    tjc's avatar
    tjc committed
        feature_filters_menu.add(bad_start_codons_item);
        feature_filters_menu.add(bad_stop_codons_item);
        feature_filters_menu.add(stop_codons_in_translation);
        feature_filters_menu.add(bad_feature_keys_item);
        feature_filters_menu.add(duplicated_keys_item);
        feature_filters_menu.add(overlapping_cds_features_item);
        feature_filters_menu.add(same_stop_cds_features_item);
        feature_filters_menu.add(missing_qualifier_features_item);
    
        feature_filters_menu.add(filter_by_multiple_sys_id);
    
    tjc's avatar
    tjc committed
        feature_filters_menu.addSeparator();
        feature_filters_menu.add(filter_by_key_item);
        feature_filters_menu.add(filter_by_selection_item);
    
        add(view_feature_item);
        add(view_selection_item);
        addSeparator();
        if(search_results_menu != null)
          add(search_results_menu);
        
        add(view_cds_item);
        add(feature_filters_menu);
        addSeparator();
        add(overview_item);
        add(forward_overview_item);
        add(reverse_overview_item);
        addSeparator();
        add(view_bases_item);
        add(view_bases_as_fasta_item);
        add(view_aa_item);
        add(view_aa_as_fasta_item);
        addSeparator();
        add(feature_info_item);
        add(plot_features_item);
    
    tjc's avatar
    tjc committed
      }
    
      /**
       *  Create a new ViewMenu object.
       *  @param entry_edit The EntryEdit that owns this JMenu.
       *  @param selection The Selection that the commands in the menu will
       *    operate on.
       *  @param entry_group The EntryGroup object where new features/entries will
       *    be added.
    
    tjc's avatar
    tjc committed
       *  @param goto_event_source The object that we will call makeBaseVisible()
    
    tjc's avatar
    tjc committed
       *    on.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      public ViewMenu(final JFrame frame,
                      final Selection selection,
                      final GotoEventSource goto_event_source,
                      final EntryGroup entry_group,
                      final BasePlotGroup base_plot_group) 
      {
        this(frame, selection, goto_event_source, entry_group,
    
    tjc's avatar
    tjc committed
              base_plot_group, "View");
      }
    
      /**
       *  The shortcut for Show Feature Plots.
       **/
      final static KeyStroke PLOT_FEATURES_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_W, 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int PLOT_FEATURES_KEY_CODE = KeyEvent.VK_W;
    
      /**
       *  The shortcut for View Selected Features.
       **/
      final static KeyStroke VIEW_FEATURES_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_V, 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int VIEW_FEATURES_KEY_CODE = KeyEvent.VK_V;
    
      /**
       *  The shortcut for Show Overview.
       **/
      final static KeyStroke OVERVIEW_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_O, 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int OVERVIEW_KEY_CODE = KeyEvent.VK_O;
    
      /**
       *  The shortcut for View FASTA in browser.
       **/
      final static KeyStroke FASTA_IN_BROWSER_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_F, 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int FASTA_IN_BROWSER_KEY_CODE = KeyEvent.VK_F;
    
      /**
       *  The shortcut for View FASTA.
       **/
      final static KeyStroke VIEW_FASTA_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_R, 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int VIEW_FASTA_KEY_CODE = KeyEvent.VK_R;
    
      /**
       *  The shortcut for View BLASTP in browser.
       **/
      final static KeyStroke BLASTP_IN_BROWSER_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_B, 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int BLASTP_IN_BROWSER_KEY_CODE = KeyEvent.VK_B;
    
      /**
       *  The shortcut for View BLASTP.
       **/
      final static KeyStroke VIEW_BLASTP_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_BACK_QUOTE , 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int VIEW_BLASTP_KEY_CODE = KeyEvent.VK_BACK_QUOTE;
    
      /**
       *  The shortcut for View HTH.
       **/
      final static KeyStroke VIEW_HTH_KEY =
    
        KeyStroke.getKeyStroke (KeyEvent.VK_H, 
                                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //InputEvent.CTRL_MASK);
    
    tjc's avatar
    tjc committed
    
      final static public int VIEW_HTH_KEY_CODE = KeyEvent.VK_H;
    
      /**
       *  Make a JMenuItem for viewing the results of running the given program.
       *  @param send_to_browser if true the results should be sent straight to
       *    the web browser rather than using a SearchResultViewer object.
       *  @param sanger_options true if the sanger_options is set to true in the
       *    options file.
       **/
    
    tjc's avatar
    tjc committed
      private JMenuItem makeSearchResultsMenu(final String program_name,
    
    tjc's avatar
    tjc committed
                                              final boolean send_to_browser,
    
    tjc's avatar
    tjc committed
                                              final boolean sanger_options) 
      {
        final String suffix;
        if(send_to_browser)
          suffix = new String(" results (in browser)");
        else
          suffix = new String(" results");
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final JMenuItem new_menu = new JMenuItem(program_name + suffix);
    
    tjc's avatar
    tjc committed
    
        if ((sanger_options && send_to_browser || !sanger_options)
    
    tjc's avatar
    tjc committed
            && program_name.equals("fasta"))
    
    tjc's avatar
    tjc committed
          new_menu.setAccelerator (FASTA_IN_BROWSER_KEY);
    
    tjc's avatar
    tjc committed
        else 
        {
    
    tjc's avatar
    tjc committed
          if ((sanger_options && send_to_browser || !sanger_options)
    
    tjc's avatar
    tjc committed
              && program_name.equals("blastp")) 
    
    tjc's avatar
    tjc committed
            new_menu.setAccelerator (BLASTP_IN_BROWSER_KEY);
    
    tjc's avatar
    tjc committed
          else 
          {
            if(program_name.equals("fasta"))
    
    tjc's avatar
    tjc committed
              new_menu.setAccelerator (VIEW_FASTA_KEY);
    
    tjc's avatar
    tjc committed
            else if(program_name.equals("blastp")) 
              new_menu.setAccelerator (VIEW_BLASTP_KEY);
            else if(program_name.equals("hth")) 
              new_menu.setAccelerator (VIEW_HTH_KEY);
    
    tjc's avatar
    tjc committed
          }
        }
    
    
    tjc's avatar
    tjc committed
        new_menu.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent event) 
          {
            viewExternalResults(getParentFrame(), getSelection(),
                                program_name, send_to_browser);
    
    tjc's avatar
    tjc committed
          }
        });
    
        return new_menu;
      }
    
      /**
       *  Popup a FeatureListFrame containing the non-pseudo CDS features that
       *  have invalid start codons.
       *  @param parent_frame The parent JFrame.
       *  @param selection The Selection to pass to the FeatureList.
       *  @param entry_group The EntryGroup to pass to the FilteredEntryGroup.
       *  @param goto_source The GotoEventSource to pass to the FeatureList.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      protected static void showBadStartCodons (final JFrame parent_frame,
    
    tjc's avatar
    tjc committed
                                             final Selection selection,
                                             final EntryGroup entry_group,
                                             final GotoEventSource goto_source,
    
    tjc's avatar
    tjc committed
                                             final BasePlotGroup base_plot_group) 
      {
        final FeaturePredicate cds_predicate;
        
        if(GeneUtils.isDatabaseEntry(entry_group))
          cds_predicate = new FeatureKeyPredicate(new Key(DatabaseDocument.EXONMODEL));
        else
          cds_predicate =
            new FeatureKeyQualifierPredicate (Key.CDS, "pseudo", false);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final FeaturePredicate feature_predicate = new FeaturePredicate ()
        {
          public boolean testPredicate (final Feature feature) 
          {
            if(!cds_predicate.testPredicate (feature))
              return false;
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
            if(feature.hasValidStartCodon (true)) 
              return false;
            else 
              return true;
          }
        };
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final String filter_name;
        
        if(GeneUtils.isDatabaseEntry(entry_group))
          filter_name =
            DatabaseDocument.EXONMODEL+" features with suspicious start codons (filtered from: " +
            parent_frame.getTitle () + ")";
        else
          filter_name =
            "CDS features with suspicious start codons (filtered from: " +
            parent_frame.getTitle () + ")";
    
    tjc's avatar
    tjc committed
    
        final FilteredEntryGroup filtered_entry_group =
          new FilteredEntryGroup (entry_group, feature_predicate, filter_name);
    
        final FeatureListFrame feature_list_frame =
          new FeatureListFrame (filter_name,
                                selection, goto_source, filtered_entry_group,
                                base_plot_group);
    
        feature_list_frame.setVisible (true);
      }
    
      /**
       *  Popup a FeatureListFrame containing the non-pseudo CDS features that
       *  have invalid stop codons.
       *  @param parent_frame The parent JFrame.
       *  @param selection The Selection to pass to the FeatureList.
       *  @param entry_group The EntryGroup to pass to the FilteredEntryGroup.
       *  @param goto_source The GotoEventSource to pass to the FeatureList.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      protected static void showBadStopCodons (final JFrame parent_frame,
    
    tjc's avatar
    tjc committed
                                            final Selection selection,
                                            final EntryGroup entry_group,
                                            final GotoEventSource goto_source,
                                            final BasePlotGroup
    
    tjc's avatar
    tjc committed
                                              base_plot_group) 
      {
        final FeaturePredicate cds_predicate;
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        if(GeneUtils.isDatabaseEntry(entry_group))
          cds_predicate = new FeatureKeyPredicate(new Key(DatabaseDocument.EXONMODEL));
        else
          cds_predicate =
            new FeatureKeyQualifierPredicate (Key.CDS, "pseudo", false);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final FeaturePredicate feature_predicate =  new FeaturePredicate () 
        {
          public boolean testPredicate (final Feature feature) 
          {
            if(!cds_predicate.testPredicate (feature)) 
              return false;
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
            if(feature.hasValidStopCodon (true)) 
              return false;
            else 
              return true;
          }
        };
    
        final String filter_name;
        
        if(GeneUtils.isDatabaseEntry(entry_group))
          filter_name=
            DatabaseDocument.EXONMODEL+" features with suspicious stop codons (filtered from: " +
            parent_frame.getTitle () + ")";
        else
          filter_name =
            "CDS features with suspicious stop codons (filtered from: " +
            parent_frame.getTitle () + ")";
    
    tjc's avatar
    tjc committed
    
        final FilteredEntryGroup filtered_entry_group =
          new FilteredEntryGroup (entry_group, feature_predicate, filter_name);
    
        final FeatureListFrame feature_list_frame =
          new FeatureListFrame (filter_name,
                                selection, goto_source, filtered_entry_group,
                                base_plot_group);
    
        feature_list_frame.setVisible (true);
      }
    
      /**
       *  Popup a FeatureListFrame containing the non-pseudo CDS features that
       *  contain a stop codon in the translation.
       *  @param parent_frame The parent Frame.
       *  @param selection The Selection to pass to the FeatureList.
       *  @param entry_group The EntryGroup to pass to the FilteredEntryGroup.
       *  @param goto_source The GotoEventSource to pass to the FeatureList.
       *  @param base_plot_group The BasePlotGroup associated with this Menu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      private static void showStopsInTranslation(final Frame parent_frame,
    
    tjc's avatar
    tjc committed
                                                 final Selection selection,
                                                 final EntryGroup entry_group,
                                                 final GotoEventSource goto_source,
                                                 final BasePlotGroup
    
    tjc's avatar
    tjc committed
                                                   base_plot_group) 
      {
        final FeaturePredicate cds_predicate;
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        if(GeneUtils.isDatabaseEntry(entry_group))
          cds_predicate = new FeatureKeyPredicate(new Key(DatabaseDocument.EXONMODEL));
        else
          cds_predicate =
            new FeatureKeyQualifierPredicate(Key.CDS, "pseudo", false);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final FeaturePredicate feature_predicate = new FeaturePredicate () 
        {
          public boolean testPredicate (final Feature feature) 
          {
            if(!cds_predicate.testPredicate (feature)) 
              return false;
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
            final AminoAcidSequence amino_acids = feature.getTranslation ();
            if(amino_acids.containsStopCodon ())
              return true;
            else
              return false;
          }
        };
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
        final String filter_name;
        if(GeneUtils.isDatabaseEntry(entry_group))
          filter_name =
            DatabaseDocument.EXONMODEL+" features with stop codon(s) in translation (filtered from: " +
            parent_frame.getTitle () + ")";
        else
          filter_name =
            "CDS features with stop codon(s) in translation (filtered from: " +
            parent_frame.getTitle () + ")";
    
    tjc's avatar
    tjc committed
    
        final FilteredEntryGroup filtered_entry_group =
          new FilteredEntryGroup (entry_group, feature_predicate, filter_name);
    
        final FeatureListFrame feature_list_frame =
          new FeatureListFrame (filter_name,
                                selection, goto_source, filtered_entry_group,
                                base_plot_group);
    
        feature_list_frame.setVisible (true);
      }
    
      /**
       *  Popup a FeatureListFrame containing the features that have non-EMBL keys.
       *  @param parent_frame The parent JFrame.
       *  @param selection The Selection to pass to the FeatureList.
       *  @param entry_group The EntryGroup to pass to the FilteredEntryGroup.
       *  @param goto_source The GotoEventSource to pass to the FeatureList.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      protected static void showNonEMBLKeys(final JFrame parent_frame,
                                            final Selection selection,
                                            final EntryGroup entry_group,
                                            final GotoEventSource goto_source,
                                            final BasePlotGroup
                                            base_plot_group) 
      {
    
    tjc's avatar
    tjc committed
        final FeaturePredicate feature_predicate =
          new FeaturePredicate () {
            public boolean testPredicate (final Feature feature) {
              if (feature.hasValidEMBLKey ()) {
                return false;
              } else {
                return true;
              }
            }
          };
    
        final String filter_name =
          "features with a non-EMBL key (filtered from: " +
          parent_frame.getTitle () + ")";
    
        final FilteredEntryGroup filtered_entry_group =
          new FilteredEntryGroup (entry_group, feature_predicate, filter_name);
    
        final FeatureListFrame feature_list_frame =
          new FeatureListFrame (filter_name,
                                selection, goto_source, filtered_entry_group,
                                base_plot_group);
    
        feature_list_frame.setVisible (true);
      }
    
    
      /**
       *  Popup a FeatureListFrame containing the features that have the same key
       *  and location as another features (ie. duplicates).
       *  @param parent_frame The parent JFrame.
       *  @param selection The Selection to pass to the FeatureList.
       *  @param entry_group The EntryGroup to pass to the FilteredEntryGroup.
       *  @param goto_source The GotoEventSource to pass to the FeatureList.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      protected static void showDuplicatedFeatures (final JFrame parent_frame,
    
    tjc's avatar
    tjc committed
                                                 final Selection selection,
                                                 final EntryGroup entry_group,
                                                 final GotoEventSource goto_source,
                                                 final BasePlotGroup
    
    tjc's avatar
    tjc committed
                                                   base_plot_group)
      {
    
    tjc's avatar
    tjc committed
        final FeaturePredicate feature_predicate =
          new FeaturePredicate () {
            public boolean testPredicate (final Feature feature) {
              final Entry feature_entry = feature.getEntry ();
    
              final int feature_index = feature_entry.indexOf (feature);
    
              if (feature_index + 1 == feature_entry.getFeatureCount ()) {
                // last in the Entry
                return false;
              }
    
              final Feature next_feature =
                feature_entry.getFeature (feature_index + 1);
    
              if (feature.getKey ().equals (next_feature.getKey ()) &&
                  feature.getLocation ().equals (next_feature.getLocation ())) {
                return true;
              } else {
                return false;
              }
            }
          };
    
        final String filter_name =
          "duplicated Features (filtered from: " +
          parent_frame.getTitle () + ")";
    
        final FilteredEntryGroup filtered_entry_group =
          new FilteredEntryGroup (entry_group, feature_predicate, filter_name);
    
        final FeatureListFrame feature_list_frame =
          new FeatureListFrame (filter_name,
                                selection, goto_source, filtered_entry_group,
                                base_plot_group);
    
        feature_list_frame.setVisible (true);
      }
    
      /**
       *  Popup a FeatureListFrame containing those CDS features that overlap with
       *  the next feature.
       *  @param parent_frame The parent JFrame.
       *  @param selection The Selection to pass to the FeatureList.
       *  @param entry_group The EntryGroup to pass to the FilteredEntryGroup.
       *  @param goto_source The GotoEventSource to pass to the FeatureList.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      protected static void showOverlappingCDSs(final JFrame parent_frame,
                                                final Selection selection,
                                                final EntryGroup entry_group,
                                                final GotoEventSource goto_source,
                                                final BasePlotGroup base_plot_group) 
      {
        final Key key;
        if(GeneUtils.isDatabaseEntry(entry_group))
          key = new Key(DatabaseDocument.EXONMODEL);
        else
          key = Key.CDS;
        
        final FeatureKeyPredicate cds_predicate = new FeatureKeyPredicate (key);
    
    tjc's avatar
    tjc committed
    
        final FeaturePredicate feature_predicate =
          new FeaturePredicate () {
            public boolean testPredicate (final Feature test_feature) {
              if (!cds_predicate.testPredicate (test_feature)) {
                return false;
              }
    
              final Range feature_range = test_feature.getMaxRawRange ();
    
              final FeatureVector overlapping_features;
    
              try {
                overlapping_features =
                  entry_group.getFeaturesInRange (feature_range);
              } catch (OutOfRangeException e) {
                throw new Error ("internal error - unexpected exception: " + e);
              }
    
              for (int i = 0 ; i < overlapping_features.size () ; ++i) {
                final Feature current_feature = overlapping_features.elementAt (i);
    
                if (current_feature != test_feature &&
                    cds_predicate.testPredicate (current_feature)) {
                  return true;
                }
              }
    
              return false;
            }
          };
    
        final String filter_name =
    
    tjc's avatar
    tjc committed
          "overlapping "+key.getKeyString()+" features (filtered from: " +
    
    tjc's avatar
    tjc committed
          parent_frame.getTitle () + ")";
    
        final FilteredEntryGroup filtered_entry_group =
          new FilteredEntryGroup (entry_group, feature_predicate, filter_name);
    
        final FeatureListFrame feature_list_frame =
          new FeatureListFrame (filter_name,
                                selection, goto_source, filtered_entry_group,
                                base_plot_group);
    
        feature_list_frame.setVisible (true);
      }
    
      /**
       *  Popup a FeatureListFrame containing those CDS features that overlap with
       *  the next feature.
       *  @param parent_frame The parent JFrame.
       *  @param selection The Selection to pass to the FeatureList.
       *  @param entry_group The EntryGroup to pass to the FilteredEntryGroup.
       *  @param goto_source The GotoEventSource to pass to the FeatureList.
       *  @param base_plot_group The BasePlotGroup associated with this JMenu -
       *    needed to call getCodonUsageAlgorithm()
       **/
    
    tjc's avatar
    tjc committed
      private static void
    
    tjc's avatar
    tjc committed
        showFeaturesWithSameStopCodons(final JFrame parent_frame,
                                       final Selection selection,
                                       final EntryGroup entry_group,
                                       final GotoEventSource goto_source,
                                       final BasePlotGroup base_plot_group) 
      {
        final Key key;
        if(GeneUtils.isDatabaseEntry(entry_group))
          key = new Key(DatabaseDocument.EXONMODEL);
        else
          key = Key.CDS;
        final FeatureKeyPredicate cds_predicate = new FeatureKeyPredicate (key);
    
    tjc's avatar
    tjc committed