2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.AlignmentSorter;
22 import jalview.analysis.Conservation;
23 import jalview.analysis.CrossRef;
24 import jalview.analysis.NJTree;
25 import jalview.analysis.ParseProperties;
26 import jalview.analysis.SequenceIdMatcher;
27 import jalview.bin.Cache;
28 import jalview.commands.CommandI;
29 import jalview.commands.EditCommand;
30 import jalview.commands.OrderCommand;
31 import jalview.commands.RemoveGapColCommand;
32 import jalview.commands.RemoveGapsCommand;
33 import jalview.commands.SlideSequencesCommand;
34 import jalview.commands.TrimRegionCommand;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.Alignment;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentOrder;
40 import jalview.datamodel.AlignmentView;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.SeqCigar;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.io.AlignmentProperties;
48 import jalview.io.AnnotationFile;
49 import jalview.io.FeaturesFile;
50 import jalview.io.FileLoader;
51 import jalview.io.FormatAdapter;
52 import jalview.io.HTMLOutput;
53 import jalview.io.IdentifyFile;
54 import jalview.io.JalviewFileChooser;
55 import jalview.io.JalviewFileView;
56 import jalview.io.JnetAnnotationMaker;
57 import jalview.io.NewickFile;
58 import jalview.io.TCoffeeScoreFile;
59 import jalview.jbgui.GAlignFrame;
60 import jalview.schemes.Blosum62ColourScheme;
61 import jalview.schemes.BuriedColourScheme;
62 import jalview.schemes.ClustalxColourScheme;
63 import jalview.schemes.ColourSchemeI;
64 import jalview.schemes.ColourSchemeProperty;
65 import jalview.schemes.HelixColourScheme;
66 import jalview.schemes.HydrophobicColourScheme;
67 import jalview.schemes.NucleotideColourScheme;
68 import jalview.schemes.PIDColourScheme;
69 import jalview.schemes.PurinePyrimidineColourScheme;
70 import jalview.schemes.RNAHelicesColourChooser;
71 import jalview.schemes.ResidueProperties;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.UserColourScheme;
77 import jalview.schemes.ZappoColourScheme;
78 import jalview.ws.jws1.Discoverer;
79 import jalview.ws.jws2.Jws2Discoverer;
80 import jalview.ws.seqfetcher.DbSourceProxy;
82 import java.awt.BorderLayout;
83 import java.awt.Color;
84 import java.awt.Component;
85 import java.awt.GridLayout;
86 import java.awt.Rectangle;
87 import java.awt.Toolkit;
88 import java.awt.datatransfer.Clipboard;
89 import java.awt.datatransfer.DataFlavor;
90 import java.awt.datatransfer.StringSelection;
91 import java.awt.datatransfer.Transferable;
92 import java.awt.dnd.DnDConstants;
93 import java.awt.dnd.DropTargetDragEvent;
94 import java.awt.dnd.DropTargetDropEvent;
95 import java.awt.dnd.DropTargetEvent;
96 import java.awt.dnd.DropTargetListener;
97 import java.awt.event.ActionEvent;
98 import java.awt.event.ActionListener;
99 import java.awt.event.KeyAdapter;
100 import java.awt.event.KeyEvent;
101 import java.awt.event.MouseAdapter;
102 import java.awt.event.MouseEvent;
103 import java.awt.print.PageFormat;
104 import java.awt.print.PrinterJob;
105 import java.beans.PropertyChangeEvent;
108 import java.util.ArrayList;
109 import java.util.Enumeration;
110 import java.util.Hashtable;
111 import java.util.List;
112 import java.util.Vector;
114 import javax.swing.JButton;
115 import javax.swing.JEditorPane;
116 import javax.swing.JInternalFrame;
117 import javax.swing.JLabel;
118 import javax.swing.JLayeredPane;
119 import javax.swing.JMenu;
120 import javax.swing.JMenuItem;
121 import javax.swing.JOptionPane;
122 import javax.swing.JPanel;
123 import javax.swing.JProgressBar;
124 import javax.swing.JRadioButtonMenuItem;
125 import javax.swing.JScrollPane;
126 import javax.swing.SwingUtilities;
132 * @version $Revision$
134 public class AlignFrame extends GAlignFrame implements DropTargetListener,
139 public static final int DEFAULT_WIDTH = 700;
142 public static final int DEFAULT_HEIGHT = 500;
144 public AlignmentPanel alignPanel;
146 AlignViewport viewport;
148 Vector alignPanels = new Vector();
151 * Last format used to load or save alignments in this window
153 String currentFileFormat = null;
156 * Current filename for this alignment
158 String fileName = null;
161 * Creates a new AlignFrame object with specific width and height.
167 public AlignFrame(AlignmentI al, int width, int height)
169 this(al, null, width, height);
173 * Creates a new AlignFrame object with specific width, height and
179 * @param sequenceSetId
181 public AlignFrame(AlignmentI al, int width, int height,
182 String sequenceSetId)
184 this(al, null, width, height, sequenceSetId);
188 * Creates a new AlignFrame object with specific width, height and
194 * @param sequenceSetId
197 public AlignFrame(AlignmentI al, int width, int height,
198 String sequenceSetId, String viewId)
200 this(al, null, width, height, sequenceSetId, viewId);
204 * new alignment window with hidden columns
208 * @param hiddenColumns
209 * ColumnSelection or null
211 * Width of alignment frame
215 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
216 int width, int height)
218 this(al, hiddenColumns, width, height, null);
222 * Create alignment frame for al with hiddenColumns, a specific width and
223 * height, and specific sequenceId
226 * @param hiddenColumns
229 * @param sequenceSetId
232 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
233 int width, int height, String sequenceSetId)
235 this(al, hiddenColumns, width, height, sequenceSetId, null);
239 * Create alignment frame for al with hiddenColumns, a specific width and
240 * height, and specific sequenceId
243 * @param hiddenColumns
246 * @param sequenceSetId
251 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
252 int width, int height, String sequenceSetId, String viewId)
254 setSize(width, height);
255 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
257 alignPanel = new AlignmentPanel(this, viewport);
259 if (al.getDataset() == null)
264 addAlignmentPanel(alignPanel, true);
269 * Make a new AlignFrame from exisiting alignmentPanels
276 public AlignFrame(AlignmentPanel ap)
280 addAlignmentPanel(ap, false);
285 * initalise the alignframe from the underlying viewport data and the
290 if (viewport.getAlignmentConservationAnnotation() == null)
292 BLOSUM62Colour.setEnabled(false);
293 conservationMenuItem.setEnabled(false);
294 modifyConservation.setEnabled(false);
295 // PIDColour.setEnabled(false);
296 // abovePIDThreshold.setEnabled(false);
297 // modifyPID.setEnabled(false);
300 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
303 if (sortby.equals("Id"))
305 sortIDMenuItem_actionPerformed(null);
307 else if (sortby.equals("Pairwise Identity"))
309 sortPairwiseMenuItem_actionPerformed(null);
312 if (Desktop.desktop != null)
314 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
315 addServiceListeners();
316 setGUINucleotide(viewport.getAlignment().isNucleotide());
319 setMenusFromViewport(viewport);
320 buildSortByAnnotationScoresMenu();
321 if (viewport.wrapAlignment)
323 wrapMenuItem_actionPerformed(null);
326 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
328 this.overviewMenuItem_actionPerformed(null);
336 * Change the filename and format for the alignment, and enable the 'reload'
337 * button functionality.
344 public void setFileName(String file, String format)
347 currentFileFormat = format;
348 reload.setEnabled(true);
351 void addKeyListener()
353 addKeyListener(new KeyAdapter()
355 public void keyPressed(KeyEvent evt)
357 if (viewport.cursorMode
358 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
359 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
360 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
361 && Character.isDigit(evt.getKeyChar()))
362 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
364 switch (evt.getKeyCode())
367 case 27: // escape key
368 deselectAllSequenceMenuItem_actionPerformed(null);
372 case KeyEvent.VK_DOWN:
373 if (evt.isAltDown() || !viewport.cursorMode)
374 moveSelectedSequences(false);
375 if (viewport.cursorMode)
376 alignPanel.seqPanel.moveCursor(0, 1);
380 if (evt.isAltDown() || !viewport.cursorMode)
381 moveSelectedSequences(true);
382 if (viewport.cursorMode)
383 alignPanel.seqPanel.moveCursor(0, -1);
387 case KeyEvent.VK_LEFT:
388 if (evt.isAltDown() || !viewport.cursorMode)
389 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
391 alignPanel.seqPanel.moveCursor(-1, 0);
395 case KeyEvent.VK_RIGHT:
396 if (evt.isAltDown() || !viewport.cursorMode)
397 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
399 alignPanel.seqPanel.moveCursor(1, 0);
402 case KeyEvent.VK_SPACE:
403 if (viewport.cursorMode)
405 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
406 || evt.isShiftDown() || evt.isAltDown());
410 // case KeyEvent.VK_A:
411 // if (viewport.cursorMode)
413 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
414 // //System.out.println("A");
418 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
419 * System.out.println("closing bracket"); } break;
421 case KeyEvent.VK_DELETE:
422 case KeyEvent.VK_BACK_SPACE:
423 if (!viewport.cursorMode)
425 cut_actionPerformed(null);
429 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
430 || evt.isShiftDown() || evt.isAltDown());
436 if (viewport.cursorMode)
438 alignPanel.seqPanel.setCursorRow();
442 if (viewport.cursorMode && !evt.isControlDown())
444 alignPanel.seqPanel.setCursorColumn();
448 if (viewport.cursorMode)
450 alignPanel.seqPanel.setCursorPosition();
454 case KeyEvent.VK_ENTER:
455 case KeyEvent.VK_COMMA:
456 if (viewport.cursorMode)
458 alignPanel.seqPanel.setCursorRowAndColumn();
463 if (viewport.cursorMode)
465 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
469 if (viewport.cursorMode)
471 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
476 viewport.cursorMode = !viewport.cursorMode;
477 statusBar.setText("Keyboard editing mode is "
478 + (viewport.cursorMode ? "on" : "off"));
479 if (viewport.cursorMode)
481 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
482 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
484 alignPanel.seqPanel.seqCanvas.repaint();
490 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
491 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
493 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
495 javax.help.HelpBroker hb = hs.createHelpBroker();
496 hb.setCurrentID("home");
497 hb.setDisplayed(true);
498 } catch (Exception ex)
500 ex.printStackTrace();
505 boolean toggleSeqs = !evt.isControlDown();
506 boolean toggleCols = !evt.isShiftDown();
507 toggleHiddenRegions(toggleSeqs, toggleCols);
510 case KeyEvent.VK_PAGE_UP:
511 if (viewport.wrapAlignment)
513 alignPanel.scrollUp(true);
517 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
518 - viewport.endSeq + viewport.startSeq);
521 case KeyEvent.VK_PAGE_DOWN:
522 if (viewport.wrapAlignment)
524 alignPanel.scrollUp(false);
528 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
529 + viewport.endSeq - viewport.startSeq);
535 public void keyReleased(KeyEvent evt)
537 switch (evt.getKeyCode())
539 case KeyEvent.VK_LEFT:
540 if (evt.isAltDown() || !viewport.cursorMode)
541 viewport.firePropertyChange("alignment", null, viewport
542 .getAlignment().getSequences());
545 case KeyEvent.VK_RIGHT:
546 if (evt.isAltDown() || !viewport.cursorMode)
547 viewport.firePropertyChange("alignment", null, viewport
548 .getAlignment().getSequences());
555 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
557 ap.alignFrame = this;
559 alignPanels.addElement(ap);
561 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
563 int aSize = alignPanels.size();
565 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
567 if (aSize == 1 && ap.av.viewName == null)
569 this.getContentPane().add(ap, BorderLayout.CENTER);
575 setInitialTabVisible();
578 expandViews.setEnabled(true);
579 gatherViews.setEnabled(true);
580 tabbedPane.addTab(ap.av.viewName, ap);
582 ap.setVisible(false);
587 if (ap.av.isPadGaps())
589 ap.av.getAlignment().padGaps();
591 ap.av.updateConservation(ap);
592 ap.av.updateConsensus(ap);
593 ap.av.updateStrucConsensus(ap);
597 public void setInitialTabVisible()
599 expandViews.setEnabled(true);
600 gatherViews.setEnabled(true);
601 tabbedPane.setVisible(true);
602 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
603 tabbedPane.addTab(first.av.viewName, first);
604 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
607 public AlignViewport getViewport()
612 /* Set up intrinsic listeners for dynamically generated GUI bits. */
613 private void addServiceListeners()
615 final java.beans.PropertyChangeListener thisListener;
616 Desktop.instance.addJalviewPropertyChangeListener("services",
617 thisListener = new java.beans.PropertyChangeListener()
619 public void propertyChange(PropertyChangeEvent evt)
621 // // System.out.println("Discoverer property change.");
622 // if (evt.getPropertyName().equals("services"))
624 SwingUtilities.invokeLater(new Runnable()
630 .println("Rebuild WS Menu for service change");
631 BuildWebServiceMenu();
638 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
640 public void internalFrameClosed(
641 javax.swing.event.InternalFrameEvent evt)
643 System.out.println("deregistering discoverer listener");
644 Desktop.instance.removeJalviewPropertyChangeListener("services",
646 closeMenuItem_actionPerformed(true);
649 // Finally, build the menu once to get current service state
650 new Thread(new Runnable()
654 BuildWebServiceMenu();
659 public void setGUINucleotide(boolean nucleotide)
661 showTranslation.setVisible(nucleotide);
662 conservationMenuItem.setEnabled(!nucleotide);
663 modifyConservation.setEnabled(!nucleotide);
664 showGroupConservation.setEnabled(!nucleotide);
665 rnahelicesColour.setEnabled(nucleotide);
666 purinePyrimidineColour.setEnabled(nucleotide);
667 // Remember AlignFrame always starts as protein
671 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
676 * set up menus for the currently viewport. This may be called after any
677 * operation that affects the data in the current view (selection changed,
678 * etc) to update the menus to reflect the new state.
680 public void setMenusForViewport()
682 setMenusFromViewport(viewport);
686 * Need to call this method when tabs are selected for multiple views, or when
687 * loading from Jalview2XML.java
692 void setMenusFromViewport(AlignViewport av)
694 padGapsMenuitem.setSelected(av.isPadGaps());
695 colourTextMenuItem.setSelected(av.showColourText);
696 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
697 conservationMenuItem.setSelected(av.getConservationSelected());
698 seqLimits.setSelected(av.getShowJVSuffix());
699 idRightAlign.setSelected(av.rightAlignIds);
700 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
701 renderGapsMenuItem.setSelected(av.renderGaps);
702 wrapMenuItem.setSelected(av.wrapAlignment);
703 scaleAbove.setVisible(av.wrapAlignment);
704 scaleLeft.setVisible(av.wrapAlignment);
705 scaleRight.setVisible(av.wrapAlignment);
706 annotationPanelMenuItem.setState(av.showAnnotation);
707 viewBoxesMenuItem.setSelected(av.showBoxes);
708 viewTextMenuItem.setSelected(av.showText);
709 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
710 showGroupConsensus.setSelected(av.isShowGroupConsensus());
711 showGroupConservation.setSelected(av.isShowGroupConservation());
712 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
713 showSequenceLogo.setSelected(av.isShowSequenceLogo());
714 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
716 setColourSelected(ColourSchemeProperty.getColourName(av
717 .getGlobalColourScheme()));
719 showSeqFeatures.setSelected(av.showSequenceFeatures);
720 hiddenMarkers.setState(av.showHiddenMarkers);
721 applyToAllGroups.setState(av.colourAppliesToAllGroups);
722 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
723 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
724 autoCalculate.setSelected(av.autoCalculateConsensus);
725 sortByTree.setSelected(av.sortByTree);
726 listenToViewSelections.setSelected(av.followSelection);
727 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
729 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
730 setShowProductsEnabled();
735 Hashtable progressBars, progressBarHandlers;
740 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
742 public void setProgressBar(String message, long id)
744 if (progressBars == null)
746 progressBars = new Hashtable();
747 progressBarHandlers = new Hashtable();
750 JPanel progressPanel;
751 Long lId = new Long(id);
752 GridLayout layout = (GridLayout) statusPanel.getLayout();
753 if (progressBars.get(lId) != null)
755 progressPanel = (JPanel) progressBars.get(new Long(id));
756 statusPanel.remove(progressPanel);
757 progressBars.remove(lId);
758 progressPanel = null;
761 statusBar.setText(message);
763 if (progressBarHandlers.contains(lId))
765 progressBarHandlers.remove(lId);
767 layout.setRows(layout.getRows() - 1);
771 progressPanel = new JPanel(new BorderLayout(10, 5));
773 JProgressBar progressBar = new JProgressBar();
774 progressBar.setIndeterminate(true);
776 progressPanel.add(new JLabel(message), BorderLayout.WEST);
777 progressPanel.add(progressBar, BorderLayout.CENTER);
779 layout.setRows(layout.getRows() + 1);
780 statusPanel.add(progressPanel);
782 progressBars.put(lId, progressPanel);
785 // setMenusForViewport();
789 public void registerHandler(final long id,
790 final IProgressIndicatorHandler handler)
792 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
795 "call setProgressBar before registering the progress bar's handler.");
797 progressBarHandlers.put(new Long(id), handler);
798 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
799 if (handler.canCancel())
801 JButton cancel = new JButton("Cancel");
802 final IProgressIndicator us = this;
803 cancel.addActionListener(new ActionListener()
806 public void actionPerformed(ActionEvent e)
808 handler.cancelActivity(id);
811 + ((JLabel) progressPanel.getComponent(0))
815 progressPanel.add(cancel, BorderLayout.EAST);
821 * @return true if any progress bars are still active
823 public boolean operationInProgress()
825 if (progressBars != null && progressBars.size() > 0)
833 * Added so Castor Mapping file can obtain Jalview Version
835 public String getVersion()
837 return jalview.bin.Cache.getProperty("VERSION");
840 public FeatureRenderer getFeatureRenderer()
842 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
845 public void fetchSequence_actionPerformed(ActionEvent e)
847 new SequenceFetcher(this);
850 public void addFromFile_actionPerformed(ActionEvent e)
852 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
855 public void reload_actionPerformed(ActionEvent e)
857 if (fileName != null)
859 // TODO: JAL-1108 - ensure all associated frames are closed regardless of originating file's format
860 // TODO: work out how to recover feature settings for correct view(s) when
862 if (currentFileFormat.equals("Jalview"))
864 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
865 for (int i = 0; i < frames.length; i++)
867 if (frames[i] instanceof AlignFrame && frames[i] != this
868 && ((AlignFrame) frames[i]).fileName.equals(fileName))
872 frames[i].setSelected(true);
873 Desktop.instance.closeAssociatedWindows();
874 } catch (java.beans.PropertyVetoException ex)
880 Desktop.instance.closeAssociatedWindows();
882 FileLoader loader = new FileLoader();
883 String protocol = fileName.startsWith("http:") ? "URL" : "File";
884 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
888 Rectangle bounds = this.getBounds();
890 FileLoader loader = new FileLoader();
891 String protocol = fileName.startsWith("http:") ? "URL" : "File";
892 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
893 protocol, currentFileFormat);
895 newframe.setBounds(bounds);
896 if (featureSettings != null && featureSettings.isShowing())
898 final Rectangle fspos = featureSettings.frame.getBounds();
899 // TODO: need a 'show feature settings' function that takes bounds -
900 // need to refactor Desktop.addFrame
901 newframe.featureSettings_actionPerformed(null);
902 final FeatureSettings nfs = newframe.featureSettings;
903 SwingUtilities.invokeLater(new Runnable()
907 nfs.frame.setBounds(fspos);
910 this.featureSettings.close();
911 this.featureSettings = null;
913 this.closeMenuItem_actionPerformed(true);
918 public void addFromText_actionPerformed(ActionEvent e)
920 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
923 public void addFromURL_actionPerformed(ActionEvent e)
925 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
928 public void save_actionPerformed(ActionEvent e)
931 || (currentFileFormat == null || !jalview.io.FormatAdapter
932 .isValidIOFormat(currentFileFormat, true))
933 || fileName.startsWith("http"))
935 saveAs_actionPerformed(null);
939 saveAlignment(fileName, currentFileFormat);
949 public void saveAs_actionPerformed(ActionEvent e)
951 JalviewFileChooser chooser = new JalviewFileChooser(
952 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
953 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
954 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
955 currentFileFormat, false);
957 chooser.setFileView(new JalviewFileView());
958 chooser.setDialogTitle("Save Alignment to file");
959 chooser.setToolTipText("Save");
961 int value = chooser.showSaveDialog(this);
963 if (value == JalviewFileChooser.APPROVE_OPTION)
965 currentFileFormat = chooser.getSelectedFormat();
966 if (currentFileFormat == null)
968 JOptionPane.showInternalMessageDialog(Desktop.desktop,
969 "You must select a file format before saving!",
970 "File format not specified", JOptionPane.WARNING_MESSAGE);
971 value = chooser.showSaveDialog(this);
975 fileName = chooser.getSelectedFile().getPath();
977 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
980 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
981 if (currentFileFormat.indexOf(" ") > -1)
983 currentFileFormat = currentFileFormat.substring(0,
984 currentFileFormat.indexOf(" "));
986 saveAlignment(fileName, currentFileFormat);
990 public boolean saveAlignment(String file, String format)
992 boolean success = true;
994 if (format.equalsIgnoreCase("Jalview"))
996 String shortName = title;
998 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1000 shortName = shortName.substring(shortName
1001 .lastIndexOf(java.io.File.separatorChar) + 1);
1004 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1006 statusBar.setText("Successfully saved to file: " + fileName + " in "
1007 + format + " format.");
1012 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1014 warningMessage("Cannot save file " + fileName + " using format "
1015 + format, "Alignment output format not supported");
1016 saveAs_actionPerformed(null);
1017 // JBPNote need to have a raise_gui flag here
1021 String[] omitHidden = null;
1023 if (viewport.hasHiddenColumns())
1025 int reply = JOptionPane
1026 .showInternalConfirmDialog(
1028 "The Alignment contains hidden columns."
1029 + "\nDo you want to save only the visible alignment?",
1030 "Save / Omit Hidden Columns",
1031 JOptionPane.YES_NO_OPTION,
1032 JOptionPane.QUESTION_MESSAGE);
1034 if (reply == JOptionPane.YES_OPTION)
1036 omitHidden = viewport.getViewAsString(false);
1039 FormatAdapter f = new FormatAdapter();
1040 String output = f.formatSequences(
1042 (Alignment) viewport.getAlignment(), // class cast exceptions will
1043 // occur in the distant future
1044 omitHidden, f.getCacheSuffixDefault(format),
1045 viewport.getColumnSelection());
1055 java.io.PrintWriter out = new java.io.PrintWriter(
1056 new java.io.FileWriter(file));
1060 this.setTitle(file);
1061 statusBar.setText("Successfully saved to file: " + fileName
1062 + " in " + format + " format.");
1063 } catch (Exception ex)
1066 ex.printStackTrace();
1073 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1074 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1080 private void warningMessage(String warning, String title)
1082 if (new jalview.util.Platform().isHeadless())
1084 System.err.println("Warning: " + title + "\nWarning: " + warning);
1089 JOptionPane.showInternalMessageDialog(this, warning, title,
1090 JOptionPane.WARNING_MESSAGE);
1101 protected void outputText_actionPerformed(ActionEvent e)
1103 String[] omitHidden = null;
1105 if (viewport.hasHiddenColumns())
1107 int reply = JOptionPane
1108 .showInternalConfirmDialog(
1110 "The Alignment contains hidden columns."
1111 + "\nDo you want to output only the visible alignment?",
1112 "Save / Omit Hidden Columns",
1113 JOptionPane.YES_NO_OPTION,
1114 JOptionPane.QUESTION_MESSAGE);
1116 if (reply == JOptionPane.YES_OPTION)
1118 omitHidden = viewport.getViewAsString(false);
1122 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1123 cap.setForInput(null);
1127 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1128 viewport.getAlignment(), omitHidden,
1129 viewport.getColumnSelection()));
1130 Desktop.addInternalFrame(cap,
1131 "Alignment output - " + e.getActionCommand(), 600, 500);
1132 } catch (OutOfMemoryError oom)
1134 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1146 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1148 new HTMLOutput(alignPanel,
1149 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1150 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1153 public void createImageMap(File file, String image)
1155 alignPanel.makePNGImageMap(file, image);
1164 public void createPNG(File f)
1166 alignPanel.makePNG(f);
1175 public void createEPS(File f)
1177 alignPanel.makeEPS(f);
1180 public void pageSetup_actionPerformed(ActionEvent e)
1182 PrinterJob printJob = PrinterJob.getPrinterJob();
1183 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1192 public void printMenuItem_actionPerformed(ActionEvent e)
1194 // Putting in a thread avoids Swing painting problems
1195 PrintThread thread = new PrintThread(alignPanel);
1199 public void exportFeatures_actionPerformed(ActionEvent e)
1201 new AnnotationExporter().exportFeatures(alignPanel);
1204 public void exportAnnotations_actionPerformed(ActionEvent e)
1206 new AnnotationExporter().exportAnnotations(alignPanel,
1207 viewport.showAnnotation ? viewport.getAlignment()
1208 .getAlignmentAnnotation() : null, viewport
1209 .getAlignment().getGroups(), ((Alignment) viewport
1210 .getAlignment()).alignmentProperties);
1213 public void associatedData_actionPerformed(ActionEvent e)
1215 // Pick the tree file
1216 JalviewFileChooser chooser = new JalviewFileChooser(
1217 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1218 chooser.setFileView(new JalviewFileView());
1219 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1220 chooser.setToolTipText("Load Jalview Annotations / Features file");
1222 int value = chooser.showOpenDialog(null);
1224 if (value == JalviewFileChooser.APPROVE_OPTION)
1226 String choice = chooser.getSelectedFile().getPath();
1227 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1228 loadJalviewDataFile(choice, null, null, null);
1234 * Close the current view or all views in the alignment frame. If the frame
1235 * only contains one view then the alignment will be removed from memory.
1237 * @param closeAllTabs
1239 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1241 if (alignPanels != null && alignPanels.size() < 2)
1243 closeAllTabs = true;
1248 if (alignPanels != null)
1252 if (this.isClosed())
1254 // really close all the windows - otherwise wait till
1255 // setClosed(true) is called
1256 for (int i = 0; i < alignPanels.size(); i++)
1258 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1265 closeView(alignPanel);
1271 this.setClosed(true);
1273 } catch (Exception ex)
1275 ex.printStackTrace();
1280 * close alignPanel2 and shuffle tabs appropriately.
1282 * @param alignPanel2
1284 public void closeView(AlignmentPanel alignPanel2)
1286 int index = tabbedPane.getSelectedIndex();
1287 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1288 alignPanels.removeElement(alignPanel2);
1290 // if (viewport == alignPanel2.av)
1294 alignPanel2.closePanel();
1297 tabbedPane.removeTabAt(closedindex);
1298 tabbedPane.validate();
1300 if (index > closedindex || index == tabbedPane.getTabCount())
1302 // modify currently selected tab index if necessary.
1306 this.tabSelectionChanged(index);
1312 void updateEditMenuBar()
1315 if (viewport.historyList.size() > 0)
1317 undoMenuItem.setEnabled(true);
1318 CommandI command = (CommandI) viewport.historyList.peek();
1319 undoMenuItem.setText("Undo " + command.getDescription());
1323 undoMenuItem.setEnabled(false);
1324 undoMenuItem.setText("Undo");
1327 if (viewport.redoList.size() > 0)
1329 redoMenuItem.setEnabled(true);
1331 CommandI command = (CommandI) viewport.redoList.peek();
1332 redoMenuItem.setText("Redo " + command.getDescription());
1336 redoMenuItem.setEnabled(false);
1337 redoMenuItem.setText("Redo");
1341 public void addHistoryItem(CommandI command)
1343 if (command.getSize() > 0)
1345 viewport.historyList.push(command);
1346 viewport.redoList.clear();
1347 updateEditMenuBar();
1348 viewport.updateHiddenColumns();
1349 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1350 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1351 // viewport.getColumnSelection()
1352 // .getHiddenColumns().size() > 0);
1358 * @return alignment objects for all views
1360 AlignmentI[] getViewAlignments()
1362 if (alignPanels != null)
1364 Enumeration e = alignPanels.elements();
1365 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1366 for (int i = 0; e.hasMoreElements(); i++)
1368 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1372 if (viewport != null)
1374 return new AlignmentI[]
1375 { viewport.getAlignment() };
1386 protected void undoMenuItem_actionPerformed(ActionEvent e)
1388 if (viewport.historyList.empty())
1390 CommandI command = (CommandI) viewport.historyList.pop();
1391 viewport.redoList.push(command);
1392 command.undoCommand(getViewAlignments());
1394 AlignViewport originalSource = getOriginatingSource(command);
1395 updateEditMenuBar();
1397 if (originalSource != null)
1399 if (originalSource != viewport)
1402 .warn("Implementation worry: mismatch of viewport origin for undo");
1404 originalSource.updateHiddenColumns();
1405 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1407 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1408 // viewport.getColumnSelection()
1409 // .getHiddenColumns().size() > 0);
1410 originalSource.firePropertyChange("alignment", null, originalSource
1411 .getAlignment().getSequences());
1421 protected void redoMenuItem_actionPerformed(ActionEvent e)
1423 if (viewport.redoList.size() < 1)
1428 CommandI command = (CommandI) viewport.redoList.pop();
1429 viewport.historyList.push(command);
1430 command.doCommand(getViewAlignments());
1432 AlignViewport originalSource = getOriginatingSource(command);
1433 updateEditMenuBar();
1435 if (originalSource != null)
1438 if (originalSource != viewport)
1441 .warn("Implementation worry: mismatch of viewport origin for redo");
1443 originalSource.updateHiddenColumns();
1444 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1446 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1447 // viewport.getColumnSelection()
1448 // .getHiddenColumns().size() > 0);
1449 originalSource.firePropertyChange("alignment", null, originalSource
1450 .getAlignment().getSequences());
1454 AlignViewport getOriginatingSource(CommandI command)
1456 AlignViewport originalSource = null;
1457 // For sequence removal and addition, we need to fire
1458 // the property change event FROM the viewport where the
1459 // original alignment was altered
1460 AlignmentI al = null;
1461 if (command instanceof EditCommand)
1463 EditCommand editCommand = (EditCommand) command;
1464 al = editCommand.getAlignment();
1465 Vector comps = (Vector) PaintRefresher.components.get(viewport
1466 .getSequenceSetId());
1468 for (int i = 0; i < comps.size(); i++)
1470 if (comps.elementAt(i) instanceof AlignmentPanel)
1472 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1474 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1481 if (originalSource == null)
1483 // The original view is closed, we must validate
1484 // the current view against the closed view first
1487 PaintRefresher.validateSequences(al, viewport.getAlignment());
1490 originalSource = viewport;
1493 return originalSource;
1502 public void moveSelectedSequences(boolean up)
1504 SequenceGroup sg = viewport.getSelectionGroup();
1513 for (int i = 1; i < viewport.getAlignment().getHeight(); i++)
1515 SequenceI seq = viewport.getAlignment().getSequenceAt(i);
1517 if (!sg.getSequences(null).contains(seq))
1522 SequenceI temp = viewport.getAlignment().getSequenceAt(i - 1);
1524 if (sg.getSequences(null).contains(temp))
1529 viewport.getAlignment().getSequences().setElementAt(temp, i);
1530 viewport.getAlignment().getSequences().setElementAt(seq, i - 1);
1535 for (int i = viewport.getAlignment().getHeight() - 2; i > -1; i--)
1537 SequenceI seq = viewport.getAlignment().getSequenceAt(i);
1539 if (!sg.getSequences(null).contains(seq))
1544 SequenceI temp = viewport.getAlignment().getSequenceAt(i + 1);
1546 if (sg.getSequences(null).contains(temp))
1551 viewport.getAlignment().getSequences().setElementAt(temp, i);
1552 viewport.getAlignment().getSequences().setElementAt(seq, i + 1);
1556 alignPanel.paintAlignment(true);
1559 synchronized void slideSequences(boolean right, int size)
1561 Vector sg = new Vector();
1562 if (viewport.cursorMode)
1564 sg.addElement(viewport.getAlignment().getSequenceAt(
1565 alignPanel.seqPanel.seqCanvas.cursorY));
1567 else if (viewport.getSelectionGroup() != null
1568 && viewport.getSelectionGroup().getSize() != viewport
1569 .getAlignment().getHeight())
1571 sg = viewport.getSelectionGroup().getSequences(
1572 viewport.getHiddenRepSequences());
1580 Vector invertGroup = new Vector();
1582 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1584 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1585 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1588 SequenceI[] seqs1 = new SequenceI[sg.size()];
1589 for (int i = 0; i < sg.size(); i++)
1590 seqs1[i] = (SequenceI) sg.elementAt(i);
1592 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1593 for (int i = 0; i < invertGroup.size(); i++)
1594 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1596 SlideSequencesCommand ssc;
1598 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1599 size, viewport.getGapCharacter());
1601 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1602 size, viewport.getGapCharacter());
1604 int groupAdjustment = 0;
1605 if (ssc.getGapsInsertedBegin() && right)
1607 if (viewport.cursorMode)
1608 alignPanel.seqPanel.moveCursor(size, 0);
1610 groupAdjustment = size;
1612 else if (!ssc.getGapsInsertedBegin() && !right)
1614 if (viewport.cursorMode)
1615 alignPanel.seqPanel.moveCursor(-size, 0);
1617 groupAdjustment = -size;
1620 if (groupAdjustment != 0)
1622 viewport.getSelectionGroup().setStartRes(
1623 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1624 viewport.getSelectionGroup().setEndRes(
1625 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1628 boolean appendHistoryItem = false;
1629 if (viewport.historyList != null && viewport.historyList.size() > 0
1630 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1632 appendHistoryItem = ssc
1633 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1637 if (!appendHistoryItem)
1638 addHistoryItem(ssc);
1649 protected void copy_actionPerformed(ActionEvent e)
1652 if (viewport.getSelectionGroup() == null)
1656 // TODO: preserve the ordering of displayed alignment annotation in any
1657 // internal paste (particularly sequence associated annotation)
1658 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1659 String[] omitHidden = null;
1661 if (viewport.hasHiddenColumns())
1663 omitHidden = viewport.getViewAsString(true);
1666 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1669 StringSelection ss = new StringSelection(output);
1673 jalview.gui.Desktop.internalCopy = true;
1674 // Its really worth setting the clipboard contents
1675 // to empty before setting the large StringSelection!!
1676 Toolkit.getDefaultToolkit().getSystemClipboard()
1677 .setContents(new StringSelection(""), null);
1679 Toolkit.getDefaultToolkit().getSystemClipboard()
1680 .setContents(ss, Desktop.instance);
1681 } catch (OutOfMemoryError er)
1683 new OOMWarning("copying region", er);
1687 Vector hiddenColumns = null;
1688 if (viewport.hasHiddenColumns())
1690 hiddenColumns = new Vector();
1691 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1692 .getSelectionGroup().getEndRes();
1693 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1696 int[] region = (int[]) viewport.getColumnSelection()
1697 .getHiddenColumns().elementAt(i);
1698 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1700 hiddenColumns.addElement(new int[]
1701 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1706 Desktop.jalviewClipboard = new Object[]
1707 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1708 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1717 protected void pasteNew_actionPerformed(ActionEvent e)
1728 protected void pasteThis_actionPerformed(ActionEvent e)
1734 * Paste contents of Jalview clipboard
1736 * @param newAlignment
1737 * true to paste to a new alignment, otherwise add to this.
1739 void paste(boolean newAlignment)
1741 boolean externalPaste = true;
1744 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1745 Transferable contents = c.getContents(this);
1747 if (contents == null)
1755 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1756 if (str.length() < 1)
1761 format = new IdentifyFile().Identify(str, "Paste");
1763 } catch (OutOfMemoryError er)
1765 new OOMWarning("Out of memory pasting sequences!!", er);
1769 SequenceI[] sequences;
1770 boolean annotationAdded = false;
1771 AlignmentI alignment = null;
1773 if (Desktop.jalviewClipboard != null)
1775 // The clipboard was filled from within Jalview, we must use the
1777 // And dataset from the copied alignment
1778 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1779 // be doubly sure that we create *new* sequence objects.
1780 sequences = new SequenceI[newseq.length];
1781 for (int i = 0; i < newseq.length; i++)
1783 sequences[i] = new Sequence(newseq[i]);
1785 alignment = new Alignment(sequences);
1786 externalPaste = false;
1790 // parse the clipboard as an alignment.
1791 alignment = new FormatAdapter().readFile(str, "Paste", format);
1792 sequences = alignment.getSequencesArray();
1800 if (Desktop.jalviewClipboard != null)
1802 // dataset is inherited
1803 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1807 // new dataset is constructed
1808 alignment.setDataset(null);
1810 alwidth = alignment.getWidth() + 1;
1814 AlignmentI pastedal = alignment; // preserve pasted alignment object
1815 // Add pasted sequences and dataset into existing alignment.
1816 alignment = viewport.getAlignment();
1817 alwidth = alignment.getWidth() + 1;
1818 // decide if we need to import sequences from an existing dataset
1819 boolean importDs = Desktop.jalviewClipboard != null
1820 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1821 // importDs==true instructs us to copy over new dataset sequences from
1822 // an existing alignment
1823 Vector newDs = (importDs) ? new Vector() : null; // used to create
1824 // minimum dataset set
1826 for (int i = 0; i < sequences.length; i++)
1830 newDs.addElement(null);
1832 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1834 if (importDs && ds != null)
1836 if (!newDs.contains(ds))
1838 newDs.setElementAt(ds, i);
1839 ds = new Sequence(ds);
1840 // update with new dataset sequence
1841 sequences[i].setDatasetSequence(ds);
1845 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1850 // copy and derive new dataset sequence
1851 sequences[i] = sequences[i].deriveSequence();
1852 alignment.getDataset().addSequence(
1853 sequences[i].getDatasetSequence());
1854 // TODO: avoid creation of duplicate dataset sequences with a
1855 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1857 alignment.addSequence(sequences[i]); // merges dataset
1861 newDs.clear(); // tidy up
1863 if (pastedal.getAlignmentAnnotation() != null)
1865 // Add any annotation attached to alignment.
1866 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1867 for (int i = 0; i < alann.length; i++)
1869 annotationAdded = true;
1870 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1872 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1873 newann.padAnnotation(alwidth);
1874 alignment.addAnnotation(newann);
1884 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1885 sequences, 0, alignment.getWidth(), alignment));
1887 // Add any annotations attached to sequences
1888 for (int i = 0; i < sequences.length; i++)
1890 if (sequences[i].getAnnotation() != null)
1892 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1894 annotationAdded = true;
1895 sequences[i].getAnnotation()[a].adjustForAlignment();
1896 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1897 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1902 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1909 // propagate alignment changed.
1910 viewport.setEndSeq(alignment.getHeight());
1911 if (annotationAdded)
1913 // Duplicate sequence annotation in all views.
1914 AlignmentI[] alview = this.getViewAlignments();
1915 for (int i = 0; i < sequences.length; i++)
1917 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1920 for (int avnum = 0; avnum < alview.length; avnum++)
1922 if (alview[avnum] != alignment)
1924 // duplicate in a view other than the one with input focus
1925 int avwidth = alview[avnum].getWidth() + 1;
1926 // this relies on sann being preserved after we
1927 // modify the sequence's annotation array for each duplication
1928 for (int a = 0; a < sann.length; a++)
1930 AlignmentAnnotation newann = new AlignmentAnnotation(
1932 sequences[i].addAlignmentAnnotation(newann);
1933 newann.padAnnotation(avwidth);
1934 alview[avnum].addAnnotation(newann); // annotation was
1935 // duplicated earlier
1936 alview[avnum].setAnnotationIndex(newann, a);
1941 buildSortByAnnotationScoresMenu();
1943 viewport.firePropertyChange("alignment", null,
1944 alignment.getSequences());
1949 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1951 String newtitle = new String("Copied sequences");
1953 if (Desktop.jalviewClipboard != null
1954 && Desktop.jalviewClipboard[2] != null)
1956 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1957 for (int i = 0; i < hc.size(); i++)
1959 int[] region = (int[]) hc.elementAt(i);
1960 af.viewport.hideColumns(region[0], region[1]);
1964 // >>>This is a fix for the moment, until a better solution is
1966 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1968 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1970 // TODO: maintain provenance of an alignment, rather than just make the
1971 // title a concatenation of operations.
1974 if (title.startsWith("Copied sequences"))
1980 newtitle = newtitle.concat("- from " + title);
1985 newtitle = new String("Pasted sequences");
1988 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1993 } catch (Exception ex)
1995 ex.printStackTrace();
1996 System.out.println("Exception whilst pasting: " + ex);
1997 // could be anything being pasted in here
2008 protected void cut_actionPerformed(ActionEvent e)
2010 copy_actionPerformed(null);
2011 delete_actionPerformed(null);
2020 protected void delete_actionPerformed(ActionEvent evt)
2023 SequenceGroup sg = viewport.getSelectionGroup();
2029 Vector seqs = new Vector();
2031 for (int i = 0; i < sg.getSize(); i++)
2033 seq = sg.getSequenceAt(i);
2034 seqs.addElement(seq);
2037 // If the cut affects all sequences, remove highlighted columns
2038 if (sg.getSize() == viewport.getAlignment().getHeight())
2040 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2041 sg.getEndRes() + 1);
2044 SequenceI[] cut = new SequenceI[seqs.size()];
2045 for (int i = 0; i < seqs.size(); i++)
2047 cut[i] = (SequenceI) seqs.elementAt(i);
2051 * //ADD HISTORY ITEM
2053 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2054 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2055 viewport.getAlignment()));
2057 viewport.setSelectionGroup(null);
2058 viewport.sendSelection();
2059 viewport.getAlignment().deleteGroup(sg);
2061 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2063 if (viewport.getAlignment().getHeight() < 1)
2067 this.setClosed(true);
2068 } catch (Exception ex)
2080 protected void deleteGroups_actionPerformed(ActionEvent e)
2082 viewport.getAlignment().deleteAllGroups();
2083 viewport.sequenceColours = null;
2084 viewport.setSelectionGroup(null);
2085 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2086 alignPanel.updateAnnotation();
2087 alignPanel.paintAlignment(true);
2096 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2098 SequenceGroup sg = new SequenceGroup();
2100 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2102 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2105 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2106 viewport.setSelectionGroup(sg);
2107 viewport.sendSelection();
2108 alignPanel.paintAlignment(true);
2109 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2118 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2120 if (viewport.cursorMode)
2122 alignPanel.seqPanel.keyboardNo1 = null;
2123 alignPanel.seqPanel.keyboardNo2 = null;
2125 viewport.setSelectionGroup(null);
2126 viewport.getColumnSelection().clear();
2127 viewport.setSelectionGroup(null);
2128 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2129 alignPanel.idPanel.idCanvas.searchResults = null;
2130 alignPanel.paintAlignment(true);
2131 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2132 viewport.sendSelection();
2141 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2143 SequenceGroup sg = viewport.getSelectionGroup();
2147 selectAllSequenceMenuItem_actionPerformed(null);
2152 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2154 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2157 alignPanel.paintAlignment(true);
2158 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2159 viewport.sendSelection();
2162 public void invertColSel_actionPerformed(ActionEvent e)
2164 viewport.invertColumnSelection();
2165 alignPanel.paintAlignment(true);
2166 viewport.sendSelection();
2175 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2177 trimAlignment(true);
2186 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2188 trimAlignment(false);
2191 void trimAlignment(boolean trimLeft)
2193 ColumnSelection colSel = viewport.getColumnSelection();
2196 if (colSel.size() > 0)
2200 column = colSel.getMin();
2204 column = colSel.getMax();
2208 if (viewport.getSelectionGroup() != null)
2210 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2211 viewport.getHiddenRepSequences());
2215 seqs = viewport.getAlignment().getSequencesArray();
2218 TrimRegionCommand trimRegion;
2221 trimRegion = new TrimRegionCommand("Remove Left",
2222 TrimRegionCommand.TRIM_LEFT, seqs, column,
2223 viewport.getAlignment(), viewport.getColumnSelection(),
2224 viewport.getSelectionGroup());
2225 viewport.setStartRes(0);
2229 trimRegion = new TrimRegionCommand("Remove Right",
2230 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2231 viewport.getAlignment(), viewport.getColumnSelection(),
2232 viewport.getSelectionGroup());
2235 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2237 addHistoryItem(trimRegion);
2239 Vector groups = viewport.getAlignment().getGroups();
2241 for (int i = 0; i < groups.size(); i++)
2243 SequenceGroup sg = (SequenceGroup) groups.get(i);
2245 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2246 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2248 viewport.getAlignment().deleteGroup(sg);
2252 viewport.firePropertyChange("alignment", null, viewport
2253 .getAlignment().getSequences());
2263 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2265 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2268 if (viewport.getSelectionGroup() != null)
2270 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2271 viewport.getHiddenRepSequences());
2272 start = viewport.getSelectionGroup().getStartRes();
2273 end = viewport.getSelectionGroup().getEndRes();
2277 seqs = viewport.getAlignment().getSequencesArray();
2280 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2281 "Remove Gapped Columns", seqs, start, end,
2282 viewport.getAlignment());
2284 addHistoryItem(removeGapCols);
2286 statusBar.setText("Removed " + removeGapCols.getSize()
2287 + " empty columns.");
2289 // This is to maintain viewport position on first residue
2290 // of first sequence
2291 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2292 int startRes = seq.findPosition(viewport.startRes);
2293 // ShiftList shifts;
2294 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2295 // edit.alColumnChanges=shifts.getInverse();
2296 // if (viewport.hasHiddenColumns)
2297 // viewport.getColumnSelection().compensateForEdits(shifts);
2298 viewport.setStartRes(seq.findIndex(startRes) - 1);
2299 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2310 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2312 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2315 if (viewport.getSelectionGroup() != null)
2317 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2318 viewport.getHiddenRepSequences());
2319 start = viewport.getSelectionGroup().getStartRes();
2320 end = viewport.getSelectionGroup().getEndRes();
2324 seqs = viewport.getAlignment().getSequencesArray();
2327 // This is to maintain viewport position on first residue
2328 // of first sequence
2329 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2330 int startRes = seq.findPosition(viewport.startRes);
2332 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2333 viewport.getAlignment()));
2335 viewport.setStartRes(seq.findIndex(startRes) - 1);
2337 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2348 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2350 viewport.setPadGaps(padGapsMenuitem.isSelected());
2351 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2357 // if (justifySeqs>0)
2359 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2371 public void findMenuItem_actionPerformed(ActionEvent e)
2376 public void newView_actionPerformed(ActionEvent e)
2383 * @param copyAnnotation
2384 * if true then duplicate all annnotation, groups and settings
2385 * @return new alignment panel, already displayed.
2387 public AlignmentPanel newView(boolean copyAnnotation)
2389 return newView(null, copyAnnotation);
2395 * title of newly created view
2396 * @return new alignment panel, already displayed.
2398 public AlignmentPanel newView(String viewTitle)
2400 return newView(viewTitle, true);
2406 * title of newly created view
2407 * @param copyAnnotation
2408 * if true then duplicate all annnotation, groups and settings
2409 * @return new alignment panel, already displayed.
2411 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2413 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2415 if (!copyAnnotation)
2417 // just remove all the current annotation except for the automatic stuff
2418 newap.av.getAlignment().deleteAllGroups();
2419 for (AlignmentAnnotation alan : newap.av.getAlignment()
2420 .getAlignmentAnnotation())
2422 if (!alan.autoCalculated)
2424 newap.av.getAlignment().deleteAnnotation(alan);
2430 newap.av.gatherViewsHere = false;
2432 if (viewport.viewName == null)
2434 viewport.viewName = "Original";
2437 newap.av.historyList = viewport.historyList;
2438 newap.av.redoList = viewport.redoList;
2440 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2441 // make sure the new view has a unique name - this is essential for Jalview
2443 boolean addFirstIndex = false;
2444 if (viewTitle == null || viewTitle.trim().length() == 0)
2447 addFirstIndex = true;
2451 index = 1;// we count from 1 if given a specific name
2453 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2454 Vector comps = (Vector) PaintRefresher.components.get(viewport
2455 .getSequenceSetId());
2456 Vector existingNames = new Vector();
2457 for (int i = 0; i < comps.size(); i++)
2459 if (comps.elementAt(i) instanceof AlignmentPanel)
2461 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2462 if (!existingNames.contains(ap.av.viewName))
2464 existingNames.addElement(ap.av.viewName);
2469 while (existingNames.contains(newViewName))
2471 newViewName = viewTitle + " " + (++index);
2474 newap.av.viewName = newViewName;
2476 addAlignmentPanel(newap, true);
2478 if (alignPanels.size() == 2)
2480 viewport.gatherViewsHere = true;
2482 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2486 public void expandViews_actionPerformed(ActionEvent e)
2488 Desktop.instance.explodeViews(this);
2491 public void gatherViews_actionPerformed(ActionEvent e)
2493 Desktop.instance.gatherViews(this);
2502 public void font_actionPerformed(ActionEvent e)
2504 new FontChooser(alignPanel);
2513 protected void seqLimit_actionPerformed(ActionEvent e)
2515 viewport.setShowJVSuffix(seqLimits.isSelected());
2517 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2518 .calculateIdWidth());
2519 alignPanel.paintAlignment(true);
2522 public void idRightAlign_actionPerformed(ActionEvent e)
2524 viewport.rightAlignIds = idRightAlign.isSelected();
2525 alignPanel.paintAlignment(true);
2528 public void centreColumnLabels_actionPerformed(ActionEvent e)
2530 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2531 alignPanel.paintAlignment(true);
2537 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2539 protected void followHighlight_actionPerformed()
2541 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2543 alignPanel.scrollToPosition(
2544 alignPanel.seqPanel.seqCanvas.searchResults, false);
2554 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2556 viewport.setColourText(colourTextMenuItem.isSelected());
2557 alignPanel.paintAlignment(true);
2566 public void wrapMenuItem_actionPerformed(ActionEvent e)
2568 scaleAbove.setVisible(wrapMenuItem.isSelected());
2569 scaleLeft.setVisible(wrapMenuItem.isSelected());
2570 scaleRight.setVisible(wrapMenuItem.isSelected());
2571 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2572 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2575 public void showAllSeqs_actionPerformed(ActionEvent e)
2577 viewport.showAllHiddenSeqs();
2580 public void showAllColumns_actionPerformed(ActionEvent e)
2582 viewport.showAllHiddenColumns();
2586 public void hideSelSequences_actionPerformed(ActionEvent e)
2588 viewport.hideAllSelectedSeqs();
2589 alignPanel.paintAlignment(true);
2593 * called by key handler and the hide all/show all menu items
2598 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2601 boolean hide = false;
2602 SequenceGroup sg = viewport.getSelectionGroup();
2603 if (!toggleSeqs && !toggleCols)
2605 // Hide everything by the current selection - this is a hack - we do the
2606 // invert and then hide
2607 // first check that there will be visible columns after the invert.
2608 if ((viewport.getColumnSelection() != null
2609 && viewport.getColumnSelection().getSelected() != null && viewport
2610 .getColumnSelection().getSelected().size() > 0)
2611 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2614 // now invert the sequence set, if required - empty selection implies
2615 // that no hiding is required.
2618 invertSequenceMenuItem_actionPerformed(null);
2619 sg = viewport.getSelectionGroup();
2623 viewport.expandColSelection(sg, true);
2624 // finally invert the column selection and get the new sequence
2626 invertColSel_actionPerformed(null);
2633 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2635 hideSelSequences_actionPerformed(null);
2638 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2641 showAllSeqs_actionPerformed(null);
2647 if (viewport.getColumnSelection().getSelected().size() > 0)
2649 hideSelColumns_actionPerformed(null);
2652 viewport.setSelectionGroup(sg);
2657 showAllColumns_actionPerformed(null);
2666 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2667 * event.ActionEvent)
2669 public void hideAllButSelection_actionPerformed(ActionEvent e)
2671 toggleHiddenRegions(false, false);
2678 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2681 public void hideAllSelection_actionPerformed(ActionEvent e)
2683 SequenceGroup sg = viewport.getSelectionGroup();
2684 viewport.expandColSelection(sg, false);
2685 viewport.hideAllSelectedSeqs();
2686 viewport.hideSelectedColumns();
2687 alignPanel.paintAlignment(true);
2694 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2697 public void showAllhidden_actionPerformed(ActionEvent e)
2699 viewport.showAllHiddenColumns();
2700 viewport.showAllHiddenSeqs();
2701 alignPanel.paintAlignment(true);
2704 public void hideSelColumns_actionPerformed(ActionEvent e)
2706 viewport.hideSelectedColumns();
2707 alignPanel.paintAlignment(true);
2710 public void hiddenMarkers_actionPerformed(ActionEvent e)
2712 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2722 protected void scaleAbove_actionPerformed(ActionEvent e)
2724 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2725 alignPanel.paintAlignment(true);
2734 protected void scaleLeft_actionPerformed(ActionEvent e)
2736 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2737 alignPanel.paintAlignment(true);
2746 protected void scaleRight_actionPerformed(ActionEvent e)
2748 viewport.setScaleRightWrapped(scaleRight.isSelected());
2749 alignPanel.paintAlignment(true);
2758 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2760 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2761 alignPanel.paintAlignment(true);
2770 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2772 viewport.setShowText(viewTextMenuItem.isSelected());
2773 alignPanel.paintAlignment(true);
2782 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2784 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2785 alignPanel.paintAlignment(true);
2788 public FeatureSettings featureSettings;
2790 public void featureSettings_actionPerformed(ActionEvent e)
2792 if (featureSettings != null)
2794 featureSettings.close();
2795 featureSettings = null;
2797 if (!showSeqFeatures.isSelected())
2799 // make sure features are actually displayed
2800 showSeqFeatures.setSelected(true);
2801 showSeqFeatures_actionPerformed(null);
2803 featureSettings = new FeatureSettings(this);
2807 * Set or clear 'Show Sequence Features'
2812 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2814 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2815 alignPanel.paintAlignment(true);
2816 if (alignPanel.getOverviewPanel() != null)
2818 alignPanel.getOverviewPanel().updateOverviewImage();
2823 * Set or clear 'Show Sequence Features'
2828 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2830 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2832 if (viewport.getShowSequenceFeaturesHeight())
2834 // ensure we're actually displaying features
2835 viewport.setShowSequenceFeatures(true);
2836 showSeqFeatures.setSelected(true);
2838 alignPanel.paintAlignment(true);
2839 if (alignPanel.getOverviewPanel() != null)
2841 alignPanel.getOverviewPanel().updateOverviewImage();
2851 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2853 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2854 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2857 public void alignmentProperties()
2859 JEditorPane editPane = new JEditorPane("text/html", "");
2860 editPane.setEditable(false);
2861 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2863 editPane.setText("<html>" + contents.toString() + "</html>");
2864 JInternalFrame frame = new JInternalFrame();
2865 frame.getContentPane().add(new JScrollPane(editPane));
2867 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2868 + getTitle(), 500, 400);
2877 public void overviewMenuItem_actionPerformed(ActionEvent e)
2879 if (alignPanel.overviewPanel != null)
2884 JInternalFrame frame = new JInternalFrame();
2885 OverviewPanel overview = new OverviewPanel(alignPanel);
2886 frame.setContentPane(overview);
2887 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2888 frame.getWidth(), frame.getHeight());
2890 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2891 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2893 public void internalFrameClosed(
2894 javax.swing.event.InternalFrameEvent evt)
2896 alignPanel.setOverviewPanel(null);
2900 alignPanel.setOverviewPanel(overview);
2903 public void textColour_actionPerformed(ActionEvent e)
2905 new TextColourChooser().chooseColour(alignPanel, null);
2914 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2925 public void clustalColour_actionPerformed(ActionEvent e)
2927 changeColour(new ClustalxColourScheme(viewport.getAlignment()
2928 .getSequences(), viewport.getAlignment().getWidth()));
2937 public void zappoColour_actionPerformed(ActionEvent e)
2939 changeColour(new ZappoColourScheme());
2948 public void taylorColour_actionPerformed(ActionEvent e)
2950 changeColour(new TaylorColourScheme());
2959 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2961 changeColour(new HydrophobicColourScheme());
2970 public void helixColour_actionPerformed(ActionEvent e)
2972 changeColour(new HelixColourScheme());
2981 public void strandColour_actionPerformed(ActionEvent e)
2983 changeColour(new StrandColourScheme());
2992 public void turnColour_actionPerformed(ActionEvent e)
2994 changeColour(new TurnColourScheme());
3003 public void buriedColour_actionPerformed(ActionEvent e)
3005 changeColour(new BuriedColourScheme());
3014 public void nucleotideColour_actionPerformed(ActionEvent e)
3016 changeColour(new NucleotideColourScheme());
3019 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3021 changeColour(new PurinePyrimidineColourScheme());
3025 * public void covariationColour_actionPerformed(ActionEvent e) {
3027 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3030 public void annotationColour_actionPerformed(ActionEvent e)
3032 new AnnotationColourChooser(viewport, alignPanel);
3035 public void rnahelicesColour_actionPerformed(ActionEvent e)
3037 new RNAHelicesColourChooser(viewport, alignPanel);
3046 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3048 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3057 public void changeColour(ColourSchemeI cs)
3059 // TODO: compare with applet and pull up to model method
3064 if (viewport.getAbovePIDThreshold())
3066 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3069 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3071 viewport.setGlobalColourScheme(cs);
3075 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3078 if (viewport.getConservationSelected())
3081 Alignment al = (Alignment) viewport.getAlignment();
3082 Conservation c = new Conservation("All",
3083 ResidueProperties.propHash, 3, al.getSequences(), 0,
3087 c.verdict(false, viewport.getConsPercGaps());
3089 cs.setConservation(c);
3091 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3096 cs.setConservation(null);
3099 cs.setConsensus(viewport.getSequenceConsensusHash());
3102 viewport.setGlobalColourScheme(cs);
3104 if (viewport.getColourAppliesToAllGroups())
3106 Vector groups = viewport.getAlignment().getGroups();
3108 for (int i = 0; i < groups.size(); i++)
3110 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3118 if (cs instanceof ClustalxColourScheme)
3120 sg.cs = new ClustalxColourScheme(sg.getSequences(viewport
3121 .getHiddenRepSequences()), sg.getWidth());
3123 else if (cs instanceof UserColourScheme)
3125 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3131 sg.cs = cs.getClass().newInstance();
3132 } catch (Exception ex)
3137 if (viewport.getAbovePIDThreshold()
3138 || cs instanceof PIDColourScheme
3139 || cs instanceof Blosum62ColourScheme)
3141 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3143 sg.cs.setConsensus(AAFrequency.calculate(
3144 sg.getSequences(viewport.getHiddenRepSequences()),
3145 sg.getStartRes(), sg.getEndRes() + 1));
3149 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3152 if (viewport.getConservationSelected())
3154 Conservation c = new Conservation("Group",
3155 ResidueProperties.propHash, 3, sg.getSequences(viewport
3156 .getHiddenRepSequences()), sg.getStartRes(),
3157 sg.getEndRes() + 1);
3159 c.verdict(false, viewport.getConsPercGaps());
3160 sg.cs.setConservation(c);
3164 sg.cs.setConservation(null);
3169 if (alignPanel.getOverviewPanel() != null)
3171 alignPanel.getOverviewPanel().updateOverviewImage();
3174 alignPanel.paintAlignment(true);
3183 protected void modifyPID_actionPerformed(ActionEvent e)
3185 if (viewport.getAbovePIDThreshold()
3186 && viewport.getGlobalColourScheme() != null)
3188 SliderPanel.setPIDSliderSource(alignPanel,
3189 viewport.getGlobalColourScheme(), "Background");
3190 SliderPanel.showPIDSlider();
3200 protected void modifyConservation_actionPerformed(ActionEvent e)
3202 if (viewport.getConservationSelected()
3203 && viewport.getGlobalColourScheme() != null)
3205 SliderPanel.setConservationSlider(alignPanel,
3206 viewport.getGlobalColourScheme(), "Background");
3207 SliderPanel.showConservationSlider();
3217 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3219 viewport.setConservationSelected(conservationMenuItem.isSelected());
3221 viewport.setAbovePIDThreshold(false);
3222 abovePIDThreshold.setSelected(false);
3224 changeColour(viewport.getGlobalColourScheme());
3226 modifyConservation_actionPerformed(null);
3235 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3237 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3239 conservationMenuItem.setSelected(false);
3240 viewport.setConservationSelected(false);
3242 changeColour(viewport.getGlobalColourScheme());
3244 modifyPID_actionPerformed(null);
3253 public void userDefinedColour_actionPerformed(ActionEvent e)
3255 if (e.getActionCommand().equals("User Defined..."))
3257 new UserDefinedColours(alignPanel, null);
3261 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3262 .getUserColourSchemes().get(e.getActionCommand());
3268 public void updateUserColourMenu()
3271 Component[] menuItems = colourMenu.getMenuComponents();
3272 int i, iSize = menuItems.length;
3273 for (i = 0; i < iSize; i++)
3275 if (menuItems[i].getName() != null
3276 && menuItems[i].getName().equals("USER_DEFINED"))
3278 colourMenu.remove(menuItems[i]);
3282 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3284 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3285 .getUserColourSchemes().keys();
3287 while (userColours.hasMoreElements())
3289 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3290 userColours.nextElement().toString());
3291 radioItem.setName("USER_DEFINED");
3292 radioItem.addMouseListener(new MouseAdapter()
3294 public void mousePressed(MouseEvent evt)
3296 if (evt.isControlDown()
3297 || SwingUtilities.isRightMouseButton(evt))
3299 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3301 int option = JOptionPane.showInternalConfirmDialog(
3302 jalview.gui.Desktop.desktop,
3303 "Remove from default list?",
3304 "Remove user defined colour",
3305 JOptionPane.YES_NO_OPTION);
3306 if (option == JOptionPane.YES_OPTION)
3308 jalview.gui.UserDefinedColours
3309 .removeColourFromDefaults(radioItem.getText());
3310 colourMenu.remove(radioItem);
3314 radioItem.addActionListener(new ActionListener()
3316 public void actionPerformed(ActionEvent evt)
3318 userDefinedColour_actionPerformed(evt);
3325 radioItem.addActionListener(new ActionListener()
3327 public void actionPerformed(ActionEvent evt)
3329 userDefinedColour_actionPerformed(evt);
3333 colourMenu.insert(radioItem, 15);
3334 colours.add(radioItem);
3345 public void PIDColour_actionPerformed(ActionEvent e)
3347 changeColour(new PIDColourScheme());
3356 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3358 changeColour(new Blosum62ColourScheme());
3367 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3369 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3370 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3371 .getAlignment().getSequenceAt(0), null);
3372 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3373 viewport.getAlignment()));
3374 alignPanel.paintAlignment(true);
3383 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3385 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3386 AlignmentSorter.sortByID(viewport.getAlignment());
3387 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3388 viewport.getAlignment()));
3389 alignPanel.paintAlignment(true);
3398 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3400 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3401 AlignmentSorter.sortByLength(viewport.getAlignment());
3402 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3403 viewport.getAlignment()));
3404 alignPanel.paintAlignment(true);
3413 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3415 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3416 AlignmentSorter.sortByGroup(viewport.getAlignment());
3417 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3418 viewport.getAlignment()));
3420 alignPanel.paintAlignment(true);
3429 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3431 new RedundancyPanel(alignPanel, this);
3440 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3442 if ((viewport.getSelectionGroup() == null)
3443 || (viewport.getSelectionGroup().getSize() < 2))
3445 JOptionPane.showInternalMessageDialog(this,
3446 "You must select at least 2 sequences.", "Invalid Selection",
3447 JOptionPane.WARNING_MESSAGE);
3451 JInternalFrame frame = new JInternalFrame();
3452 frame.setContentPane(new PairwiseAlignPanel(viewport));
3453 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3463 public void PCAMenuItem_actionPerformed(ActionEvent e)
3465 if (((viewport.getSelectionGroup() != null)
3466 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3467 .getSelectionGroup().getSize() > 0))
3468 || (viewport.getAlignment().getHeight() < 4))
3470 JOptionPane.showInternalMessageDialog(this,
3471 "Principal component analysis must take\n"
3472 + "at least 4 input sequences.",
3473 "Sequence selection insufficient",
3474 JOptionPane.WARNING_MESSAGE);
3479 new PCAPanel(alignPanel);
3482 public void autoCalculate_actionPerformed(ActionEvent e)
3484 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3485 if (viewport.autoCalculateConsensus)
3487 viewport.firePropertyChange("alignment", null, viewport
3488 .getAlignment().getSequences());
3492 public void sortByTreeOption_actionPerformed(ActionEvent e)
3494 viewport.sortByTree = sortByTree.isSelected();
3498 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3500 viewport.followSelection = listenToViewSelections.isSelected();
3509 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3511 NewTreePanel("AV", "PID", "Average distance tree using PID");
3520 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3522 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3531 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3533 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3542 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3544 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3557 void NewTreePanel(String type, String pwType, String title)
3561 if (viewport.getSelectionGroup() != null)
3563 if (viewport.getSelectionGroup().getSize() < 3)
3568 "You need to have more than two sequences selected to build a tree!",
3569 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3574 SequenceGroup sg = viewport.getSelectionGroup();
3576 /* Decide if the selection is a column region */
3577 while (s < sg.getSize())
3579 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3585 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3586 + "Try using the Pad function in the edit menu,\n"
3587 + "or one of the multiple sequence alignment web services.",
3588 "Sequences in selection are not aligned",
3589 JOptionPane.WARNING_MESSAGE);
3595 title = title + " on region";
3596 tp = new TreePanel(alignPanel, type, pwType);
3600 // are the visible sequences aligned?
3601 if (!viewport.getAlignment().isAligned(false))
3606 "The sequences must be aligned before creating a tree.\n"
3607 + "Try using the Pad function in the edit menu,\n"
3608 + "or one of the multiple sequence alignment web services.",
3609 "Sequences not aligned",
3610 JOptionPane.WARNING_MESSAGE);
3615 if (viewport.getAlignment().getHeight() < 2)
3620 tp = new TreePanel(alignPanel, type, pwType);
3625 if (viewport.viewName != null)
3627 title += viewport.viewName + " of ";
3630 title += this.title;
3632 Desktop.addInternalFrame(tp, title, 600, 500);
3643 public void addSortByOrderMenuItem(String title,
3644 final AlignmentOrder order)
3646 final JMenuItem item = new JMenuItem("by " + title);
3648 item.addActionListener(new java.awt.event.ActionListener()
3650 public void actionPerformed(ActionEvent e)
3652 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3654 // TODO: JBPNote - have to map order entries to curent SequenceI
3656 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3658 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3661 alignPanel.paintAlignment(true);
3667 * Add a new sort by annotation score menu item
3670 * the menu to add the option to
3672 * the label used to retrieve scores for each sequence on the
3675 public void addSortByAnnotScoreMenuItem(JMenu sort,
3676 final String scoreLabel)
3678 final JMenuItem item = new JMenuItem(scoreLabel);
3680 item.addActionListener(new java.awt.event.ActionListener()
3682 public void actionPerformed(ActionEvent e)
3684 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3685 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3686 viewport.getAlignment());// ,viewport.getSelectionGroup());
3687 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3688 viewport.getAlignment()));
3689 alignPanel.paintAlignment(true);
3695 * last hash for alignment's annotation array - used to minimise cost of
3698 protected int _annotationScoreVectorHash;
3701 * search the alignment and rebuild the sort by annotation score submenu the
3702 * last alignment annotation vector hash is stored to minimize cost of
3703 * rebuilding in subsequence calls.
3706 public void buildSortByAnnotationScoresMenu()
3708 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3713 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3715 sortByAnnotScore.removeAll();
3716 // almost certainly a quicker way to do this - but we keep it simple
3717 Hashtable scoreSorts = new Hashtable();
3718 AlignmentAnnotation aann[];
3719 Enumeration sq = viewport.getAlignment().getSequences().elements();
3720 while (sq.hasMoreElements())
3722 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3723 for (int i = 0; aann != null && i < aann.length; i++)
3725 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3727 scoreSorts.put(aann[i].label, aann[i].label);
3731 Enumeration labels = scoreSorts.keys();
3732 while (labels.hasMoreElements())
3734 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3735 (String) labels.nextElement());
3737 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3740 _annotationScoreVectorHash = viewport.getAlignment()
3741 .getAlignmentAnnotation().hashCode();
3746 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3747 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3748 * call. Listeners are added to remove the menu item when the treePanel is
3749 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3753 * Displayed tree window.
3755 * SortBy menu item title.
3757 public void buildTreeMenu()
3759 sortByTreeMenu.removeAll();
3761 Vector comps = (Vector) PaintRefresher.components.get(viewport
3762 .getSequenceSetId());
3763 Vector treePanels = new Vector();
3764 int i, iSize = comps.size();
3765 for (i = 0; i < iSize; i++)
3767 if (comps.elementAt(i) instanceof TreePanel)
3769 treePanels.add(comps.elementAt(i));
3773 iSize = treePanels.size();
3777 sortByTreeMenu.setVisible(false);
3781 sortByTreeMenu.setVisible(true);
3783 for (i = 0; i < treePanels.size(); i++)
3785 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3786 final JMenuItem item = new JMenuItem(tp.getTitle());
3787 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3788 item.addActionListener(new java.awt.event.ActionListener()
3790 public void actionPerformed(ActionEvent e)
3792 tp.sortByTree_actionPerformed(null);
3793 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3798 sortByTreeMenu.add(item);
3802 public boolean sortBy(AlignmentOrder alorder, String undoname)
3804 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3805 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3806 if (undoname != null)
3808 addHistoryItem(new OrderCommand(undoname, oldOrder,
3809 viewport.getAlignment()));
3811 alignPanel.paintAlignment(true);
3816 * Work out whether the whole set of sequences or just the selected set will
3817 * be submitted for multiple alignment.
3820 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3822 // Now, check we have enough sequences
3823 AlignmentView msa = null;
3825 if ((viewport.getSelectionGroup() != null)
3826 && (viewport.getSelectionGroup().getSize() > 1))
3828 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3829 // some common interface!
3831 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3832 * SequenceI[sz = seqs.getSize(false)];
3834 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3835 * seqs.getSequenceAt(i); }
3837 msa = viewport.getAlignmentView(true);
3842 * Vector seqs = viewport.getAlignment().getSequences();
3844 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3846 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3847 * seqs.elementAt(i); } }
3849 msa = viewport.getAlignmentView(false);
3855 * Decides what is submitted to a secondary structure prediction service: the
3856 * first sequence in the alignment, or in the current selection, or, if the
3857 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3858 * region or the whole alignment. (where the first sequence in the set is the
3859 * one that the prediction will be for).
3861 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3863 AlignmentView seqs = null;
3865 if ((viewport.getSelectionGroup() != null)
3866 && (viewport.getSelectionGroup().getSize() > 0))
3868 seqs = viewport.getAlignmentView(true);
3872 seqs = viewport.getAlignmentView(false);
3874 // limit sequences - JBPNote in future - could spawn multiple prediction
3876 // TODO: viewport.getAlignment().isAligned is a global state - the local
3877 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3878 if (!viewport.getAlignment().isAligned(false))
3880 seqs.setSequences(new SeqCigar[]
3881 { seqs.getSequences()[0] });
3882 // TODO: if seqs.getSequences().length>1 then should really have warned
3895 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3897 // Pick the tree file
3898 JalviewFileChooser chooser = new JalviewFileChooser(
3899 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3900 chooser.setFileView(new JalviewFileView());
3901 chooser.setDialogTitle("Select a newick-like tree file");
3902 chooser.setToolTipText("Load a tree file");
3904 int value = chooser.showOpenDialog(null);
3906 if (value == JalviewFileChooser.APPROVE_OPTION)
3908 String choice = chooser.getSelectedFile().getPath();
3909 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3910 jalview.io.NewickFile fin = null;
3913 fin = new jalview.io.NewickFile(choice, "File");
3914 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3915 } catch (Exception ex)
3917 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3918 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3919 ex.printStackTrace();
3921 if (fin != null && fin.hasWarningMessage())
3923 JOptionPane.showMessageDialog(Desktop.desktop,
3924 fin.getWarningMessage(), "Possible problem with tree file",
3925 JOptionPane.WARNING_MESSAGE);
3931 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
3933 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
3936 public TreePanel ShowNewickTree(NewickFile nf, String title)
3938 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3941 public TreePanel ShowNewickTree(NewickFile nf, String title,
3942 AlignmentView input)
3944 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3947 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3948 int h, int x, int y)
3950 return ShowNewickTree(nf, title, null, w, h, x, y);
3954 * Add a treeviewer for the tree extracted from a newick file object to the
3955 * current alignment view
3962 * Associated alignment input data (or null)
3971 * @return TreePanel handle
3973 public TreePanel ShowNewickTree(NewickFile nf, String title,
3974 AlignmentView input, int w, int h, int x, int y)
3976 TreePanel tp = null;
3982 if (nf.getTree() != null)
3984 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3990 tp.setLocation(x, y);
3993 Desktop.addInternalFrame(tp, title, w, h);
3995 } catch (Exception ex)
3997 ex.printStackTrace();
4003 private boolean buildingMenu = false;
4006 * Generates menu items and listener event actions for web service clients
4009 public void BuildWebServiceMenu()
4011 while (buildingMenu)
4015 System.err.println("Waiting for building menu to finish.");
4017 } catch (Exception e)
4022 final AlignFrame me = this;
4023 buildingMenu = true;
4024 new Thread(new Runnable()
4030 System.err.println("Building ws menu again "
4031 + Thread.currentThread());
4032 // TODO: add support for context dependent disabling of services based
4034 // alignment and current selection
4035 // TODO: add additional serviceHandle parameter to specify abstract
4037 // class independently of AbstractName
4038 // TODO: add in rediscovery GUI function to restart discoverer
4039 // TODO: group services by location as well as function and/or
4041 // object broker mechanism.
4042 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4043 final IProgressIndicator af = me;
4044 final JMenu msawsmenu = new JMenu("Alignment");
4045 final JMenu secstrmenu = new JMenu(
4046 "Secondary Structure Prediction");
4047 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4048 final JMenu analymenu = new JMenu("Analysis");
4049 final JMenu dismenu = new JMenu("Disorder");
4050 // JAL-940 - only show secondary structure prediction services from
4051 // the legacy server
4052 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4054 Discoverer.services != null && (Discoverer.services.size() > 0))
4056 // TODO: refactor to allow list of AbstractName/Handler bindings to
4058 // stored or retrieved from elsewhere
4059 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4060 Vector secstrpr = (Vector) Discoverer.services
4062 Vector seqsrch = null; // (Vector)
4063 // Discoverer.services.get("SeqSearch");
4064 // TODO: move GUI generation code onto service implementation - so a
4065 // client instance attaches itself to the GUI with method call like
4066 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4070 // Add any Multiple Sequence Alignment Services
4071 for (int i = 0, j = msaws.size(); i < j; i++)
4073 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4075 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4076 .getServiceClient(sh);
4077 impl.attachWSMenuEntry(msawsmenu, me);
4081 if (secstrpr != null)
4083 // Add any secondary structure prediction services
4084 for (int i = 0, j = secstrpr.size(); i < j; i++)
4086 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4088 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4089 .getServiceClient(sh);
4090 impl.attachWSMenuEntry(secstrmenu, me);
4093 if (seqsrch != null)
4095 // Add any sequence search services
4096 for (int i = 0, j = seqsrch.size(); i < j; i++)
4098 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4100 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4101 .getServiceClient(sh);
4102 impl.attachWSMenuEntry(seqsrchmenu, me);
4107 // Add all submenus in the order they should appear on the web
4109 wsmenu.add(msawsmenu);
4110 wsmenu.add(secstrmenu);
4111 wsmenu.add(dismenu);
4112 wsmenu.add(analymenu);
4113 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4114 // submens.add(msawsmenu);
4115 // submens.add(secstrmenu);
4116 // submens.add(dismenu);
4117 // submens.add(analymenu);
4119 // No search services yet
4120 // wsmenu.add(seqsrchmenu);
4122 javax.swing.SwingUtilities.invokeLater(new Runnable()
4128 webService.removeAll();
4129 // first, add discovered services onto the webservices menu
4130 if (wsmenu.size() > 0)
4132 for (int i = 0, j = wsmenu.size(); i < j; i++)
4134 webService.add((JMenu) wsmenu.get(i));
4139 webService.add(me.webServiceNoServices);
4141 // TODO: move into separate menu builder class.
4142 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4144 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4145 if (jws2servs != null)
4147 if (jws2servs.hasServices())
4149 jws2servs.attachWSMenuEntry(webService, me);
4151 if (jws2servs.isRunning())
4153 JMenuItem tm = new JMenuItem(
4154 "Still discovering JABA Services");
4155 tm.setEnabled(false);
4161 build_urlServiceMenu(me.webService);
4162 build_fetchdbmenu(webService);
4163 for (JMenu item : wsmenu)
4165 if (item.getItemCount() == 0)
4167 item.setEnabled(false);
4171 item.setEnabled(true);
4174 } catch (Exception e)
4180 } catch (Exception e)
4185 buildingMenu = false;
4192 * construct any groupURL type service menu entries.
4196 private void build_urlServiceMenu(JMenu webService)
4198 // TODO: remove this code when 2.7 is released
4199 // DEBUG - alignmentView
4201 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4202 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4204 * @Override public void actionPerformed(ActionEvent e) {
4205 * jalview.datamodel.AlignmentView
4206 * .testSelectionViews(af.viewport.getAlignment(),
4207 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4209 * }); webService.add(testAlView);
4211 // TODO: refactor to RestClient discoverer and merge menu entries for
4212 // rest-style services with other types of analysis/calculation service
4213 // SHmmr test client - still being implemented.
4214 // DEBUG - alignmentView
4216 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4219 client.attachWSMenuEntry(
4220 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4224 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4226 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4232 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4233 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4234 * getProperty("LAST_DIRECTORY"));
4236 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4237 * to Vamsas file"); chooser.setToolTipText("Export");
4239 * int value = chooser.showSaveDialog(this);
4241 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4242 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4243 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4244 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4247 * prototype of an automatically enabled/disabled analysis function
4250 protected void setShowProductsEnabled()
4252 SequenceI[] selection = viewport.getSequenceSelection();
4253 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4254 viewport.getAlignment().getDataset()))
4256 showProducts.setEnabled(true);
4261 showProducts.setEnabled(false);
4266 * search selection for sequence xRef products and build the show products
4271 * @return true if showProducts menu should be enabled.
4273 public boolean canShowProducts(SequenceI[] selection,
4274 boolean isRegionSelection, Alignment dataset)
4276 boolean showp = false;
4279 showProducts.removeAll();
4280 final boolean dna = viewport.getAlignment().isNucleotide();
4281 final Alignment ds = dataset;
4282 String[] ptypes = (selection == null || selection.length == 0) ? null
4283 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4285 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4286 // selection, dataset, true);
4287 final SequenceI[] sel = selection;
4288 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4291 final boolean isRegSel = isRegionSelection;
4292 final AlignFrame af = this;
4293 final String source = ptypes[t];
4294 JMenuItem xtype = new JMenuItem(ptypes[t]);
4295 xtype.addActionListener(new ActionListener()
4298 public void actionPerformed(ActionEvent e)
4300 // TODO: new thread for this call with vis-delay
4301 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4302 isRegSel, dna, source);
4306 showProducts.add(xtype);
4308 showProducts.setVisible(showp);
4309 showProducts.setEnabled(showp);
4310 } catch (Exception e)
4312 jalview.bin.Cache.log
4313 .warn("canTranslate threw an exception - please report to help@jalview.org",
4320 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4321 boolean isRegSel, boolean dna, String source)
4323 final boolean fisRegSel = isRegSel;
4324 final boolean fdna = dna;
4325 final String fsrc = source;
4326 final AlignFrame ths = this;
4327 final SequenceI[] fsel = sel;
4328 Runnable foo = new Runnable()
4333 final long sttime = System.currentTimeMillis();
4334 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4337 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4341 Alignment prods = CrossRef
4342 .findXrefSequences(fsel, fdna, fsrc, ds);
4345 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4346 for (int s = 0; s < sprods.length; s++)
4348 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4349 if (ds.getSequences() == null
4350 || !ds.getSequences().contains(
4351 sprods[s].getDatasetSequence()))
4352 ds.addSequence(sprods[s].getDatasetSequence());
4353 sprods[s].updatePDBIds();
4355 Alignment al = new Alignment(sprods);
4356 AlignedCodonFrame[] cf = prods.getCodonFrames();
4358 for (int s = 0; cf != null && s < cf.length; s++)
4360 al.addCodonFrame(cf[s]);
4363 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4365 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4366 + " for " + ((fisRegSel) ? "selected region of " : "")
4368 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4373 System.err.println("No Sequences generated for xRef type "
4376 } catch (Exception e)
4378 jalview.bin.Cache.log.error(
4379 "Exception when finding crossreferences", e);
4380 } catch (OutOfMemoryError e)
4382 new OOMWarning("whilst fetching crossreferences", e);
4385 jalview.bin.Cache.log.error("Error when finding crossreferences",
4388 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4393 Thread frunner = new Thread(foo);
4397 public boolean canShowTranslationProducts(SequenceI[] selection,
4398 AlignmentI alignment)
4403 return (jalview.analysis.Dna.canTranslate(selection,
4404 viewport.getViewAsVisibleContigs(true)));
4405 } catch (Exception e)
4407 jalview.bin.Cache.log
4408 .warn("canTranslate threw an exception - please report to help@jalview.org",
4414 public void showProducts_actionPerformed(ActionEvent e)
4416 // /////////////////////////////
4417 // Collect Data to be translated/transferred
4419 SequenceI[] selection = viewport.getSequenceSelection();
4420 AlignmentI al = null;
4423 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4424 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4425 viewport.getAlignment().getDataset());
4426 } catch (Exception ex)
4429 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4436 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4437 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4441 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4442 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4443 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4447 public void showTranslation_actionPerformed(ActionEvent e)
4449 // /////////////////////////////
4450 // Collect Data to be translated/transferred
4452 SequenceI[] selection = viewport.getSequenceSelection();
4453 String[] seqstring = viewport.getViewAsString(true);
4454 AlignmentI al = null;
4457 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4458 viewport.getViewAsVisibleContigs(true), viewport
4459 .getGapCharacter(), viewport.getAlignment()
4460 .getAlignmentAnnotation(), viewport.getAlignment()
4461 .getWidth(), viewport.getAlignment().getDataset());
4462 } catch (Exception ex)
4465 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4472 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4473 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4477 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4478 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4479 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4484 * Try to load a features file onto the alignment.
4487 * contents or path to retrieve file
4489 * access mode of file (see jalview.io.AlignFile)
4490 * @return true if features file was parsed corectly.
4492 public boolean parseFeaturesFile(String file, String type)
4494 boolean featuresFile = false;
4497 featuresFile = new FeaturesFile(file, type).parse(viewport
4498 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4499 .getFeatureRenderer().featureColours, false,
4500 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4501 } catch (Exception ex)
4503 ex.printStackTrace();
4508 viewport.showSequenceFeatures = true;
4509 showSeqFeatures.setSelected(true);
4510 if (alignPanel.seqPanel.seqCanvas.fr != null)
4512 // update the min/max ranges where necessary
4513 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4515 if (featureSettings != null)
4517 featureSettings.setTableData();
4519 alignPanel.paintAlignment(true);
4522 return featuresFile;
4525 public void dragEnter(DropTargetDragEvent evt)
4529 public void dragExit(DropTargetEvent evt)
4533 public void dragOver(DropTargetDragEvent evt)
4537 public void dropActionChanged(DropTargetDragEvent evt)
4541 public void drop(DropTargetDropEvent evt)
4543 Transferable t = evt.getTransferable();
4544 java.util.List files = null;
4548 DataFlavor uriListFlavor = new DataFlavor(
4549 "text/uri-list;class=java.lang.String");
4550 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4552 // Works on Windows and MacOSX
4553 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4554 files = (java.util.List) t
4555 .getTransferData(DataFlavor.javaFileListFlavor);
4557 else if (t.isDataFlavorSupported(uriListFlavor))
4559 // This is used by Unix drag system
4560 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4561 String data = (String) t.getTransferData(uriListFlavor);
4562 files = new java.util.ArrayList(1);
4563 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4564 data, "\r\n"); st.hasMoreTokens();)
4566 String s = st.nextToken();
4567 if (s.startsWith("#"))
4569 // the line is a comment (as per the RFC 2483)
4573 java.net.URI uri = new java.net.URI(s);
4574 // check to see if we can handle this kind of URI
4575 if (uri.getScheme().toLowerCase().startsWith("http"))
4577 files.add(uri.toString());
4581 // otherwise preserve old behaviour: catch all for file objects
4582 java.io.File file = new java.io.File(uri);
4583 files.add(file.toString());
4587 } catch (Exception e)
4589 e.printStackTrace();
4595 // check to see if any of these files have names matching sequences in
4597 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4598 .getAlignment().getSequencesArray());
4600 * Object[] { String,SequenceI}
4602 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4603 ArrayList<String> filesnotmatched = new ArrayList<String>();
4604 for (int i = 0; i < files.size(); i++)
4606 String file = files.get(i).toString();
4608 String protocol = FormatAdapter.checkProtocol(file);
4609 if (protocol == jalview.io.FormatAdapter.FILE)
4611 File fl = new File(file);
4612 pdbfn = fl.getName();
4614 else if (protocol == jalview.io.FormatAdapter.URL)
4616 URL url = new URL(file);
4617 pdbfn = url.getFile();
4619 if (pdbfn.length() > 0)
4621 // attempt to find a match in the alignment
4622 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4623 int l = 0, c = pdbfn.indexOf(".");
4624 while (mtch == null && c != -1)
4629 } while ((c = pdbfn.indexOf(".", l)) > l);
4632 pdbfn = pdbfn.substring(0, l);
4634 mtch = idm.findAllIdMatches(pdbfn);
4641 type = new IdentifyFile().Identify(file, protocol);
4642 } catch (Exception ex)
4648 if (type.equalsIgnoreCase("PDB"))
4650 filesmatched.add(new Object[]
4651 { file, protocol, mtch });
4656 // File wasn't named like one of the sequences or wasn't a PDB file.
4657 filesnotmatched.add(file);
4661 if (filesmatched.size() > 0)
4663 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4667 "Do you want to automatically associate the "
4668 + filesmatched.size()
4669 + " PDB files with sequences in the alignment that have the same name ?",
4670 "Automatically Associate PDB files by name",
4671 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4674 for (Object[] fm : filesmatched)
4676 // try and associate
4677 // TODO: may want to set a standard ID naming formalism for
4678 // associating PDB files which have no IDs.
4679 for (SequenceI toassoc : (SequenceI[]) fm[2])
4681 PDBEntry pe = new AssociatePdbFileWithSeq()
4682 .associatePdbWithSeq((String) fm[0],
4683 (String) fm[1], toassoc, false);
4686 System.err.println("Associated file : "
4687 + ((String) fm[0]) + " with "
4688 + toassoc.getDisplayId(true));
4692 alignPanel.paintAlignment(true);
4696 if (filesnotmatched.size() > 0)
4699 && (Cache.getDefault(
4700 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4703 "<html>Do you want to <em>ignore</em> the "
4704 + filesnotmatched.size()
4705 + " files whose names did not match any sequence IDs ?</html>",
4706 "Ignore unmatched dropped files ?",
4707 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4711 for (String fn : filesnotmatched)
4713 loadJalviewDataFile(fn, null, null, null);
4717 } catch (Exception ex)
4719 ex.printStackTrace();
4725 * Attempt to load a "dropped" file or URL string: First by testing whether
4726 * it's and Annotation file, then a JNet file, and finally a features file. If
4727 * all are false then the user may have dropped an alignment file onto this
4731 * either a filename or a URL string.
4733 public void loadJalviewDataFile(String file, String protocol,
4734 String format, SequenceI assocSeq)
4738 if (protocol == null)
4740 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4742 // if the file isn't identified, or not positively identified as some
4743 // other filetype (PFAM is default unidentified alignment file type) then
4744 // try to parse as annotation.
4745 boolean isAnnotation = (format == null || format
4746 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4747 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4752 // first see if its a T-COFFEE score file
4753 TCoffeeScoreFile tcf = null;
4756 tcf = new TCoffeeScoreFile(file, protocol);
4759 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4761 tcoffeeColour.setEnabled(true);
4762 tcoffeeColour.setSelected(true);
4763 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4764 isAnnotation = true;
4766 .setText("Successfully pasted T-Coffee scores to alignment.");
4770 // some problem - if no warning its probable that the ID matching process didn't work
4771 JOptionPane.showMessageDialog(Desktop.desktop,
4772 tcf.getWarningMessage()==null ? "Check that the file matches sequence IDs in the alignment." : tcf.getWarningMessage(),
4773 "Problem reading T-COFFEE score file",
4774 JOptionPane.WARNING_MESSAGE);
4781 } catch (Exception x)
4783 Cache.log.debug("Exception when processing data source as T-COFFEE score file",x);
4788 // try to see if its a JNet 'concise' style annotation file *before*
4790 // try to parse it as a features file
4793 format = new IdentifyFile().Identify(file, protocol);
4795 if (format.equalsIgnoreCase("JnetFile"))
4797 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4799 new JnetAnnotationMaker().add_annotation(predictions,
4800 viewport.getAlignment(), 0, false);
4801 isAnnotation = true;
4806 * if (format.equalsIgnoreCase("PDB")) {
4808 * String pdbfn = ""; // try to match up filename with sequence id
4809 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4810 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4811 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4812 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4813 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4814 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4815 * // attempt to find a match in the alignment SequenceI mtch =
4816 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4817 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4818 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4819 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4820 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4821 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4822 * { System.err.println("Associated file : " + file + " with " +
4823 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4824 * TODO: maybe need to load as normal otherwise return; } }
4826 // try to parse it as a features file
4827 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4828 // if it wasn't a features file then we just treat it as a general
4829 // alignment file to load into the current view.
4832 new FileLoader().LoadFile(viewport, file, protocol, format);
4836 alignPanel.paintAlignment(true);
4844 alignPanel.adjustAnnotationHeight();
4845 viewport.updateSequenceIdColours();
4846 buildSortByAnnotationScoresMenu();
4847 alignPanel.paintAlignment(true);
4849 } catch (Exception ex)
4851 ex.printStackTrace();
4855 public void tabSelectionChanged(int index)
4859 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4860 viewport = alignPanel.av;
4861 setMenusFromViewport(viewport);
4865 public void tabbedPane_mousePressed(MouseEvent e)
4867 if (SwingUtilities.isRightMouseButton(e))
4869 String reply = JOptionPane.showInternalInputDialog(this,
4870 "Enter View Name", "Edit View Name",
4871 JOptionPane.QUESTION_MESSAGE);
4875 viewport.viewName = reply;
4876 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4881 public AlignViewport getCurrentView()
4887 * Open the dialog for regex description parsing.
4889 protected void extractScores_actionPerformed(ActionEvent e)
4891 ParseProperties pp = new jalview.analysis.ParseProperties(
4892 viewport.getAlignment());
4893 // TODO: verify regex and introduce GUI dialog for version 2.5
4894 // if (pp.getScoresFromDescription("col", "score column ",
4895 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4897 if (pp.getScoresFromDescription("description column",
4898 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4900 buildSortByAnnotationScoresMenu();
4908 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4911 protected void showDbRefs_actionPerformed(ActionEvent e)
4913 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4919 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4922 protected void showNpFeats_actionPerformed(ActionEvent e)
4924 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4928 * find the viewport amongst the tabs in this alignment frame and close that
4933 public boolean closeView(AlignViewport av)
4937 this.closeMenuItem_actionPerformed(false);
4940 Component[] comp = tabbedPane.getComponents();
4941 for (int i = 0; comp != null && i < comp.length; i++)
4943 if (comp[i] instanceof AlignmentPanel)
4945 if (((AlignmentPanel) comp[i]).av == av)
4948 closeView((AlignmentPanel) comp[i]);
4956 protected void build_fetchdbmenu(JMenu webService)
4958 // Temporary hack - DBRef Fetcher always top level ws entry.
4959 // TODO We probably want to store a sequence database checklist in
4960 // preferences and have checkboxes.. rather than individual sources selected
4962 final JMenu rfetch = new JMenu("Fetch DB References");
4963 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4964 webService.add(rfetch);
4966 JMenuItem fetchr = new JMenuItem("Standard Databases");
4967 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4968 fetchr.addActionListener(new ActionListener()
4971 public void actionPerformed(ActionEvent e)
4973 new Thread(new Runnable()
4978 new jalview.ws.DBRefFetcher(alignPanel.av
4979 .getSequenceSelection(), alignPanel.alignFrame)
4980 .fetchDBRefs(false);
4988 final AlignFrame me = this;
4989 new Thread(new Runnable()
4993 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4994 .getSequenceFetcherSingleton(me);
4995 javax.swing.SwingUtilities.invokeLater(new Runnable()
4999 String[] dbclasses = sf.getOrderedSupportedSources();
5000 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5001 // jalview.util.QuickSort.sort(otherdb, otherdb);
5002 List<DbSourceProxy> otherdb;
5003 JMenu dfetch = new JMenu();
5004 JMenu ifetch = new JMenu();
5005 JMenuItem fetchr = null;
5006 int comp = 0, icomp = 0, mcomp = 15;
5007 String mname = null;
5009 for (String dbclass : dbclasses)
5011 otherdb = sf.getSourceProxy(dbclass);
5012 // add a single entry for this class, or submenu allowing 'fetch
5014 if (otherdb == null || otherdb.size() < 1)
5018 // List<DbSourceProxy> dbs=otherdb;
5019 // otherdb=new ArrayList<DbSourceProxy>();
5020 // for (DbSourceProxy db:dbs)
5022 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5026 mname = "From " + dbclass;
5028 if (otherdb.size() == 1)
5030 final DbSourceProxy[] dassource = otherdb
5031 .toArray(new DbSourceProxy[0]);
5032 DbSourceProxy src = otherdb.get(0);
5033 fetchr = new JMenuItem(src.getDbSource());
5034 fetchr.addActionListener(new ActionListener()
5037 public void actionPerformed(ActionEvent e)
5039 new Thread(new Runnable()
5044 new jalview.ws.DBRefFetcher(alignPanel.av
5045 .getSequenceSelection(),
5046 alignPanel.alignFrame, dassource)
5047 .fetchDBRefs(false);
5053 fetchr.setToolTipText("<html>"
5054 + JvSwingUtils.wrapTooltip("Retrieve from "
5055 + src.getDbName()) + "<html>");
5061 final DbSourceProxy[] dassource = otherdb
5062 .toArray(new DbSourceProxy[0]);
5064 DbSourceProxy src = otherdb.get(0);
5065 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5067 fetchr.addActionListener(new ActionListener()
5069 public void actionPerformed(ActionEvent e)
5071 new Thread(new Runnable()
5076 new jalview.ws.DBRefFetcher(alignPanel.av
5077 .getSequenceSelection(),
5078 alignPanel.alignFrame, dassource)
5079 .fetchDBRefs(false);
5085 fetchr.setToolTipText("<html>"
5086 + JvSwingUtils.wrapTooltip("Retrieve from all "
5087 + otherdb.size() + " sources in "
5088 + src.getDbSource() + "<br>First is :"
5089 + src.getDbName()) + "<html>");
5092 // and then build the rest of the individual menus
5093 ifetch = new JMenu("Sources from " + src.getDbSource());
5095 String imname = null;
5097 for (DbSourceProxy sproxy : otherdb)
5099 String dbname = sproxy.getDbName();
5100 String sname = dbname.length() > 5 ? dbname.substring(0,
5101 5) + "..." : dbname;
5102 String msname = dbname.length() > 10 ? dbname.substring(
5103 0, 10) + "..." : dbname;
5106 imname = "from '" + sname + "'";
5108 fetchr = new JMenuItem(msname);
5109 final DbSourceProxy[] dassrc =
5111 fetchr.addActionListener(new ActionListener()
5114 public void actionPerformed(ActionEvent e)
5116 new Thread(new Runnable()
5121 new jalview.ws.DBRefFetcher(alignPanel.av
5122 .getSequenceSelection(),
5123 alignPanel.alignFrame, dassrc)
5124 .fetchDBRefs(false);
5130 fetchr.setToolTipText("<html>"
5131 + JvSwingUtils.wrapTooltip("Retrieve from "
5132 + dbname) + "</html>");
5135 if (++icomp >= mcomp || i == (otherdb.size()))
5137 ifetch.setText(imname + " to '" + sname + "'");
5139 ifetch = new JMenu();
5147 if (comp >= mcomp || dbi >= (dbclasses.length))
5149 dfetch.setText(mname + " to '" + dbclass + "'");
5151 dfetch = new JMenu();
5164 * Left justify the whole alignment.
5166 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5168 AlignmentI al = viewport.getAlignment();
5170 viewport.firePropertyChange("alignment", null, al);
5174 * Right justify the whole alignment.
5176 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5178 AlignmentI al = viewport.getAlignment();
5180 viewport.firePropertyChange("alignment", null, al);
5183 public void setShowSeqFeatures(boolean b)
5185 showSeqFeatures.setSelected(true);
5186 viewport.setShowSequenceFeatures(true);
5193 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5194 * awt.event.ActionEvent)
5196 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5198 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5199 alignPanel.paintAlignment(true);
5206 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5209 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5211 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5212 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5220 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5221 * .event.ActionEvent)
5223 protected void showGroupConservation_actionPerformed(ActionEvent e)
5225 viewport.setShowGroupConservation(showGroupConservation.getState());
5226 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5233 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5234 * .event.ActionEvent)
5236 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5238 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5239 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5246 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5247 * .event.ActionEvent)
5249 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5251 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5252 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5255 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5257 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5258 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5261 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5263 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5270 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5271 * .event.ActionEvent)
5273 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5275 if (viewport.getSelectionGroup() != null)
5277 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5278 viewport.getSequenceSelection(),
5279 viewport.getAlignmentView(true).getSequenceStrings(
5280 viewport.getGapCharacter()), viewport.getAlignment()
5282 viewport.getAlignment().deleteAllGroups();
5283 viewport.sequenceColours = null;
5284 viewport.setSelectionGroup(null);
5285 // set view properties for each group
5286 for (int g = 0; g < gps.length; g++)
5288 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5289 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5290 viewport.getAlignment().addGroup(gps[g]);
5291 Color col = new Color((int) (Math.random() * 255),
5292 (int) (Math.random() * 255), (int) (Math.random() * 255));
5293 col = col.brighter();
5294 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5295 .hasMoreElements(); viewport.setSequenceColour(
5296 (SequenceI) sq.nextElement(), col))
5299 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5300 alignPanel.updateAnnotation();
5301 alignPanel.paintAlignment(true);
5306 * make the given alignmentPanel the currently selected tab
5308 * @param alignmentPanel
5310 public void setDisplayedView(AlignmentPanel alignmentPanel)
5312 if (!viewport.getSequenceSetId().equals(
5313 alignmentPanel.av.getSequenceSetId()))
5316 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5318 if (tabbedPane != null
5319 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5320 .getSelectedIndex())
5322 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5327 class PrintThread extends Thread
5331 public PrintThread(AlignmentPanel ap)
5336 static PageFormat pf;
5340 PrinterJob printJob = PrinterJob.getPrinterJob();
5344 printJob.setPrintable(ap, pf);
5348 printJob.setPrintable(ap);
5351 if (printJob.printDialog())
5356 } catch (Exception PrintException)
5358 PrintException.printStackTrace();