2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentSorter;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.AlignmentUtils.MappingResult;
27 import jalview.analysis.Conservation;
28 import jalview.analysis.CrossRef;
29 import jalview.analysis.Dna;
30 import jalview.analysis.ParseProperties;
31 import jalview.analysis.SequenceIdMatcher;
32 import jalview.api.AlignViewControllerGuiI;
33 import jalview.api.AlignViewControllerI;
34 import jalview.api.AlignViewportI;
35 import jalview.api.AlignmentViewPanel;
36 import jalview.api.analysis.ScoreModelI;
37 import jalview.bin.Cache;
38 import jalview.commands.CommandI;
39 import jalview.commands.EditCommand;
40 import jalview.commands.EditCommand.Action;
41 import jalview.commands.OrderCommand;
42 import jalview.commands.RemoveGapColCommand;
43 import jalview.commands.RemoveGapsCommand;
44 import jalview.commands.SlideSequencesCommand;
45 import jalview.commands.TrimRegionCommand;
46 import jalview.datamodel.AlignedCodonFrame;
47 import jalview.datamodel.Alignment;
48 import jalview.datamodel.AlignmentAnnotation;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.AlignmentOrder;
51 import jalview.datamodel.AlignmentView;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.PDBEntry;
54 import jalview.datamodel.SeqCigar;
55 import jalview.datamodel.Sequence;
56 import jalview.datamodel.SequenceGroup;
57 import jalview.datamodel.SequenceI;
58 import jalview.io.AlignmentProperties;
59 import jalview.io.AnnotationFile;
60 import jalview.io.FeaturesFile;
61 import jalview.io.FileLoader;
62 import jalview.io.FormatAdapter;
63 import jalview.io.HTMLOutput;
64 import jalview.io.IdentifyFile;
65 import jalview.io.JalviewFileChooser;
66 import jalview.io.JalviewFileView;
67 import jalview.io.JnetAnnotationMaker;
68 import jalview.io.NewickFile;
69 import jalview.io.TCoffeeScoreFile;
70 import jalview.jbgui.GAlignFrame;
71 import jalview.schemes.Blosum62ColourScheme;
72 import jalview.schemes.BuriedColourScheme;
73 import jalview.schemes.ClustalxColourScheme;
74 import jalview.schemes.ColourSchemeI;
75 import jalview.schemes.ColourSchemeProperty;
76 import jalview.schemes.HelixColourScheme;
77 import jalview.schemes.HydrophobicColourScheme;
78 import jalview.schemes.NucleotideColourScheme;
79 import jalview.schemes.PIDColourScheme;
80 import jalview.schemes.PurinePyrimidineColourScheme;
81 import jalview.schemes.RNAHelicesColourChooser;
82 import jalview.schemes.ResidueProperties;
83 import jalview.schemes.StrandColourScheme;
84 import jalview.schemes.TCoffeeColourScheme;
85 import jalview.schemes.TaylorColourScheme;
86 import jalview.schemes.TurnColourScheme;
87 import jalview.schemes.UserColourScheme;
88 import jalview.schemes.ZappoColourScheme;
89 import jalview.structure.StructureSelectionManager;
90 import jalview.util.MessageManager;
91 import jalview.viewmodel.AlignmentViewport;
92 import jalview.ws.jws1.Discoverer;
93 import jalview.ws.jws2.Jws2Discoverer;
94 import jalview.ws.jws2.jabaws2.Jws2Instance;
95 import jalview.ws.seqfetcher.DbSourceProxy;
97 import java.awt.BorderLayout;
98 import java.awt.Component;
99 import java.awt.GridLayout;
100 import java.awt.Rectangle;
101 import java.awt.Toolkit;
102 import java.awt.datatransfer.Clipboard;
103 import java.awt.datatransfer.DataFlavor;
104 import java.awt.datatransfer.StringSelection;
105 import java.awt.datatransfer.Transferable;
106 import java.awt.dnd.DnDConstants;
107 import java.awt.dnd.DropTargetDragEvent;
108 import java.awt.dnd.DropTargetDropEvent;
109 import java.awt.dnd.DropTargetEvent;
110 import java.awt.dnd.DropTargetListener;
111 import java.awt.event.ActionEvent;
112 import java.awt.event.ActionListener;
113 import java.awt.event.KeyAdapter;
114 import java.awt.event.KeyEvent;
115 import java.awt.event.MouseAdapter;
116 import java.awt.event.MouseEvent;
117 import java.awt.print.PageFormat;
118 import java.awt.print.PrinterJob;
119 import java.beans.PropertyChangeEvent;
122 import java.util.ArrayList;
123 import java.util.Arrays;
124 import java.util.Enumeration;
125 import java.util.Hashtable;
126 import java.util.List;
127 import java.util.Set;
128 import java.util.Vector;
130 import javax.swing.JButton;
131 import javax.swing.JCheckBoxMenuItem;
132 import javax.swing.JEditorPane;
133 import javax.swing.JInternalFrame;
134 import javax.swing.JLabel;
135 import javax.swing.JLayeredPane;
136 import javax.swing.JMenu;
137 import javax.swing.JMenuItem;
138 import javax.swing.JOptionPane;
139 import javax.swing.JPanel;
140 import javax.swing.JProgressBar;
141 import javax.swing.JRadioButtonMenuItem;
142 import javax.swing.JScrollPane;
143 import javax.swing.SwingUtilities;
149 * @version $Revision$
151 public class AlignFrame extends GAlignFrame implements DropTargetListener,
152 IProgressIndicator, AlignViewControllerGuiI
156 public static final int DEFAULT_WIDTH = 700;
159 public static final int DEFAULT_HEIGHT = 500;
161 public AlignmentPanel alignPanel;
163 AlignViewport viewport;
165 public AlignViewControllerI avc;
167 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
170 * Last format used to load or save alignments in this window
172 String currentFileFormat = null;
175 * Current filename for this alignment
177 String fileName = null;
180 * Creates a new AlignFrame object with specific width and height.
186 public AlignFrame(AlignmentI al, int width, int height)
188 this(al, null, width, height);
192 * Creates a new AlignFrame object with specific width, height and
198 * @param sequenceSetId
200 public AlignFrame(AlignmentI al, int width, int height,
201 String sequenceSetId)
203 this(al, null, width, height, sequenceSetId);
207 * Creates a new AlignFrame object with specific width, height and
213 * @param sequenceSetId
216 public AlignFrame(AlignmentI al, int width, int height,
217 String sequenceSetId, String viewId)
219 this(al, null, width, height, sequenceSetId, viewId);
223 * new alignment window with hidden columns
227 * @param hiddenColumns
228 * ColumnSelection or null
230 * Width of alignment frame
234 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
235 int width, int height)
237 this(al, hiddenColumns, width, height, null);
241 * Create alignment frame for al with hiddenColumns, a specific width and
242 * height, and specific sequenceId
245 * @param hiddenColumns
248 * @param sequenceSetId
251 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
252 int width, int height, String sequenceSetId)
254 this(al, hiddenColumns, width, height, sequenceSetId, null);
258 * Create alignment frame for al with hiddenColumns, a specific width and
259 * height, and specific sequenceId
262 * @param hiddenColumns
265 * @param sequenceSetId
270 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
271 int width, int height, String sequenceSetId, String viewId)
273 setSize(width, height);
275 if (al.getDataset() == null)
280 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
282 alignPanel = new AlignmentPanel(this, viewport);
285 addAlignmentPanel(alignPanel, true);
290 * Make a new AlignFrame from existing alignmentPanels
297 public AlignFrame(AlignmentPanel ap)
301 addAlignmentPanel(ap, false);
306 * initalise the alignframe from the underlying viewport data and the
311 avc = new jalview.controller.AlignViewController(this, viewport,
313 if (viewport.getAlignmentConservationAnnotation() == null)
315 BLOSUM62Colour.setEnabled(false);
316 conservationMenuItem.setEnabled(false);
317 modifyConservation.setEnabled(false);
318 // PIDColour.setEnabled(false);
319 // abovePIDThreshold.setEnabled(false);
320 // modifyPID.setEnabled(false);
323 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
326 if (sortby.equals("Id"))
328 sortIDMenuItem_actionPerformed(null);
330 else if (sortby.equals("Pairwise Identity"))
332 sortPairwiseMenuItem_actionPerformed(null);
335 if (Desktop.desktop != null)
337 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
338 addServiceListeners();
339 setGUINucleotide(viewport.getAlignment().isNucleotide());
342 setMenusFromViewport(viewport);
343 buildSortByAnnotationScoresMenu();
346 if (viewport.wrapAlignment)
348 wrapMenuItem_actionPerformed(null);
351 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
353 this.overviewMenuItem_actionPerformed(null);
361 * Change the filename and format for the alignment, and enable the 'reload'
362 * button functionality.
369 public void setFileName(String file, String format)
372 currentFileFormat = format;
373 reload.setEnabled(true);
377 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
380 void addKeyListener()
382 addKeyListener(new KeyAdapter()
385 public void keyPressed(KeyEvent evt)
387 if (viewport.cursorMode
388 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
389 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
390 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
391 && Character.isDigit(evt.getKeyChar()))
393 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
396 switch (evt.getKeyCode())
399 case 27: // escape key
400 deselectAllSequenceMenuItem_actionPerformed(null);
404 case KeyEvent.VK_DOWN:
405 if (evt.isAltDown() || !viewport.cursorMode)
407 moveSelectedSequences(false);
409 if (viewport.cursorMode)
411 alignPanel.seqPanel.moveCursor(0, 1);
416 if (evt.isAltDown() || !viewport.cursorMode)
418 moveSelectedSequences(true);
420 if (viewport.cursorMode)
422 alignPanel.seqPanel.moveCursor(0, -1);
427 case KeyEvent.VK_LEFT:
428 if (evt.isAltDown() || !viewport.cursorMode)
430 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
434 alignPanel.seqPanel.moveCursor(-1, 0);
439 case KeyEvent.VK_RIGHT:
440 if (evt.isAltDown() || !viewport.cursorMode)
442 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
446 alignPanel.seqPanel.moveCursor(1, 0);
450 case KeyEvent.VK_SPACE:
451 if (viewport.cursorMode)
453 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
454 || evt.isShiftDown() || evt.isAltDown());
458 // case KeyEvent.VK_A:
459 // if (viewport.cursorMode)
461 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
462 // //System.out.println("A");
466 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
467 * System.out.println("closing bracket"); } break;
469 case KeyEvent.VK_DELETE:
470 case KeyEvent.VK_BACK_SPACE:
471 if (!viewport.cursorMode)
473 cut_actionPerformed(null);
477 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
478 || evt.isShiftDown() || evt.isAltDown());
484 if (viewport.cursorMode)
486 alignPanel.seqPanel.setCursorRow();
490 if (viewport.cursorMode && !evt.isControlDown())
492 alignPanel.seqPanel.setCursorColumn();
496 if (viewport.cursorMode)
498 alignPanel.seqPanel.setCursorPosition();
502 case KeyEvent.VK_ENTER:
503 case KeyEvent.VK_COMMA:
504 if (viewport.cursorMode)
506 alignPanel.seqPanel.setCursorRowAndColumn();
511 if (viewport.cursorMode)
513 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
517 if (viewport.cursorMode)
519 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
524 viewport.cursorMode = !viewport.cursorMode;
525 statusBar.setText(MessageManager.formatMessage(
526 "label.keyboard_editing_mode", new String[]
527 { (viewport.cursorMode ? "on" : "off") }));
528 if (viewport.cursorMode)
530 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
531 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
533 alignPanel.seqPanel.seqCanvas.repaint();
539 Help.showHelpWindow();
540 } catch (Exception ex)
542 ex.printStackTrace();
547 boolean toggleSeqs = !evt.isControlDown();
548 boolean toggleCols = !evt.isShiftDown();
549 toggleHiddenRegions(toggleSeqs, toggleCols);
552 case KeyEvent.VK_PAGE_UP:
553 if (viewport.wrapAlignment)
555 alignPanel.scrollUp(true);
559 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
560 - viewport.endSeq + viewport.startSeq);
563 case KeyEvent.VK_PAGE_DOWN:
564 if (viewport.wrapAlignment)
566 alignPanel.scrollUp(false);
570 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
571 + viewport.endSeq - viewport.startSeq);
578 public void keyReleased(KeyEvent evt)
580 switch (evt.getKeyCode())
582 case KeyEvent.VK_LEFT:
583 if (evt.isAltDown() || !viewport.cursorMode)
585 viewport.firePropertyChange("alignment", null, viewport
586 .getAlignment().getSequences());
590 case KeyEvent.VK_RIGHT:
591 if (evt.isAltDown() || !viewport.cursorMode)
593 viewport.firePropertyChange("alignment", null, viewport
594 .getAlignment().getSequences());
602 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
604 ap.alignFrame = this;
605 avc = new jalview.controller.AlignViewController(this, viewport,
610 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
612 int aSize = alignPanels.size();
614 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
616 if (aSize == 1 && ap.av.viewName == null)
618 this.getContentPane().add(ap, BorderLayout.CENTER);
624 setInitialTabVisible();
627 expandViews.setEnabled(true);
628 gatherViews.setEnabled(true);
629 tabbedPane.addTab(ap.av.viewName, ap);
631 ap.setVisible(false);
636 if (ap.av.isPadGaps())
638 ap.av.getAlignment().padGaps();
640 ap.av.updateConservation(ap);
641 ap.av.updateConsensus(ap);
642 ap.av.updateStrucConsensus(ap);
646 public void setInitialTabVisible()
648 expandViews.setEnabled(true);
649 gatherViews.setEnabled(true);
650 tabbedPane.setVisible(true);
651 AlignmentPanel first = alignPanels.get(0);
652 tabbedPane.addTab(first.av.viewName, first);
653 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
656 public AlignViewport getViewport()
661 /* Set up intrinsic listeners for dynamically generated GUI bits. */
662 private void addServiceListeners()
664 final java.beans.PropertyChangeListener thisListener;
665 Desktop.instance.addJalviewPropertyChangeListener("services",
666 thisListener = new java.beans.PropertyChangeListener()
669 public void propertyChange(PropertyChangeEvent evt)
671 // // System.out.println("Discoverer property change.");
672 // if (evt.getPropertyName().equals("services"))
674 SwingUtilities.invokeLater(new Runnable()
681 .println("Rebuild WS Menu for service change");
682 BuildWebServiceMenu();
689 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
692 public void internalFrameClosed(
693 javax.swing.event.InternalFrameEvent evt)
695 System.out.println("deregistering discoverer listener");
696 Desktop.instance.removeJalviewPropertyChangeListener("services",
698 closeMenuItem_actionPerformed(true);
701 // Finally, build the menu once to get current service state
702 new Thread(new Runnable()
707 BuildWebServiceMenu();
712 public void setGUINucleotide(boolean nucleotide)
714 showTranslation.setVisible(nucleotide);
715 cdna.setVisible(!nucleotide);
716 conservationMenuItem.setEnabled(!nucleotide);
717 modifyConservation.setEnabled(!nucleotide);
718 showGroupConservation.setEnabled(!nucleotide);
719 rnahelicesColour.setEnabled(nucleotide);
720 purinePyrimidineColour.setEnabled(nucleotide);
724 * Builds codon mappings from this (protein) alignment to any compatible
725 * nucleotide alignments. Mappings are built between sequences with the same
726 * name and compatible lengths. Also makes the cDNA alignment a
727 * CommandListener for the protein alignment so that edits are mirrored.
730 protected void linkCdna_actionPerformed()
733 int alreadyLinkedCount = 0;
734 final AlignmentI thisAlignment = this.alignPanel.getAlignment();
736 for (AlignFrame af : Desktop.getAlignFrames())
738 if (af.alignPanel != null)
740 final AlignmentI thatAlignment = af.alignPanel.getAlignment();
741 if (thatAlignment.isNucleotide())
743 MappingResult mapped = AlignmentUtils.mapProteinToCdna(
744 thisAlignment, thatAlignment);
745 if (mapped == MappingResult.AlreadyMapped)
747 alreadyLinkedCount++;
749 else if (mapped == MappingResult.Mapped)
751 final StructureSelectionManager ssm = StructureSelectionManager
752 .getStructureSelectionManager(Desktop.instance);
753 ssm.addMappings(thisAlignment.getCodonFrames());
754 // enable the next line to enable linked editing
755 // ssm.addCommandListener(af.getViewport());
762 if (linkedCount == 0 && alreadyLinkedCount == 0)
764 msg = MessageManager.getString("label.no_cdna");
766 else if (linkedCount > 0)
768 msg = MessageManager.formatMessage("label.linked_cdna", linkedCount);
772 msg = MessageManager.formatMessage("label.cdna_all_linked",
779 * Align any linked cDNA to match the alignment of this (protein) alignment.
780 * Any mapped sequence regions will be realigned, unmapped sequences are not
784 protected void alignCdna_actionPerformed()
788 final AlignmentI thisAlignment = this.alignPanel.getAlignment();
789 for (AlignFrame af : Desktop.getAlignFrames())
791 if (af.alignPanel != null)
793 final AlignmentI thatAlignment = af.alignPanel.getAlignment();
794 if (thatAlignment.isNucleotide())
796 int seqsAligned = thatAlignment.alignAs(thisAlignment);
797 seqCount += seqsAligned;
800 af.alignPanel.alignmentChanged();
806 setStatus(MessageManager.formatMessage("label.cdna_aligned", seqCount,
810 * set up menus for the current viewport. This may be called after any
811 * operation that affects the data in the current view (selection changed,
812 * etc) to update the menus to reflect the new state.
814 public void setMenusForViewport()
816 setMenusFromViewport(viewport);
820 * Need to call this method when tabs are selected for multiple views, or when
821 * loading from Jalview2XML.java
826 void setMenusFromViewport(AlignViewport av)
828 padGapsMenuitem.setSelected(av.isPadGaps());
829 colourTextMenuItem.setSelected(av.showColourText);
830 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
831 conservationMenuItem.setSelected(av.getConservationSelected());
832 seqLimits.setSelected(av.getShowJVSuffix());
833 idRightAlign.setSelected(av.rightAlignIds);
834 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
835 renderGapsMenuItem.setSelected(av.renderGaps);
836 wrapMenuItem.setSelected(av.wrapAlignment);
837 scaleAbove.setVisible(av.wrapAlignment);
838 scaleLeft.setVisible(av.wrapAlignment);
839 scaleRight.setVisible(av.wrapAlignment);
840 annotationPanelMenuItem.setState(av.showAnnotation);
842 * Show/hide annotations only enabled if annotation panel is shown
844 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
845 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
846 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
847 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
848 viewBoxesMenuItem.setSelected(av.showBoxes);
849 viewTextMenuItem.setSelected(av.showText);
850 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
851 showGroupConsensus.setSelected(av.isShowGroupConsensus());
852 showGroupConservation.setSelected(av.isShowGroupConservation());
853 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
854 showSequenceLogo.setSelected(av.isShowSequenceLogo());
855 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
857 setColourSelected(ColourSchemeProperty.getColourName(av
858 .getGlobalColourScheme()));
860 showSeqFeatures.setSelected(av.showSequenceFeatures);
861 hiddenMarkers.setState(av.showHiddenMarkers);
862 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
863 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
864 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
865 autoCalculate.setSelected(av.autoCalculateConsensus);
866 sortByTree.setSelected(av.sortByTree);
867 listenToViewSelections.setSelected(av.followSelection);
868 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
870 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
871 setShowProductsEnabled();
875 // methods for implementing IProgressIndicator
876 // need to refactor to a reusable stub class
877 Hashtable progressBars, progressBarHandlers;
882 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
885 public void setProgressBar(String message, long id)
887 if (progressBars == null)
889 progressBars = new Hashtable();
890 progressBarHandlers = new Hashtable();
893 JPanel progressPanel;
894 Long lId = new Long(id);
895 GridLayout layout = (GridLayout) statusPanel.getLayout();
896 if (progressBars.get(lId) != null)
898 progressPanel = (JPanel) progressBars.get(new Long(id));
899 statusPanel.remove(progressPanel);
900 progressBars.remove(lId);
901 progressPanel = null;
904 statusBar.setText(message);
906 if (progressBarHandlers.contains(lId))
908 progressBarHandlers.remove(lId);
910 layout.setRows(layout.getRows() - 1);
914 progressPanel = new JPanel(new BorderLayout(10, 5));
916 JProgressBar progressBar = new JProgressBar();
917 progressBar.setIndeterminate(true);
919 progressPanel.add(new JLabel(message), BorderLayout.WEST);
920 progressPanel.add(progressBar, BorderLayout.CENTER);
922 layout.setRows(layout.getRows() + 1);
923 statusPanel.add(progressPanel);
925 progressBars.put(lId, progressPanel);
928 // setMenusForViewport();
933 public void registerHandler(final long id,
934 final IProgressIndicatorHandler handler)
936 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
938 throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler"));
940 progressBarHandlers.put(new Long(id), handler);
941 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
942 if (handler.canCancel())
944 JButton cancel = new JButton(
945 MessageManager.getString("action.cancel"));
946 final IProgressIndicator us = this;
947 cancel.addActionListener(new ActionListener()
951 public void actionPerformed(ActionEvent e)
953 handler.cancelActivity(id);
954 us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id);
957 progressPanel.add(cancel, BorderLayout.EAST);
963 * @return true if any progress bars are still active
966 public boolean operationInProgress()
968 if (progressBars != null && progressBars.size() > 0)
976 public void setStatus(String text)
978 statusBar.setText(text);
982 * Added so Castor Mapping file can obtain Jalview Version
984 public String getVersion()
986 return jalview.bin.Cache.getProperty("VERSION");
989 public FeatureRenderer getFeatureRenderer()
991 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
995 public void fetchSequence_actionPerformed(ActionEvent e)
997 new SequenceFetcher(this);
1001 public void addFromFile_actionPerformed(ActionEvent e)
1003 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1007 public void reload_actionPerformed(ActionEvent e)
1009 if (fileName != null)
1011 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1012 // originating file's format
1013 // TODO: work out how to recover feature settings for correct view(s) when
1014 // file is reloaded.
1015 if (currentFileFormat.equals("Jalview"))
1017 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1018 for (int i = 0; i < frames.length; i++)
1020 if (frames[i] instanceof AlignFrame && frames[i] != this
1021 && ((AlignFrame) frames[i]).fileName != null
1022 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1026 frames[i].setSelected(true);
1027 Desktop.instance.closeAssociatedWindows();
1028 } catch (java.beans.PropertyVetoException ex)
1034 Desktop.instance.closeAssociatedWindows();
1036 FileLoader loader = new FileLoader();
1037 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1038 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1042 Rectangle bounds = this.getBounds();
1044 FileLoader loader = new FileLoader();
1045 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1046 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1047 protocol, currentFileFormat);
1049 newframe.setBounds(bounds);
1050 if (featureSettings != null && featureSettings.isShowing())
1052 final Rectangle fspos = featureSettings.frame.getBounds();
1053 // TODO: need a 'show feature settings' function that takes bounds -
1054 // need to refactor Desktop.addFrame
1055 newframe.featureSettings_actionPerformed(null);
1056 final FeatureSettings nfs = newframe.featureSettings;
1057 SwingUtilities.invokeLater(new Runnable()
1062 nfs.frame.setBounds(fspos);
1065 this.featureSettings.close();
1066 this.featureSettings = null;
1068 this.closeMenuItem_actionPerformed(true);
1074 public void addFromText_actionPerformed(ActionEvent e)
1076 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1080 public void addFromURL_actionPerformed(ActionEvent e)
1082 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1086 public void save_actionPerformed(ActionEvent e)
1088 if (fileName == null
1089 || (currentFileFormat == null || !jalview.io.FormatAdapter
1090 .isValidIOFormat(currentFileFormat, true))
1091 || fileName.startsWith("http"))
1093 saveAs_actionPerformed(null);
1097 saveAlignment(fileName, currentFileFormat);
1108 public void saveAs_actionPerformed(ActionEvent e)
1110 JalviewFileChooser chooser = new JalviewFileChooser(
1111 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1112 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1113 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1114 currentFileFormat, false);
1116 chooser.setFileView(new JalviewFileView());
1117 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1118 chooser.setToolTipText(MessageManager.getString("action.save"));
1120 int value = chooser.showSaveDialog(this);
1122 if (value == JalviewFileChooser.APPROVE_OPTION)
1124 currentFileFormat = chooser.getSelectedFormat();
1125 while (currentFileFormat == null)
1128 .showInternalMessageDialog(
1131 .getString("label.select_file_format_before_saving"),
1133 .getString("label.file_format_not_specified"),
1134 JOptionPane.WARNING_MESSAGE);
1135 currentFileFormat = chooser.getSelectedFormat();
1136 value = chooser.showSaveDialog(this);
1137 if (value != JalviewFileChooser.APPROVE_OPTION)
1143 fileName = chooser.getSelectedFile().getPath();
1145 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1148 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1149 if (currentFileFormat.indexOf(" ") > -1)
1151 currentFileFormat = currentFileFormat.substring(0,
1152 currentFileFormat.indexOf(" "));
1154 saveAlignment(fileName, currentFileFormat);
1158 public boolean saveAlignment(String file, String format)
1160 boolean success = true;
1162 if (format.equalsIgnoreCase("Jalview"))
1164 String shortName = title;
1166 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1168 shortName = shortName.substring(shortName
1169 .lastIndexOf(java.io.File.separatorChar) + 1);
1172 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1174 statusBar.setText(MessageManager.formatMessage(
1175 "label.successfully_saved_to_file_in_format", new String[]
1176 { fileName, format }));
1181 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1183 warningMessage("Cannot save file " + fileName + " using format "
1184 + format, "Alignment output format not supported");
1185 saveAs_actionPerformed(null);
1186 // JBPNote need to have a raise_gui flag here
1190 String[] omitHidden = null;
1192 if (viewport.hasHiddenColumns())
1194 int reply = JOptionPane
1195 .showInternalConfirmDialog(
1198 .getString("label.alignment_contains_hidden_columns"),
1200 .getString("action.save_omit_hidden_columns"),
1201 JOptionPane.YES_NO_OPTION,
1202 JOptionPane.QUESTION_MESSAGE);
1204 if (reply == JOptionPane.YES_OPTION)
1206 omitHidden = viewport.getViewAsString(false);
1209 FormatAdapter f = new FormatAdapter();
1210 String output = f.formatSequences(format,
1211 viewport.getAlignment(), // class cast exceptions will
1212 // occur in the distant future
1213 omitHidden, f.getCacheSuffixDefault(format),
1214 viewport.getColumnSelection());
1224 java.io.PrintWriter out = new java.io.PrintWriter(
1225 new java.io.FileWriter(file));
1229 this.setTitle(file);
1230 statusBar.setText(MessageManager.formatMessage(
1231 "label.successfully_saved_to_file_in_format",
1233 { fileName, format }));
1234 } catch (Exception ex)
1237 ex.printStackTrace();
1244 JOptionPane.showInternalMessageDialog(this, MessageManager
1245 .formatMessage("label.couldnt_save_file", new String[]
1246 { fileName }), MessageManager
1247 .getString("label.error_saving_file"),
1248 JOptionPane.WARNING_MESSAGE);
1254 private void warningMessage(String warning, String title)
1256 if (new jalview.util.Platform().isHeadless())
1258 System.err.println("Warning: " + title + "\nWarning: " + warning);
1263 JOptionPane.showInternalMessageDialog(this, warning, title,
1264 JOptionPane.WARNING_MESSAGE);
1276 protected void outputText_actionPerformed(ActionEvent e)
1278 String[] omitHidden = null;
1280 if (viewport.hasHiddenColumns())
1282 int reply = JOptionPane
1283 .showInternalConfirmDialog(
1286 .getString("label.alignment_contains_hidden_columns"),
1288 .getString("action.save_omit_hidden_columns"),
1289 JOptionPane.YES_NO_OPTION,
1290 JOptionPane.QUESTION_MESSAGE);
1292 if (reply == JOptionPane.YES_OPTION)
1294 omitHidden = viewport.getViewAsString(false);
1298 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1299 cap.setForInput(null);
1303 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1304 viewport.getAlignment(), omitHidden,
1305 viewport.getColumnSelection()));
1306 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1307 "label.alignment_output_command", new String[]
1308 { e.getActionCommand() }), 600, 500);
1309 } catch (OutOfMemoryError oom)
1311 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1324 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1326 new HTMLOutput(alignPanel,
1327 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1328 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1331 public void createImageMap(File file, String image)
1333 alignPanel.makePNGImageMap(file, image);
1343 public void createPNG(File f)
1345 alignPanel.makePNG(f);
1355 public void createEPS(File f)
1357 alignPanel.makeEPS(f);
1360 public void createSVG(File f)
1362 alignPanel.makeSVG(f);
1365 public void pageSetup_actionPerformed(ActionEvent e)
1367 PrinterJob printJob = PrinterJob.getPrinterJob();
1368 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1378 public void printMenuItem_actionPerformed(ActionEvent e)
1380 // Putting in a thread avoids Swing painting problems
1381 PrintThread thread = new PrintThread(alignPanel);
1386 public void exportFeatures_actionPerformed(ActionEvent e)
1388 new AnnotationExporter().exportFeatures(alignPanel);
1392 public void exportAnnotations_actionPerformed(ActionEvent e)
1394 new AnnotationExporter().exportAnnotations(alignPanel,
1395 viewport.showAnnotation ? viewport.getAlignment()
1396 .getAlignmentAnnotation() : null, viewport
1397 .getAlignment().getGroups(), ((Alignment) viewport
1398 .getAlignment()).alignmentProperties);
1402 public void associatedData_actionPerformed(ActionEvent e)
1404 // Pick the tree file
1405 JalviewFileChooser chooser = new JalviewFileChooser(
1406 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1407 chooser.setFileView(new JalviewFileView());
1408 chooser.setDialogTitle(MessageManager
1409 .getString("label.load_jalview_annotations"));
1410 chooser.setToolTipText(MessageManager
1411 .getString("label.load_jalview_annotations"));
1413 int value = chooser.showOpenDialog(null);
1415 if (value == JalviewFileChooser.APPROVE_OPTION)
1417 String choice = chooser.getSelectedFile().getPath();
1418 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1419 loadJalviewDataFile(choice, null, null, null);
1425 * Close the current view or all views in the alignment frame. If the frame
1426 * only contains one view then the alignment will be removed from memory.
1428 * @param closeAllTabs
1431 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1433 if (alignPanels != null && alignPanels.size() < 2)
1435 closeAllTabs = true;
1440 if (alignPanels != null)
1444 if (this.isClosed())
1446 // really close all the windows - otherwise wait till
1447 // setClosed(true) is called
1448 for (int i = 0; i < alignPanels.size(); i++)
1450 AlignmentPanel ap = alignPanels.get(i);
1457 closeView(alignPanel);
1463 this.setClosed(true);
1465 } catch (Exception ex)
1467 ex.printStackTrace();
1472 * close alignPanel2 and shuffle tabs appropriately.
1474 * @param alignPanel2
1476 public void closeView(AlignmentPanel alignPanel2)
1478 int index = tabbedPane.getSelectedIndex();
1479 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1480 alignPanels.remove(alignPanel2);
1482 // if (viewport == alignPanel2.av)
1486 alignPanel2.closePanel();
1489 tabbedPane.removeTabAt(closedindex);
1490 tabbedPane.validate();
1492 if (index > closedindex || index == tabbedPane.getTabCount())
1494 // modify currently selected tab index if necessary.
1498 this.tabSelectionChanged(index);
1504 void updateEditMenuBar()
1507 if (viewport.getHistoryList().size() > 0)
1509 undoMenuItem.setEnabled(true);
1510 CommandI command = viewport.getHistoryList().peek();
1511 undoMenuItem.setText(MessageManager.formatMessage(
1512 "label.undo_command", new String[]
1513 { command.getDescription() }));
1517 undoMenuItem.setEnabled(false);
1518 undoMenuItem.setText(MessageManager.getString("action.undo"));
1521 if (viewport.getRedoList().size() > 0)
1523 redoMenuItem.setEnabled(true);
1525 CommandI command = viewport.getRedoList().peek();
1526 redoMenuItem.setText(MessageManager.formatMessage(
1527 "label.redo_command", new String[]
1528 { command.getDescription() }));
1532 redoMenuItem.setEnabled(false);
1533 redoMenuItem.setText(MessageManager.getString("action.redo"));
1537 public void addHistoryItem(CommandI command)
1539 if (command.getSize() > 0)
1541 viewport.addToHistoryList(command);
1542 viewport.clearRedoList();
1543 updateEditMenuBar();
1544 viewport.updateHiddenColumns();
1545 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1546 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1547 // viewport.getColumnSelection()
1548 // .getHiddenColumns().size() > 0);
1554 * @return alignment objects for all views
1556 AlignmentI[] getViewAlignments()
1558 if (alignPanels != null)
1560 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1562 for (AlignmentPanel ap : alignPanels)
1564 als[i++] = ap.av.getAlignment();
1568 if (viewport != null)
1570 return new AlignmentI[]
1571 { viewport.getAlignment() };
1583 protected void undoMenuItem_actionPerformed(ActionEvent e)
1585 if (viewport.getHistoryList().isEmpty())
1589 CommandI command = viewport.getHistoryList().pop();
1590 viewport.addToRedoList(command);
1591 // TODO: execute command before adding to redo list / broadcasting?
1592 command.undoCommand(getViewAlignments());
1594 AlignmentViewport originalSource = getOriginatingSource(command);
1595 updateEditMenuBar();
1597 if (originalSource != null)
1599 if (originalSource != viewport)
1602 .warn("Implementation worry: mismatch of viewport origin for undo");
1604 originalSource.updateHiddenColumns();
1605 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1607 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1608 // viewport.getColumnSelection()
1609 // .getHiddenColumns().size() > 0);
1610 originalSource.firePropertyChange("alignment", null, originalSource
1611 .getAlignment().getSequences());
1622 protected void redoMenuItem_actionPerformed(ActionEvent e)
1624 if (viewport.getRedoList().size() < 1)
1629 CommandI command = viewport.getRedoList().pop();
1630 viewport.addToHistoryList(command);
1631 command.doCommand(getViewAlignments());
1633 AlignmentViewport originalSource = getOriginatingSource(command);
1634 updateEditMenuBar();
1636 if (originalSource != null)
1639 if (originalSource != viewport)
1642 .warn("Implementation worry: mismatch of viewport origin for redo");
1644 originalSource.updateHiddenColumns();
1645 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1647 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1648 // viewport.getColumnSelection()
1649 // .getHiddenColumns().size() > 0);
1650 originalSource.firePropertyChange("alignment", null, originalSource
1651 .getAlignment().getSequences());
1655 AlignmentViewport getOriginatingSource(CommandI command)
1657 AlignmentViewport originalSource = null;
1658 // For sequence removal and addition, we need to fire
1659 // the property change event FROM the viewport where the
1660 // original alignment was altered
1661 AlignmentI al = null;
1662 if (command instanceof EditCommand)
1664 EditCommand editCommand = (EditCommand) command;
1665 al = editCommand.getAlignment();
1666 Vector comps = (Vector) PaintRefresher.components.get(viewport
1667 .getSequenceSetId());
1669 for (int i = 0; i < comps.size(); i++)
1671 if (comps.elementAt(i) instanceof AlignmentPanel)
1673 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1675 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1682 if (originalSource == null)
1684 // The original view is closed, we must validate
1685 // the current view against the closed view first
1688 PaintRefresher.validateSequences(al, viewport.getAlignment());
1691 originalSource = viewport;
1694 return originalSource;
1703 public void moveSelectedSequences(boolean up)
1705 SequenceGroup sg = viewport.getSelectionGroup();
1711 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1712 viewport.getHiddenRepSequences(), up);
1713 alignPanel.paintAlignment(true);
1715 final AlignViewportI peer = viewport.getCodingComplement();
1718 final SequenceGroup selectionGroup = peer.getSelectionGroup();
1719 if (selectionGroup != null)
1721 peer.getAlignment().moveSelectedSequencesByOne(
1722 peer.getSelectionGroup(), peer.getHiddenRepSequences(), up);
1723 ((AlignViewport) peer).getAlignPanel().paintAlignment(true);
1728 synchronized void slideSequences(boolean right, int size)
1730 List<SequenceI> sg = new ArrayList<SequenceI>();
1731 if (viewport.cursorMode)
1733 sg.add(viewport.getAlignment().getSequenceAt(
1734 alignPanel.seqPanel.seqCanvas.cursorY));
1736 else if (viewport.getSelectionGroup() != null
1737 && viewport.getSelectionGroup().getSize() != viewport
1738 .getAlignment().getHeight())
1740 sg = viewport.getSelectionGroup().getSequences(
1741 viewport.getHiddenRepSequences());
1749 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1751 for (SequenceI seq : viewport.getAlignment().getSequences())
1753 if (!sg.contains(seq))
1755 invertGroup.add(seq);
1759 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1761 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1762 for (int i = 0; i < invertGroup.size(); i++)
1764 seqs2[i] = invertGroup.get(i);
1767 SlideSequencesCommand ssc;
1770 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1771 size, viewport.getGapCharacter());
1775 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1776 size, viewport.getGapCharacter());
1779 int groupAdjustment = 0;
1780 if (ssc.getGapsInsertedBegin() && right)
1782 if (viewport.cursorMode)
1784 alignPanel.seqPanel.moveCursor(size, 0);
1788 groupAdjustment = size;
1791 else if (!ssc.getGapsInsertedBegin() && !right)
1793 if (viewport.cursorMode)
1795 alignPanel.seqPanel.moveCursor(-size, 0);
1799 groupAdjustment = -size;
1803 if (groupAdjustment != 0)
1805 viewport.getSelectionGroup().setStartRes(
1806 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1807 viewport.getSelectionGroup().setEndRes(
1808 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1811 boolean appendHistoryItem = false;
1812 if (viewport.getHistoryList() != null
1813 && viewport.getHistoryList().size() > 0
1814 && viewport.getHistoryList().peek() instanceof SlideSequencesCommand)
1816 appendHistoryItem = ssc
1817 .appendSlideCommand((SlideSequencesCommand) viewport
1822 if (!appendHistoryItem)
1824 addHistoryItem(ssc);
1837 protected void copy_actionPerformed(ActionEvent e)
1840 if (viewport.getSelectionGroup() == null)
1844 // TODO: preserve the ordering of displayed alignment annotation in any
1845 // internal paste (particularly sequence associated annotation)
1846 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1847 String[] omitHidden = null;
1849 if (viewport.hasHiddenColumns())
1851 omitHidden = viewport.getViewAsString(true);
1854 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1857 StringSelection ss = new StringSelection(output);
1861 jalview.gui.Desktop.internalCopy = true;
1862 // Its really worth setting the clipboard contents
1863 // to empty before setting the large StringSelection!!
1864 Toolkit.getDefaultToolkit().getSystemClipboard()
1865 .setContents(new StringSelection(""), null);
1867 Toolkit.getDefaultToolkit().getSystemClipboard()
1868 .setContents(ss, Desktop.instance);
1869 } catch (OutOfMemoryError er)
1871 new OOMWarning("copying region", er);
1875 Vector hiddenColumns = null;
1876 if (viewport.hasHiddenColumns())
1878 hiddenColumns = new Vector();
1879 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1880 .getSelectionGroup().getEndRes();
1881 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1884 int[] region = viewport.getColumnSelection()
1885 .getHiddenColumns().get(i);
1886 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1888 hiddenColumns.addElement(new int[]
1889 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1894 Desktop.jalviewClipboard = new Object[]
1895 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1896 statusBar.setText(MessageManager.formatMessage(
1897 "label.copied_sequences_to_clipboard", new Object[]
1898 { Integer.valueOf(seqs.length).toString() }));
1908 protected void pasteNew_actionPerformed(ActionEvent e)
1920 protected void pasteThis_actionPerformed(ActionEvent e)
1926 * Paste contents of Jalview clipboard
1928 * @param newAlignment
1929 * true to paste to a new alignment, otherwise add to this.
1931 void paste(boolean newAlignment)
1933 boolean externalPaste = true;
1936 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1937 Transferable contents = c.getContents(this);
1939 if (contents == null)
1947 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1948 if (str.length() < 1)
1953 format = new IdentifyFile().Identify(str, "Paste");
1955 } catch (OutOfMemoryError er)
1957 new OOMWarning("Out of memory pasting sequences!!", er);
1961 SequenceI[] sequences;
1962 boolean annotationAdded = false;
1963 AlignmentI alignment = null;
1965 if (Desktop.jalviewClipboard != null)
1967 // The clipboard was filled from within Jalview, we must use the
1969 // And dataset from the copied alignment
1970 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1971 // be doubly sure that we create *new* sequence objects.
1972 sequences = new SequenceI[newseq.length];
1973 for (int i = 0; i < newseq.length; i++)
1975 sequences[i] = new Sequence(newseq[i]);
1977 alignment = new Alignment(sequences);
1978 externalPaste = false;
1982 // parse the clipboard as an alignment.
1983 alignment = new FormatAdapter().readFile(str, "Paste", format);
1984 sequences = alignment.getSequencesArray();
1988 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1994 if (Desktop.jalviewClipboard != null)
1996 // dataset is inherited
1997 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2001 // new dataset is constructed
2002 alignment.setDataset(null);
2004 alwidth = alignment.getWidth() + 1;
2008 AlignmentI pastedal = alignment; // preserve pasted alignment object
2009 // Add pasted sequences and dataset into existing alignment.
2010 alignment = viewport.getAlignment();
2011 alwidth = alignment.getWidth() + 1;
2012 // decide if we need to import sequences from an existing dataset
2013 boolean importDs = Desktop.jalviewClipboard != null
2014 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2015 // importDs==true instructs us to copy over new dataset sequences from
2016 // an existing alignment
2017 Vector newDs = (importDs) ? new Vector() : null; // used to create
2018 // minimum dataset set
2020 for (int i = 0; i < sequences.length; i++)
2024 newDs.addElement(null);
2026 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2028 if (importDs && ds != null)
2030 if (!newDs.contains(ds))
2032 newDs.setElementAt(ds, i);
2033 ds = new Sequence(ds);
2034 // update with new dataset sequence
2035 sequences[i].setDatasetSequence(ds);
2039 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2044 // copy and derive new dataset sequence
2045 sequences[i] = sequences[i].deriveSequence();
2046 alignment.getDataset().addSequence(
2047 sequences[i].getDatasetSequence());
2048 // TODO: avoid creation of duplicate dataset sequences with a
2049 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2051 alignment.addSequence(sequences[i]); // merges dataset
2055 newDs.clear(); // tidy up
2057 if (alignment.getAlignmentAnnotation() != null)
2059 for (AlignmentAnnotation alan : alignment
2060 .getAlignmentAnnotation())
2062 if (alan.graphGroup > fgroup)
2064 fgroup = alan.graphGroup;
2068 if (pastedal.getAlignmentAnnotation() != null)
2070 // Add any annotation attached to alignment.
2071 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2072 for (int i = 0; i < alann.length; i++)
2074 annotationAdded = true;
2075 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2077 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2078 if (newann.graphGroup > -1)
2080 if (newGraphGroups.size() <= newann.graphGroup
2081 || newGraphGroups.get(newann.graphGroup) == null)
2083 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2085 newGraphGroups.add(q, null);
2087 newGraphGroups.set(newann.graphGroup, new Integer(
2090 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2094 newann.padAnnotation(alwidth);
2095 alignment.addAnnotation(newann);
2105 addHistoryItem(new EditCommand(
2106 MessageManager.getString("label.add_sequences"),
2108 sequences, 0, alignment.getWidth(), alignment));
2110 // Add any annotations attached to sequences
2111 for (int i = 0; i < sequences.length; i++)
2113 if (sequences[i].getAnnotation() != null)
2115 AlignmentAnnotation newann;
2116 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2118 annotationAdded = true;
2119 newann = sequences[i].getAnnotation()[a];
2120 newann.adjustForAlignment();
2121 newann.padAnnotation(alwidth);
2122 if (newann.graphGroup > -1)
2124 if (newann.graphGroup > -1)
2126 if (newGraphGroups.size() <= newann.graphGroup
2127 || newGraphGroups.get(newann.graphGroup) == null)
2129 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2131 newGraphGroups.add(q, null);
2133 newGraphGroups.set(newann.graphGroup, new Integer(
2136 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2140 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2145 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2152 // propagate alignment changed.
2153 viewport.setEndSeq(alignment.getHeight());
2154 if (annotationAdded)
2156 // Duplicate sequence annotation in all views.
2157 AlignmentI[] alview = this.getViewAlignments();
2158 for (int i = 0; i < sequences.length; i++)
2160 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2165 for (int avnum = 0; avnum < alview.length; avnum++)
2167 if (alview[avnum] != alignment)
2169 // duplicate in a view other than the one with input focus
2170 int avwidth = alview[avnum].getWidth() + 1;
2171 // this relies on sann being preserved after we
2172 // modify the sequence's annotation array for each duplication
2173 for (int a = 0; a < sann.length; a++)
2175 AlignmentAnnotation newann = new AlignmentAnnotation(
2177 sequences[i].addAlignmentAnnotation(newann);
2178 newann.padAnnotation(avwidth);
2179 alview[avnum].addAnnotation(newann); // annotation was
2180 // duplicated earlier
2181 // TODO JAL-1145 graphGroups are not updated for sequence
2182 // annotation added to several views. This may cause
2184 alview[avnum].setAnnotationIndex(newann, a);
2189 buildSortByAnnotationScoresMenu();
2191 viewport.firePropertyChange("alignment", null,
2192 alignment.getSequences());
2193 if (alignPanels != null)
2195 for (AlignmentPanel ap : alignPanels)
2197 ap.validateAnnotationDimensions(false);
2202 alignPanel.validateAnnotationDimensions(false);
2208 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2210 String newtitle = new String("Copied sequences");
2212 if (Desktop.jalviewClipboard != null
2213 && Desktop.jalviewClipboard[2] != null)
2215 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2216 for (int i = 0; i < hc.size(); i++)
2218 int[] region = (int[]) hc.elementAt(i);
2219 af.viewport.hideColumns(region[0], region[1]);
2223 // >>>This is a fix for the moment, until a better solution is
2225 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2227 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2229 // TODO: maintain provenance of an alignment, rather than just make the
2230 // title a concatenation of operations.
2233 if (title.startsWith("Copied sequences"))
2239 newtitle = newtitle.concat("- from " + title);
2244 newtitle = new String("Pasted sequences");
2247 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2252 } catch (Exception ex)
2254 ex.printStackTrace();
2255 System.out.println("Exception whilst pasting: " + ex);
2256 // could be anything being pasted in here
2262 protected void expand_newalign(ActionEvent e)
2266 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2267 .getAlignment(), -1);
2268 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2270 String newtitle = new String("Flanking alignment");
2272 if (Desktop.jalviewClipboard != null
2273 && Desktop.jalviewClipboard[2] != null)
2275 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2276 for (int i = 0; i < hc.size(); i++)
2278 int[] region = (int[]) hc.elementAt(i);
2279 af.viewport.hideColumns(region[0], region[1]);
2283 // >>>This is a fix for the moment, until a better solution is
2285 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2287 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2289 // TODO: maintain provenance of an alignment, rather than just make the
2290 // title a concatenation of operations.
2292 if (title.startsWith("Copied sequences"))
2298 newtitle = newtitle.concat("- from " + title);
2302 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2304 } catch (Exception ex)
2306 ex.printStackTrace();
2307 System.out.println("Exception whilst pasting: " + ex);
2308 // could be anything being pasted in here
2309 } catch (OutOfMemoryError oom)
2311 new OOMWarning("Viewing flanking region of alignment", oom);
2322 protected void cut_actionPerformed(ActionEvent e)
2324 copy_actionPerformed(null);
2325 delete_actionPerformed(null);
2335 protected void delete_actionPerformed(ActionEvent evt)
2338 SequenceGroup sg = viewport.getSelectionGroup();
2344 List<SequenceI> seqs = new ArrayList<SequenceI>(sg.getSize());
2346 for (int i = 0; i < sg.getSize(); i++)
2348 seq = sg.getSequenceAt(i);
2352 // If the cut affects all sequences, warn, remove highlighted columns
2353 if (sg.getSize() == viewport.getAlignment().getHeight())
2355 int confirm = JOptionPane.showConfirmDialog(this,
2356 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2357 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2358 JOptionPane.OK_CANCEL_OPTION);
2360 if (confirm == JOptionPane.CANCEL_OPTION
2361 || confirm == JOptionPane.CLOSED_OPTION)
2365 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2366 sg.getEndRes() + 1);
2369 SequenceI[] cut = new SequenceI[seqs.size()];
2370 for (int i = 0; i < seqs.size(); i++)
2372 cut[i] = seqs.get(i);
2376 * //ADD HISTORY ITEM
2378 addHistoryItem(new EditCommand(
2379 MessageManager.getString("label.cut_sequences"), Action.CUT,
2380 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2381 viewport.getAlignment()));
2383 viewport.setSelectionGroup(null);
2384 viewport.sendSelection();
2385 viewport.getAlignment().deleteGroup(sg);
2387 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2389 if (viewport.getAlignment().getHeight() < 1)
2393 this.setClosed(true);
2394 } catch (Exception ex)
2407 protected void deleteGroups_actionPerformed(ActionEvent e)
2409 if (avc.deleteGroups())
2411 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2412 alignPanel.updateAnnotation();
2413 alignPanel.paintAlignment(true);
2424 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2426 SequenceGroup sg = new SequenceGroup();
2428 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2430 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2433 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2434 viewport.setSelectionGroup(sg);
2435 viewport.sendSelection();
2436 alignPanel.paintAlignment(true);
2437 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2447 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2449 if (viewport.cursorMode)
2451 alignPanel.seqPanel.keyboardNo1 = null;
2452 alignPanel.seqPanel.keyboardNo2 = null;
2454 viewport.setSelectionGroup(null);
2455 viewport.getColumnSelection().clear();
2456 viewport.setSelectionGroup(null);
2457 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2458 alignPanel.idPanel.idCanvas.searchResults = null;
2459 alignPanel.paintAlignment(true);
2460 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2461 viewport.sendSelection();
2471 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2473 SequenceGroup sg = viewport.getSelectionGroup();
2477 selectAllSequenceMenuItem_actionPerformed(null);
2482 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2484 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2487 alignPanel.paintAlignment(true);
2488 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2489 viewport.sendSelection();
2493 public void invertColSel_actionPerformed(ActionEvent e)
2495 viewport.invertColumnSelection();
2496 alignPanel.paintAlignment(true);
2497 viewport.sendSelection();
2507 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2509 trimAlignment(true);
2519 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2521 trimAlignment(false);
2524 void trimAlignment(boolean trimLeft)
2526 ColumnSelection colSel = viewport.getColumnSelection();
2529 if (colSel.size() > 0)
2533 column = colSel.getMin();
2537 column = colSel.getMax();
2541 if (viewport.getSelectionGroup() != null)
2543 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2544 viewport.getHiddenRepSequences());
2548 seqs = viewport.getAlignment().getSequencesArray();
2551 TrimRegionCommand trimRegion;
2554 trimRegion = new TrimRegionCommand("Remove Left",
2555 TrimRegionCommand.TRIM_LEFT, seqs, column,
2556 viewport.getAlignment(), viewport.getColumnSelection(),
2557 viewport.getSelectionGroup());
2558 viewport.setStartRes(0);
2562 trimRegion = new TrimRegionCommand("Remove Right",
2563 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2564 viewport.getAlignment(), viewport.getColumnSelection(),
2565 viewport.getSelectionGroup());
2568 statusBar.setText(MessageManager.formatMessage(
2569 "label.removed_columns", new String[]
2570 { Integer.valueOf(trimRegion.getSize()).toString() }));
2572 addHistoryItem(trimRegion);
2574 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2576 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2577 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2579 viewport.getAlignment().deleteGroup(sg);
2583 viewport.firePropertyChange("alignment", null, viewport
2584 .getAlignment().getSequences());
2595 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2597 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2600 if (viewport.getSelectionGroup() != null)
2602 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2603 viewport.getHiddenRepSequences());
2604 start = viewport.getSelectionGroup().getStartRes();
2605 end = viewport.getSelectionGroup().getEndRes();
2609 seqs = viewport.getAlignment().getSequencesArray();
2612 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2613 "Remove Gapped Columns", seqs, start, end,
2614 viewport.getAlignment());
2616 addHistoryItem(removeGapCols);
2618 statusBar.setText(MessageManager.formatMessage(
2619 "label.removed_empty_columns", new String[]
2620 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2622 // This is to maintain viewport position on first residue
2623 // of first sequence
2624 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2625 int startRes = seq.findPosition(viewport.startRes);
2626 // ShiftList shifts;
2627 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2628 // edit.alColumnChanges=shifts.getInverse();
2629 // if (viewport.hasHiddenColumns)
2630 // viewport.getColumnSelection().compensateForEdits(shifts);
2631 viewport.setStartRes(seq.findIndex(startRes) - 1);
2632 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2644 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2646 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2649 if (viewport.getSelectionGroup() != null)
2651 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2652 viewport.getHiddenRepSequences());
2653 start = viewport.getSelectionGroup().getStartRes();
2654 end = viewport.getSelectionGroup().getEndRes();
2658 seqs = viewport.getAlignment().getSequencesArray();
2661 // This is to maintain viewport position on first residue
2662 // of first sequence
2663 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2664 int startRes = seq.findPosition(viewport.startRes);
2666 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2667 viewport.getAlignment()));
2669 viewport.setStartRes(seq.findIndex(startRes) - 1);
2671 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2683 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2685 viewport.setPadGaps(padGapsMenuitem.isSelected());
2686 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2697 public void findMenuItem_actionPerformed(ActionEvent e)
2703 * Create a new view of the current alignment.
2706 public void newView_actionPerformed(ActionEvent e)
2713 * @param copyAnnotation
2714 * if true then duplicate all annnotation, groups and settings
2715 * @return new alignment panel, already displayed.
2717 public AlignmentPanel newView(boolean copyAnnotation)
2719 return newView(null, copyAnnotation);
2725 * title of newly created view
2726 * @return new alignment panel, already displayed.
2728 public AlignmentPanel newView(String viewTitle)
2730 return newView(viewTitle, true);
2736 * title of newly created view
2737 * @param copyAnnotation
2738 * if true then duplicate all annnotation, groups and settings
2739 * @return new alignment panel, already displayed.
2741 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2743 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2745 if (!copyAnnotation)
2747 // just remove all the current annotation except for the automatic stuff
2748 newap.av.getAlignment().deleteAllGroups();
2749 for (AlignmentAnnotation alan : newap.av.getAlignment()
2750 .getAlignmentAnnotation())
2752 if (!alan.autoCalculated)
2754 newap.av.getAlignment().deleteAnnotation(alan);
2760 newap.av.gatherViewsHere = false;
2762 if (viewport.viewName == null)
2764 viewport.viewName = "Original";
2767 newap.av.setHistoryList(viewport.getHistoryList());
2768 newap.av.setRedoList(viewport.getRedoList());
2770 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2771 // make sure the new view has a unique name - this is essential for Jalview
2773 boolean addFirstIndex = false;
2774 if (viewTitle == null || viewTitle.trim().length() == 0)
2776 viewTitle = MessageManager.getString("action.view");
2777 addFirstIndex = true;
2781 index = 1;// we count from 1 if given a specific name
2783 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2784 Vector comps = (Vector) PaintRefresher.components.get(viewport
2785 .getSequenceSetId());
2786 Vector existingNames = new Vector();
2787 for (int i = 0; i < comps.size(); i++)
2789 if (comps.elementAt(i) instanceof AlignmentPanel)
2791 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2792 if (!existingNames.contains(ap.av.viewName))
2794 existingNames.addElement(ap.av.viewName);
2799 while (existingNames.contains(newViewName))
2801 newViewName = viewTitle + " " + (++index);
2804 newap.av.viewName = newViewName;
2806 addAlignmentPanel(newap, true);
2807 newap.alignmentChanged();
2809 if (alignPanels.size() == 2)
2811 viewport.gatherViewsHere = true;
2813 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2818 public void expandViews_actionPerformed(ActionEvent e)
2820 Desktop.instance.explodeViews(this);
2824 public void gatherViews_actionPerformed(ActionEvent e)
2826 Desktop.instance.gatherViews(this);
2836 public void font_actionPerformed(ActionEvent e)
2838 new FontChooser(alignPanel);
2848 protected void seqLimit_actionPerformed(ActionEvent e)
2850 viewport.setShowJVSuffix(seqLimits.isSelected());
2852 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2853 .calculateIdWidth());
2854 alignPanel.paintAlignment(true);
2858 public void idRightAlign_actionPerformed(ActionEvent e)
2860 viewport.rightAlignIds = idRightAlign.isSelected();
2861 alignPanel.paintAlignment(true);
2865 public void centreColumnLabels_actionPerformed(ActionEvent e)
2867 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2868 alignPanel.paintAlignment(true);
2874 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2877 protected void followHighlight_actionPerformed()
2879 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2881 alignPanel.scrollToPosition(
2882 alignPanel.seqPanel.seqCanvas.searchResults, false);
2893 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2895 viewport.setColourText(colourTextMenuItem.isSelected());
2896 alignPanel.paintAlignment(true);
2906 public void wrapMenuItem_actionPerformed(ActionEvent e)
2908 scaleAbove.setVisible(wrapMenuItem.isSelected());
2909 scaleLeft.setVisible(wrapMenuItem.isSelected());
2910 scaleRight.setVisible(wrapMenuItem.isSelected());
2911 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2912 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2916 public void showAllSeqs_actionPerformed(ActionEvent e)
2918 viewport.showAllHiddenSeqs();
2922 public void showAllColumns_actionPerformed(ActionEvent e)
2924 viewport.showAllHiddenColumns();
2929 public void hideSelSequences_actionPerformed(ActionEvent e)
2931 viewport.hideAllSelectedSeqs();
2932 alignPanel.paintAlignment(true);
2936 * called by key handler and the hide all/show all menu items
2941 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2944 boolean hide = false;
2945 SequenceGroup sg = viewport.getSelectionGroup();
2946 if (!toggleSeqs && !toggleCols)
2948 // Hide everything by the current selection - this is a hack - we do the
2949 // invert and then hide
2950 // first check that there will be visible columns after the invert.
2951 if ((viewport.getColumnSelection() != null
2952 && viewport.getColumnSelection().getSelected() != null && viewport
2953 .getColumnSelection().getSelected().size() > 0)
2954 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2957 // now invert the sequence set, if required - empty selection implies
2958 // that no hiding is required.
2961 invertSequenceMenuItem_actionPerformed(null);
2962 sg = viewport.getSelectionGroup();
2966 viewport.expandColSelection(sg, true);
2967 // finally invert the column selection and get the new sequence
2969 invertColSel_actionPerformed(null);
2976 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2978 hideSelSequences_actionPerformed(null);
2981 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2984 showAllSeqs_actionPerformed(null);
2990 if (viewport.getColumnSelection().getSelected().size() > 0)
2992 hideSelColumns_actionPerformed(null);
2995 viewport.setSelectionGroup(sg);
3000 showAllColumns_actionPerformed(null);
3009 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3010 * event.ActionEvent)
3013 public void hideAllButSelection_actionPerformed(ActionEvent e)
3015 toggleHiddenRegions(false, false);
3022 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3026 public void hideAllSelection_actionPerformed(ActionEvent e)
3028 SequenceGroup sg = viewport.getSelectionGroup();
3029 viewport.expandColSelection(sg, false);
3030 viewport.hideAllSelectedSeqs();
3031 viewport.hideSelectedColumns();
3032 alignPanel.paintAlignment(true);
3039 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3043 public void showAllhidden_actionPerformed(ActionEvent e)
3045 viewport.showAllHiddenColumns();
3046 viewport.showAllHiddenSeqs();
3047 alignPanel.paintAlignment(true);
3051 public void hideSelColumns_actionPerformed(ActionEvent e)
3053 viewport.hideSelectedColumns();
3054 alignPanel.paintAlignment(true);
3058 public void hiddenMarkers_actionPerformed(ActionEvent e)
3060 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3071 protected void scaleAbove_actionPerformed(ActionEvent e)
3073 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3074 alignPanel.paintAlignment(true);
3084 protected void scaleLeft_actionPerformed(ActionEvent e)
3086 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3087 alignPanel.paintAlignment(true);
3097 protected void scaleRight_actionPerformed(ActionEvent e)
3099 viewport.setScaleRightWrapped(scaleRight.isSelected());
3100 alignPanel.paintAlignment(true);
3110 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3112 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3113 alignPanel.paintAlignment(true);
3123 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3125 viewport.setShowText(viewTextMenuItem.isSelected());
3126 alignPanel.paintAlignment(true);
3136 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3138 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3139 alignPanel.paintAlignment(true);
3142 public FeatureSettings featureSettings;
3145 public void featureSettings_actionPerformed(ActionEvent e)
3147 if (featureSettings != null)
3149 featureSettings.close();
3150 featureSettings = null;
3152 if (!showSeqFeatures.isSelected())
3154 // make sure features are actually displayed
3155 showSeqFeatures.setSelected(true);
3156 showSeqFeatures_actionPerformed(null);
3158 featureSettings = new FeatureSettings(this);
3162 * Set or clear 'Show Sequence Features'
3168 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3170 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3171 alignPanel.paintAlignment(true);
3172 if (alignPanel.getOverviewPanel() != null)
3174 alignPanel.getOverviewPanel().updateOverviewImage();
3179 * Set or clear 'Show Sequence Features'
3185 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3187 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3189 if (viewport.getShowSequenceFeaturesHeight())
3191 // ensure we're actually displaying features
3192 viewport.setShowSequenceFeatures(true);
3193 showSeqFeatures.setSelected(true);
3195 alignPanel.paintAlignment(true);
3196 if (alignPanel.getOverviewPanel() != null)
3198 alignPanel.getOverviewPanel().updateOverviewImage();
3203 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3204 * the annotations panel as a whole.
3206 * The options to show/hide all annotations should be enabled when the panel
3207 * is shown, and disabled when the panel is hidden.
3212 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3214 final boolean setVisible = annotationPanelMenuItem.isSelected();
3215 viewport.setShowAnnotation(setVisible);
3216 alignPanel.setAnnotationVisible(setVisible);
3217 this.showAllSeqAnnotations.setEnabled(setVisible);
3218 this.hideAllSeqAnnotations.setEnabled(setVisible);
3219 this.showAllAlAnnotations.setEnabled(setVisible);
3220 this.hideAllAlAnnotations.setEnabled(setVisible);
3224 public void alignmentProperties()
3226 JEditorPane editPane = new JEditorPane("text/html", "");
3227 editPane.setEditable(false);
3228 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3230 editPane.setText(MessageManager.formatMessage("label.html_content",
3232 { contents.toString() }));
3233 JInternalFrame frame = new JInternalFrame();
3234 frame.getContentPane().add(new JScrollPane(editPane));
3236 Desktop.instance.addInternalFrame(frame, MessageManager.formatMessage(
3237 "label.alignment_properties", new String[]
3238 { getTitle() }), 500, 400);
3248 public void overviewMenuItem_actionPerformed(ActionEvent e)
3250 if (alignPanel.overviewPanel != null)
3255 JInternalFrame frame = new JInternalFrame();
3256 OverviewPanel overview = new OverviewPanel(alignPanel);
3257 frame.setContentPane(overview);
3258 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3259 "label.overview_params", new String[]
3260 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3262 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3263 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3266 public void internalFrameClosed(
3267 javax.swing.event.InternalFrameEvent evt)
3269 alignPanel.setOverviewPanel(null);
3273 alignPanel.setOverviewPanel(overview);
3277 public void textColour_actionPerformed(ActionEvent e)
3279 new TextColourChooser().chooseColour(alignPanel, null);
3289 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3301 public void clustalColour_actionPerformed(ActionEvent e)
3303 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3304 viewport.getHiddenRepSequences()));
3314 public void zappoColour_actionPerformed(ActionEvent e)
3316 changeColour(new ZappoColourScheme());
3326 public void taylorColour_actionPerformed(ActionEvent e)
3328 changeColour(new TaylorColourScheme());
3338 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3340 changeColour(new HydrophobicColourScheme());
3350 public void helixColour_actionPerformed(ActionEvent e)
3352 changeColour(new HelixColourScheme());
3362 public void strandColour_actionPerformed(ActionEvent e)
3364 changeColour(new StrandColourScheme());
3374 public void turnColour_actionPerformed(ActionEvent e)
3376 changeColour(new TurnColourScheme());
3386 public void buriedColour_actionPerformed(ActionEvent e)
3388 changeColour(new BuriedColourScheme());
3398 public void nucleotideColour_actionPerformed(ActionEvent e)
3400 changeColour(new NucleotideColourScheme());
3404 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3406 changeColour(new PurinePyrimidineColourScheme());
3410 * public void covariationColour_actionPerformed(ActionEvent e) {
3412 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3416 public void annotationColour_actionPerformed(ActionEvent e)
3418 new AnnotationColourChooser(viewport, alignPanel);
3422 public void rnahelicesColour_actionPerformed(ActionEvent e)
3424 new RNAHelicesColourChooser(viewport, alignPanel);
3434 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3436 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3445 public void changeColour(ColourSchemeI cs)
3447 // TODO: compare with applet and pull up to model method
3452 if (viewport.getAbovePIDThreshold())
3454 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3456 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3460 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3463 if (viewport.getConservationSelected())
3466 Alignment al = (Alignment) viewport.getAlignment();
3467 Conservation c = new Conservation("All",
3468 ResidueProperties.propHash, 3, al.getSequences(), 0,
3472 c.verdict(false, viewport.getConsPercGaps());
3474 cs.setConservation(c);
3476 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3481 cs.setConservation(null);
3484 cs.setConsensus(viewport.getSequenceConsensusHash());
3487 viewport.setGlobalColourScheme(cs);
3489 if (viewport.getColourAppliesToAllGroups())
3492 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3500 if (cs instanceof ClustalxColourScheme)
3502 sg.cs = new ClustalxColourScheme(sg,
3503 viewport.getHiddenRepSequences());
3505 else if (cs instanceof UserColourScheme)
3507 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3513 sg.cs = cs.getClass().newInstance();
3514 } catch (Exception ex)
3519 if (viewport.getAbovePIDThreshold()
3520 || cs instanceof PIDColourScheme
3521 || cs instanceof Blosum62ColourScheme)
3523 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3525 sg.cs.setConsensus(AAFrequency.calculate(
3526 sg.getSequences(viewport.getHiddenRepSequences()),
3527 sg.getStartRes(), sg.getEndRes() + 1));
3531 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3534 if (viewport.getConservationSelected())
3536 Conservation c = new Conservation("Group",
3537 ResidueProperties.propHash, 3, sg.getSequences(viewport
3538 .getHiddenRepSequences()), sg.getStartRes(),
3539 sg.getEndRes() + 1);
3541 c.verdict(false, viewport.getConsPercGaps());
3542 sg.cs.setConservation(c);
3546 sg.cs.setConservation(null);
3551 if (alignPanel.getOverviewPanel() != null)
3553 alignPanel.getOverviewPanel().updateOverviewImage();
3556 alignPanel.paintAlignment(true);
3566 protected void modifyPID_actionPerformed(ActionEvent e)
3568 if (viewport.getAbovePIDThreshold()
3569 && viewport.getGlobalColourScheme() != null)
3571 SliderPanel.setPIDSliderSource(alignPanel,
3572 viewport.getGlobalColourScheme(), "Background");
3573 SliderPanel.showPIDSlider();
3584 protected void modifyConservation_actionPerformed(ActionEvent e)
3586 if (viewport.getConservationSelected()
3587 && viewport.getGlobalColourScheme() != null)
3589 SliderPanel.setConservationSlider(alignPanel,
3590 viewport.getGlobalColourScheme(), "Background");
3591 SliderPanel.showConservationSlider();
3602 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3604 viewport.setConservationSelected(conservationMenuItem.isSelected());
3606 viewport.setAbovePIDThreshold(false);
3607 abovePIDThreshold.setSelected(false);
3609 changeColour(viewport.getGlobalColourScheme());
3611 modifyConservation_actionPerformed(null);
3621 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3623 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3625 conservationMenuItem.setSelected(false);
3626 viewport.setConservationSelected(false);
3628 changeColour(viewport.getGlobalColourScheme());
3630 modifyPID_actionPerformed(null);
3640 public void userDefinedColour_actionPerformed(ActionEvent e)
3642 if (e.getActionCommand().equals(
3643 MessageManager.getString("action.user_defined")))
3645 new UserDefinedColours(alignPanel, null);
3649 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3650 .getUserColourSchemes().get(e.getActionCommand());
3656 public void updateUserColourMenu()
3659 Component[] menuItems = colourMenu.getMenuComponents();
3660 int i, iSize = menuItems.length;
3661 for (i = 0; i < iSize; i++)
3663 if (menuItems[i].getName() != null
3664 && menuItems[i].getName().equals("USER_DEFINED"))
3666 colourMenu.remove(menuItems[i]);
3670 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3672 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3673 .getUserColourSchemes().keys();
3675 while (userColours.hasMoreElements())
3677 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3678 userColours.nextElement().toString());
3679 radioItem.setName("USER_DEFINED");
3680 radioItem.addMouseListener(new MouseAdapter()
3683 public void mousePressed(MouseEvent evt)
3685 if (evt.isControlDown()
3686 || SwingUtilities.isRightMouseButton(evt))
3688 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3690 int option = JOptionPane.showInternalConfirmDialog(
3691 jalview.gui.Desktop.desktop,
3693 .getString("label.remove_from_default_list"),
3695 .getString("label.remove_user_defined_colour"),
3696 JOptionPane.YES_NO_OPTION);
3697 if (option == JOptionPane.YES_OPTION)
3699 jalview.gui.UserDefinedColours
3700 .removeColourFromDefaults(radioItem.getText());
3701 colourMenu.remove(radioItem);
3705 radioItem.addActionListener(new ActionListener()
3708 public void actionPerformed(ActionEvent evt)
3710 userDefinedColour_actionPerformed(evt);
3717 radioItem.addActionListener(new ActionListener()
3720 public void actionPerformed(ActionEvent evt)
3722 userDefinedColour_actionPerformed(evt);
3726 colourMenu.insert(radioItem, 15);
3727 colours.add(radioItem);
3739 public void PIDColour_actionPerformed(ActionEvent e)
3741 changeColour(new PIDColourScheme());
3751 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3753 changeColour(new Blosum62ColourScheme());
3763 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3765 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3766 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3767 .getAlignment().getSequenceAt(0), null);
3768 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3769 viewport.getAlignment()));
3770 alignPanel.paintAlignment(true);
3780 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3782 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3783 AlignmentSorter.sortByID(viewport.getAlignment());
3784 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3785 viewport.getAlignment()));
3786 alignPanel.paintAlignment(true);
3796 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3798 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3799 AlignmentSorter.sortByLength(viewport.getAlignment());
3800 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3801 viewport.getAlignment()));
3802 alignPanel.paintAlignment(true);
3812 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3814 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3815 AlignmentSorter.sortByGroup(viewport.getAlignment());
3816 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3817 viewport.getAlignment()));
3819 alignPanel.paintAlignment(true);
3829 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3831 new RedundancyPanel(alignPanel, this);
3841 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3843 if ((viewport.getSelectionGroup() == null)
3844 || (viewport.getSelectionGroup().getSize() < 2))
3846 JOptionPane.showInternalMessageDialog(this, MessageManager
3847 .getString("label.you_must_select_least_two_sequences"),
3848 MessageManager.getString("label.invalid_selection"),
3849 JOptionPane.WARNING_MESSAGE);
3853 JInternalFrame frame = new JInternalFrame();
3854 frame.setContentPane(new PairwiseAlignPanel(viewport));
3855 Desktop.addInternalFrame(frame,
3856 MessageManager.getString("action.pairwise_alignment"), 600,
3868 public void PCAMenuItem_actionPerformed(ActionEvent e)
3870 if (((viewport.getSelectionGroup() != null)
3871 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3872 .getSelectionGroup().getSize() > 0))
3873 || (viewport.getAlignment().getHeight() < 4))
3876 .showInternalMessageDialog(
3879 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3881 .getString("label.sequence_selection_insufficient"),
3882 JOptionPane.WARNING_MESSAGE);
3887 new PCAPanel(alignPanel);
3891 public void autoCalculate_actionPerformed(ActionEvent e)
3893 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3894 if (viewport.autoCalculateConsensus)
3896 viewport.firePropertyChange("alignment", null, viewport
3897 .getAlignment().getSequences());
3902 public void sortByTreeOption_actionPerformed(ActionEvent e)
3904 viewport.sortByTree = sortByTree.isSelected();
3908 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3910 viewport.followSelection = listenToViewSelections.isSelected();
3920 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3922 NewTreePanel("AV", "PID", "Average distance tree using PID");
3932 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3934 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3944 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3946 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3956 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3958 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3971 void NewTreePanel(String type, String pwType, String title)
3975 if (viewport.getSelectionGroup() != null
3976 && viewport.getSelectionGroup().getSize() > 0)
3978 if (viewport.getSelectionGroup().getSize() < 3)
3984 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3986 .getString("label.not_enough_sequences"),
3987 JOptionPane.WARNING_MESSAGE);
3991 SequenceGroup sg = viewport.getSelectionGroup();
3993 /* Decide if the selection is a column region */
3994 for (SequenceI _s : sg.getSequences())
3996 if (_s.getLength() < sg.getEndRes())
4002 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4004 .getString("label.sequences_selection_not_aligned"),
4005 JOptionPane.WARNING_MESSAGE);
4011 title = title + " on region";
4012 tp = new TreePanel(alignPanel, type, pwType);
4016 // are the visible sequences aligned?
4017 if (!viewport.getAlignment().isAligned(false))
4023 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4025 .getString("label.sequences_not_aligned"),
4026 JOptionPane.WARNING_MESSAGE);
4031 if (viewport.getAlignment().getHeight() < 2)
4036 tp = new TreePanel(alignPanel, type, pwType);
4041 if (viewport.viewName != null)
4043 title += viewport.viewName + " of ";
4046 title += this.title;
4048 Desktop.addInternalFrame(tp, title, 600, 500);
4059 public void addSortByOrderMenuItem(String title,
4060 final AlignmentOrder order)
4062 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new String[]{title}));
4064 item.addActionListener(new java.awt.event.ActionListener()
4067 public void actionPerformed(ActionEvent e)
4069 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4071 // TODO: JBPNote - have to map order entries to curent SequenceI
4073 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4075 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4078 alignPanel.paintAlignment(true);
4084 * Add a new sort by annotation score menu item
4087 * the menu to add the option to
4089 * the label used to retrieve scores for each sequence on the
4092 public void addSortByAnnotScoreMenuItem(JMenu sort,
4093 final String scoreLabel)
4095 final JMenuItem item = new JMenuItem(scoreLabel);
4097 item.addActionListener(new java.awt.event.ActionListener()
4100 public void actionPerformed(ActionEvent e)
4102 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4103 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4104 viewport.getAlignment());// ,viewport.getSelectionGroup());
4105 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4106 viewport.getAlignment()));
4107 alignPanel.paintAlignment(true);
4113 * last hash for alignment's annotation array - used to minimise cost of
4116 protected int _annotationScoreVectorHash;
4119 * search the alignment and rebuild the sort by annotation score submenu the
4120 * last alignment annotation vector hash is stored to minimize cost of
4121 * rebuilding in subsequence calls.
4125 public void buildSortByAnnotationScoresMenu()
4127 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4132 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4134 sortByAnnotScore.removeAll();
4135 // almost certainly a quicker way to do this - but we keep it simple
4136 Hashtable scoreSorts = new Hashtable();
4137 AlignmentAnnotation aann[];
4138 for (SequenceI sqa : viewport.getAlignment().getSequences())
4140 aann = sqa.getAnnotation();
4141 for (int i = 0; aann != null && i < aann.length; i++)
4143 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4145 scoreSorts.put(aann[i].label, aann[i].label);
4149 Enumeration labels = scoreSorts.keys();
4150 while (labels.hasMoreElements())
4152 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4153 (String) labels.nextElement());
4155 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4158 _annotationScoreVectorHash = viewport.getAlignment()
4159 .getAlignmentAnnotation().hashCode();
4164 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4165 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4166 * call. Listeners are added to remove the menu item when the treePanel is
4167 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4171 * Displayed tree window.
4173 * SortBy menu item title.
4176 public void buildTreeMenu()
4178 calculateTree.removeAll();
4179 // build the calculate menu
4181 for (final String type : new String[]
4184 String treecalcnm = MessageManager.getString("label.tree_calc_"
4185 + type.toLowerCase());
4186 for (final Object pwtype : ResidueProperties.scoreMatrices.keySet())
4188 JMenuItem tm = new JMenuItem();
4189 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4190 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4192 String smn = MessageManager.getStringOrReturn(
4193 "label.score_model_", sm.getName());
4194 final String title = MessageManager.formatMessage(
4195 "label.treecalc_title", treecalcnm, smn);
4196 tm.setText(title);//
4197 tm.addActionListener(new java.awt.event.ActionListener()
4200 public void actionPerformed(ActionEvent e)
4202 NewTreePanel(type, (String) pwtype, title);
4205 calculateTree.add(tm);
4210 sortByTreeMenu.removeAll();
4212 Vector comps = (Vector) PaintRefresher.components.get(viewport
4213 .getSequenceSetId());
4214 Vector treePanels = new Vector();
4215 int i, iSize = comps.size();
4216 for (i = 0; i < iSize; i++)
4218 if (comps.elementAt(i) instanceof TreePanel)
4220 treePanels.add(comps.elementAt(i));
4224 iSize = treePanels.size();
4228 sortByTreeMenu.setVisible(false);
4232 sortByTreeMenu.setVisible(true);
4234 for (i = 0; i < treePanels.size(); i++)
4236 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
4237 final JMenuItem item = new JMenuItem(tp.getTitle());
4238 item.addActionListener(new java.awt.event.ActionListener()
4241 public void actionPerformed(ActionEvent e)
4243 tp.sortByTree_actionPerformed();
4244 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4249 sortByTreeMenu.add(item);
4253 public boolean sortBy(AlignmentOrder alorder, String undoname)
4255 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4256 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4257 if (undoname != null)
4259 addHistoryItem(new OrderCommand(undoname, oldOrder,
4260 viewport.getAlignment()));
4262 alignPanel.paintAlignment(true);
4267 * Work out whether the whole set of sequences or just the selected set will
4268 * be submitted for multiple alignment.
4271 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4273 // Now, check we have enough sequences
4274 AlignmentView msa = null;
4276 if ((viewport.getSelectionGroup() != null)
4277 && (viewport.getSelectionGroup().getSize() > 1))
4279 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4280 // some common interface!
4282 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4283 * SequenceI[sz = seqs.getSize(false)];
4285 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4286 * seqs.getSequenceAt(i); }
4288 msa = viewport.getAlignmentView(true);
4290 else if (viewport.getSelectionGroup() != null
4291 && viewport.getSelectionGroup().getSize() == 1)
4293 int option = JOptionPane.showConfirmDialog(this,
4294 MessageManager.getString("warn.oneseq_msainput_selection"),
4295 MessageManager.getString("label.invalid_selection"),
4296 JOptionPane.OK_CANCEL_OPTION);
4297 if (option == JOptionPane.OK_OPTION)
4299 msa = viewport.getAlignmentView(false);
4304 msa = viewport.getAlignmentView(false);
4310 * Decides what is submitted to a secondary structure prediction service: the
4311 * first sequence in the alignment, or in the current selection, or, if the
4312 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4313 * region or the whole alignment. (where the first sequence in the set is the
4314 * one that the prediction will be for).
4316 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4318 AlignmentView seqs = null;
4320 if ((viewport.getSelectionGroup() != null)
4321 && (viewport.getSelectionGroup().getSize() > 0))
4323 seqs = viewport.getAlignmentView(true);
4327 seqs = viewport.getAlignmentView(false);
4329 // limit sequences - JBPNote in future - could spawn multiple prediction
4331 // TODO: viewport.getAlignment().isAligned is a global state - the local
4332 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4333 if (!viewport.getAlignment().isAligned(false))
4335 seqs.setSequences(new SeqCigar[]
4336 { seqs.getSequences()[0] });
4337 // TODO: if seqs.getSequences().length>1 then should really have warned
4351 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4353 // Pick the tree file
4354 JalviewFileChooser chooser = new JalviewFileChooser(
4355 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4356 chooser.setFileView(new JalviewFileView());
4357 chooser.setDialogTitle(MessageManager
4358 .getString("label.select_newick_like_tree_file"));
4359 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4361 int value = chooser.showOpenDialog(null);
4363 if (value == JalviewFileChooser.APPROVE_OPTION)
4365 String choice = chooser.getSelectedFile().getPath();
4366 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4367 jalview.io.NewickFile fin = null;
4370 fin = new jalview.io.NewickFile(choice, "File");
4371 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4372 } catch (Exception ex)
4379 .getString("label.problem_reading_tree_file"),
4380 JOptionPane.WARNING_MESSAGE);
4381 ex.printStackTrace();
4383 if (fin != null && fin.hasWarningMessage())
4385 JOptionPane.showMessageDialog(Desktop.desktop, fin
4386 .getWarningMessage(), MessageManager
4387 .getString("label.possible_problem_with_tree_file"),
4388 JOptionPane.WARNING_MESSAGE);
4394 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4396 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4399 public TreePanel ShowNewickTree(NewickFile nf, String title)
4401 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4404 public TreePanel ShowNewickTree(NewickFile nf, String title,
4405 AlignmentView input)
4407 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4410 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4411 int h, int x, int y)
4413 return ShowNewickTree(nf, title, null, w, h, x, y);
4417 * Add a treeviewer for the tree extracted from a newick file object to the
4418 * current alignment view
4425 * Associated alignment input data (or null)
4434 * @return TreePanel handle
4436 public TreePanel ShowNewickTree(NewickFile nf, String title,
4437 AlignmentView input, int w, int h, int x, int y)
4439 TreePanel tp = null;
4445 if (nf.getTree() != null)
4447 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4453 tp.setLocation(x, y);
4456 Desktop.addInternalFrame(tp, title, w, h);
4458 } catch (Exception ex)
4460 ex.printStackTrace();
4466 private boolean buildingMenu = false;
4469 * Generates menu items and listener event actions for web service clients
4472 public void BuildWebServiceMenu()
4474 while (buildingMenu)
4478 System.err.println("Waiting for building menu to finish.");
4480 } catch (Exception e)
4485 final AlignFrame me = this;
4486 buildingMenu = true;
4487 new Thread(new Runnable()
4492 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4495 System.err.println("Building ws menu again "
4496 + Thread.currentThread());
4497 // TODO: add support for context dependent disabling of services based
4499 // alignment and current selection
4500 // TODO: add additional serviceHandle parameter to specify abstract
4502 // class independently of AbstractName
4503 // TODO: add in rediscovery GUI function to restart discoverer
4504 // TODO: group services by location as well as function and/or
4506 // object broker mechanism.
4507 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4508 final IProgressIndicator af = me;
4509 final JMenu msawsmenu = new JMenu("Alignment");
4510 final JMenu secstrmenu = new JMenu(
4511 "Secondary Structure Prediction");
4512 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4513 final JMenu analymenu = new JMenu("Analysis");
4514 final JMenu dismenu = new JMenu("Protein Disorder");
4515 // final JMenu msawsmenu = new
4516 // JMenu(MessageManager.getString("label.alignment"));
4517 // final JMenu secstrmenu = new
4518 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4519 // final JMenu seqsrchmenu = new
4520 // JMenu(MessageManager.getString("label.sequence_database_search"));
4521 // final JMenu analymenu = new
4522 // JMenu(MessageManager.getString("label.analysis"));
4523 // final JMenu dismenu = new
4524 // JMenu(MessageManager.getString("label.protein_disorder"));
4525 // JAL-940 - only show secondary structure prediction services from
4526 // the legacy server
4527 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4529 Discoverer.services != null && (Discoverer.services.size() > 0))
4531 // TODO: refactor to allow list of AbstractName/Handler bindings to
4533 // stored or retrieved from elsewhere
4534 // No MSAWS used any more:
4535 // Vector msaws = null; // (Vector)
4536 // Discoverer.services.get("MsaWS");
4537 Vector secstrpr = (Vector) Discoverer.services
4539 if (secstrpr != null)
4541 // Add any secondary structure prediction services
4542 for (int i = 0, j = secstrpr.size(); i < j; i++)
4544 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4546 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4547 .getServiceClient(sh);
4548 int p = secstrmenu.getItemCount();
4549 impl.attachWSMenuEntry(secstrmenu, me);
4550 int q = secstrmenu.getItemCount();
4551 for (int litm = p; litm < q; litm++)
4553 legacyItems.add(secstrmenu.getItem(litm));
4559 // Add all submenus in the order they should appear on the web
4561 wsmenu.add(msawsmenu);
4562 wsmenu.add(secstrmenu);
4563 wsmenu.add(dismenu);
4564 wsmenu.add(analymenu);
4565 // No search services yet
4566 // wsmenu.add(seqsrchmenu);
4568 javax.swing.SwingUtilities.invokeLater(new Runnable()
4575 webService.removeAll();
4576 // first, add discovered services onto the webservices menu
4577 if (wsmenu.size() > 0)
4579 for (int i = 0, j = wsmenu.size(); i < j; i++)
4581 webService.add(wsmenu.get(i));
4586 webService.add(me.webServiceNoServices);
4588 // TODO: move into separate menu builder class.
4589 boolean new_sspred = false;
4590 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4592 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4593 if (jws2servs != null)
4595 if (jws2servs.hasServices())
4597 jws2servs.attachWSMenuEntry(webService, me);
4598 for (Jws2Instance sv : jws2servs.getServices())
4600 if (sv.description.toLowerCase().contains("jpred"))
4602 for (JMenuItem jmi : legacyItems)
4604 jmi.setVisible(false);
4610 if (jws2servs.isRunning())
4612 JMenuItem tm = new JMenuItem(
4613 "Still discovering JABA Services");
4614 tm.setEnabled(false);
4619 build_urlServiceMenu(me.webService);
4620 build_fetchdbmenu(webService);
4621 for (JMenu item : wsmenu)
4623 if (item.getItemCount() == 0)
4625 item.setEnabled(false);
4629 item.setEnabled(true);
4632 } catch (Exception e)
4635 .debug("Exception during web service menu building process.",
4641 } catch (Exception e)
4646 buildingMenu = false;
4653 * construct any groupURL type service menu entries.
4657 private void build_urlServiceMenu(JMenu webService)
4659 // TODO: remove this code when 2.7 is released
4660 // DEBUG - alignmentView
4662 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4663 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4665 * @Override public void actionPerformed(ActionEvent e) {
4666 * jalview.datamodel.AlignmentView
4667 * .testSelectionViews(af.viewport.getAlignment(),
4668 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4670 * }); webService.add(testAlView);
4672 // TODO: refactor to RestClient discoverer and merge menu entries for
4673 // rest-style services with other types of analysis/calculation service
4674 // SHmmr test client - still being implemented.
4675 // DEBUG - alignmentView
4677 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4680 client.attachWSMenuEntry(
4681 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4687 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4688 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4689 * getProperty("LAST_DIRECTORY"));
4691 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4692 * to Vamsas file"); chooser.setToolTipText("Export");
4694 * int value = chooser.showSaveDialog(this);
4696 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4697 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4698 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4699 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4702 * prototype of an automatically enabled/disabled analysis function
4705 protected void setShowProductsEnabled()
4707 SequenceI[] selection = viewport.getSequenceSelection();
4708 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4709 viewport.getAlignment().getDataset()))
4711 showProducts.setEnabled(true);
4716 showProducts.setEnabled(false);
4721 * search selection for sequence xRef products and build the show products
4726 * @return true if showProducts menu should be enabled.
4728 public boolean canShowProducts(SequenceI[] selection,
4729 boolean isRegionSelection, Alignment dataset)
4731 boolean showp = false;
4734 showProducts.removeAll();
4735 final boolean dna = viewport.getAlignment().isNucleotide();
4736 final Alignment ds = dataset;
4737 String[] ptypes = (selection == null || selection.length == 0) ? null
4738 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4740 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4741 // selection, dataset, true);
4742 final SequenceI[] sel = selection;
4743 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4746 final boolean isRegSel = isRegionSelection;
4747 final AlignFrame af = this;
4748 final String source = ptypes[t];
4749 JMenuItem xtype = new JMenuItem(ptypes[t]);
4750 xtype.addActionListener(new ActionListener()
4754 public void actionPerformed(ActionEvent e)
4756 // TODO: new thread for this call with vis-delay
4757 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4758 isRegSel, dna, source);
4762 showProducts.add(xtype);
4764 showProducts.setVisible(showp);
4765 showProducts.setEnabled(showp);
4766 } catch (Exception e)
4768 jalview.bin.Cache.log
4769 .warn("canTranslate threw an exception - please report to help@jalview.org",
4776 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4777 boolean isRegSel, boolean dna, String source)
4779 final boolean fisRegSel = isRegSel;
4780 final boolean fdna = dna;
4781 final String fsrc = source;
4782 final AlignFrame ths = this;
4783 final SequenceI[] fsel = sel;
4784 Runnable foo = new Runnable()
4790 final long sttime = System.currentTimeMillis();
4791 ths.setProgressBar(MessageManager.formatMessage("status.searching_for_sequences_from", new String[]{fsrc}), sttime);
4794 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4798 Alignment prods = CrossRef
4799 .findXrefSequences(fsel, fdna, fsrc, ds);
4802 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4803 for (int s = 0; s < sprods.length; s++)
4805 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4806 if (ds.getSequences() == null
4807 || !ds.getSequences().contains(
4808 sprods[s].getDatasetSequence()))
4810 ds.addSequence(sprods[s].getDatasetSequence());
4812 sprods[s].updatePDBIds();
4814 Alignment al = new Alignment(sprods);
4815 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4817 for (AlignedCodonFrame acf : cf)
4819 al.addCodonFrame(acf);
4821 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4823 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4824 + " for " + ((fisRegSel) ? "selected region of " : "")
4826 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4831 System.err.println("No Sequences generated for xRef type "
4834 } catch (Exception e)
4836 jalview.bin.Cache.log.error(
4837 "Exception when finding crossreferences", e);
4838 } catch (OutOfMemoryError e)
4840 new OOMWarning("whilst fetching crossreferences", e);
4843 jalview.bin.Cache.log.error("Error when finding crossreferences",
4846 ths.setProgressBar(MessageManager.formatMessage("status.finished_searching_for_sequences_from", new String[]{fsrc}),
4851 Thread frunner = new Thread(foo);
4855 public boolean canShowTranslationProducts(SequenceI[] selection,
4856 AlignmentI alignment)
4861 return (jalview.analysis.Dna.canTranslate(selection,
4862 viewport.getViewAsVisibleContigs(true)));
4863 } catch (Exception e)
4865 jalview.bin.Cache.log
4866 .warn("canTranslate threw an exception - please report to help@jalview.org",
4873 * Construct and display a new frame containing the translation of this
4874 * frame's cDNA sequences to their aligned protein (amino acid) equivalents.
4877 public void showTranslation_actionPerformed(ActionEvent e)
4879 AlignmentI al = null;
4882 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4884 al = dna.translateCdna();
4885 } catch (Exception ex)
4887 jalview.bin.Cache.log.error(
4888 "Exception during translation. Please report this !", ex);
4889 final String msg = MessageManager
4890 .getString("label.error_when_translating_sequences_submit_bug_report");
4891 final String title = MessageManager
4892 .getString("label.implementation_error")
4893 + MessageManager.getString("translation_failed");
4894 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4895 JOptionPane.ERROR_MESSAGE);
4898 if (al == null || al.getHeight() == 0)
4900 final String msg = MessageManager
4901 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4902 final String title = MessageManager
4903 .getString("label.translation_failed");
4904 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4905 JOptionPane.WARNING_MESSAGE);
4909 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4910 Desktop.addInternalFrame(af, MessageManager.formatMessage(
4911 "label.translation_of_params", new String[]
4912 { this.getTitle() }), DEFAULT_WIDTH, DEFAULT_HEIGHT);
4913 // enable next line for linked editing
4914 // viewport.getStructureSelectionManager().addCommandListener(viewport);
4919 * Try to load a features file onto the alignment.
4922 * contents or path to retrieve file
4924 * access mode of file (see jalview.io.AlignFile)
4925 * @return true if features file was parsed corectly.
4927 public boolean parseFeaturesFile(String file, String type)
4929 boolean featuresFile = false;
4932 featuresFile = new FeaturesFile(file, type).parse(viewport
4933 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4934 .getFeatureRenderer().featureColours, false,
4935 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4936 } catch (Exception ex)
4938 ex.printStackTrace();
4943 viewport.showSequenceFeatures = true;
4944 showSeqFeatures.setSelected(true);
4945 if (alignPanel.seqPanel.seqCanvas.fr != null)
4947 // update the min/max ranges where necessary
4948 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4950 if (featureSettings != null)
4952 featureSettings.setTableData();
4954 alignPanel.paintAlignment(true);
4957 return featuresFile;
4961 public void dragEnter(DropTargetDragEvent evt)
4966 public void dragExit(DropTargetEvent evt)
4971 public void dragOver(DropTargetDragEvent evt)
4976 public void dropActionChanged(DropTargetDragEvent evt)
4981 public void drop(DropTargetDropEvent evt)
4983 Transferable t = evt.getTransferable();
4984 java.util.List files = null;
4988 DataFlavor uriListFlavor = new DataFlavor(
4989 "text/uri-list;class=java.lang.String");
4990 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4992 // Works on Windows and MacOSX
4993 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4994 files = (java.util.List) t
4995 .getTransferData(DataFlavor.javaFileListFlavor);
4997 else if (t.isDataFlavorSupported(uriListFlavor))
4999 // This is used by Unix drag system
5000 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5001 String data = (String) t.getTransferData(uriListFlavor);
5002 files = new java.util.ArrayList(1);
5003 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5004 data, "\r\n"); st.hasMoreTokens();)
5006 String s = st.nextToken();
5007 if (s.startsWith("#"))
5009 // the line is a comment (as per the RFC 2483)
5013 java.net.URI uri = new java.net.URI(s);
5014 // check to see if we can handle this kind of URI
5015 if (uri.getScheme().toLowerCase().startsWith("http"))
5017 files.add(uri.toString());
5021 // otherwise preserve old behaviour: catch all for file objects
5022 java.io.File file = new java.io.File(uri);
5023 files.add(file.toString());
5027 } catch (Exception e)
5029 e.printStackTrace();
5035 // check to see if any of these files have names matching sequences in
5037 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5038 .getAlignment().getSequencesArray());
5040 * Object[] { String,SequenceI}
5042 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5043 ArrayList<String> filesnotmatched = new ArrayList<String>();
5044 for (int i = 0; i < files.size(); i++)
5046 String file = files.get(i).toString();
5048 String protocol = FormatAdapter.checkProtocol(file);
5049 if (protocol == jalview.io.FormatAdapter.FILE)
5051 File fl = new File(file);
5052 pdbfn = fl.getName();
5054 else if (protocol == jalview.io.FormatAdapter.URL)
5056 URL url = new URL(file);
5057 pdbfn = url.getFile();
5059 if (pdbfn.length() > 0)
5061 // attempt to find a match in the alignment
5062 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5063 int l = 0, c = pdbfn.indexOf(".");
5064 while (mtch == null && c != -1)
5069 } while ((c = pdbfn.indexOf(".", l)) > l);
5072 pdbfn = pdbfn.substring(0, l);
5074 mtch = idm.findAllIdMatches(pdbfn);
5081 type = new IdentifyFile().Identify(file, protocol);
5082 } catch (Exception ex)
5088 if (type.equalsIgnoreCase("PDB"))
5090 filesmatched.add(new Object[]
5091 { file, protocol, mtch });
5096 // File wasn't named like one of the sequences or wasn't a PDB file.
5097 filesnotmatched.add(file);
5101 if (filesmatched.size() > 0)
5103 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5109 "label.automatically_associate_pdb_files_with_sequences_same_name",
5116 .getString("label.automatically_associate_pdb_files_by_name"),
5117 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5120 for (Object[] fm : filesmatched)
5122 // try and associate
5123 // TODO: may want to set a standard ID naming formalism for
5124 // associating PDB files which have no IDs.
5125 for (SequenceI toassoc : (SequenceI[]) fm[2])
5127 PDBEntry pe = new AssociatePdbFileWithSeq()
5128 .associatePdbWithSeq((String) fm[0],
5129 (String) fm[1], toassoc, false,
5133 System.err.println("Associated file : "
5134 + ((String) fm[0]) + " with "
5135 + toassoc.getDisplayId(true));
5139 alignPanel.paintAlignment(true);
5143 if (filesnotmatched.size() > 0)
5146 && (Cache.getDefault(
5147 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5150 "<html>"+MessageManager
5152 "label.ignore_unmatched_dropped_files_info",
5157 .toString() })+"</html>",
5159 .getString("label.ignore_unmatched_dropped_files"),
5160 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5164 for (String fn : filesnotmatched)
5166 loadJalviewDataFile(fn, null, null, null);
5170 } catch (Exception ex)
5172 ex.printStackTrace();
5178 * Attempt to load a "dropped" file or URL string: First by testing whether
5179 * it's and Annotation file, then a JNet file, and finally a features file. If
5180 * all are false then the user may have dropped an alignment file onto this
5184 * either a filename or a URL string.
5186 public void loadJalviewDataFile(String file, String protocol,
5187 String format, SequenceI assocSeq)
5191 if (protocol == null)
5193 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5195 // if the file isn't identified, or not positively identified as some
5196 // other filetype (PFAM is default unidentified alignment file type) then
5197 // try to parse as annotation.
5198 boolean isAnnotation = (format == null || format
5199 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5200 .readAnnotationFile(viewport.getAlignment(), file, protocol)
5205 // first see if its a T-COFFEE score file
5206 TCoffeeScoreFile tcf = null;
5209 tcf = new TCoffeeScoreFile(file, protocol);
5212 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5214 tcoffeeColour.setEnabled(true);
5215 tcoffeeColour.setSelected(true);
5216 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5217 isAnnotation = true;
5219 .setText(MessageManager
5220 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5224 // some problem - if no warning its probable that the ID matching
5225 // process didn't work
5229 tcf.getWarningMessage() == null ? MessageManager
5230 .getString("label.check_file_matches_sequence_ids_alignment")
5231 : tcf.getWarningMessage(),
5233 .getString("label.problem_reading_tcoffee_score_file"),
5234 JOptionPane.WARNING_MESSAGE);
5241 } catch (Exception x)
5244 .debug("Exception when processing data source as T-COFFEE score file",
5250 // try to see if its a JNet 'concise' style annotation file *before*
5252 // try to parse it as a features file
5255 format = new IdentifyFile().Identify(file, protocol);
5257 if (format.equalsIgnoreCase("JnetFile"))
5259 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5261 new JnetAnnotationMaker().add_annotation(predictions,
5262 viewport.getAlignment(), 0, false);
5263 isAnnotation = true;
5268 * if (format.equalsIgnoreCase("PDB")) {
5270 * String pdbfn = ""; // try to match up filename with sequence id
5271 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5272 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5273 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5274 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5275 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5276 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5277 * // attempt to find a match in the alignment SequenceI mtch =
5278 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5279 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5280 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5281 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5282 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5283 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5284 * { System.err.println("Associated file : " + file + " with " +
5285 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5286 * TODO: maybe need to load as normal otherwise return; } }
5288 // try to parse it as a features file
5289 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5290 // if it wasn't a features file then we just treat it as a general
5291 // alignment file to load into the current view.
5294 new FileLoader().LoadFile(viewport, file, protocol, format);
5298 alignPanel.paintAlignment(true);
5306 alignPanel.adjustAnnotationHeight();
5307 viewport.updateSequenceIdColours();
5308 buildSortByAnnotationScoresMenu();
5309 alignPanel.paintAlignment(true);
5311 } catch (Exception ex)
5313 ex.printStackTrace();
5314 } catch (OutOfMemoryError oom)
5319 } catch (Exception x)
5325 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5326 : "using " + protocol + " from " + file)
5328 + (format != null ? "(parsing as '" + format
5329 + "' file)" : ""), oom, Desktop.desktop);
5334 public void tabSelectionChanged(int index)
5338 alignPanel = alignPanels.get(index);
5339 viewport = alignPanel.av;
5340 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5341 setMenusFromViewport(viewport);
5346 public void tabbedPane_mousePressed(MouseEvent e)
5348 if (SwingUtilities.isRightMouseButton(e))
5350 String reply = JOptionPane.showInternalInputDialog(this,
5351 MessageManager.getString("label.enter_view_name"),
5352 MessageManager.getString("label.enter_view_name"),
5353 JOptionPane.QUESTION_MESSAGE);
5357 viewport.viewName = reply;
5358 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5363 public AlignViewport getCurrentView()
5369 * Open the dialog for regex description parsing.
5372 protected void extractScores_actionPerformed(ActionEvent e)
5374 ParseProperties pp = new jalview.analysis.ParseProperties(
5375 viewport.getAlignment());
5376 // TODO: verify regex and introduce GUI dialog for version 2.5
5377 // if (pp.getScoresFromDescription("col", "score column ",
5378 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5380 if (pp.getScoresFromDescription("description column",
5381 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5383 buildSortByAnnotationScoresMenu();
5391 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5395 protected void showDbRefs_actionPerformed(ActionEvent e)
5397 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5403 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5407 protected void showNpFeats_actionPerformed(ActionEvent e)
5409 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5413 * find the viewport amongst the tabs in this alignment frame and close that
5418 public boolean closeView(AlignmentViewport av)
5422 this.closeMenuItem_actionPerformed(false);
5425 Component[] comp = tabbedPane.getComponents();
5426 for (int i = 0; comp != null && i < comp.length; i++)
5428 if (comp[i] instanceof AlignmentPanel)
5430 if (((AlignmentPanel) comp[i]).av == av)
5433 closeView((AlignmentPanel) comp[i]);
5441 protected void build_fetchdbmenu(JMenu webService)
5443 // Temporary hack - DBRef Fetcher always top level ws entry.
5444 // TODO We probably want to store a sequence database checklist in
5445 // preferences and have checkboxes.. rather than individual sources selected
5447 final JMenu rfetch = new JMenu(
5448 MessageManager.getString("action.fetch_db_references"));
5449 rfetch.setToolTipText(MessageManager
5450 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5451 webService.add(rfetch);
5453 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5454 MessageManager.getString("option.trim_retrieved_seqs"));
5455 trimrs.setToolTipText(MessageManager
5456 .getString("label.trim_retrieved_sequences"));
5457 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5458 trimrs.addActionListener(new ActionListener()
5461 public void actionPerformed(ActionEvent e)
5463 trimrs.setSelected(trimrs.isSelected());
5464 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5465 Boolean.valueOf(trimrs.isSelected()).toString());
5469 JMenuItem fetchr = new JMenuItem(
5470 MessageManager.getString("label.standard_databases"));
5471 fetchr.setToolTipText(MessageManager
5472 .getString("label.fetch_embl_uniprot"));
5473 fetchr.addActionListener(new ActionListener()
5477 public void actionPerformed(ActionEvent e)
5479 new Thread(new Runnable()
5485 new jalview.ws.DBRefFetcher(alignPanel.av
5486 .getSequenceSelection(), alignPanel.alignFrame)
5487 .fetchDBRefs(false);
5495 final AlignFrame me = this;
5496 new Thread(new Runnable()
5501 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5502 .getSequenceFetcherSingleton(me);
5503 javax.swing.SwingUtilities.invokeLater(new Runnable()
5508 String[] dbclasses = sf.getOrderedSupportedSources();
5509 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5510 // jalview.util.QuickSort.sort(otherdb, otherdb);
5511 List<DbSourceProxy> otherdb;
5512 JMenu dfetch = new JMenu();
5513 JMenu ifetch = new JMenu();
5514 JMenuItem fetchr = null;
5515 int comp = 0, icomp = 0, mcomp = 15;
5516 String mname = null;
5518 for (String dbclass : dbclasses)
5520 otherdb = sf.getSourceProxy(dbclass);
5521 // add a single entry for this class, or submenu allowing 'fetch
5523 if (otherdb == null || otherdb.size() < 1)
5527 // List<DbSourceProxy> dbs=otherdb;
5528 // otherdb=new ArrayList<DbSourceProxy>();
5529 // for (DbSourceProxy db:dbs)
5531 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5535 mname = "From " + dbclass;
5537 if (otherdb.size() == 1)
5539 final DbSourceProxy[] dassource = otherdb
5540 .toArray(new DbSourceProxy[0]);
5541 DbSourceProxy src = otherdb.get(0);
5542 fetchr = new JMenuItem(src.getDbSource());
5543 fetchr.addActionListener(new ActionListener()
5547 public void actionPerformed(ActionEvent e)
5549 new Thread(new Runnable()
5555 new jalview.ws.DBRefFetcher(alignPanel.av
5556 .getSequenceSelection(),
5557 alignPanel.alignFrame, dassource)
5558 .fetchDBRefs(false);
5564 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new String[]{src.getDbName()})));
5570 final DbSourceProxy[] dassource = otherdb
5571 .toArray(new DbSourceProxy[0]);
5573 DbSourceProxy src = otherdb.get(0);
5574 fetchr = new JMenuItem(MessageManager.formatMessage(
5575 "label.fetch_all_param", new String[]
5576 { src.getDbSource() }));
5577 fetchr.addActionListener(new ActionListener()
5580 public void actionPerformed(ActionEvent e)
5582 new Thread(new Runnable()
5588 new jalview.ws.DBRefFetcher(alignPanel.av
5589 .getSequenceSelection(),
5590 alignPanel.alignFrame, dassource)
5591 .fetchDBRefs(false);
5597 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new String[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5600 // and then build the rest of the individual menus
5601 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new String[]{src.getDbSource()}));
5603 String imname = null;
5605 for (DbSourceProxy sproxy : otherdb)
5607 String dbname = sproxy.getDbName();
5608 String sname = dbname.length() > 5 ? dbname.substring(0,
5609 5) + "..." : dbname;
5610 String msname = dbname.length() > 10 ? dbname.substring(
5611 0, 10) + "..." : dbname;
5614 imname = MessageManager.formatMessage("label.from_msname", new String[]{sname});
5616 fetchr = new JMenuItem(msname);
5617 final DbSourceProxy[] dassrc =
5619 fetchr.addActionListener(new ActionListener()
5623 public void actionPerformed(ActionEvent e)
5625 new Thread(new Runnable()
5631 new jalview.ws.DBRefFetcher(alignPanel.av
5632 .getSequenceSelection(),
5633 alignPanel.alignFrame, dassrc)
5634 .fetchDBRefs(false);
5640 fetchr.setToolTipText("<html>"
5641 + MessageManager.formatMessage("label.fetch_retrieve_from", new String[]{dbname}));
5644 if (++icomp >= mcomp || i == (otherdb.size()))
5646 ifetch.setText(MessageManager.formatMessage(
5647 "label.source_to_target", imname, sname));
5649 ifetch = new JMenu();
5657 if (comp >= mcomp || dbi >= (dbclasses.length))
5659 dfetch.setText(MessageManager.formatMessage(
5660 "label.source_to_target", mname, dbclass));
5662 dfetch = new JMenu();
5675 * Left justify the whole alignment.
5678 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5680 AlignmentI al = viewport.getAlignment();
5682 viewport.firePropertyChange("alignment", null, al);
5686 * Right justify the whole alignment.
5689 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5691 AlignmentI al = viewport.getAlignment();
5693 viewport.firePropertyChange("alignment", null, al);
5696 public void setShowSeqFeatures(boolean b)
5698 showSeqFeatures.setSelected(true);
5699 viewport.setShowSequenceFeatures(true);
5706 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5707 * awt.event.ActionEvent)
5710 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5712 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5713 alignPanel.paintAlignment(true);
5720 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5724 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5726 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5727 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5735 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5736 * .event.ActionEvent)
5739 protected void showGroupConservation_actionPerformed(ActionEvent e)
5741 viewport.setShowGroupConservation(showGroupConservation.getState());
5742 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5749 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5750 * .event.ActionEvent)
5753 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5755 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5756 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5763 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5764 * .event.ActionEvent)
5767 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5769 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5770 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5774 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5776 showSequenceLogo.setState(true);
5777 viewport.setShowSequenceLogo(true);
5778 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5779 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5783 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5785 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5792 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5793 * .event.ActionEvent)
5796 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5798 if (avc.makeGroupsFromSelection())
5800 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5801 alignPanel.updateAnnotation();
5802 alignPanel.paintAlignment(true);
5807 protected void createGroup_actionPerformed(ActionEvent e)
5809 if (avc.createGroup())
5811 alignPanel.alignmentChanged();
5816 protected void unGroup_actionPerformed(ActionEvent e)
5820 alignPanel.alignmentChanged();
5825 * make the given alignmentPanel the currently selected tab
5827 * @param alignmentPanel
5829 public void setDisplayedView(AlignmentPanel alignmentPanel)
5831 if (!viewport.getSequenceSetId().equals(
5832 alignmentPanel.av.getSequenceSetId()))
5834 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5836 if (tabbedPane != null
5837 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5838 .getSelectedIndex())
5840 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5845 * Action on selection of menu options to Show or Hide annotations.
5848 * @param forSequences
5849 * update sequence-related annotations
5850 * @param forAlignment
5851 * update non-sequence-related annotations
5854 protected void setAnnotationsVisibility(boolean visible,
5855 boolean forSequences, boolean forAlignment)
5857 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5858 .getAlignmentAnnotation())
5860 boolean apply = (aa.sequenceRef == null && forAlignment)
5861 || (aa.sequenceRef != null && forSequences);
5864 aa.visible = visible;
5867 alignPanel.validateAnnotationDimensions(false);
5868 alignPanel.alignmentChanged();
5872 * Store selected annotation sort order for the view and repaint.
5875 protected void sortAnnotations_actionPerformed()
5877 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5879 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5880 alignPanel.paintAlignment(true);
5885 * @return alignment panels in this alignment frame
5887 public List<? extends AlignmentViewPanel> getAlignPanels()
5889 return alignPanels == null ? Arrays.asList(alignPanel)
5894 * Open a new alignment window, with the cDNA associated with this (protein)
5895 * alignment, aligned as is the protein.
5898 protected void viewAsCdna_actionPerformed()
5900 final AlignmentI alignment = getViewport().getAlignment();
5901 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5902 if (mappings == null)
5906 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
5907 for (SequenceI aaSeq : alignment.getSequences()) {
5908 for (AlignedCodonFrame acf : mappings) {
5909 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5913 * There is a cDNA mapping for this protein sequence - add to new
5914 * alignment. It will share the same dataset sequence as other mapped
5915 * cDNA (no new mappings need to be created).
5917 final Sequence newSeq = new Sequence(dnaSeq);
5918 newSeq.setDatasetSequence(dnaSeq);
5919 cdnaSeqs.add(newSeq);
5923 if (cdnaSeqs.size() == 0)
5925 // show a warning dialog no mapped cDNA
5928 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
5930 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5931 AlignFrame.DEFAULT_HEIGHT);
5932 cdna.alignAs(alignment);
5933 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5935 Desktop.addInternalFrame(alignFrame, newtitle,
5936 AlignFrame.DEFAULT_WIDTH,
5937 AlignFrame.DEFAULT_HEIGHT);
5942 class PrintThread extends Thread
5946 public PrintThread(AlignmentPanel ap)
5951 static PageFormat pf;
5956 PrinterJob printJob = PrinterJob.getPrinterJob();
5960 printJob.setPrintable(ap, pf);
5964 printJob.setPrintable(ap);
5967 if (printJob.printDialog())
5972 } catch (Exception PrintException)
5974 PrintException.printStackTrace();