+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
+ * )
+ */
+ @Override
+ protected void showDbRefs_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
+ * ActionEvent)
+ */
+ @Override
+ protected void showNpFeats_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
+ }
+
+ /**
+ * find the viewport amongst the tabs in this alignment frame and close that
+ * tab
+ *
+ * @param av
+ */
+ public boolean closeView(AlignViewportI av)
+ {
+ if (viewport == av)
+ {
+ this.closeMenuItem_actionPerformed(false);
+ return true;
+ }
+ Component[] comp = tabbedPane.getComponents();
+ for (int i = 0; comp != null && i < comp.length; i++)
+ {
+ if (comp[i] instanceof AlignmentPanel)
+ {
+ if (((AlignmentPanel) comp[i]).av == av)
+ {
+ // close the view.
+ closeView((AlignmentPanel) comp[i]);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ protected void build_fetchdbmenu(JMenu webService)
+ {
+ // Temporary hack - DBRef Fetcher always top level ws entry.
+ // TODO We probably want to store a sequence database checklist in
+ // preferences and have checkboxes.. rather than individual sources selected
+ // here
+ final JMenu rfetch = new JMenu(
+ MessageManager.getString("action.fetch_db_references"));
+ rfetch.setToolTipText(MessageManager
+ .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
+ webService.add(rfetch);
+
+ final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
+ MessageManager.getString("option.trim_retrieved_seqs"));
+ trimrs.setToolTipText(MessageManager
+ .getString("label.trim_retrieved_sequences"));
+ trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
+ trimrs.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ trimrs.setSelected(trimrs.isSelected());
+ Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
+ Boolean.valueOf(trimrs.isSelected()).toString());
+ };
+ });
+ rfetch.add(trimrs);
+ JMenuItem fetchr = new JMenuItem(
+ MessageManager.getString("label.standard_databases"));
+ fetchr.setToolTipText(MessageManager
+ .getString("label.fetch_embl_uniprot"));
+ fetchr.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ new Thread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ new jalview.ws.DBRefFetcher(alignPanel.av
+ .getSequenceSelection(), alignPanel.alignFrame)
+ .fetchDBRefs(false);
+ }
+ }).start();
+
+ }
+
+ });
+ rfetch.add(fetchr);
+ final AlignFrame me = this;
+ new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ final jalview.ws.SequenceFetcher sf = SequenceFetcher
+ .getSequenceFetcherSingleton(me);
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ String[] dbclasses = sf.getOrderedSupportedSources();
+ // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
+ // jalview.util.QuickSort.sort(otherdb, otherdb);
+ List<DbSourceProxy> otherdb;
+ JMenu dfetch = new JMenu();
+ JMenu ifetch = new JMenu();
+ JMenuItem fetchr = null;
+ int comp = 0, icomp = 0, mcomp = 15;
+ String mname = null;
+ int dbi = 0;
+ for (String dbclass : dbclasses)
+ {
+ otherdb = sf.getSourceProxy(dbclass);
+ // add a single entry for this class, or submenu allowing 'fetch
+ // all' or pick one
+ if (otherdb == null || otherdb.size() < 1)
+ {
+ continue;
+ }
+ // List<DbSourceProxy> dbs=otherdb;
+ // otherdb=new ArrayList<DbSourceProxy>();
+ // for (DbSourceProxy db:dbs)
+ // {
+ // if (!db.isA(DBRefSource.ALIGNMENTDB)
+ // }
+ if (mname == null)
+ {
+ mname = "From " + dbclass;
+ }
+ if (otherdb.size() == 1)
+ {
+ final DbSourceProxy[] dassource = otherdb
+ .toArray(new DbSourceProxy[0]);
+ DbSourceProxy src = otherdb.get(0);
+ fetchr = new JMenuItem(src.getDbSource());
+ fetchr.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ new Thread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ new jalview.ws.DBRefFetcher(alignPanel.av
+ .getSequenceSelection(),
+ alignPanel.alignFrame, dassource)
+ .fetchDBRefs(false);
+ }
+ }).start();
+ }
+
+ });
+ fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
+ MessageManager.formatMessage(
+ "label.fetch_retrieve_from",
+ new Object[] { src.getDbName() })));
+ dfetch.add(fetchr);
+ comp++;
+ }
+ else
+ {
+ final DbSourceProxy[] dassource = otherdb
+ .toArray(new DbSourceProxy[0]);
+ // fetch all entry
+ DbSourceProxy src = otherdb.get(0);
+ fetchr = new JMenuItem(MessageManager.formatMessage(
+ "label.fetch_all_param",
+ new Object[] { src.getDbSource() }));
+ fetchr.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ new Thread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ new jalview.ws.DBRefFetcher(alignPanel.av
+ .getSequenceSelection(),
+ alignPanel.alignFrame, dassource)
+ .fetchDBRefs(false);
+ }
+ }).start();
+ }
+ });
+
+ fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
+ MessageManager.formatMessage(
+ "label.fetch_retrieve_from_all_sources",
+ new Object[] {
+ Integer.valueOf(otherdb.size())
+ .toString(), src.getDbSource(),
+ src.getDbName() })));
+ dfetch.add(fetchr);
+ comp++;
+ // and then build the rest of the individual menus
+ ifetch = new JMenu(MessageManager.formatMessage(
+ "label.source_from_db_source",
+ new Object[] { src.getDbSource() }));
+ icomp = 0;
+ String imname = null;
+ int i = 0;
+ for (DbSourceProxy sproxy : otherdb)
+ {
+ String dbname = sproxy.getDbName();
+ String sname = dbname.length() > 5 ? dbname.substring(0,
+ 5) + "..." : dbname;
+ String msname = dbname.length() > 10 ? dbname.substring(
+ 0, 10) + "..." : dbname;
+ if (imname == null)
+ {
+ imname = MessageManager.formatMessage(
+ "label.from_msname", new Object[] { sname });
+ }
+ fetchr = new JMenuItem(msname);
+ final DbSourceProxy[] dassrc = { sproxy };
+ fetchr.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ new Thread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ new jalview.ws.DBRefFetcher(alignPanel.av
+ .getSequenceSelection(),
+ alignPanel.alignFrame, dassrc)
+ .fetchDBRefs(false);
+ }
+ }).start();
+ }
+
+ });
+ fetchr.setToolTipText("<html>"
+ + MessageManager.formatMessage(
+ "label.fetch_retrieve_from", new Object[]
+ { dbname }));
+ ifetch.add(fetchr);
+ ++i;
+ if (++icomp >= mcomp || i == (otherdb.size()))
+ {
+ ifetch.setText(MessageManager.formatMessage(
+ "label.source_to_target", imname, sname));
+ dfetch.add(ifetch);
+ ifetch = new JMenu();
+ imname = null;
+ icomp = 0;
+ comp++;
+ }
+ }
+ }
+ ++dbi;
+ if (comp >= mcomp || dbi >= (dbclasses.length))
+ {
+ dfetch.setText(MessageManager.formatMessage(
+ "label.source_to_target", mname, dbclass));
+ rfetch.add(dfetch);
+ dfetch = new JMenu();
+ mname = null;
+ comp = 0;
+ }
+ }
+ }
+ });
+ }
+ }).start();
+
+ }
+
+ /**
+ * Left justify the whole alignment.
+ */
+ @Override
+ protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
+ {
+ AlignmentI al = viewport.getAlignment();
+ al.justify(false);
+ viewport.firePropertyChange("alignment", null, al);
+ }
+
+ /**
+ * Right justify the whole alignment.
+ */
+ @Override
+ protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
+ {
+ AlignmentI al = viewport.getAlignment();
+ al.justify(true);
+ viewport.firePropertyChange("alignment", null, al);
+ }
+
+ public void setShowSeqFeatures(boolean b)
+ {
+ showSeqFeatures.setSelected(b);
+ viewport.setShowSequenceFeatures(b);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
+ * awt.event.ActionEvent)
+ */
+ @Override
+ protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowUnconserved(showNonconservedMenuItem.getState());
+ alignPanel.paintAlignment(true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
+ * .ActionEvent)
+ */
+ @Override
+ protected void showGroupConsensus_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowGroupConsensus(showGroupConsensus.getState());
+ alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
+ * .event.ActionEvent)
+ */
+ @Override
+ protected void showGroupConservation_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowGroupConservation(showGroupConservation.getState());
+ alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
+ * .event.ActionEvent)
+ */
+ @Override
+ protected void showConsensusHistogram_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
+ alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
+ * .event.ActionEvent)
+ */
+ @Override
+ protected void showSequenceLogo_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowSequenceLogo(showSequenceLogo.getState());
+ alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+ }
+
+ @Override
+ protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
+ {
+ showSequenceLogo.setState(true);
+ viewport.setShowSequenceLogo(true);
+ viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
+ alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+ }
+
+ @Override
+ protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
+ {
+ alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
+ * .event.ActionEvent)
+ */
+ @Override
+ protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
+ {
+ if (avc.makeGroupsFromSelection())
+ {
+ PaintRefresher.Refresh(this, viewport.getSequenceSetId());
+ alignPanel.updateAnnotation();
+ 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)
+ {
+ if (avc.createGroup())
+ {
+ alignPanel.alignmentChanged();
+ }
+ }
+
+ @Override
+ protected void unGroup_actionPerformed(ActionEvent e)
+ {
+ if (avc.unGroup())
+ {
+ alignPanel.alignmentChanged();
+ }
+ }
+
+ /**
+ * make the given alignmentPanel the currently selected tab
+ *
+ * @param alignmentPanel
+ */
+ public void setDisplayedView(AlignmentPanel alignmentPanel)
+ {
+ if (!viewport.getSequenceSetId().equals(
+ alignmentPanel.av.getSequenceSetId()))
+ {
+ throw new Error(
+ MessageManager
+ .getString("error.implementation_error_cannot_show_view_alignment_frame"));
+ }
+ if (tabbedPane != null
+ && tabbedPane.getTabCount() > 0
+ && alignPanels.indexOf(alignmentPanel) != tabbedPane
+ .getSelectedIndex())
+ {
+ tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
+ }
+ }
+
+ /**
+ * Action on selection of menu options to Show or Hide annotations.
+ *
+ * @param visible
+ * @param forSequences
+ * update sequence-related annotations
+ * @param forAlignment
+ * update non-sequence-related annotations
+ */
+ @Override
+ protected void setAnnotationsVisibility(boolean visible,
+ boolean forSequences, boolean forAlignment)
+ {
+ for (AlignmentAnnotation aa : alignPanel.getAlignment()
+ .getAlignmentAnnotation())
+ {
+ /*
+ * don't display non-positional annotations on an alignment
+ */
+ if (aa.annotations == null)
+ {
+ continue;
+ }
+ boolean apply = (aa.sequenceRef == null && forAlignment)
+ || (aa.sequenceRef != null && forSequences);
+ if (apply)
+ {
+ aa.visible = visible;
+ }
+ }
+ alignPanel.validateAnnotationDimensions(true);
+ alignPanel.alignmentChanged();
+ }
+
+ /**
+ * Store selected annotation sort order for the view and repaint.
+ */
+ @Override
+ protected void sortAnnotations_actionPerformed()
+ {
+ this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
+ this.alignPanel.av
+ .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ *
+ * @return alignment panels in this alignment frame
+ */
+ public List<? extends AlignmentViewPanel> getAlignPanels()
+ {
+ return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
+ }
+
+ /**
+ * Open a new alignment window, with the cDNA associated with this (protein)
+ * alignment, aligned as is the protein.
+ */
+ protected void viewAsCdna_actionPerformed()
+ {
+ // TODO no longer a menu action - refactor as required
+ final AlignmentI alignment = getViewport().getAlignment();
+ Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
+ if (mappings == null)
+ {
+ return;
+ }
+ List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
+ for (SequenceI aaSeq : alignment.getSequences())
+ {
+ for (AlignedCodonFrame acf : mappings)
+ {
+ SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
+ if (dnaSeq != null)
+ {
+ /*
+ * There is a cDNA mapping for this protein sequence - add to new
+ * alignment. It will share the same dataset sequence as other mapped
+ * cDNA (no new mappings need to be created).
+ */
+ final Sequence newSeq = new Sequence(dnaSeq);
+ newSeq.setDatasetSequence(dnaSeq);
+ cdnaSeqs.add(newSeq);
+ }
+ }
+ }
+ if (cdnaSeqs.size() == 0)
+ {
+ // show a warning dialog no mapped cDNA
+ return;
+ }
+ AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
+ .size()]));
+ AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
+ cdna.alignAs(alignment);
+ String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
+ + this.title;
+ Desktop.addInternalFrame(alignFrame, newtitle,
+ AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ }
+
+ /**
+ * Set visibility of dna/protein complement view (available when shown in a
+ * split frame).
+ *
+ * @param show
+ */
+ @Override
+ protected void showComplement_actionPerformed(boolean show)
+ {
+ SplitContainerI sf = getSplitViewContainer();
+ if (sf != null)
+ {
+ sf.setComplementVisible(this, show);
+ }
+ }