2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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.util.MessageManager;
79 import jalview.ws.jws1.Discoverer;
80 import jalview.ws.jws2.Jws2Discoverer;
81 import jalview.ws.seqfetcher.DbSourceProxy;
83 import java.awt.BorderLayout;
84 import java.awt.Color;
85 import java.awt.Component;
86 import java.awt.GridLayout;
87 import java.awt.Rectangle;
88 import java.awt.Toolkit;
89 import java.awt.datatransfer.Clipboard;
90 import java.awt.datatransfer.DataFlavor;
91 import java.awt.datatransfer.StringSelection;
92 import java.awt.datatransfer.Transferable;
93 import java.awt.dnd.DnDConstants;
94 import java.awt.dnd.DropTargetDragEvent;
95 import java.awt.dnd.DropTargetDropEvent;
96 import java.awt.dnd.DropTargetEvent;
97 import java.awt.dnd.DropTargetListener;
98 import java.awt.event.ActionEvent;
99 import java.awt.event.ActionListener;
100 import java.awt.event.KeyAdapter;
101 import java.awt.event.KeyEvent;
102 import java.awt.event.MouseAdapter;
103 import java.awt.event.MouseEvent;
104 import java.awt.print.PageFormat;
105 import java.awt.print.PrinterJob;
106 import java.beans.PropertyChangeEvent;
109 import java.util.ArrayList;
110 import java.util.Enumeration;
111 import java.util.Hashtable;
112 import java.util.List;
113 import java.util.Vector;
115 import javax.swing.JButton;
116 import javax.swing.JEditorPane;
117 import javax.swing.JInternalFrame;
118 import javax.swing.JLabel;
119 import javax.swing.JLayeredPane;
120 import javax.swing.JMenu;
121 import javax.swing.JMenuItem;
122 import javax.swing.JOptionPane;
123 import javax.swing.JPanel;
124 import javax.swing.JProgressBar;
125 import javax.swing.JRadioButtonMenuItem;
126 import javax.swing.JScrollPane;
127 import javax.swing.SwingUtilities;
133 * @version $Revision$
135 public class AlignFrame extends GAlignFrame implements DropTargetListener,
140 public static final int DEFAULT_WIDTH = 700;
143 public static final int DEFAULT_HEIGHT = 500;
145 public AlignmentPanel alignPanel;
147 AlignViewport viewport;
149 Vector alignPanels = new Vector();
152 * Last format used to load or save alignments in this window
154 String currentFileFormat = null;
157 * Current filename for this alignment
159 String fileName = null;
162 * Creates a new AlignFrame object with specific width and height.
168 public AlignFrame(AlignmentI al, int width, int height)
170 this(al, null, width, height);
174 * Creates a new AlignFrame object with specific width, height and
180 * @param sequenceSetId
182 public AlignFrame(AlignmentI al, int width, int height,
183 String sequenceSetId)
185 this(al, null, width, height, sequenceSetId);
189 * Creates a new AlignFrame object with specific width, height and
195 * @param sequenceSetId
198 public AlignFrame(AlignmentI al, int width, int height,
199 String sequenceSetId, String viewId)
201 this(al, null, width, height, sequenceSetId, viewId);
205 * new alignment window with hidden columns
209 * @param hiddenColumns
210 * ColumnSelection or null
212 * Width of alignment frame
216 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
217 int width, int height)
219 this(al, hiddenColumns, width, height, null);
223 * Create alignment frame for al with hiddenColumns, a specific width and
224 * height, and specific sequenceId
227 * @param hiddenColumns
230 * @param sequenceSetId
233 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
234 int width, int height, String sequenceSetId)
236 this(al, hiddenColumns, width, height, sequenceSetId, null);
240 * Create alignment frame for al with hiddenColumns, a specific width and
241 * height, and specific sequenceId
244 * @param hiddenColumns
247 * @param sequenceSetId
252 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
253 int width, int height, String sequenceSetId, String viewId)
255 setSize(width, height);
256 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
258 alignPanel = new AlignmentPanel(this, viewport);
260 if (al.getDataset() == null)
265 addAlignmentPanel(alignPanel, true);
270 * Make a new AlignFrame from exisiting alignmentPanels
277 public AlignFrame(AlignmentPanel ap)
281 addAlignmentPanel(ap, false);
286 * initalise the alignframe from the underlying viewport data and the
291 if (viewport.getAlignmentConservationAnnotation() == null)
293 BLOSUM62Colour.setEnabled(false);
294 conservationMenuItem.setEnabled(false);
295 modifyConservation.setEnabled(false);
296 // PIDColour.setEnabled(false);
297 // abovePIDThreshold.setEnabled(false);
298 // modifyPID.setEnabled(false);
301 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
304 if (sortby.equals("Id"))
306 sortIDMenuItem_actionPerformed(null);
308 else if (sortby.equals("Pairwise Identity"))
310 sortPairwiseMenuItem_actionPerformed(null);
313 if (Desktop.desktop != null)
315 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
316 addServiceListeners();
317 setGUINucleotide(viewport.getAlignment().isNucleotide());
320 setMenusFromViewport(viewport);
321 buildSortByAnnotationScoresMenu();
322 if (viewport.wrapAlignment)
324 wrapMenuItem_actionPerformed(null);
327 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
329 this.overviewMenuItem_actionPerformed(null);
337 * Change the filename and format for the alignment, and enable the 'reload'
338 * button functionality.
345 public void setFileName(String file, String format)
348 currentFileFormat = format;
349 reload.setEnabled(true);
352 void addKeyListener()
354 addKeyListener(new KeyAdapter()
357 public void keyPressed(KeyEvent evt)
359 if (viewport.cursorMode
360 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
361 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
362 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
363 && Character.isDigit(evt.getKeyChar()))
364 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
366 switch (evt.getKeyCode())
369 case 27: // escape key
370 deselectAllSequenceMenuItem_actionPerformed(null);
374 case KeyEvent.VK_DOWN:
375 if (evt.isAltDown() || !viewport.cursorMode)
376 moveSelectedSequences(false);
377 if (viewport.cursorMode)
378 alignPanel.seqPanel.moveCursor(0, 1);
382 if (evt.isAltDown() || !viewport.cursorMode)
383 moveSelectedSequences(true);
384 if (viewport.cursorMode)
385 alignPanel.seqPanel.moveCursor(0, -1);
389 case KeyEvent.VK_LEFT:
390 if (evt.isAltDown() || !viewport.cursorMode)
391 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
393 alignPanel.seqPanel.moveCursor(-1, 0);
397 case KeyEvent.VK_RIGHT:
398 if (evt.isAltDown() || !viewport.cursorMode)
399 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
401 alignPanel.seqPanel.moveCursor(1, 0);
404 case KeyEvent.VK_SPACE:
405 if (viewport.cursorMode)
407 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
408 || evt.isShiftDown() || evt.isAltDown());
412 // case KeyEvent.VK_A:
413 // if (viewport.cursorMode)
415 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
416 // //System.out.println("A");
420 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
421 * System.out.println("closing bracket"); } break;
423 case KeyEvent.VK_DELETE:
424 case KeyEvent.VK_BACK_SPACE:
425 if (!viewport.cursorMode)
427 cut_actionPerformed(null);
431 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
432 || evt.isShiftDown() || evt.isAltDown());
438 if (viewport.cursorMode)
440 alignPanel.seqPanel.setCursorRow();
444 if (viewport.cursorMode && !evt.isControlDown())
446 alignPanel.seqPanel.setCursorColumn();
450 if (viewport.cursorMode)
452 alignPanel.seqPanel.setCursorPosition();
456 case KeyEvent.VK_ENTER:
457 case KeyEvent.VK_COMMA:
458 if (viewport.cursorMode)
460 alignPanel.seqPanel.setCursorRowAndColumn();
465 if (viewport.cursorMode)
467 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
471 if (viewport.cursorMode)
473 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
478 viewport.cursorMode = !viewport.cursorMode;
479 statusBar.setText(MessageManager.formatMessage("label.keyboard_editing_mode", new String[]{(viewport.cursorMode ? "on" : "off")}));
480 if (viewport.cursorMode)
482 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
483 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
485 alignPanel.seqPanel.seqCanvas.repaint();
491 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
492 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
494 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
496 javax.help.HelpBroker hb = hs.createHelpBroker();
497 hb.setCurrentID("home");
498 hb.setDisplayed(true);
499 } catch (Exception ex)
501 ex.printStackTrace();
506 boolean toggleSeqs = !evt.isControlDown();
507 boolean toggleCols = !evt.isShiftDown();
508 toggleHiddenRegions(toggleSeqs, toggleCols);
511 case KeyEvent.VK_PAGE_UP:
512 if (viewport.wrapAlignment)
514 alignPanel.scrollUp(true);
518 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
519 - viewport.endSeq + viewport.startSeq);
522 case KeyEvent.VK_PAGE_DOWN:
523 if (viewport.wrapAlignment)
525 alignPanel.scrollUp(false);
529 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
530 + viewport.endSeq - viewport.startSeq);
537 public void keyReleased(KeyEvent evt)
539 switch (evt.getKeyCode())
541 case KeyEvent.VK_LEFT:
542 if (evt.isAltDown() || !viewport.cursorMode)
543 viewport.firePropertyChange("alignment", null, viewport
544 .getAlignment().getSequences());
547 case KeyEvent.VK_RIGHT:
548 if (evt.isAltDown() || !viewport.cursorMode)
549 viewport.firePropertyChange("alignment", null, viewport
550 .getAlignment().getSequences());
557 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
559 ap.alignFrame = this;
561 alignPanels.addElement(ap);
563 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
565 int aSize = alignPanels.size();
567 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
569 if (aSize == 1 && ap.av.viewName == null)
571 this.getContentPane().add(ap, BorderLayout.CENTER);
577 setInitialTabVisible();
580 expandViews.setEnabled(true);
581 gatherViews.setEnabled(true);
582 tabbedPane.addTab(ap.av.viewName, ap);
584 ap.setVisible(false);
589 if (ap.av.isPadGaps())
591 ap.av.getAlignment().padGaps();
593 ap.av.updateConservation(ap);
594 ap.av.updateConsensus(ap);
595 ap.av.updateStrucConsensus(ap);
599 public void setInitialTabVisible()
601 expandViews.setEnabled(true);
602 gatherViews.setEnabled(true);
603 tabbedPane.setVisible(true);
604 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
605 tabbedPane.addTab(first.av.viewName, first);
606 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
609 public AlignViewport getViewport()
614 /* Set up intrinsic listeners for dynamically generated GUI bits. */
615 private void addServiceListeners()
617 final java.beans.PropertyChangeListener thisListener;
618 Desktop.instance.addJalviewPropertyChangeListener("services",
619 thisListener = new java.beans.PropertyChangeListener()
622 public void propertyChange(PropertyChangeEvent evt)
624 // // System.out.println("Discoverer property change.");
625 // if (evt.getPropertyName().equals("services"))
627 SwingUtilities.invokeLater(new Runnable()
634 .println("Rebuild WS Menu for service change");
635 BuildWebServiceMenu();
642 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
645 public void internalFrameClosed(
646 javax.swing.event.InternalFrameEvent evt)
648 System.out.println("deregistering discoverer listener");
649 Desktop.instance.removeJalviewPropertyChangeListener("services",
651 closeMenuItem_actionPerformed(true);
654 // Finally, build the menu once to get current service state
655 new Thread(new Runnable()
660 BuildWebServiceMenu();
665 public void setGUINucleotide(boolean nucleotide)
667 showTranslation.setVisible(nucleotide);
668 conservationMenuItem.setEnabled(!nucleotide);
669 modifyConservation.setEnabled(!nucleotide);
670 showGroupConservation.setEnabled(!nucleotide);
671 rnahelicesColour.setEnabled(nucleotide);
672 purinePyrimidineColour.setEnabled(nucleotide);
673 // Remember AlignFrame always starts as protein
677 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
682 * set up menus for the currently viewport. This may be called after any
683 * operation that affects the data in the current view (selection changed,
684 * etc) to update the menus to reflect the new state.
686 public void setMenusForViewport()
688 setMenusFromViewport(viewport);
692 * Need to call this method when tabs are selected for multiple views, or when
693 * loading from Jalview2XML.java
698 void setMenusFromViewport(AlignViewport av)
700 padGapsMenuitem.setSelected(av.isPadGaps());
701 colourTextMenuItem.setSelected(av.showColourText);
702 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
703 conservationMenuItem.setSelected(av.getConservationSelected());
704 seqLimits.setSelected(av.getShowJVSuffix());
705 idRightAlign.setSelected(av.rightAlignIds);
706 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
707 renderGapsMenuItem.setSelected(av.renderGaps);
708 wrapMenuItem.setSelected(av.wrapAlignment);
709 scaleAbove.setVisible(av.wrapAlignment);
710 scaleLeft.setVisible(av.wrapAlignment);
711 scaleRight.setVisible(av.wrapAlignment);
712 annotationPanelMenuItem.setState(av.showAnnotation);
713 viewBoxesMenuItem.setSelected(av.showBoxes);
714 viewTextMenuItem.setSelected(av.showText);
715 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
716 showGroupConsensus.setSelected(av.isShowGroupConsensus());
717 showGroupConservation.setSelected(av.isShowGroupConservation());
718 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
719 showSequenceLogo.setSelected(av.isShowSequenceLogo());
720 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
722 setColourSelected(ColourSchemeProperty.getColourName(av
723 .getGlobalColourScheme()));
725 showSeqFeatures.setSelected(av.showSequenceFeatures);
726 hiddenMarkers.setState(av.showHiddenMarkers);
727 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
728 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
729 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
730 autoCalculate.setSelected(av.autoCalculateConsensus);
731 sortByTree.setSelected(av.sortByTree);
732 listenToViewSelections.setSelected(av.followSelection);
733 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
735 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
736 setShowProductsEnabled();
741 // methods for implementing IProgressIndicator
742 // need to refactor to a reusable stub class
743 Hashtable progressBars, progressBarHandlers;
748 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
751 public void setProgressBar(String message, long id)
753 if (progressBars == null)
755 progressBars = new Hashtable();
756 progressBarHandlers = new Hashtable();
759 JPanel progressPanel;
760 Long lId = new Long(id);
761 GridLayout layout = (GridLayout) statusPanel.getLayout();
762 if (progressBars.get(lId) != null)
764 progressPanel = (JPanel) progressBars.get(new Long(id));
765 statusPanel.remove(progressPanel);
766 progressBars.remove(lId);
767 progressPanel = null;
770 statusBar.setText(message);
772 if (progressBarHandlers.contains(lId))
774 progressBarHandlers.remove(lId);
776 layout.setRows(layout.getRows() - 1);
780 progressPanel = new JPanel(new BorderLayout(10, 5));
782 JProgressBar progressBar = new JProgressBar();
783 progressBar.setIndeterminate(true);
785 progressPanel.add(new JLabel(message), BorderLayout.WEST);
786 progressPanel.add(progressBar, BorderLayout.CENTER);
788 layout.setRows(layout.getRows() + 1);
789 statusPanel.add(progressPanel);
791 progressBars.put(lId, progressPanel);
794 // setMenusForViewport();
799 public void registerHandler(final long id,
800 final IProgressIndicatorHandler handler)
802 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
805 "call setProgressBar before registering the progress bar's handler.");
807 progressBarHandlers.put(new Long(id), handler);
808 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
809 if (handler.canCancel())
811 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
812 final IProgressIndicator us = this;
813 cancel.addActionListener(new ActionListener()
817 public void actionPerformed(ActionEvent e)
819 handler.cancelActivity(id);
822 + ((JLabel) progressPanel.getComponent(0))
826 progressPanel.add(cancel, BorderLayout.EAST);
832 * @return true if any progress bars are still active
835 public boolean operationInProgress()
837 if (progressBars != null && progressBars.size() > 0)
845 * Added so Castor Mapping file can obtain Jalview Version
847 public String getVersion()
849 return jalview.bin.Cache.getProperty("VERSION");
852 public FeatureRenderer getFeatureRenderer()
854 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
858 public void fetchSequence_actionPerformed(ActionEvent e)
860 new SequenceFetcher(this);
864 public void addFromFile_actionPerformed(ActionEvent e)
866 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
870 public void reload_actionPerformed(ActionEvent e)
872 if (fileName != null)
874 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
875 // originating file's format
876 // TODO: work out how to recover feature settings for correct view(s) when
878 if (currentFileFormat.equals("Jalview"))
880 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
881 for (int i = 0; i < frames.length; i++)
883 if (frames[i] instanceof AlignFrame && frames[i] != this
884 && ((AlignFrame) frames[i]).fileName != null
885 && ((AlignFrame) frames[i]).fileName.equals(fileName))
889 frames[i].setSelected(true);
890 Desktop.instance.closeAssociatedWindows();
891 } catch (java.beans.PropertyVetoException ex)
897 Desktop.instance.closeAssociatedWindows();
899 FileLoader loader = new FileLoader();
900 String protocol = fileName.startsWith("http:") ? "URL" : "File";
901 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
905 Rectangle bounds = this.getBounds();
907 FileLoader loader = new FileLoader();
908 String protocol = fileName.startsWith("http:") ? "URL" : "File";
909 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
910 protocol, currentFileFormat);
912 newframe.setBounds(bounds);
913 if (featureSettings != null && featureSettings.isShowing())
915 final Rectangle fspos = featureSettings.frame.getBounds();
916 // TODO: need a 'show feature settings' function that takes bounds -
917 // need to refactor Desktop.addFrame
918 newframe.featureSettings_actionPerformed(null);
919 final FeatureSettings nfs = newframe.featureSettings;
920 SwingUtilities.invokeLater(new Runnable()
925 nfs.frame.setBounds(fspos);
928 this.featureSettings.close();
929 this.featureSettings = null;
931 this.closeMenuItem_actionPerformed(true);
937 public void addFromText_actionPerformed(ActionEvent e)
939 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
943 public void addFromURL_actionPerformed(ActionEvent e)
945 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
949 public void save_actionPerformed(ActionEvent e)
952 || (currentFileFormat == null || !jalview.io.FormatAdapter
953 .isValidIOFormat(currentFileFormat, true))
954 || fileName.startsWith("http"))
956 saveAs_actionPerformed(null);
960 saveAlignment(fileName, currentFileFormat);
971 public void saveAs_actionPerformed(ActionEvent e)
973 JalviewFileChooser chooser = new JalviewFileChooser(
974 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
975 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
976 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
977 currentFileFormat, false);
979 chooser.setFileView(new JalviewFileView());
980 chooser.setDialogTitle("Save Alignment to file");
981 chooser.setToolTipText("Save");
983 int value = chooser.showSaveDialog(this);
985 if (value == JalviewFileChooser.APPROVE_OPTION)
987 currentFileFormat = chooser.getSelectedFormat();
988 if (currentFileFormat == null)
990 JOptionPane.showInternalMessageDialog(Desktop.desktop,
991 "You must select a file format before saving!",
992 "File format not specified", JOptionPane.WARNING_MESSAGE);
993 value = chooser.showSaveDialog(this);
997 fileName = chooser.getSelectedFile().getPath();
999 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1002 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1003 if (currentFileFormat.indexOf(" ") > -1)
1005 currentFileFormat = currentFileFormat.substring(0,
1006 currentFileFormat.indexOf(" "));
1008 saveAlignment(fileName, currentFileFormat);
1012 public boolean saveAlignment(String file, String format)
1014 boolean success = true;
1016 if (format.equalsIgnoreCase("Jalview"))
1018 String shortName = title;
1020 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1022 shortName = shortName.substring(shortName
1023 .lastIndexOf(java.io.File.separatorChar) + 1);
1026 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1028 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1034 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1036 warningMessage("Cannot save file " + fileName + " using format "
1037 + format, "Alignment output format not supported");
1038 saveAs_actionPerformed(null);
1039 // JBPNote need to have a raise_gui flag here
1043 String[] omitHidden = null;
1045 if (viewport.hasHiddenColumns())
1047 int reply = JOptionPane
1048 .showInternalConfirmDialog(
1050 "The Alignment contains hidden columns."
1051 + "\nDo you want to save only the visible alignment?",
1052 "Save / Omit Hidden Columns",
1053 JOptionPane.YES_NO_OPTION,
1054 JOptionPane.QUESTION_MESSAGE);
1056 if (reply == JOptionPane.YES_OPTION)
1058 omitHidden = viewport.getViewAsString(false);
1061 FormatAdapter f = new FormatAdapter();
1062 String output = f.formatSequences(format,
1063 viewport.getAlignment(), // class cast exceptions will
1064 // occur in the distant future
1065 omitHidden, f.getCacheSuffixDefault(format),
1066 viewport.getColumnSelection());
1076 java.io.PrintWriter out = new java.io.PrintWriter(
1077 new java.io.FileWriter(file));
1081 this.setTitle(file);
1082 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1083 } catch (Exception ex)
1086 ex.printStackTrace();
1093 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1094 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1100 private void warningMessage(String warning, String title)
1102 if (new jalview.util.Platform().isHeadless())
1104 System.err.println("Warning: " + title + "\nWarning: " + warning);
1109 JOptionPane.showInternalMessageDialog(this, warning, title,
1110 JOptionPane.WARNING_MESSAGE);
1122 protected void outputText_actionPerformed(ActionEvent e)
1124 String[] omitHidden = null;
1126 if (viewport.hasHiddenColumns())
1128 int reply = JOptionPane
1129 .showInternalConfirmDialog(
1131 "The Alignment contains hidden columns."
1132 + "\nDo you want to output only the visible alignment?",
1133 "Save / Omit Hidden Columns",
1134 JOptionPane.YES_NO_OPTION,
1135 JOptionPane.QUESTION_MESSAGE);
1137 if (reply == JOptionPane.YES_OPTION)
1139 omitHidden = viewport.getViewAsString(false);
1143 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1144 cap.setForInput(null);
1148 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1149 viewport.getAlignment(), omitHidden,
1150 viewport.getColumnSelection()));
1151 Desktop.addInternalFrame(cap,
1152 "Alignment output - " + e.getActionCommand(), 600, 500);
1153 } catch (OutOfMemoryError oom)
1155 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1168 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1170 new HTMLOutput(alignPanel,
1171 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1172 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1175 public void createImageMap(File file, String image)
1177 alignPanel.makePNGImageMap(file, image);
1187 public void createPNG(File f)
1189 alignPanel.makePNG(f);
1199 public void createEPS(File f)
1201 alignPanel.makeEPS(f);
1205 public void pageSetup_actionPerformed(ActionEvent e)
1207 PrinterJob printJob = PrinterJob.getPrinterJob();
1208 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1218 public void printMenuItem_actionPerformed(ActionEvent e)
1220 // Putting in a thread avoids Swing painting problems
1221 PrintThread thread = new PrintThread(alignPanel);
1226 public void exportFeatures_actionPerformed(ActionEvent e)
1228 new AnnotationExporter().exportFeatures(alignPanel);
1232 public void exportAnnotations_actionPerformed(ActionEvent e)
1234 new AnnotationExporter().exportAnnotations(alignPanel,
1235 viewport.showAnnotation ? viewport.getAlignment()
1236 .getAlignmentAnnotation() : null, viewport
1237 .getAlignment().getGroups(), ((Alignment) viewport
1238 .getAlignment()).alignmentProperties);
1242 public void associatedData_actionPerformed(ActionEvent e)
1244 // Pick the tree file
1245 JalviewFileChooser chooser = new JalviewFileChooser(
1246 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1247 chooser.setFileView(new JalviewFileView());
1248 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1249 chooser.setToolTipText("Load Jalview Annotations / Features file");
1251 int value = chooser.showOpenDialog(null);
1253 if (value == JalviewFileChooser.APPROVE_OPTION)
1255 String choice = chooser.getSelectedFile().getPath();
1256 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1257 loadJalviewDataFile(choice, null, null, null);
1263 * Close the current view or all views in the alignment frame. If the frame
1264 * only contains one view then the alignment will be removed from memory.
1266 * @param closeAllTabs
1269 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1271 if (alignPanels != null && alignPanels.size() < 2)
1273 closeAllTabs = true;
1278 if (alignPanels != null)
1282 if (this.isClosed())
1284 // really close all the windows - otherwise wait till
1285 // setClosed(true) is called
1286 for (int i = 0; i < alignPanels.size(); i++)
1288 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1295 closeView(alignPanel);
1301 this.setClosed(true);
1303 } catch (Exception ex)
1305 ex.printStackTrace();
1310 * close alignPanel2 and shuffle tabs appropriately.
1312 * @param alignPanel2
1314 public void closeView(AlignmentPanel alignPanel2)
1316 int index = tabbedPane.getSelectedIndex();
1317 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1318 alignPanels.removeElement(alignPanel2);
1320 // if (viewport == alignPanel2.av)
1324 alignPanel2.closePanel();
1327 tabbedPane.removeTabAt(closedindex);
1328 tabbedPane.validate();
1330 if (index > closedindex || index == tabbedPane.getTabCount())
1332 // modify currently selected tab index if necessary.
1336 this.tabSelectionChanged(index);
1342 void updateEditMenuBar()
1345 if (viewport.historyList.size() > 0)
1347 undoMenuItem.setEnabled(true);
1348 CommandI command = (CommandI) viewport.historyList.peek();
1349 undoMenuItem.setText(MessageManager.formatMessage("label.undo_command", new String[]{command.getDescription()}));
1353 undoMenuItem.setEnabled(false);
1354 undoMenuItem.setText(MessageManager.getString("action.undo"));
1357 if (viewport.redoList.size() > 0)
1359 redoMenuItem.setEnabled(true);
1361 CommandI command = (CommandI) viewport.redoList.peek();
1362 redoMenuItem.setText(MessageManager.formatMessage("label.redo_command", new String[]{command.getDescription()}));
1366 redoMenuItem.setEnabled(false);
1367 redoMenuItem.setText(MessageManager.getString("action.redo"));
1371 public void addHistoryItem(CommandI command)
1373 if (command.getSize() > 0)
1375 viewport.historyList.push(command);
1376 viewport.redoList.clear();
1377 updateEditMenuBar();
1378 viewport.updateHiddenColumns();
1379 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1380 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1381 // viewport.getColumnSelection()
1382 // .getHiddenColumns().size() > 0);
1388 * @return alignment objects for all views
1390 AlignmentI[] getViewAlignments()
1392 if (alignPanels != null)
1394 Enumeration e = alignPanels.elements();
1395 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1396 for (int i = 0; e.hasMoreElements(); i++)
1398 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1402 if (viewport != null)
1404 return new AlignmentI[]
1405 { viewport.getAlignment() };
1417 protected void undoMenuItem_actionPerformed(ActionEvent e)
1419 if (viewport.historyList.empty())
1421 CommandI command = (CommandI) viewport.historyList.pop();
1422 viewport.redoList.push(command);
1423 command.undoCommand(getViewAlignments());
1425 AlignViewport originalSource = getOriginatingSource(command);
1426 updateEditMenuBar();
1428 if (originalSource != null)
1430 if (originalSource != viewport)
1433 .warn("Implementation worry: mismatch of viewport origin for undo");
1435 originalSource.updateHiddenColumns();
1436 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1438 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1439 // viewport.getColumnSelection()
1440 // .getHiddenColumns().size() > 0);
1441 originalSource.firePropertyChange("alignment", null, originalSource
1442 .getAlignment().getSequences());
1453 protected void redoMenuItem_actionPerformed(ActionEvent e)
1455 if (viewport.redoList.size() < 1)
1460 CommandI command = (CommandI) viewport.redoList.pop();
1461 viewport.historyList.push(command);
1462 command.doCommand(getViewAlignments());
1464 AlignViewport originalSource = getOriginatingSource(command);
1465 updateEditMenuBar();
1467 if (originalSource != null)
1470 if (originalSource != viewport)
1473 .warn("Implementation worry: mismatch of viewport origin for redo");
1475 originalSource.updateHiddenColumns();
1476 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1478 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1479 // viewport.getColumnSelection()
1480 // .getHiddenColumns().size() > 0);
1481 originalSource.firePropertyChange("alignment", null, originalSource
1482 .getAlignment().getSequences());
1486 AlignViewport getOriginatingSource(CommandI command)
1488 AlignViewport originalSource = null;
1489 // For sequence removal and addition, we need to fire
1490 // the property change event FROM the viewport where the
1491 // original alignment was altered
1492 AlignmentI al = null;
1493 if (command instanceof EditCommand)
1495 EditCommand editCommand = (EditCommand) command;
1496 al = editCommand.getAlignment();
1497 Vector comps = (Vector) PaintRefresher.components.get(viewport
1498 .getSequenceSetId());
1500 for (int i = 0; i < comps.size(); i++)
1502 if (comps.elementAt(i) instanceof AlignmentPanel)
1504 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1506 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1513 if (originalSource == null)
1515 // The original view is closed, we must validate
1516 // the current view against the closed view first
1519 PaintRefresher.validateSequences(al, viewport.getAlignment());
1522 originalSource = viewport;
1525 return originalSource;
1534 public void moveSelectedSequences(boolean up)
1536 SequenceGroup sg = viewport.getSelectionGroup();
1542 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1543 viewport.getHiddenRepSequences(), up);
1544 alignPanel.paintAlignment(true);
1547 synchronized void slideSequences(boolean right, int size)
1549 List<SequenceI> sg = new Vector();
1550 if (viewport.cursorMode)
1552 sg.add(viewport.getAlignment().getSequenceAt(
1553 alignPanel.seqPanel.seqCanvas.cursorY));
1555 else if (viewport.getSelectionGroup() != null
1556 && viewport.getSelectionGroup().getSize() != viewport
1557 .getAlignment().getHeight())
1559 sg = viewport.getSelectionGroup().getSequences(
1560 viewport.getHiddenRepSequences());
1568 Vector invertGroup = new Vector();
1570 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1572 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1573 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1576 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1578 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1579 for (int i = 0; i < invertGroup.size(); i++)
1580 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1582 SlideSequencesCommand ssc;
1584 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1585 size, viewport.getGapCharacter());
1587 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1588 size, viewport.getGapCharacter());
1590 int groupAdjustment = 0;
1591 if (ssc.getGapsInsertedBegin() && right)
1593 if (viewport.cursorMode)
1594 alignPanel.seqPanel.moveCursor(size, 0);
1596 groupAdjustment = size;
1598 else if (!ssc.getGapsInsertedBegin() && !right)
1600 if (viewport.cursorMode)
1601 alignPanel.seqPanel.moveCursor(-size, 0);
1603 groupAdjustment = -size;
1606 if (groupAdjustment != 0)
1608 viewport.getSelectionGroup().setStartRes(
1609 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1610 viewport.getSelectionGroup().setEndRes(
1611 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1614 boolean appendHistoryItem = false;
1615 if (viewport.historyList != null && viewport.historyList.size() > 0
1616 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1618 appendHistoryItem = ssc
1619 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1623 if (!appendHistoryItem)
1624 addHistoryItem(ssc);
1636 protected void copy_actionPerformed(ActionEvent e)
1639 if (viewport.getSelectionGroup() == null)
1643 // TODO: preserve the ordering of displayed alignment annotation in any
1644 // internal paste (particularly sequence associated annotation)
1645 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1646 String[] omitHidden = null;
1648 if (viewport.hasHiddenColumns())
1650 omitHidden = viewport.getViewAsString(true);
1653 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1656 StringSelection ss = new StringSelection(output);
1660 jalview.gui.Desktop.internalCopy = true;
1661 // Its really worth setting the clipboard contents
1662 // to empty before setting the large StringSelection!!
1663 Toolkit.getDefaultToolkit().getSystemClipboard()
1664 .setContents(new StringSelection(""), null);
1666 Toolkit.getDefaultToolkit().getSystemClipboard()
1667 .setContents(ss, Desktop.instance);
1668 } catch (OutOfMemoryError er)
1670 new OOMWarning("copying region", er);
1674 Vector hiddenColumns = null;
1675 if (viewport.hasHiddenColumns())
1677 hiddenColumns = new Vector();
1678 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1679 .getSelectionGroup().getEndRes();
1680 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1683 int[] region = (int[]) viewport.getColumnSelection()
1684 .getHiddenColumns().elementAt(i);
1685 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1687 hiddenColumns.addElement(new int[]
1688 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1693 Desktop.jalviewClipboard = new Object[]
1694 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1695 statusBar.setText(MessageManager.formatMessage("label.copied_sequences_to_clipboard", new String[]{Integer.valueOf(seqs.length).toString()}));
1705 protected void pasteNew_actionPerformed(ActionEvent e)
1717 protected void pasteThis_actionPerformed(ActionEvent e)
1723 * Paste contents of Jalview clipboard
1725 * @param newAlignment
1726 * true to paste to a new alignment, otherwise add to this.
1728 void paste(boolean newAlignment)
1730 boolean externalPaste = true;
1733 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1734 Transferable contents = c.getContents(this);
1736 if (contents == null)
1744 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1745 if (str.length() < 1)
1750 format = new IdentifyFile().Identify(str, "Paste");
1752 } catch (OutOfMemoryError er)
1754 new OOMWarning("Out of memory pasting sequences!!", er);
1758 SequenceI[] sequences;
1759 boolean annotationAdded = false;
1760 AlignmentI alignment = null;
1762 if (Desktop.jalviewClipboard != null)
1764 // The clipboard was filled from within Jalview, we must use the
1766 // And dataset from the copied alignment
1767 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1768 // be doubly sure that we create *new* sequence objects.
1769 sequences = new SequenceI[newseq.length];
1770 for (int i = 0; i < newseq.length; i++)
1772 sequences[i] = new Sequence(newseq[i]);
1774 alignment = new Alignment(sequences);
1775 externalPaste = false;
1779 // parse the clipboard as an alignment.
1780 alignment = new FormatAdapter().readFile(str, "Paste", format);
1781 sequences = alignment.getSequencesArray();
1785 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1791 if (Desktop.jalviewClipboard != null)
1793 // dataset is inherited
1794 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1798 // new dataset is constructed
1799 alignment.setDataset(null);
1801 alwidth = alignment.getWidth() + 1;
1805 AlignmentI pastedal = alignment; // preserve pasted alignment object
1806 // Add pasted sequences and dataset into existing alignment.
1807 alignment = viewport.getAlignment();
1808 alwidth = alignment.getWidth() + 1;
1809 // decide if we need to import sequences from an existing dataset
1810 boolean importDs = Desktop.jalviewClipboard != null
1811 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1812 // importDs==true instructs us to copy over new dataset sequences from
1813 // an existing alignment
1814 Vector newDs = (importDs) ? new Vector() : null; // used to create
1815 // minimum dataset set
1817 for (int i = 0; i < sequences.length; i++)
1821 newDs.addElement(null);
1823 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1825 if (importDs && ds != null)
1827 if (!newDs.contains(ds))
1829 newDs.setElementAt(ds, i);
1830 ds = new Sequence(ds);
1831 // update with new dataset sequence
1832 sequences[i].setDatasetSequence(ds);
1836 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1841 // copy and derive new dataset sequence
1842 sequences[i] = sequences[i].deriveSequence();
1843 alignment.getDataset().addSequence(
1844 sequences[i].getDatasetSequence());
1845 // TODO: avoid creation of duplicate dataset sequences with a
1846 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1848 alignment.addSequence(sequences[i]); // merges dataset
1852 newDs.clear(); // tidy up
1854 if (alignment.getAlignmentAnnotation() != null)
1856 for (AlignmentAnnotation alan : alignment
1857 .getAlignmentAnnotation())
1859 if (alan.graphGroup > fgroup)
1861 fgroup = alan.graphGroup;
1865 if (pastedal.getAlignmentAnnotation() != null)
1867 // Add any annotation attached to alignment.
1868 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1869 for (int i = 0; i < alann.length; i++)
1871 annotationAdded = true;
1872 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1874 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1875 if (newann.graphGroup > -1)
1877 if (newGraphGroups.size() <= newann.graphGroup
1878 || newGraphGroups.get(newann.graphGroup) == null)
1880 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1882 newGraphGroups.add(q, null);
1884 newGraphGroups.set(newann.graphGroup, new Integer(
1887 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1891 newann.padAnnotation(alwidth);
1892 alignment.addAnnotation(newann);
1902 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1903 sequences, 0, alignment.getWidth(), alignment));
1905 // Add any annotations attached to sequences
1906 for (int i = 0; i < sequences.length; i++)
1908 if (sequences[i].getAnnotation() != null)
1910 AlignmentAnnotation newann;
1911 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1913 annotationAdded = true;
1914 newann = sequences[i].getAnnotation()[a];
1915 newann.adjustForAlignment();
1916 newann.padAnnotation(alwidth);
1917 if (newann.graphGroup > -1)
1919 if (newann.graphGroup > -1)
1921 if (newGraphGroups.size() <= newann.graphGroup
1922 || newGraphGroups.get(newann.graphGroup) == null)
1924 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1926 newGraphGroups.add(q, null);
1928 newGraphGroups.set(newann.graphGroup, new Integer(
1931 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1935 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1940 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1947 // propagate alignment changed.
1948 viewport.setEndSeq(alignment.getHeight());
1949 if (annotationAdded)
1951 // Duplicate sequence annotation in all views.
1952 AlignmentI[] alview = this.getViewAlignments();
1953 for (int i = 0; i < sequences.length; i++)
1955 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1958 for (int avnum = 0; avnum < alview.length; avnum++)
1960 if (alview[avnum] != alignment)
1962 // duplicate in a view other than the one with input focus
1963 int avwidth = alview[avnum].getWidth() + 1;
1964 // this relies on sann being preserved after we
1965 // modify the sequence's annotation array for each duplication
1966 for (int a = 0; a < sann.length; a++)
1968 AlignmentAnnotation newann = new AlignmentAnnotation(
1970 sequences[i].addAlignmentAnnotation(newann);
1971 newann.padAnnotation(avwidth);
1972 alview[avnum].addAnnotation(newann); // annotation was
1973 // duplicated earlier
1974 // TODO JAL-1145 graphGroups are not updated for sequence
1975 // annotation added to several views. This may cause
1977 alview[avnum].setAnnotationIndex(newann, a);
1982 buildSortByAnnotationScoresMenu();
1984 viewport.firePropertyChange("alignment", null,
1985 alignment.getSequences());
1986 if (alignPanels != null)
1988 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
1990 ap.validateAnnotationDimensions(false);
1995 alignPanel.validateAnnotationDimensions(false);
2001 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2003 String newtitle = new String("Copied sequences");
2005 if (Desktop.jalviewClipboard != null
2006 && Desktop.jalviewClipboard[2] != null)
2008 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2009 for (int i = 0; i < hc.size(); i++)
2011 int[] region = (int[]) hc.elementAt(i);
2012 af.viewport.hideColumns(region[0], region[1]);
2016 // >>>This is a fix for the moment, until a better solution is
2018 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2020 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2022 // TODO: maintain provenance of an alignment, rather than just make the
2023 // title a concatenation of operations.
2026 if (title.startsWith("Copied sequences"))
2032 newtitle = newtitle.concat("- from " + title);
2037 newtitle = new String("Pasted sequences");
2040 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2045 } catch (Exception ex)
2047 ex.printStackTrace();
2048 System.out.println("Exception whilst pasting: " + ex);
2049 // could be anything being pasted in here
2061 protected void cut_actionPerformed(ActionEvent e)
2063 copy_actionPerformed(null);
2064 delete_actionPerformed(null);
2074 protected void delete_actionPerformed(ActionEvent evt)
2077 SequenceGroup sg = viewport.getSelectionGroup();
2083 Vector seqs = new Vector();
2085 for (int i = 0; i < sg.getSize(); i++)
2087 seq = sg.getSequenceAt(i);
2088 seqs.addElement(seq);
2091 // If the cut affects all sequences, remove highlighted columns
2092 if (sg.getSize() == viewport.getAlignment().getHeight())
2094 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2095 sg.getEndRes() + 1);
2098 SequenceI[] cut = new SequenceI[seqs.size()];
2099 for (int i = 0; i < seqs.size(); i++)
2101 cut[i] = (SequenceI) seqs.elementAt(i);
2105 * //ADD HISTORY ITEM
2107 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2108 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2109 viewport.getAlignment()));
2111 viewport.setSelectionGroup(null);
2112 viewport.sendSelection();
2113 viewport.getAlignment().deleteGroup(sg);
2115 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2117 if (viewport.getAlignment().getHeight() < 1)
2121 this.setClosed(true);
2122 } catch (Exception ex)
2135 protected void deleteGroups_actionPerformed(ActionEvent e)
2137 viewport.getAlignment().deleteAllGroups();
2138 viewport.sequenceColours = null;
2139 viewport.setSelectionGroup(null);
2140 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2141 alignPanel.updateAnnotation();
2142 alignPanel.paintAlignment(true);
2152 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2154 SequenceGroup sg = new SequenceGroup();
2156 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2158 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2161 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2162 viewport.setSelectionGroup(sg);
2163 viewport.sendSelection();
2164 alignPanel.paintAlignment(true);
2165 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2175 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2177 if (viewport.cursorMode)
2179 alignPanel.seqPanel.keyboardNo1 = null;
2180 alignPanel.seqPanel.keyboardNo2 = null;
2182 viewport.setSelectionGroup(null);
2183 viewport.getColumnSelection().clear();
2184 viewport.setSelectionGroup(null);
2185 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2186 alignPanel.idPanel.idCanvas.searchResults = null;
2187 alignPanel.paintAlignment(true);
2188 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2189 viewport.sendSelection();
2199 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2201 SequenceGroup sg = viewport.getSelectionGroup();
2205 selectAllSequenceMenuItem_actionPerformed(null);
2210 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2212 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2215 alignPanel.paintAlignment(true);
2216 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2217 viewport.sendSelection();
2221 public void invertColSel_actionPerformed(ActionEvent e)
2223 viewport.invertColumnSelection();
2224 alignPanel.paintAlignment(true);
2225 viewport.sendSelection();
2235 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2237 trimAlignment(true);
2247 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2249 trimAlignment(false);
2252 void trimAlignment(boolean trimLeft)
2254 ColumnSelection colSel = viewport.getColumnSelection();
2257 if (colSel.size() > 0)
2261 column = colSel.getMin();
2265 column = colSel.getMax();
2269 if (viewport.getSelectionGroup() != null)
2271 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2272 viewport.getHiddenRepSequences());
2276 seqs = viewport.getAlignment().getSequencesArray();
2279 TrimRegionCommand trimRegion;
2282 trimRegion = new TrimRegionCommand("Remove Left",
2283 TrimRegionCommand.TRIM_LEFT, seqs, column,
2284 viewport.getAlignment(), viewport.getColumnSelection(),
2285 viewport.getSelectionGroup());
2286 viewport.setStartRes(0);
2290 trimRegion = new TrimRegionCommand("Remove Right",
2291 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2292 viewport.getAlignment(), viewport.getColumnSelection(),
2293 viewport.getSelectionGroup());
2296 statusBar.setText(MessageManager.formatMessage("label.removed_columns", new String[]{Integer.valueOf(trimRegion.getSize()).toString()}));
2298 addHistoryItem(trimRegion);
2300 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2302 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2303 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2305 viewport.getAlignment().deleteGroup(sg);
2309 viewport.firePropertyChange("alignment", null, viewport
2310 .getAlignment().getSequences());
2321 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2323 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2326 if (viewport.getSelectionGroup() != null)
2328 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2329 viewport.getHiddenRepSequences());
2330 start = viewport.getSelectionGroup().getStartRes();
2331 end = viewport.getSelectionGroup().getEndRes();
2335 seqs = viewport.getAlignment().getSequencesArray();
2338 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2339 "Remove Gapped Columns", seqs, start, end,
2340 viewport.getAlignment());
2342 addHistoryItem(removeGapCols);
2344 statusBar.setText(MessageManager.formatMessage("label.removed_empty_columns", new String[]{Integer.valueOf(removeGapCols.getSize()).toString()}));
2346 // This is to maintain viewport position on first residue
2347 // of first sequence
2348 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2349 int startRes = seq.findPosition(viewport.startRes);
2350 // ShiftList shifts;
2351 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2352 // edit.alColumnChanges=shifts.getInverse();
2353 // if (viewport.hasHiddenColumns)
2354 // viewport.getColumnSelection().compensateForEdits(shifts);
2355 viewport.setStartRes(seq.findIndex(startRes) - 1);
2356 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2368 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2370 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2373 if (viewport.getSelectionGroup() != null)
2375 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2376 viewport.getHiddenRepSequences());
2377 start = viewport.getSelectionGroup().getStartRes();
2378 end = viewport.getSelectionGroup().getEndRes();
2382 seqs = viewport.getAlignment().getSequencesArray();
2385 // This is to maintain viewport position on first residue
2386 // of first sequence
2387 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2388 int startRes = seq.findPosition(viewport.startRes);
2390 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2391 viewport.getAlignment()));
2393 viewport.setStartRes(seq.findIndex(startRes) - 1);
2395 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2407 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2409 viewport.setPadGaps(padGapsMenuitem.isSelected());
2410 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2416 // if (justifySeqs>0)
2418 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2431 public void findMenuItem_actionPerformed(ActionEvent e)
2437 public void newView_actionPerformed(ActionEvent e)
2444 * @param copyAnnotation
2445 * if true then duplicate all annnotation, groups and settings
2446 * @return new alignment panel, already displayed.
2448 public AlignmentPanel newView(boolean copyAnnotation)
2450 return newView(null, copyAnnotation);
2456 * title of newly created view
2457 * @return new alignment panel, already displayed.
2459 public AlignmentPanel newView(String viewTitle)
2461 return newView(viewTitle, true);
2467 * title of newly created view
2468 * @param copyAnnotation
2469 * if true then duplicate all annnotation, groups and settings
2470 * @return new alignment panel, already displayed.
2472 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2474 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2476 if (!copyAnnotation)
2478 // just remove all the current annotation except for the automatic stuff
2479 newap.av.getAlignment().deleteAllGroups();
2480 for (AlignmentAnnotation alan : newap.av.getAlignment()
2481 .getAlignmentAnnotation())
2483 if (!alan.autoCalculated)
2485 newap.av.getAlignment().deleteAnnotation(alan);
2491 newap.av.gatherViewsHere = false;
2493 if (viewport.viewName == null)
2495 viewport.viewName = "Original";
2498 newap.av.historyList = viewport.historyList;
2499 newap.av.redoList = viewport.redoList;
2501 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2502 // make sure the new view has a unique name - this is essential for Jalview
2504 boolean addFirstIndex = false;
2505 if (viewTitle == null || viewTitle.trim().length() == 0)
2508 addFirstIndex = true;
2512 index = 1;// we count from 1 if given a specific name
2514 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2515 Vector comps = (Vector) PaintRefresher.components.get(viewport
2516 .getSequenceSetId());
2517 Vector existingNames = new Vector();
2518 for (int i = 0; i < comps.size(); i++)
2520 if (comps.elementAt(i) instanceof AlignmentPanel)
2522 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2523 if (!existingNames.contains(ap.av.viewName))
2525 existingNames.addElement(ap.av.viewName);
2530 while (existingNames.contains(newViewName))
2532 newViewName = viewTitle + " " + (++index);
2535 newap.av.viewName = newViewName;
2537 addAlignmentPanel(newap, true);
2539 if (alignPanels.size() == 2)
2541 viewport.gatherViewsHere = true;
2543 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2548 public void expandViews_actionPerformed(ActionEvent e)
2550 Desktop.instance.explodeViews(this);
2554 public void gatherViews_actionPerformed(ActionEvent e)
2556 Desktop.instance.gatherViews(this);
2566 public void font_actionPerformed(ActionEvent e)
2568 new FontChooser(alignPanel);
2578 protected void seqLimit_actionPerformed(ActionEvent e)
2580 viewport.setShowJVSuffix(seqLimits.isSelected());
2582 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2583 .calculateIdWidth());
2584 alignPanel.paintAlignment(true);
2588 public void idRightAlign_actionPerformed(ActionEvent e)
2590 viewport.rightAlignIds = idRightAlign.isSelected();
2591 alignPanel.paintAlignment(true);
2595 public void centreColumnLabels_actionPerformed(ActionEvent e)
2597 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2598 alignPanel.paintAlignment(true);
2604 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2607 protected void followHighlight_actionPerformed()
2609 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2611 alignPanel.scrollToPosition(
2612 alignPanel.seqPanel.seqCanvas.searchResults, false);
2623 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2625 viewport.setColourText(colourTextMenuItem.isSelected());
2626 alignPanel.paintAlignment(true);
2636 public void wrapMenuItem_actionPerformed(ActionEvent e)
2638 scaleAbove.setVisible(wrapMenuItem.isSelected());
2639 scaleLeft.setVisible(wrapMenuItem.isSelected());
2640 scaleRight.setVisible(wrapMenuItem.isSelected());
2641 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2642 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2646 public void showAllSeqs_actionPerformed(ActionEvent e)
2648 viewport.showAllHiddenSeqs();
2652 public void showAllColumns_actionPerformed(ActionEvent e)
2654 viewport.showAllHiddenColumns();
2659 public void hideSelSequences_actionPerformed(ActionEvent e)
2661 viewport.hideAllSelectedSeqs();
2662 alignPanel.paintAlignment(true);
2666 * called by key handler and the hide all/show all menu items
2671 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2674 boolean hide = false;
2675 SequenceGroup sg = viewport.getSelectionGroup();
2676 if (!toggleSeqs && !toggleCols)
2678 // Hide everything by the current selection - this is a hack - we do the
2679 // invert and then hide
2680 // first check that there will be visible columns after the invert.
2681 if ((viewport.getColumnSelection() != null
2682 && viewport.getColumnSelection().getSelected() != null && viewport
2683 .getColumnSelection().getSelected().size() > 0)
2684 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2687 // now invert the sequence set, if required - empty selection implies
2688 // that no hiding is required.
2691 invertSequenceMenuItem_actionPerformed(null);
2692 sg = viewport.getSelectionGroup();
2696 viewport.expandColSelection(sg, true);
2697 // finally invert the column selection and get the new sequence
2699 invertColSel_actionPerformed(null);
2706 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2708 hideSelSequences_actionPerformed(null);
2711 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2714 showAllSeqs_actionPerformed(null);
2720 if (viewport.getColumnSelection().getSelected().size() > 0)
2722 hideSelColumns_actionPerformed(null);
2725 viewport.setSelectionGroup(sg);
2730 showAllColumns_actionPerformed(null);
2739 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2740 * event.ActionEvent)
2743 public void hideAllButSelection_actionPerformed(ActionEvent e)
2745 toggleHiddenRegions(false, false);
2752 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2756 public void hideAllSelection_actionPerformed(ActionEvent e)
2758 SequenceGroup sg = viewport.getSelectionGroup();
2759 viewport.expandColSelection(sg, false);
2760 viewport.hideAllSelectedSeqs();
2761 viewport.hideSelectedColumns();
2762 alignPanel.paintAlignment(true);
2769 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2773 public void showAllhidden_actionPerformed(ActionEvent e)
2775 viewport.showAllHiddenColumns();
2776 viewport.showAllHiddenSeqs();
2777 alignPanel.paintAlignment(true);
2781 public void hideSelColumns_actionPerformed(ActionEvent e)
2783 viewport.hideSelectedColumns();
2784 alignPanel.paintAlignment(true);
2788 public void hiddenMarkers_actionPerformed(ActionEvent e)
2790 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2801 protected void scaleAbove_actionPerformed(ActionEvent e)
2803 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2804 alignPanel.paintAlignment(true);
2814 protected void scaleLeft_actionPerformed(ActionEvent e)
2816 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2817 alignPanel.paintAlignment(true);
2827 protected void scaleRight_actionPerformed(ActionEvent e)
2829 viewport.setScaleRightWrapped(scaleRight.isSelected());
2830 alignPanel.paintAlignment(true);
2840 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2842 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2843 alignPanel.paintAlignment(true);
2853 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2855 viewport.setShowText(viewTextMenuItem.isSelected());
2856 alignPanel.paintAlignment(true);
2866 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2868 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2869 alignPanel.paintAlignment(true);
2872 public FeatureSettings featureSettings;
2875 public void featureSettings_actionPerformed(ActionEvent e)
2877 if (featureSettings != null)
2879 featureSettings.close();
2880 featureSettings = null;
2882 if (!showSeqFeatures.isSelected())
2884 // make sure features are actually displayed
2885 showSeqFeatures.setSelected(true);
2886 showSeqFeatures_actionPerformed(null);
2888 featureSettings = new FeatureSettings(this);
2892 * Set or clear 'Show Sequence Features'
2898 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2900 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2901 alignPanel.paintAlignment(true);
2902 if (alignPanel.getOverviewPanel() != null)
2904 alignPanel.getOverviewPanel().updateOverviewImage();
2909 * Set or clear 'Show Sequence Features'
2915 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2917 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2919 if (viewport.getShowSequenceFeaturesHeight())
2921 // ensure we're actually displaying features
2922 viewport.setShowSequenceFeatures(true);
2923 showSeqFeatures.setSelected(true);
2925 alignPanel.paintAlignment(true);
2926 if (alignPanel.getOverviewPanel() != null)
2928 alignPanel.getOverviewPanel().updateOverviewImage();
2939 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2941 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2942 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2946 public void alignmentProperties()
2948 JEditorPane editPane = new JEditorPane("text/html", "");
2949 editPane.setEditable(false);
2950 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2952 editPane.setText(MessageManager.formatMessage("label.html_content", new String[]{contents.toString()}));
2953 JInternalFrame frame = new JInternalFrame();
2954 frame.getContentPane().add(new JScrollPane(editPane));
2956 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2957 + getTitle(), 500, 400);
2967 public void overviewMenuItem_actionPerformed(ActionEvent e)
2969 if (alignPanel.overviewPanel != null)
2974 JInternalFrame frame = new JInternalFrame();
2975 OverviewPanel overview = new OverviewPanel(alignPanel);
2976 frame.setContentPane(overview);
2977 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2978 frame.getWidth(), frame.getHeight());
2980 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2981 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2984 public void internalFrameClosed(
2985 javax.swing.event.InternalFrameEvent evt)
2987 alignPanel.setOverviewPanel(null);
2991 alignPanel.setOverviewPanel(overview);
2995 public void textColour_actionPerformed(ActionEvent e)
2997 new TextColourChooser().chooseColour(alignPanel, null);
3007 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3019 public void clustalColour_actionPerformed(ActionEvent e)
3021 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3022 viewport.getHiddenRepSequences()));
3032 public void zappoColour_actionPerformed(ActionEvent e)
3034 changeColour(new ZappoColourScheme());
3044 public void taylorColour_actionPerformed(ActionEvent e)
3046 changeColour(new TaylorColourScheme());
3056 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3058 changeColour(new HydrophobicColourScheme());
3068 public void helixColour_actionPerformed(ActionEvent e)
3070 changeColour(new HelixColourScheme());
3080 public void strandColour_actionPerformed(ActionEvent e)
3082 changeColour(new StrandColourScheme());
3092 public void turnColour_actionPerformed(ActionEvent e)
3094 changeColour(new TurnColourScheme());
3104 public void buriedColour_actionPerformed(ActionEvent e)
3106 changeColour(new BuriedColourScheme());
3116 public void nucleotideColour_actionPerformed(ActionEvent e)
3118 changeColour(new NucleotideColourScheme());
3122 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3124 changeColour(new PurinePyrimidineColourScheme());
3128 * public void covariationColour_actionPerformed(ActionEvent e) {
3130 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3134 public void annotationColour_actionPerformed(ActionEvent e)
3136 new AnnotationColourChooser(viewport, alignPanel);
3140 public void rnahelicesColour_actionPerformed(ActionEvent e)
3142 new RNAHelicesColourChooser(viewport, alignPanel);
3152 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3154 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3163 public void changeColour(ColourSchemeI cs)
3165 // TODO: compare with applet and pull up to model method
3170 if (viewport.getAbovePIDThreshold())
3172 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3175 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3177 viewport.setGlobalColourScheme(cs);
3181 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3184 if (viewport.getConservationSelected())
3187 Alignment al = (Alignment) viewport.getAlignment();
3188 Conservation c = new Conservation("All",
3189 ResidueProperties.propHash, 3, al.getSequences(), 0,
3193 c.verdict(false, viewport.getConsPercGaps());
3195 cs.setConservation(c);
3197 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3202 cs.setConservation(null);
3205 cs.setConsensus(viewport.getSequenceConsensusHash());
3208 viewport.setGlobalColourScheme(cs);
3210 if (viewport.getColourAppliesToAllGroups())
3213 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3221 if (cs instanceof ClustalxColourScheme)
3223 sg.cs = new ClustalxColourScheme(sg,
3224 viewport.getHiddenRepSequences());
3226 else if (cs instanceof UserColourScheme)
3228 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3234 sg.cs = cs.getClass().newInstance();
3235 } catch (Exception ex)
3240 if (viewport.getAbovePIDThreshold()
3241 || cs instanceof PIDColourScheme
3242 || cs instanceof Blosum62ColourScheme)
3244 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3246 sg.cs.setConsensus(AAFrequency.calculate(
3247 sg.getSequences(viewport.getHiddenRepSequences()),
3248 sg.getStartRes(), sg.getEndRes() + 1));
3252 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3255 if (viewport.getConservationSelected())
3257 Conservation c = new Conservation("Group",
3258 ResidueProperties.propHash, 3, sg.getSequences(viewport
3259 .getHiddenRepSequences()), sg.getStartRes(),
3260 sg.getEndRes() + 1);
3262 c.verdict(false, viewport.getConsPercGaps());
3263 sg.cs.setConservation(c);
3267 sg.cs.setConservation(null);
3272 if (alignPanel.getOverviewPanel() != null)
3274 alignPanel.getOverviewPanel().updateOverviewImage();
3277 alignPanel.paintAlignment(true);
3287 protected void modifyPID_actionPerformed(ActionEvent e)
3289 if (viewport.getAbovePIDThreshold()
3290 && viewport.getGlobalColourScheme() != null)
3292 SliderPanel.setPIDSliderSource(alignPanel,
3293 viewport.getGlobalColourScheme(), "Background");
3294 SliderPanel.showPIDSlider();
3305 protected void modifyConservation_actionPerformed(ActionEvent e)
3307 if (viewport.getConservationSelected()
3308 && viewport.getGlobalColourScheme() != null)
3310 SliderPanel.setConservationSlider(alignPanel,
3311 viewport.getGlobalColourScheme(), "Background");
3312 SliderPanel.showConservationSlider();
3323 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3325 viewport.setConservationSelected(conservationMenuItem.isSelected());
3327 viewport.setAbovePIDThreshold(false);
3328 abovePIDThreshold.setSelected(false);
3330 changeColour(viewport.getGlobalColourScheme());
3332 modifyConservation_actionPerformed(null);
3342 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3344 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3346 conservationMenuItem.setSelected(false);
3347 viewport.setConservationSelected(false);
3349 changeColour(viewport.getGlobalColourScheme());
3351 modifyPID_actionPerformed(null);
3361 public void userDefinedColour_actionPerformed(ActionEvent e)
3363 if (e.getActionCommand().equals("User Defined..."))
3365 new UserDefinedColours(alignPanel, null);
3369 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3370 .getUserColourSchemes().get(e.getActionCommand());
3376 public void updateUserColourMenu()
3379 Component[] menuItems = colourMenu.getMenuComponents();
3380 int i, iSize = menuItems.length;
3381 for (i = 0; i < iSize; i++)
3383 if (menuItems[i].getName() != null
3384 && menuItems[i].getName().equals("USER_DEFINED"))
3386 colourMenu.remove(menuItems[i]);
3390 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3392 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3393 .getUserColourSchemes().keys();
3395 while (userColours.hasMoreElements())
3397 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3398 userColours.nextElement().toString());
3399 radioItem.setName("USER_DEFINED");
3400 radioItem.addMouseListener(new MouseAdapter()
3403 public void mousePressed(MouseEvent evt)
3405 if (evt.isControlDown()
3406 || SwingUtilities.isRightMouseButton(evt))
3408 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3410 int option = JOptionPane.showInternalConfirmDialog(
3411 jalview.gui.Desktop.desktop,
3412 "Remove from default list?",
3413 "Remove user defined colour",
3414 JOptionPane.YES_NO_OPTION);
3415 if (option == JOptionPane.YES_OPTION)
3417 jalview.gui.UserDefinedColours
3418 .removeColourFromDefaults(radioItem.getText());
3419 colourMenu.remove(radioItem);
3423 radioItem.addActionListener(new ActionListener()
3426 public void actionPerformed(ActionEvent evt)
3428 userDefinedColour_actionPerformed(evt);
3435 radioItem.addActionListener(new ActionListener()
3438 public void actionPerformed(ActionEvent evt)
3440 userDefinedColour_actionPerformed(evt);
3444 colourMenu.insert(radioItem, 15);
3445 colours.add(radioItem);
3457 public void PIDColour_actionPerformed(ActionEvent e)
3459 changeColour(new PIDColourScheme());
3469 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3471 changeColour(new Blosum62ColourScheme());
3481 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3483 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3484 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3485 .getAlignment().getSequenceAt(0), null);
3486 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3487 viewport.getAlignment()));
3488 alignPanel.paintAlignment(true);
3498 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3500 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3501 AlignmentSorter.sortByID(viewport.getAlignment());
3502 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3503 viewport.getAlignment()));
3504 alignPanel.paintAlignment(true);
3514 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3516 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3517 AlignmentSorter.sortByLength(viewport.getAlignment());
3518 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3519 viewport.getAlignment()));
3520 alignPanel.paintAlignment(true);
3530 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3532 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3533 AlignmentSorter.sortByGroup(viewport.getAlignment());
3534 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3535 viewport.getAlignment()));
3537 alignPanel.paintAlignment(true);
3547 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3549 new RedundancyPanel(alignPanel, this);
3559 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3561 if ((viewport.getSelectionGroup() == null)
3562 || (viewport.getSelectionGroup().getSize() < 2))
3564 JOptionPane.showInternalMessageDialog(this,
3565 "You must select at least 2 sequences.", "Invalid Selection",
3566 JOptionPane.WARNING_MESSAGE);
3570 JInternalFrame frame = new JInternalFrame();
3571 frame.setContentPane(new PairwiseAlignPanel(viewport));
3572 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3583 public void PCAMenuItem_actionPerformed(ActionEvent e)
3585 if (((viewport.getSelectionGroup() != null)
3586 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3587 .getSelectionGroup().getSize() > 0))
3588 || (viewport.getAlignment().getHeight() < 4))
3590 JOptionPane.showInternalMessageDialog(this,
3591 "Principal component analysis must take\n"
3592 + "at least 4 input sequences.",
3593 "Sequence selection insufficient",
3594 JOptionPane.WARNING_MESSAGE);
3599 new PCAPanel(alignPanel);
3603 public void autoCalculate_actionPerformed(ActionEvent e)
3605 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3606 if (viewport.autoCalculateConsensus)
3608 viewport.firePropertyChange("alignment", null, viewport
3609 .getAlignment().getSequences());
3614 public void sortByTreeOption_actionPerformed(ActionEvent e)
3616 viewport.sortByTree = sortByTree.isSelected();
3620 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3622 viewport.followSelection = listenToViewSelections.isSelected();
3632 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3634 NewTreePanel("AV", "PID", "Average distance tree using PID");
3644 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3646 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3656 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3658 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3668 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3670 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3683 void NewTreePanel(String type, String pwType, String title)
3687 if (viewport.getSelectionGroup() != null
3688 && viewport.getSelectionGroup().getSize() > 0)
3690 if (viewport.getSelectionGroup().getSize() < 3)
3695 "You need to have more than two sequences selected to build a tree!",
3696 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3700 SequenceGroup sg = viewport.getSelectionGroup();
3702 /* Decide if the selection is a column region */
3703 for (SequenceI _s : sg.getSequences())
3705 if (_s.getLength() < sg.getEndRes())
3710 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3711 + "Try using the Pad function in the edit menu,\n"
3712 + "or one of the multiple sequence alignment web services.",
3713 "Sequences in selection are not aligned",
3714 JOptionPane.WARNING_MESSAGE);
3720 title = title + " on region";
3721 tp = new TreePanel(alignPanel, type, pwType);
3725 // are the visible sequences aligned?
3726 if (!viewport.getAlignment().isAligned(false))
3731 "The sequences must be aligned before creating a tree.\n"
3732 + "Try using the Pad function in the edit menu,\n"
3733 + "or one of the multiple sequence alignment web services.",
3734 "Sequences not aligned",
3735 JOptionPane.WARNING_MESSAGE);
3740 if (viewport.getAlignment().getHeight() < 2)
3745 tp = new TreePanel(alignPanel, type, pwType);
3750 if (viewport.viewName != null)
3752 title += viewport.viewName + " of ";
3755 title += this.title;
3757 Desktop.addInternalFrame(tp, title, 600, 500);
3768 public void addSortByOrderMenuItem(String title,
3769 final AlignmentOrder order)
3771 final JMenuItem item = new JMenuItem("by " + title);
3773 item.addActionListener(new java.awt.event.ActionListener()
3776 public void actionPerformed(ActionEvent e)
3778 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3780 // TODO: JBPNote - have to map order entries to curent SequenceI
3782 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3784 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3787 alignPanel.paintAlignment(true);
3793 * Add a new sort by annotation score menu item
3796 * the menu to add the option to
3798 * the label used to retrieve scores for each sequence on the
3801 public void addSortByAnnotScoreMenuItem(JMenu sort,
3802 final String scoreLabel)
3804 final JMenuItem item = new JMenuItem(scoreLabel);
3806 item.addActionListener(new java.awt.event.ActionListener()
3809 public void actionPerformed(ActionEvent e)
3811 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3812 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3813 viewport.getAlignment());// ,viewport.getSelectionGroup());
3814 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3815 viewport.getAlignment()));
3816 alignPanel.paintAlignment(true);
3822 * last hash for alignment's annotation array - used to minimise cost of
3825 protected int _annotationScoreVectorHash;
3828 * search the alignment and rebuild the sort by annotation score submenu the
3829 * last alignment annotation vector hash is stored to minimize cost of
3830 * rebuilding in subsequence calls.
3834 public void buildSortByAnnotationScoresMenu()
3836 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3841 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3843 sortByAnnotScore.removeAll();
3844 // almost certainly a quicker way to do this - but we keep it simple
3845 Hashtable scoreSorts = new Hashtable();
3846 AlignmentAnnotation aann[];
3847 for (SequenceI sqa : viewport.getAlignment().getSequences())
3849 aann = sqa.getAnnotation();
3850 for (int i = 0; aann != null && i < aann.length; i++)
3852 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3854 scoreSorts.put(aann[i].label, aann[i].label);
3858 Enumeration labels = scoreSorts.keys();
3859 while (labels.hasMoreElements())
3861 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3862 (String) labels.nextElement());
3864 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3867 _annotationScoreVectorHash = viewport.getAlignment()
3868 .getAlignmentAnnotation().hashCode();
3873 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3874 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3875 * call. Listeners are added to remove the menu item when the treePanel is
3876 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3880 * Displayed tree window.
3882 * SortBy menu item title.
3885 public void buildTreeMenu()
3887 sortByTreeMenu.removeAll();
3889 Vector comps = (Vector) PaintRefresher.components.get(viewport
3890 .getSequenceSetId());
3891 Vector treePanels = new Vector();
3892 int i, iSize = comps.size();
3893 for (i = 0; i < iSize; i++)
3895 if (comps.elementAt(i) instanceof TreePanel)
3897 treePanels.add(comps.elementAt(i));
3901 iSize = treePanels.size();
3905 sortByTreeMenu.setVisible(false);
3909 sortByTreeMenu.setVisible(true);
3911 for (i = 0; i < treePanels.size(); i++)
3913 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3914 final JMenuItem item = new JMenuItem(tp.getTitle());
3915 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3916 item.addActionListener(new java.awt.event.ActionListener()
3919 public void actionPerformed(ActionEvent e)
3921 tp.sortByTree_actionPerformed(null);
3922 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3927 sortByTreeMenu.add(item);
3931 public boolean sortBy(AlignmentOrder alorder, String undoname)
3933 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3934 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3935 if (undoname != null)
3937 addHistoryItem(new OrderCommand(undoname, oldOrder,
3938 viewport.getAlignment()));
3940 alignPanel.paintAlignment(true);
3945 * Work out whether the whole set of sequences or just the selected set will
3946 * be submitted for multiple alignment.
3949 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3951 // Now, check we have enough sequences
3952 AlignmentView msa = null;
3954 if ((viewport.getSelectionGroup() != null)
3955 && (viewport.getSelectionGroup().getSize() > 1))
3957 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3958 // some common interface!
3960 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3961 * SequenceI[sz = seqs.getSize(false)];
3963 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3964 * seqs.getSequenceAt(i); }
3966 msa = viewport.getAlignmentView(true);
3971 * Vector seqs = viewport.getAlignment().getSequences();
3973 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3975 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3976 * seqs.elementAt(i); } }
3978 msa = viewport.getAlignmentView(false);
3984 * Decides what is submitted to a secondary structure prediction service: the
3985 * first sequence in the alignment, or in the current selection, or, if the
3986 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3987 * region or the whole alignment. (where the first sequence in the set is the
3988 * one that the prediction will be for).
3990 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3992 AlignmentView seqs = null;
3994 if ((viewport.getSelectionGroup() != null)
3995 && (viewport.getSelectionGroup().getSize() > 0))
3997 seqs = viewport.getAlignmentView(true);
4001 seqs = viewport.getAlignmentView(false);
4003 // limit sequences - JBPNote in future - could spawn multiple prediction
4005 // TODO: viewport.getAlignment().isAligned is a global state - the local
4006 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4007 if (!viewport.getAlignment().isAligned(false))
4009 seqs.setSequences(new SeqCigar[]
4010 { seqs.getSequences()[0] });
4011 // TODO: if seqs.getSequences().length>1 then should really have warned
4025 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4027 // Pick the tree file
4028 JalviewFileChooser chooser = new JalviewFileChooser(
4029 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4030 chooser.setFileView(new JalviewFileView());
4031 chooser.setDialogTitle("Select a newick-like tree file");
4032 chooser.setToolTipText("Load a tree file");
4034 int value = chooser.showOpenDialog(null);
4036 if (value == JalviewFileChooser.APPROVE_OPTION)
4038 String choice = chooser.getSelectedFile().getPath();
4039 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4040 jalview.io.NewickFile fin = null;
4043 fin = new jalview.io.NewickFile(choice, "File");
4044 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4045 } catch (Exception ex)
4047 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4048 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
4049 ex.printStackTrace();
4051 if (fin != null && fin.hasWarningMessage())
4053 JOptionPane.showMessageDialog(Desktop.desktop,
4054 fin.getWarningMessage(), "Possible problem with tree file",
4055 JOptionPane.WARNING_MESSAGE);
4061 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4063 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4066 public TreePanel ShowNewickTree(NewickFile nf, String title)
4068 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4071 public TreePanel ShowNewickTree(NewickFile nf, String title,
4072 AlignmentView input)
4074 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4077 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4078 int h, int x, int y)
4080 return ShowNewickTree(nf, title, null, w, h, x, y);
4084 * Add a treeviewer for the tree extracted from a newick file object to the
4085 * current alignment view
4092 * Associated alignment input data (or null)
4101 * @return TreePanel handle
4103 public TreePanel ShowNewickTree(NewickFile nf, String title,
4104 AlignmentView input, int w, int h, int x, int y)
4106 TreePanel tp = null;
4112 if (nf.getTree() != null)
4114 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4120 tp.setLocation(x, y);
4123 Desktop.addInternalFrame(tp, title, w, h);
4125 } catch (Exception ex)
4127 ex.printStackTrace();
4133 private boolean buildingMenu = false;
4136 * Generates menu items and listener event actions for web service clients
4139 public void BuildWebServiceMenu()
4141 while (buildingMenu)
4145 System.err.println("Waiting for building menu to finish.");
4147 } catch (Exception e)
4152 final AlignFrame me = this;
4153 buildingMenu = true;
4154 new Thread(new Runnable()
4161 System.err.println("Building ws menu again "
4162 + Thread.currentThread());
4163 // TODO: add support for context dependent disabling of services based
4165 // alignment and current selection
4166 // TODO: add additional serviceHandle parameter to specify abstract
4168 // class independently of AbstractName
4169 // TODO: add in rediscovery GUI function to restart discoverer
4170 // TODO: group services by location as well as function and/or
4172 // object broker mechanism.
4173 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4174 final IProgressIndicator af = me;
4175 final JMenu msawsmenu = new JMenu("Alignment");
4176 final JMenu secstrmenu = new JMenu(
4177 "Secondary Structure Prediction");
4178 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4179 final JMenu analymenu = new JMenu("Analysis");
4180 final JMenu dismenu = new JMenu("Protein Disorder");
4181 // JAL-940 - only show secondary structure prediction services from
4182 // the legacy server
4183 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4185 Discoverer.services != null && (Discoverer.services.size() > 0))
4187 // TODO: refactor to allow list of AbstractName/Handler bindings to
4189 // stored or retrieved from elsewhere
4190 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4191 Vector secstrpr = (Vector) Discoverer.services
4193 Vector seqsrch = null; // (Vector)
4194 // Discoverer.services.get("SeqSearch");
4195 // TODO: move GUI generation code onto service implementation - so a
4196 // client instance attaches itself to the GUI with method call like
4197 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4201 // Add any Multiple Sequence Alignment Services
4202 for (int i = 0, j = msaws.size(); i < j; i++)
4204 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4206 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4207 .getServiceClient(sh);
4208 impl.attachWSMenuEntry(msawsmenu, me);
4212 if (secstrpr != null)
4214 // Add any secondary structure prediction services
4215 for (int i = 0, j = secstrpr.size(); i < j; i++)
4217 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4219 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4220 .getServiceClient(sh);
4221 impl.attachWSMenuEntry(secstrmenu, me);
4224 if (seqsrch != null)
4226 // Add any sequence search services
4227 for (int i = 0, j = seqsrch.size(); i < j; i++)
4229 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4231 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4232 .getServiceClient(sh);
4233 impl.attachWSMenuEntry(seqsrchmenu, me);
4238 // Add all submenus in the order they should appear on the web
4240 wsmenu.add(msawsmenu);
4241 wsmenu.add(secstrmenu);
4242 wsmenu.add(dismenu);
4243 wsmenu.add(analymenu);
4244 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4245 // submens.add(msawsmenu);
4246 // submens.add(secstrmenu);
4247 // submens.add(dismenu);
4248 // submens.add(analymenu);
4250 // No search services yet
4251 // wsmenu.add(seqsrchmenu);
4253 javax.swing.SwingUtilities.invokeLater(new Runnable()
4260 webService.removeAll();
4261 // first, add discovered services onto the webservices menu
4262 if (wsmenu.size() > 0)
4264 for (int i = 0, j = wsmenu.size(); i < j; i++)
4266 webService.add(wsmenu.get(i));
4271 webService.add(me.webServiceNoServices);
4273 // TODO: move into separate menu builder class.
4274 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4276 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4277 if (jws2servs != null)
4279 if (jws2servs.hasServices())
4281 jws2servs.attachWSMenuEntry(webService, me);
4283 if (jws2servs.isRunning())
4285 JMenuItem tm = new JMenuItem(
4286 "Still discovering JABA Services");
4287 tm.setEnabled(false);
4293 build_urlServiceMenu(me.webService);
4294 build_fetchdbmenu(webService);
4295 for (JMenu item : wsmenu)
4297 if (item.getItemCount() == 0)
4299 item.setEnabled(false);
4303 item.setEnabled(true);
4306 } catch (Exception e)
4309 .debug("Exception during web service menu building process.",
4315 } catch (Exception e)
4320 buildingMenu = false;
4327 * construct any groupURL type service menu entries.
4331 private void build_urlServiceMenu(JMenu webService)
4333 // TODO: remove this code when 2.7 is released
4334 // DEBUG - alignmentView
4336 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4337 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4339 * @Override public void actionPerformed(ActionEvent e) {
4340 * jalview.datamodel.AlignmentView
4341 * .testSelectionViews(af.viewport.getAlignment(),
4342 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4344 * }); webService.add(testAlView);
4346 // TODO: refactor to RestClient discoverer and merge menu entries for
4347 // rest-style services with other types of analysis/calculation service
4348 // SHmmr test client - still being implemented.
4349 // DEBUG - alignmentView
4351 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4354 client.attachWSMenuEntry(
4355 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4359 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4361 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4367 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4368 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4369 * getProperty("LAST_DIRECTORY"));
4371 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4372 * to Vamsas file"); chooser.setToolTipText("Export");
4374 * int value = chooser.showSaveDialog(this);
4376 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4377 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4378 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4379 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4382 * prototype of an automatically enabled/disabled analysis function
4385 protected void setShowProductsEnabled()
4387 SequenceI[] selection = viewport.getSequenceSelection();
4388 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4389 viewport.getAlignment().getDataset()))
4391 showProducts.setEnabled(true);
4396 showProducts.setEnabled(false);
4401 * search selection for sequence xRef products and build the show products
4406 * @return true if showProducts menu should be enabled.
4408 public boolean canShowProducts(SequenceI[] selection,
4409 boolean isRegionSelection, Alignment dataset)
4411 boolean showp = false;
4414 showProducts.removeAll();
4415 final boolean dna = viewport.getAlignment().isNucleotide();
4416 final Alignment ds = dataset;
4417 String[] ptypes = (selection == null || selection.length == 0) ? null
4418 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4420 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4421 // selection, dataset, true);
4422 final SequenceI[] sel = selection;
4423 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4426 final boolean isRegSel = isRegionSelection;
4427 final AlignFrame af = this;
4428 final String source = ptypes[t];
4429 JMenuItem xtype = new JMenuItem(ptypes[t]);
4430 xtype.addActionListener(new ActionListener()
4434 public void actionPerformed(ActionEvent e)
4436 // TODO: new thread for this call with vis-delay
4437 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4438 isRegSel, dna, source);
4442 showProducts.add(xtype);
4444 showProducts.setVisible(showp);
4445 showProducts.setEnabled(showp);
4446 } catch (Exception e)
4448 jalview.bin.Cache.log
4449 .warn("canTranslate threw an exception - please report to help@jalview.org",
4456 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4457 boolean isRegSel, boolean dna, String source)
4459 final boolean fisRegSel = isRegSel;
4460 final boolean fdna = dna;
4461 final String fsrc = source;
4462 final AlignFrame ths = this;
4463 final SequenceI[] fsel = sel;
4464 Runnable foo = new Runnable()
4470 final long sttime = System.currentTimeMillis();
4471 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4474 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4478 Alignment prods = CrossRef
4479 .findXrefSequences(fsel, fdna, fsrc, ds);
4482 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4483 for (int s = 0; s < sprods.length; s++)
4485 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4486 if (ds.getSequences() == null
4487 || !ds.getSequences().contains(
4488 sprods[s].getDatasetSequence()))
4489 ds.addSequence(sprods[s].getDatasetSequence());
4490 sprods[s].updatePDBIds();
4492 Alignment al = new Alignment(sprods);
4493 AlignedCodonFrame[] cf = prods.getCodonFrames();
4495 for (int s = 0; cf != null && s < cf.length; s++)
4497 al.addCodonFrame(cf[s]);
4500 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4502 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4503 + " for " + ((fisRegSel) ? "selected region of " : "")
4505 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4510 System.err.println("No Sequences generated for xRef type "
4513 } catch (Exception e)
4515 jalview.bin.Cache.log.error(
4516 "Exception when finding crossreferences", e);
4517 } catch (OutOfMemoryError e)
4519 new OOMWarning("whilst fetching crossreferences", e);
4522 jalview.bin.Cache.log.error("Error when finding crossreferences",
4525 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4530 Thread frunner = new Thread(foo);
4534 public boolean canShowTranslationProducts(SequenceI[] selection,
4535 AlignmentI alignment)
4540 return (jalview.analysis.Dna.canTranslate(selection,
4541 viewport.getViewAsVisibleContigs(true)));
4542 } catch (Exception e)
4544 jalview.bin.Cache.log
4545 .warn("canTranslate threw an exception - please report to help@jalview.org",
4552 public void showProducts_actionPerformed(ActionEvent e)
4554 // /////////////////////////////
4555 // Collect Data to be translated/transferred
4557 SequenceI[] selection = viewport.getSequenceSelection();
4558 AlignmentI al = null;
4561 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4562 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4563 viewport.getAlignment().getDataset());
4564 } catch (Exception ex)
4567 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4574 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4575 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4579 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4580 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4581 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4586 public void showTranslation_actionPerformed(ActionEvent e)
4588 // /////////////////////////////
4589 // Collect Data to be translated/transferred
4591 SequenceI[] selection = viewport.getSequenceSelection();
4592 String[] seqstring = viewport.getViewAsString(true);
4593 AlignmentI al = null;
4596 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4597 viewport.getViewAsVisibleContigs(true), viewport
4598 .getGapCharacter(), viewport.getAlignment()
4599 .getAlignmentAnnotation(), viewport.getAlignment()
4600 .getWidth(), viewport.getAlignment().getDataset());
4601 } catch (Exception ex)
4604 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4608 "Unfortunately, something went wrong when translating your sequences.\nPlease take a look in the Jalview java console\nand submit a bug report including the stacktrace.",
4609 "Implementation error: Translation Failed", JOptionPane.ERROR_MESSAGE);
4617 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4618 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4622 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4623 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4624 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4629 * Try to load a features file onto the alignment.
4632 * contents or path to retrieve file
4634 * access mode of file (see jalview.io.AlignFile)
4635 * @return true if features file was parsed corectly.
4637 public boolean parseFeaturesFile(String file, String type)
4639 boolean featuresFile = false;
4642 featuresFile = new FeaturesFile(file, type).parse(viewport
4643 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4644 .getFeatureRenderer().featureColours, false,
4645 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4646 } catch (Exception ex)
4648 ex.printStackTrace();
4653 viewport.showSequenceFeatures = true;
4654 showSeqFeatures.setSelected(true);
4655 if (alignPanel.seqPanel.seqCanvas.fr != null)
4657 // update the min/max ranges where necessary
4658 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4660 if (featureSettings != null)
4662 featureSettings.setTableData();
4664 alignPanel.paintAlignment(true);
4667 return featuresFile;
4671 public void dragEnter(DropTargetDragEvent evt)
4676 public void dragExit(DropTargetEvent evt)
4681 public void dragOver(DropTargetDragEvent evt)
4686 public void dropActionChanged(DropTargetDragEvent evt)
4691 public void drop(DropTargetDropEvent evt)
4693 Transferable t = evt.getTransferable();
4694 java.util.List files = null;
4698 DataFlavor uriListFlavor = new DataFlavor(
4699 "text/uri-list;class=java.lang.String");
4700 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4702 // Works on Windows and MacOSX
4703 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4704 files = (java.util.List) t
4705 .getTransferData(DataFlavor.javaFileListFlavor);
4707 else if (t.isDataFlavorSupported(uriListFlavor))
4709 // This is used by Unix drag system
4710 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4711 String data = (String) t.getTransferData(uriListFlavor);
4712 files = new java.util.ArrayList(1);
4713 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4714 data, "\r\n"); st.hasMoreTokens();)
4716 String s = st.nextToken();
4717 if (s.startsWith("#"))
4719 // the line is a comment (as per the RFC 2483)
4723 java.net.URI uri = new java.net.URI(s);
4724 // check to see if we can handle this kind of URI
4725 if (uri.getScheme().toLowerCase().startsWith("http"))
4727 files.add(uri.toString());
4731 // otherwise preserve old behaviour: catch all for file objects
4732 java.io.File file = new java.io.File(uri);
4733 files.add(file.toString());
4737 } catch (Exception e)
4739 e.printStackTrace();
4745 // check to see if any of these files have names matching sequences in
4747 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4748 .getAlignment().getSequencesArray());
4750 * Object[] { String,SequenceI}
4752 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4753 ArrayList<String> filesnotmatched = new ArrayList<String>();
4754 for (int i = 0; i < files.size(); i++)
4756 String file = files.get(i).toString();
4758 String protocol = FormatAdapter.checkProtocol(file);
4759 if (protocol == jalview.io.FormatAdapter.FILE)
4761 File fl = new File(file);
4762 pdbfn = fl.getName();
4764 else if (protocol == jalview.io.FormatAdapter.URL)
4766 URL url = new URL(file);
4767 pdbfn = url.getFile();
4769 if (pdbfn.length() > 0)
4771 // attempt to find a match in the alignment
4772 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4773 int l = 0, c = pdbfn.indexOf(".");
4774 while (mtch == null && c != -1)
4779 } while ((c = pdbfn.indexOf(".", l)) > l);
4782 pdbfn = pdbfn.substring(0, l);
4784 mtch = idm.findAllIdMatches(pdbfn);
4791 type = new IdentifyFile().Identify(file, protocol);
4792 } catch (Exception ex)
4798 if (type.equalsIgnoreCase("PDB"))
4800 filesmatched.add(new Object[]
4801 { file, protocol, mtch });
4806 // File wasn't named like one of the sequences or wasn't a PDB file.
4807 filesnotmatched.add(file);
4811 if (filesmatched.size() > 0)
4813 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4817 "Do you want to automatically associate the "
4818 + filesmatched.size()
4819 + " PDB files with sequences in the alignment that have the same name ?",
4820 "Automatically Associate PDB files by name",
4821 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4824 for (Object[] fm : filesmatched)
4826 // try and associate
4827 // TODO: may want to set a standard ID naming formalism for
4828 // associating PDB files which have no IDs.
4829 for (SequenceI toassoc : (SequenceI[]) fm[2])
4831 PDBEntry pe = new AssociatePdbFileWithSeq()
4832 .associatePdbWithSeq((String) fm[0],
4833 (String) fm[1], toassoc, false);
4836 System.err.println("Associated file : "
4837 + ((String) fm[0]) + " with "
4838 + toassoc.getDisplayId(true));
4842 alignPanel.paintAlignment(true);
4846 if (filesnotmatched.size() > 0)
4849 && (Cache.getDefault(
4850 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4853 "<html>Do you want to <em>ignore</em> the "
4854 + filesnotmatched.size()
4855 + " files whose names did not match any sequence IDs ?</html>",
4856 "Ignore unmatched dropped files ?",
4857 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4861 for (String fn : filesnotmatched)
4863 loadJalviewDataFile(fn, null, null, null);
4867 } catch (Exception ex)
4869 ex.printStackTrace();
4875 * Attempt to load a "dropped" file or URL string: First by testing whether
4876 * it's and Annotation file, then a JNet file, and finally a features file. If
4877 * all are false then the user may have dropped an alignment file onto this
4881 * either a filename or a URL string.
4883 public void loadJalviewDataFile(String file, String protocol,
4884 String format, SequenceI assocSeq)
4888 if (protocol == null)
4890 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4892 // if the file isn't identified, or not positively identified as some
4893 // other filetype (PFAM is default unidentified alignment file type) then
4894 // try to parse as annotation.
4895 boolean isAnnotation = (format == null || format
4896 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4897 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4902 // first see if its a T-COFFEE score file
4903 TCoffeeScoreFile tcf = null;
4906 tcf = new TCoffeeScoreFile(file, protocol);
4909 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4911 tcoffeeColour.setEnabled(true);
4912 tcoffeeColour.setSelected(true);
4913 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4914 isAnnotation = true;
4915 statusBar.setText(MessageManager.getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
4919 // some problem - if no warning its probable that the ID matching
4920 // process didn't work
4924 tcf.getWarningMessage() == null ? MessageManager.getString("label.check_file_matches_sequence_ids_alignment")
4925 : tcf.getWarningMessage(),
4926 MessageManager.getString("label.problem_reading_tcoffee_score_file"),
4927 JOptionPane.WARNING_MESSAGE);
4934 } catch (Exception x)
4937 .debug("Exception when processing data source as T-COFFEE score file",
4943 // try to see if its a JNet 'concise' style annotation file *before*
4945 // try to parse it as a features file
4948 format = new IdentifyFile().Identify(file, protocol);
4950 if (format.equalsIgnoreCase("JnetFile"))
4952 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4954 new JnetAnnotationMaker().add_annotation(predictions,
4955 viewport.getAlignment(), 0, false);
4956 isAnnotation = true;
4961 * if (format.equalsIgnoreCase("PDB")) {
4963 * String pdbfn = ""; // try to match up filename with sequence id
4964 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4965 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4966 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4967 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4968 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4969 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4970 * // attempt to find a match in the alignment SequenceI mtch =
4971 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4972 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4973 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4974 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4975 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4976 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4977 * { System.err.println("Associated file : " + file + " with " +
4978 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4979 * TODO: maybe need to load as normal otherwise return; } }
4981 // try to parse it as a features file
4982 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4983 // if it wasn't a features file then we just treat it as a general
4984 // alignment file to load into the current view.
4987 new FileLoader().LoadFile(viewport, file, protocol, format);
4991 alignPanel.paintAlignment(true);
4999 alignPanel.adjustAnnotationHeight();
5000 viewport.updateSequenceIdColours();
5001 buildSortByAnnotationScoresMenu();
5002 alignPanel.paintAlignment(true);
5004 } catch (Exception ex)
5006 ex.printStackTrace();
5007 } catch (OutOfMemoryError oom)
5012 } catch (Exception x)
5018 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5019 : "using " + protocol + " from " + file)
5021 + (format != null ? "(parsing as '" + format
5022 + "' file)" : ""), oom, Desktop.desktop);
5027 public void tabSelectionChanged(int index)
5031 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5032 viewport = alignPanel.av;
5033 setMenusFromViewport(viewport);
5038 public void tabbedPane_mousePressed(MouseEvent e)
5040 if (SwingUtilities.isRightMouseButton(e))
5042 String reply = JOptionPane.showInternalInputDialog(this,
5043 "Enter View Name", "Edit View Name",
5044 JOptionPane.QUESTION_MESSAGE);
5048 viewport.viewName = reply;
5049 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5054 public AlignViewport getCurrentView()
5060 * Open the dialog for regex description parsing.
5063 protected void extractScores_actionPerformed(ActionEvent e)
5065 ParseProperties pp = new jalview.analysis.ParseProperties(
5066 viewport.getAlignment());
5067 // TODO: verify regex and introduce GUI dialog for version 2.5
5068 // if (pp.getScoresFromDescription("col", "score column ",
5069 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5071 if (pp.getScoresFromDescription("description column",
5072 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5074 buildSortByAnnotationScoresMenu();
5082 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5086 protected void showDbRefs_actionPerformed(ActionEvent e)
5088 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5094 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5098 protected void showNpFeats_actionPerformed(ActionEvent e)
5100 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5104 * find the viewport amongst the tabs in this alignment frame and close that
5109 public boolean closeView(AlignViewport av)
5113 this.closeMenuItem_actionPerformed(false);
5116 Component[] comp = tabbedPane.getComponents();
5117 for (int i = 0; comp != null && i < comp.length; i++)
5119 if (comp[i] instanceof AlignmentPanel)
5121 if (((AlignmentPanel) comp[i]).av == av)
5124 closeView((AlignmentPanel) comp[i]);
5132 protected void build_fetchdbmenu(JMenu webService)
5134 // Temporary hack - DBRef Fetcher always top level ws entry.
5135 // TODO We probably want to store a sequence database checklist in
5136 // preferences and have checkboxes.. rather than individual sources selected
5138 final JMenu rfetch = new JMenu("Fetch DB References");
5139 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5140 webService.add(rfetch);
5142 JMenuItem fetchr = new JMenuItem("Standard Databases");
5143 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5144 fetchr.addActionListener(new ActionListener()
5148 public void actionPerformed(ActionEvent e)
5150 new Thread(new Runnable()
5156 new jalview.ws.DBRefFetcher(alignPanel.av
5157 .getSequenceSelection(), alignPanel.alignFrame)
5158 .fetchDBRefs(false);
5166 final AlignFrame me = this;
5167 new Thread(new Runnable()
5172 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5173 .getSequenceFetcherSingleton(me);
5174 javax.swing.SwingUtilities.invokeLater(new Runnable()
5179 String[] dbclasses = sf.getOrderedSupportedSources();
5180 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5181 // jalview.util.QuickSort.sort(otherdb, otherdb);
5182 List<DbSourceProxy> otherdb;
5183 JMenu dfetch = new JMenu();
5184 JMenu ifetch = new JMenu();
5185 JMenuItem fetchr = null;
5186 int comp = 0, icomp = 0, mcomp = 15;
5187 String mname = null;
5189 for (String dbclass : dbclasses)
5191 otherdb = sf.getSourceProxy(dbclass);
5192 // add a single entry for this class, or submenu allowing 'fetch
5194 if (otherdb == null || otherdb.size() < 1)
5198 // List<DbSourceProxy> dbs=otherdb;
5199 // otherdb=new ArrayList<DbSourceProxy>();
5200 // for (DbSourceProxy db:dbs)
5202 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5206 mname = "From " + dbclass;
5208 if (otherdb.size() == 1)
5210 final DbSourceProxy[] dassource = otherdb
5211 .toArray(new DbSourceProxy[0]);
5212 DbSourceProxy src = otherdb.get(0);
5213 fetchr = new JMenuItem(src.getDbSource());
5214 fetchr.addActionListener(new ActionListener()
5218 public void actionPerformed(ActionEvent e)
5220 new Thread(new Runnable()
5226 new jalview.ws.DBRefFetcher(alignPanel.av
5227 .getSequenceSelection(),
5228 alignPanel.alignFrame, dassource)
5229 .fetchDBRefs(false);
5235 fetchr.setToolTipText("<html>"
5236 + JvSwingUtils.wrapTooltip("Retrieve from "
5237 + src.getDbName()) + "<html>");
5243 final DbSourceProxy[] dassource = otherdb
5244 .toArray(new DbSourceProxy[0]);
5246 DbSourceProxy src = otherdb.get(0);
5247 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5249 fetchr.addActionListener(new ActionListener()
5252 public void actionPerformed(ActionEvent e)
5254 new Thread(new Runnable()
5260 new jalview.ws.DBRefFetcher(alignPanel.av
5261 .getSequenceSelection(),
5262 alignPanel.alignFrame, dassource)
5263 .fetchDBRefs(false);
5269 fetchr.setToolTipText("<html>"
5270 + JvSwingUtils.wrapTooltip("Retrieve from all "
5271 + otherdb.size() + " sources in "
5272 + src.getDbSource() + "<br>First is :"
5273 + src.getDbName()) + "<html>");
5276 // and then build the rest of the individual menus
5277 ifetch = new JMenu("Sources from " + src.getDbSource());
5279 String imname = null;
5281 for (DbSourceProxy sproxy : otherdb)
5283 String dbname = sproxy.getDbName();
5284 String sname = dbname.length() > 5 ? dbname.substring(0,
5285 5) + "..." : dbname;
5286 String msname = dbname.length() > 10 ? dbname.substring(
5287 0, 10) + "..." : dbname;
5290 imname = "from '" + sname + "'";
5292 fetchr = new JMenuItem(msname);
5293 final DbSourceProxy[] dassrc =
5295 fetchr.addActionListener(new ActionListener()
5299 public void actionPerformed(ActionEvent e)
5301 new Thread(new Runnable()
5307 new jalview.ws.DBRefFetcher(alignPanel.av
5308 .getSequenceSelection(),
5309 alignPanel.alignFrame, dassrc)
5310 .fetchDBRefs(false);
5316 fetchr.setToolTipText("<html>"
5317 + JvSwingUtils.wrapTooltip("Retrieve from "
5318 + dbname) + "</html>");
5321 if (++icomp >= mcomp || i == (otherdb.size()))
5323 ifetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{imname,sname}));
5325 ifetch = new JMenu();
5333 if (comp >= mcomp || dbi >= (dbclasses.length))
5335 dfetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{mname,dbclass}));
5337 dfetch = new JMenu();
5350 * Left justify the whole alignment.
5353 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5355 AlignmentI al = viewport.getAlignment();
5357 viewport.firePropertyChange("alignment", null, al);
5361 * Right justify the whole alignment.
5364 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5366 AlignmentI al = viewport.getAlignment();
5368 viewport.firePropertyChange("alignment", null, al);
5371 public void setShowSeqFeatures(boolean b)
5373 showSeqFeatures.setSelected(true);
5374 viewport.setShowSequenceFeatures(true);
5381 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5382 * awt.event.ActionEvent)
5385 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5387 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5388 alignPanel.paintAlignment(true);
5395 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5399 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5401 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5402 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5410 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5411 * .event.ActionEvent)
5414 protected void showGroupConservation_actionPerformed(ActionEvent e)
5416 viewport.setShowGroupConservation(showGroupConservation.getState());
5417 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5424 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5425 * .event.ActionEvent)
5428 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5430 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5431 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5438 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5439 * .event.ActionEvent)
5442 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5444 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5445 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5449 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5451 showSequenceLogo.setState(true);
5452 viewport.setShowSequenceLogo(true);
5453 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5454 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5458 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5460 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5467 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5468 * .event.ActionEvent)
5471 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5473 if (viewport.getSelectionGroup() != null)
5475 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5476 viewport.getSequenceSelection(),
5477 viewport.getAlignmentView(true).getSequenceStrings(
5478 viewport.getGapCharacter()), viewport.getAlignment()
5480 viewport.getAlignment().deleteAllGroups();
5481 viewport.sequenceColours = null;
5482 viewport.setSelectionGroup(null);
5483 // set view properties for each group
5484 for (int g = 0; g < gps.length; g++)
5486 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5487 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5488 viewport.getAlignment().addGroup(gps[g]);
5489 Color col = new Color((int) (Math.random() * 255),
5490 (int) (Math.random() * 255), (int) (Math.random() * 255));
5491 col = col.brighter();
5492 for (SequenceI s : gps[g].getSequences())
5493 viewport.setSequenceColour(s, col);
5495 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5496 alignPanel.updateAnnotation();
5497 alignPanel.paintAlignment(true);
5502 * make the given alignmentPanel the currently selected tab
5504 * @param alignmentPanel
5506 public void setDisplayedView(AlignmentPanel alignmentPanel)
5508 if (!viewport.getSequenceSetId().equals(
5509 alignmentPanel.av.getSequenceSetId()))
5512 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5514 if (tabbedPane != null
5515 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5516 .getSelectedIndex())
5518 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5523 class PrintThread extends Thread
5527 public PrintThread(AlignmentPanel ap)
5532 static PageFormat pf;
5537 PrinterJob printJob = PrinterJob.getPrinterJob();
5541 printJob.setPrintable(ap, pf);
5545 printJob.setPrintable(ap);
5548 if (printJob.printDialog())
5553 } catch (Exception PrintException)
5555 PrintException.printStackTrace();