2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Softwarechang
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 import java.awt.datatransfer.*;
27 import java.awt.event.*;
28 import java.awt.print.*;
31 import jalview.analysis.*;
32 import jalview.datamodel.*;
34 import jalview.jbgui.*;
35 import jalview.schemes.*;
36 import jalview.util.ShiftList;
38 import java.awt.dnd.*;
39 import org.biojava.dasobert.eventmodel.*;
47 public class AlignFrame
48 extends GAlignFrame implements DropTargetListener, FeatureListener
51 public static final int NEW_WINDOW_WIDTH = 700;
54 public static final int NEW_WINDOW_HEIGHT = 500;
55 AlignmentPanel alignPanel;
56 AlignViewport viewport;
59 public String currentFileFormat = null;
60 Stack historyList = new Stack();
61 Stack redoList = new Stack();
62 private int treeCount = 0;
65 * new alignment window with hidden columns
66 * @param al AlignmentI
67 * @param hiddenColumns ColumnSelection or null
69 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns) {
71 viewport = new AlignViewport(al, hiddenColumns);
73 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
75 if(viewport.vconsensus==null)
77 //Out of memory calculating consensus.
78 BLOSUM62Colour.setEnabled(false);
79 PIDColour.setEnabled(false);
80 conservationMenuItem.setEnabled(false);
81 modifyConservation.setEnabled(false);
82 abovePIDThreshold.setEnabled(false);
83 modifyPID.setEnabled(false);
86 alignPanel = new AlignmentPanel(this, viewport);
88 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
90 if(sortby.equals("Id"))
91 sortIDMenuItem_actionPerformed(null);
92 else if(sortby.equals("Pairwise Identity"))
93 sortPairwiseMenuItem_actionPerformed(null);
95 // remove(tabbedPane);
96 getContentPane().add(alignPanel, BorderLayout.CENTER);
100 // tabbedPane.add(al.isNucleotide() ? "DNA":"Protein", alignPanel);
103 /////////////////////////
104 if(al.getDataset()==null)
108 // AlignViewport ds = new AlignViewport(al.getDataset(), true);
109 // AlignmentPanel dap = new AlignmentPanel(this, ds);
110 // tabbedPane.add("Dataset", dap);
111 // viewports.add(ds);
112 // alignPanels.add(dap);
113 /////////////////////////
116 viewport.addPropertyChangeListener(new PropertyChangeListener()
118 public void propertyChange(PropertyChangeEvent evt)
120 if (evt.getPropertyName().equals("alignment"))
128 if (Desktop.desktop != null)
130 addServiceListeners();
131 setGUINucleotide(al.isNucleotide());
135 if (jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false))
137 wrapMenuItem.setSelected(true);
138 wrapMenuItem_actionPerformed(null);
145 * Creates a new AlignFrame object.
147 * @param al DOCUMENT ME!
149 public AlignFrame(AlignmentI al)
154 public AlignViewport getViewport()
159 /* Set up intrinsic listeners for dynamically generated GUI bits. */
160 private void addServiceListeners()
162 final java.beans.PropertyChangeListener thisListener;
163 // Do this once to get current state
164 BuildWebServiceMenu();
165 Desktop.discoverer.addPropertyChangeListener(
166 thisListener = new java.beans.PropertyChangeListener()
168 public void propertyChange(PropertyChangeEvent evt)
170 // System.out.println("Discoverer property change.");
171 if (evt.getPropertyName().equals("services"))
173 // System.out.println("Rebuilding web service menu");
174 BuildWebServiceMenu();
178 addInternalFrameListener(new javax.swing.event.
179 InternalFrameAdapter()
181 public void internalFrameClosed(
182 javax.swing.event.InternalFrameEvent evt)
184 // System.out.println("deregistering discoverer listener");
185 Desktop.discoverer.removePropertyChangeListener(thisListener);
186 closeMenuItem_actionPerformed(null);
192 public void setGUINucleotide(boolean nucleotide)
194 showTranslation.setVisible( nucleotide );
195 //sequenceFeatures.setVisible(!nucleotide );
196 //featureSettings.setVisible( !nucleotide );
197 conservationMenuItem.setVisible( !nucleotide );
198 modifyConservation.setVisible( !nucleotide );
200 //Remember AlignFrame always starts as protein
203 calculateMenu.remove(calculateMenu.getItemCount()-2);
207 public void comeBackLater(FeatureEvent evt)
210 public void newFeatures(FeatureEvent evt)
212 if (evt.getFeatures().length > 0)
214 alignPanel.seqPanel.seqCanvas.fr.featuresAdded();
215 alignPanel.repaint();
219 Hashtable progressBars;
220 public void setProgressBar(String message, long id)
222 if(progressBars == null)
223 progressBars = new Hashtable();
225 JPanel progressPanel;
226 GridLayout layout = (GridLayout) statusPanel.getLayout();
227 if(progressBars.get( new Long(id) )!=null)
229 progressPanel = (JPanel)progressBars.get( new Long(id) );
230 statusPanel.remove(progressPanel);
231 progressBars.remove( progressPanel );
232 progressPanel = null;
234 statusBar.setText(message);
236 layout.setRows(layout.getRows() - 1);
240 progressPanel = new JPanel(new BorderLayout(10, 5));
242 JProgressBar progressBar = new JProgressBar();
243 progressBar.setIndeterminate(true);
245 progressPanel.add(new JLabel(message), BorderLayout.WEST);
246 progressPanel.add(progressBar, BorderLayout.CENTER);
248 layout.setRows(layout.getRows() + 1);
249 statusPanel.add(progressPanel);
251 progressBars.put(new Long(id), progressPanel);
259 Added so Castor Mapping file can obtain Jalview Version
261 public String getVersion()
263 return jalview.bin.Cache.getProperty("VERSION");
266 public FeatureRenderer getFeatureRenderer()
268 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
272 public void fetchSequence_actionPerformed(ActionEvent e)
274 new SequenceFetcher(this);
277 public void addFromFile_actionPerformed(ActionEvent e)
279 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
282 public void addFromText_actionPerformed(ActionEvent e)
284 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
287 public void addFromURL_actionPerformed(ActionEvent e)
289 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
295 * @param e DOCUMENT ME!
297 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
299 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
300 getProperty( "LAST_DIRECTORY"),
302 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
304 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
309 chooser.setFileView(new JalviewFileView());
310 chooser.setDialogTitle("Save Alignment to file");
311 chooser.setToolTipText("Save");
313 int value = chooser.showSaveDialog(this);
315 if (value == JalviewFileChooser.APPROVE_OPTION)
317 currentFileFormat = chooser.getSelectedFormat();
319 if (currentFileFormat == null)
321 JOptionPane.showInternalMessageDialog(Desktop.desktop,
322 "You must select a file format before saving!",
323 "File format not specified",
324 JOptionPane.WARNING_MESSAGE);
325 value = chooser.showSaveDialog(this);
329 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
332 String choice = chooser.getSelectedFile().getPath();
333 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
335 saveAlignment(choice, currentFileFormat);
339 public boolean saveAlignment(String file, String format)
341 if (format.equalsIgnoreCase("Jalview"))
343 String shortName = title;
345 if (shortName.indexOf(java.io.File.separatorChar) > -1)
347 shortName = shortName.substring(shortName.lastIndexOf(
348 java.io.File.separatorChar) + 1);
351 new Jalview2XML().SaveAlignment(this, file, shortName);
353 // USE Jalview2XML to save this file
359 String[] omitHidden = null;
361 if (viewport.hasHiddenColumns)
363 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
364 "The Alignment contains hidden columns."
365 + "\nDo you want to save only the visible alignment?",
366 "Save / Omit Hidden Columns",
367 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
369 if (reply == JOptionPane.YES_OPTION)
370 omitHidden = viewport.getViewAsString(false);
373 String output = new FormatAdapter().formatSequences(
375 viewport.alignment.getSequencesArray(),
385 java.io.PrintWriter out = new java.io.PrintWriter(
386 new java.io.FileWriter(file));
395 ex.printStackTrace();
404 * @param e DOCUMENT ME!
406 protected void outputText_actionPerformed(ActionEvent e)
408 String [] omitHidden = null;
410 if(viewport.hasHiddenColumns)
412 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
413 "The Alignment contains hidden columns."
414 +"\nDo you want to output only the visible alignment?",
415 "Save / Omit Hidden Columns",
416 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
418 if(reply==JOptionPane.YES_OPTION)
420 omitHidden = viewport.getViewAsString(false);
424 CutAndPasteTransfer cap = new CutAndPasteTransfer();
425 Desktop.addInternalFrame(cap,
426 "Alignment output - " + e.getActionCommand(), 600,
430 cap.setText(new FormatAdapter().formatSequences(
431 e.getActionCommand(),
432 viewport.alignment.getSequencesArray(),
439 * @param e DOCUMENT ME!
441 protected void htmlMenuItem_actionPerformed(ActionEvent e)
443 new HTMLOutput(viewport,
444 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
445 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
448 public void createImageMap(File file, String image)
450 alignPanel.makePNGImageMap(file, image);
456 * @param e DOCUMENT ME!
458 public void createPNG(File f)
460 alignPanel.makePNG(f);
466 * @param e DOCUMENT ME!
468 public void createEPS(File f)
470 alignPanel.makeEPS(f);
476 * @param e DOCUMENT ME!
478 public void printMenuItem_actionPerformed(ActionEvent e)
480 //Putting in a thread avoids Swing painting problems
481 PrintThread thread = new PrintThread();
485 public void exportFeatures_actionPerformed(ActionEvent e)
487 new AnnotationExporter().exportFeatures(alignPanel);
491 public void exportAnnotations_actionPerformed(ActionEvent e)
493 new AnnotationExporter().exportAnnotations(
495 viewport.alignment.getAlignmentAnnotation()
500 public void associatedData_actionPerformed(ActionEvent e)
502 // Pick the tree file
503 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
506 chooser.setFileView(new JalviewFileView());
507 chooser.setDialogTitle("Load Jalview Annotations or Features File");
508 chooser.setToolTipText("Load Jalview Annotations / Features file");
510 int value = chooser.showOpenDialog(null);
512 if (value == JalviewFileChooser.APPROVE_OPTION)
514 String choice = chooser.getSelectedFile().getPath();
515 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
516 loadJalviewDataFile(choice);
524 * @param e DOCUMENT ME!
526 public void closeMenuItem_actionPerformed(ActionEvent e)
530 PaintRefresher.components.remove(viewport.alignment);
531 this.setClosed(true);
541 void updateEditMenuBar()
543 if (historyList.size() > 0)
545 undoMenuItem.setEnabled(true);
547 HistoryItem hi = (HistoryItem) historyList.peek();
548 undoMenuItem.setText("Undo " + hi.getDescription());
552 undoMenuItem.setEnabled(false);
553 undoMenuItem.setText("Undo");
556 if (redoList.size() > 0)
558 redoMenuItem.setEnabled(true);
560 HistoryItem hi = (HistoryItem) redoList.peek();
561 redoMenuItem.setText("Redo " + hi.getDescription());
565 redoMenuItem.setEnabled(false);
566 redoMenuItem.setText("Redo");
573 * @param hi DOCUMENT ME!
575 public void addHistoryItem(HistoryItem hi)
577 historyList.push(hi);
585 * @param e DOCUMENT ME!
587 protected void undoMenuItem_actionPerformed(ActionEvent e)
589 HistoryItem nh,hi = (HistoryItem) historyList.pop();
590 redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
592 if (hi.alColumnChanges!=null)
593 nh.alColumnChanges = hi.alColumnChanges.getInverse();
594 restoreHistoryItem(hi);
595 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
601 * @param e DOCUMENT ME!
603 protected void redoMenuItem_actionPerformed(ActionEvent e)
605 HistoryItem nh,hi = (HistoryItem) redoList.pop();
606 historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
608 if (hi.alColumnChanges!=null)
609 nh.alColumnChanges=hi.alColumnChanges.getInverse();
610 restoreHistoryItem(hi);
612 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
615 // used by undo and redo
616 void restoreHistoryItem(HistoryItem hi)
619 hi.restore(viewport.getColumnSelection());
623 viewport.firePropertyChange("alignment", null,
624 viewport.getAlignment().getSequences());
630 * @param up DOCUMENT ME!
632 public void moveSelectedSequences(boolean up)
634 SequenceGroup sg = viewport.getSelectionGroup();
643 for (int i = 1; i < viewport.alignment.getHeight(); i++)
645 SequenceI seq = viewport.alignment.getSequenceAt(i);
647 if (!sg.getSequences(false).contains(seq))
652 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
654 if (sg.getSequences(false).contains(temp))
659 viewport.alignment.getSequences().setElementAt(temp, i);
660 viewport.alignment.getSequences().setElementAt(seq, i - 1);
665 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
667 SequenceI seq = viewport.alignment.getSequenceAt(i);
669 if (!sg.getSequences(false).contains(seq))
674 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
676 if (sg.getSequences(false).contains(temp))
681 viewport.alignment.getSequences().setElementAt(temp, i);
682 viewport.alignment.getSequences().setElementAt(seq, i + 1);
686 alignPanel.repaint();
694 * @param e DOCUMENT ME!
696 protected void copy_actionPerformed(ActionEvent e)
698 if (viewport.getSelectionGroup() == null)
703 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
704 String[] omitHidden = null;
706 if (viewport.hasHiddenColumns)
708 omitHidden = viewport.getViewAsString(true);
711 String output = new FormatAdapter().formatSequences(
717 Toolkit.getDefaultToolkit().getSystemClipboard()
718 .setContents(new StringSelection(output), Desktop.instance);
720 Vector hiddenColumns = null;
721 if(viewport.hasHiddenColumns)
723 hiddenColumns =new Vector();
724 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
725 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
727 int[] region = (int[])
728 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
730 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
731 region[1]-hiddenOffset});
735 Desktop.jalviewClipboard = new Object[]{ seqs,
736 viewport.alignment.getDataset(),
743 * @param e DOCUMENT ME!
745 protected void pasteNew_actionPerformed(ActionEvent e)
753 * @param e DOCUMENT ME!
755 protected void pasteThis_actionPerformed(ActionEvent e)
757 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
765 * @param newAlignment DOCUMENT ME!
767 void paste(boolean newAlignment)
771 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
772 Transferable contents = c.getContents(this);
774 if (contents == null)
779 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
783 String format = new IdentifyFile().Identify(str, "Paste");
784 SequenceI[] sequences;
787 if(Desktop.jalviewClipboard!=null)
789 // The clipboard was filled from within Jalview, we must use the sequences
790 // And dataset from the copied alignment
791 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
795 sequences = new FormatAdapter().readFile(str, "Paste", format);
798 AlignmentI alignment = null;
802 alignment = new Alignment(sequences);
804 if(Desktop.jalviewClipboard!=null)
805 alignment.setDataset( (Alignment)Desktop.jalviewClipboard[1] );
807 alignment.setDataset( null );
812 alignment = viewport.getAlignment();
815 for (int i = 0; i < sequences.length; i++)
817 Sequence newseq = new Sequence(sequences[i].getName(),
818 sequences[i].getSequence(), sequences[i].getStart(),
819 sequences[i].getEnd());
821 alignment.addSequence(newseq);
825 viewport.setEndSeq(alignment.getHeight());
826 alignment.getWidth();
827 viewport.firePropertyChange("alignment", null, alignment.getSequences());
834 // Add any annotations attached to sequences
835 for (int i = 0; i < sequences.length; i++)
837 if (sequences[i].getAnnotation() != null)
839 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
841 AlignmentAnnotation newAnnot =
842 new AlignmentAnnotation(
843 sequences[i].getAnnotation()[a].label,
844 sequences[i].getAnnotation()[a].description,
845 sequences[i].getAnnotation()[a].annotations,
846 sequences[i].getAnnotation()[a].graphMin,
847 sequences[i].getAnnotation()[a].graphMax,
848 sequences[i].getAnnotation()[a].graph);
850 sequences[i].getAnnotation()[a] = newAnnot;
851 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
853 newAnnot.sequenceRef = sequences[i];
854 newAnnot.adjustForAlignment();
855 alignment.addAnnotation(newAnnot);
856 alignment.setAnnotationIndex(newAnnot, a);
859 alignPanel.annotationPanel.adjustPanelHeight();
865 AlignFrame af = new AlignFrame(alignment);
866 String newtitle = new String("Copied sequences");
868 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
870 Vector hc = (Vector)Desktop.jalviewClipboard[2];
871 for(int i=0; i<hc.size(); i++)
873 int [] region = (int[]) hc.elementAt(i);
874 af.viewport.hideColumns(region[0], region[1]);
879 //>>>This is a fix for the moment, until a better solution is found!!<<<
880 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
881 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
884 if (title.startsWith("Copied sequences"))
890 newtitle = newtitle.concat("- from " + title);
893 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH,
902 ex.printStackTrace();
903 System.out.println("Exception whilst pasting: "+ex);
904 // could be anything being pasted in here
913 * @param e DOCUMENT ME!
915 protected void cut_actionPerformed(ActionEvent e)
917 copy_actionPerformed(null);
918 delete_actionPerformed(null);
924 * @param e DOCUMENT ME!
926 protected void delete_actionPerformed(ActionEvent e)
929 if (viewport.getSelectionGroup() == null)
935 SequenceGroup sg = viewport.getSelectionGroup();
939 //Jalview no longer allows deletion of residues.
940 //Check here whether any residues are in selection area
941 /* if( sg.getEndRes()-sg.getStartRes() < viewport.alignment.getWidth()-1)
943 for (int i = 0; i < sg.sequences.size(); i++)
945 SequenceI seq = sg.getSequenceAt(i);
946 int j = sg.getStartRes();
949 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
951 JOptionPane.showInternalMessageDialog(
952 Desktop.desktop, "Cannot delete residues from alignment!\n"
953 + "Try hiding columns instead.",
954 "Deletion of residues not permitted",
955 JOptionPane.WARNING_MESSAGE);
960 }while(j<=sg.getEndRes());
965 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
969 for (int i = 0; i < sg.getSize(false); i++)
971 SequenceI seq = sg.getSequenceAt(i);
972 int index = viewport.getAlignment().findIndex(seq);
974 seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);
976 // If the cut affects all sequences, remove highlighted columns
977 if (sg.getSize(false) == viewport.alignment.getHeight())
979 viewport.getColumnSelection().removeElements(sg.getStartRes(),
983 if (seq.getSequence().length() < 1)
985 viewport.getAlignment().deleteSequence(seq);
989 viewport.getAlignment().getSequences().setElementAt(seq, index);
993 viewport.setSelectionGroup(null);
994 viewport.alignment.deleteGroup(sg);
996 viewport.firePropertyChange("alignment", null,
997 viewport.getAlignment().getSequences());
1001 if (viewport.getAlignment().getHeight() < 1)
1005 this.setClosed(true);
1007 catch (Exception ex)
1016 * @param e DOCUMENT ME!
1018 protected void deleteGroups_actionPerformed(ActionEvent e)
1020 viewport.alignment.deleteAllGroups();
1021 viewport.setSelectionGroup(null);
1022 alignPanel.repaint();
1028 * @param e DOCUMENT ME!
1030 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1032 SequenceGroup sg = new SequenceGroup();
1034 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1037 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1040 sg.setEndRes(viewport.alignment.getWidth() - 1);
1041 viewport.setSelectionGroup(sg);
1042 PaintRefresher.Refresh(null, viewport.alignment);
1048 * @param e DOCUMENT ME!
1050 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1052 if(viewport.cursorMode)
1054 alignPanel.seqPanel.keyboardNo1 = null;
1055 alignPanel.seqPanel.keyboardNo2 = null;
1057 viewport.setSelectionGroup(null);
1058 viewport.getColumnSelection().clear();
1059 viewport.setSelectionGroup(null);
1060 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1061 alignPanel.idPanel.idCanvas.searchResults = null;
1062 alignPanel.repaint();
1063 PaintRefresher.Refresh(null, viewport.alignment);
1069 * @param e DOCUMENT ME!
1071 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1073 SequenceGroup sg = viewport.getSelectionGroup();
1077 selectAllSequenceMenuItem_actionPerformed(null);
1082 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1085 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1088 PaintRefresher.Refresh(null, viewport.alignment);
1091 public void invertColSel_actionPerformed(ActionEvent e)
1093 viewport.invertColumnSelection();
1094 alignPanel.repaint();
1101 * @param e DOCUMENT ME!
1103 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1105 ColumnSelection colSel = viewport.getColumnSelection();
1107 if (colSel.size() > 0)
1110 addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,
1113 int min = colSel.getMin();
1114 viewport.getAlignment().trimLeft(min);
1115 colSel.compensateForEdit(0, min);
1116 edit.addShift(0,min);
1117 if (viewport.getSelectionGroup() != null)
1119 viewport.getSelectionGroup().adjustForRemoveLeft(min);
1122 Vector groups = viewport.alignment.getGroups();
1124 for (int i = 0; i < groups.size(); i++)
1126 SequenceGroup sg = (SequenceGroup) groups.get(i);
1128 if (!sg.adjustForRemoveLeft(min))
1130 viewport.alignment.deleteGroup(sg);
1134 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1141 * @param e DOCUMENT ME!
1143 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1145 ColumnSelection colSel = viewport.getColumnSelection();
1147 if (colSel.size() > 0)
1149 addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
1152 int max = colSel.getMax();
1153 viewport.getAlignment().trimRight(max);
1154 // TODO: delete hidden column entries in colSel to right of max
1155 // TODO: record hidden columns in history for undo.
1156 if (viewport.getSelectionGroup() != null)
1158 viewport.getSelectionGroup().adjustForRemoveRight(max);
1161 Vector groups = viewport.alignment.getGroups();
1163 for (int i = 0; i < groups.size(); i++)
1165 SequenceGroup sg = (SequenceGroup) groups.get(i);
1167 if (!sg.adjustForRemoveRight(max))
1169 viewport.alignment.deleteGroup(sg);
1173 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1180 * @param e DOCUMENT ME!
1182 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1185 addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",
1186 viewport.alignment, HistoryItem.HIDE));
1188 //This is to maintain viewport position on first residue
1190 SequenceI seq = viewport.alignment.getSequenceAt(0);
1191 int startRes = seq.findPosition(viewport.startRes);
1193 viewport.getAlignment().removeGaps(shifts=new ShiftList());
1194 edit.alColumnChanges=shifts.getInverse();
1195 if (viewport.hasHiddenColumns)
1196 viewport.getColumnSelection().compensateForEdits(shifts);
1197 viewport.setStartRes(seq.findIndex(startRes)-1);
1198 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1204 * @param e DOCUMENT ME!
1206 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1208 // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences
1209 // TODO: columnSelection.compensateforedits should be called (and passed to history item)
1210 addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
1213 //This is to maintain viewport position on first residue
1215 SequenceI seq = viewport.alignment.getSequenceAt(0);
1216 int startRes = seq.findPosition(viewport.startRes);
1225 int end = viewport.alignment.getWidth();
1227 if (viewport.getSelectionGroup() != null
1228 && viewport.getSelectionGroup().getSequences(true) != null
1229 && viewport.getSelectionGroup().getSize(true) > 0)
1231 seqs = viewport.getSelectionGroup().getSequences(true);
1232 start = viewport.getSelectionGroup().getStartRes();
1233 end = viewport.getSelectionGroup().getEndRes()+1;
1237 seqs = viewport.alignment.getSequences();
1239 /* Commented out regions below are partial implementation of todo above.
1240 * divide start,end into visible chunks, and for each:
1241 int diff=end-start+1;
1243 int dr[] = new int[seqs.size()];
1245 for (int i = 0; i < seqs.size(); i++)
1247 current = (SequenceI) seqs.elementAt(i);
1249 current.removeGaps(start, end);
1250 /*if (d<diff) // can only shift
1256 /* // after the end of each chunk -
1258 // record shift for history.
1259 editgaps.addShift(start, diff);
1260 if (viewport.hasHiddenColumns && diffmax>diff) {
1262 StringBuffer gaps=new StringBuffer(diffmax);
1263 for (int i=0,j=diffmax-diff; i<j; i++)
1264 gaps.append(viewport.getGapCharacter());
1265 for (int i=0, j=seqs.size(); i<j; i++) {
1266 current = (SequenceI) seqs.elementAt(i);
1268 String sq = current.getSequence();
1269 current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());
1275 viewport.setStartRes(seq.findIndex(startRes)-1);
1277 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1280 public void alignmentChanged()
1282 if(viewport.padGaps)
1283 viewport.getAlignment().padGaps();
1285 if(viewport.vconsensus!=null && viewport.autoCalculateConsensus)
1287 viewport.updateConsensus();
1288 viewport.updateConservation();
1291 resetAllColourSchemes();
1292 if(alignPanel.overviewPanel!=null)
1293 alignPanel.overviewPanel.updateOverviewImage();
1295 viewport.alignment.adjustSequenceAnnotations();
1297 if(alignPanel.overviewPanel!=null)
1298 alignPanel.overviewPanel.updateOverviewImage();
1300 alignPanel.repaint();
1303 void resetAllColourSchemes()
1305 ColourSchemeI cs = viewport.globalColourScheme;
1308 if (cs instanceof ClustalxColourScheme)
1310 ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
1311 resetClustalX(viewport.alignment.getSequences(),
1312 viewport.alignment.getWidth());
1315 cs.setConsensus(viewport.vconsensus);
1316 if (cs.conservationApplied())
1318 Alignment al = (Alignment) viewport.alignment;
1319 Conservation c = new Conservation("All",
1320 ResidueProperties.propHash, 3,
1321 al.getSequences(), 0,
1324 c.verdict(false, viewport.ConsPercGaps);
1326 cs.setConservation(c);
1330 int s, sSize = viewport.alignment.getGroups().size();
1331 for(s=0; s<sSize; s++)
1333 SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);
1334 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1336 ((ClustalxColourScheme)sg.cs).resetClustalX(
1337 sg.getSequences(true), sg.getWidth());
1339 sg.recalcConservation();
1346 * @param e DOCUMENT ME!
1348 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1350 addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,
1353 viewport.padGaps = padGapsMenuitem.isSelected();
1355 // if (viewport.padGaps)
1362 * @param e DOCUMENT ME!
1364 public void findMenuItem_actionPerformed(ActionEvent e)
1366 JInternalFrame frame = new JInternalFrame();
1367 Finder finder = new Finder(viewport, alignPanel, frame);
1368 frame.setContentPane(finder);
1369 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1370 Desktop.addInternalFrame(frame, "Find", 340, 110);
1376 * @param e DOCUMENT ME!
1378 public void font_actionPerformed(ActionEvent e)
1380 new FontChooser(alignPanel);
1383 public void smoothFont_actionPerformed(ActionEvent e)
1385 viewport.antiAlias = smoothFont.isSelected();
1386 alignPanel.annotationPanel.image = null;
1387 alignPanel.repaint();
1394 * @param e DOCUMENT ME!
1396 protected void seqLimit_actionPerformed(ActionEvent e)
1398 viewport.setShowJVSuffix(seqLimits.isSelected());
1400 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1401 alignPanel.repaint();
1408 * @param e DOCUMENT ME!
1410 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1412 viewport.setColourText(colourTextMenuItem.isSelected());
1413 alignPanel.repaint();
1419 * @param e DOCUMENT ME!
1421 public void wrapMenuItem_actionPerformed(ActionEvent e)
1423 scaleAbove.setVisible(wrapMenuItem.isSelected());
1424 scaleLeft.setVisible(wrapMenuItem.isSelected());
1425 scaleRight.setVisible(wrapMenuItem.isSelected());
1426 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1427 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1430 public void showAllSeqs_actionPerformed(ActionEvent e)
1432 viewport.showAllHiddenSeqs();
1435 public void showAllColumns_actionPerformed(ActionEvent e)
1437 viewport.showAllHiddenColumns();
1441 public void hideSelSequences_actionPerformed(ActionEvent e)
1443 viewport.hideAllSelectedSeqs();
1446 public void hideSelColumns_actionPerformed(ActionEvent e)
1448 viewport.hideSelectedColumns();
1449 alignPanel.repaint();
1452 public void hiddenMarkers_actionPerformed(ActionEvent e)
1454 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1461 * @param e DOCUMENT ME!
1463 protected void scaleAbove_actionPerformed(ActionEvent e)
1465 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1466 alignPanel.repaint();
1472 * @param e DOCUMENT ME!
1474 protected void scaleLeft_actionPerformed(ActionEvent e)
1476 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1477 alignPanel.repaint();
1483 * @param e DOCUMENT ME!
1485 protected void scaleRight_actionPerformed(ActionEvent e)
1487 viewport.setScaleRightWrapped(scaleRight.isSelected());
1488 alignPanel.repaint();
1494 * @param e DOCUMENT ME!
1496 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1498 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1499 alignPanel.repaint();
1505 * @param e DOCUMENT ME!
1507 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1509 viewport.setShowText(viewTextMenuItem.isSelected());
1510 alignPanel.repaint();
1516 * @param e DOCUMENT ME!
1518 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1520 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1521 alignPanel.repaint();
1525 public FeatureSettings featureSettings;
1526 public void featureSettings_actionPerformed(ActionEvent e)
1528 if(featureSettings !=null )
1530 featureSettings.close();
1531 featureSettings = null;
1533 featureSettings = new FeatureSettings(this);
1539 * @param evt DOCUMENT ME!
1541 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1543 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1544 alignPanel.repaint();
1545 if (alignPanel.getOverviewPanel() != null)
1547 alignPanel.getOverviewPanel().updateOverviewImage();
1554 * @param e DOCUMENT ME!
1556 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1558 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1559 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1565 * @param e DOCUMENT ME!
1567 public void overviewMenuItem_actionPerformed(ActionEvent e)
1569 if (alignPanel.overviewPanel != null)
1574 JInternalFrame frame = new JInternalFrame();
1575 OverviewPanel overview = new OverviewPanel(alignPanel);
1576 frame.setContentPane(overview);
1577 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1578 frame.getWidth(), frame.getHeight());
1580 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1581 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1583 public void internalFrameClosed(
1584 javax.swing.event.InternalFrameEvent evt)
1586 alignPanel.setOverviewPanel(null);
1591 alignPanel.setOverviewPanel(overview);
1597 * @param e DOCUMENT ME!
1599 protected void noColourmenuItem_actionPerformed(ActionEvent e)
1607 * @param e DOCUMENT ME!
1609 public void clustalColour_actionPerformed(ActionEvent e)
1611 changeColour(new ClustalxColourScheme(
1612 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
1618 * @param e DOCUMENT ME!
1620 public void zappoColour_actionPerformed(ActionEvent e)
1622 changeColour(new ZappoColourScheme());
1628 * @param e DOCUMENT ME!
1630 public void taylorColour_actionPerformed(ActionEvent e)
1632 changeColour(new TaylorColourScheme());
1638 * @param e DOCUMENT ME!
1640 public void hydrophobicityColour_actionPerformed(ActionEvent e)
1642 changeColour(new HydrophobicColourScheme());
1648 * @param e DOCUMENT ME!
1650 public void helixColour_actionPerformed(ActionEvent e)
1652 changeColour(new HelixColourScheme());
1658 * @param e DOCUMENT ME!
1660 public void strandColour_actionPerformed(ActionEvent e)
1662 changeColour(new StrandColourScheme());
1668 * @param e DOCUMENT ME!
1670 public void turnColour_actionPerformed(ActionEvent e)
1672 changeColour(new TurnColourScheme());
1678 * @param e DOCUMENT ME!
1680 public void buriedColour_actionPerformed(ActionEvent e)
1682 changeColour(new BuriedColourScheme());
1688 * @param e DOCUMENT ME!
1690 public void nucleotideColour_actionPerformed(ActionEvent e)
1692 changeColour(new NucleotideColourScheme());
1695 public void annotationColour_actionPerformed(ActionEvent e)
1697 new AnnotationColourChooser(viewport, alignPanel);
1704 * @param e DOCUMENT ME!
1706 protected void applyToAllGroups_actionPerformed(ActionEvent e)
1708 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
1714 * @param cs DOCUMENT ME!
1716 public void changeColour(ColourSchemeI cs)
1722 if (viewport.getAbovePIDThreshold())
1724 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
1727 cs.setThreshold(threshold,
1728 viewport.getIgnoreGapsConsensus());
1730 viewport.setGlobalColourScheme(cs);
1734 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
1737 if (viewport.getConservationSelected())
1740 Alignment al = (Alignment) viewport.alignment;
1741 Conservation c = new Conservation("All",
1742 ResidueProperties.propHash, 3,
1743 al.getSequences(), 0,
1747 c.verdict(false, viewport.ConsPercGaps);
1749 cs.setConservation(c);
1751 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
1756 cs.setConservation(null);
1759 cs.setConsensus(viewport.vconsensus);
1762 viewport.setGlobalColourScheme(cs);
1764 if (viewport.getColourAppliesToAllGroups())
1766 Vector groups = viewport.alignment.getGroups();
1768 for (int i = 0; i < groups.size(); i++)
1770 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1778 if (cs instanceof ClustalxColourScheme)
1780 sg.cs = new ClustalxColourScheme(
1781 sg.getSequences(true), sg.getWidth());
1783 else if (cs instanceof UserColourScheme)
1785 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
1791 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
1793 catch (Exception ex)
1798 if (viewport.getAbovePIDThreshold()
1799 || cs instanceof PIDColourScheme
1800 || cs instanceof Blosum62ColourScheme)
1802 sg.cs.setThreshold(threshold,
1803 viewport.getIgnoreGapsConsensus());
1805 sg.cs.setConsensus(AAFrequency.calculate(
1806 sg.getSequences(true), 0,
1810 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
1813 if (viewport.getConservationSelected())
1815 Conservation c = new Conservation("Group",
1816 ResidueProperties.propHash, 3,
1817 sg.getSequences(true), 0,
1818 viewport.alignment.getWidth() - 1);
1820 c.verdict(false, viewport.ConsPercGaps);
1821 sg.cs.setConservation(c);
1824 sg.cs.setConservation(null);
1828 if (alignPanel.getOverviewPanel() != null)
1830 alignPanel.getOverviewPanel().updateOverviewImage();
1833 alignPanel.repaint();
1839 * @param e DOCUMENT ME!
1841 protected void modifyPID_actionPerformed(ActionEvent e)
1843 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
1845 SliderPanel.setPIDSliderSource(alignPanel,
1846 viewport.getGlobalColourScheme(),
1848 SliderPanel.showPIDSlider();
1855 * @param e DOCUMENT ME!
1857 protected void modifyConservation_actionPerformed(ActionEvent e)
1859 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
1861 SliderPanel.setConservationSlider(alignPanel,
1862 viewport.globalColourScheme,
1864 SliderPanel.showConservationSlider();
1871 * @param e DOCUMENT ME!
1873 protected void conservationMenuItem_actionPerformed(ActionEvent e)
1875 viewport.setConservationSelected(conservationMenuItem.isSelected());
1877 viewport.setAbovePIDThreshold(false);
1878 abovePIDThreshold.setSelected(false);
1880 changeColour(viewport.getGlobalColourScheme());
1882 modifyConservation_actionPerformed(null);
1888 * @param e DOCUMENT ME!
1890 public void abovePIDThreshold_actionPerformed(ActionEvent e)
1892 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
1894 conservationMenuItem.setSelected(false);
1895 viewport.setConservationSelected(false);
1897 changeColour(viewport.getGlobalColourScheme());
1899 modifyPID_actionPerformed(null);
1905 * @param e DOCUMENT ME!
1907 public void userDefinedColour_actionPerformed(ActionEvent e)
1909 if (e.getActionCommand().equals("User Defined..."))
1911 new UserDefinedColours(alignPanel, null);
1915 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
1916 getUserColourSchemes().get(e.getActionCommand());
1922 public void updateUserColourMenu()
1925 Component[] menuItems = colourMenu.getMenuComponents();
1926 int i, iSize = menuItems.length;
1927 for (i = 0; i < iSize; i++)
1929 if (menuItems[i].getName() != null &&
1930 menuItems[i].getName().equals("USER_DEFINED"))
1932 colourMenu.remove(menuItems[i]);
1936 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1938 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
1939 getUserColourSchemes().keys();
1941 while (userColours.hasMoreElements())
1943 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
1944 nextElement().toString());
1945 radioItem.setName("USER_DEFINED");
1946 radioItem.addMouseListener(new MouseAdapter()
1948 public void mousePressed(MouseEvent evt)
1950 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
1952 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
1954 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
1955 "Remove from default list?",
1956 "Remove user defined colour",
1957 JOptionPane.YES_NO_OPTION);
1958 if(option == JOptionPane.YES_OPTION)
1960 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
1961 colourMenu.remove(radioItem);
1964 radioItem.addActionListener(new ActionListener()
1966 public void actionPerformed(ActionEvent evt)
1968 userDefinedColour_actionPerformed(evt);
1974 radioItem.addActionListener(new ActionListener()
1976 public void actionPerformed(ActionEvent evt)
1978 userDefinedColour_actionPerformed(evt);
1982 colourMenu.insert(radioItem, 15);
1983 colours.add(radioItem);
1991 * @param e DOCUMENT ME!
1993 public void PIDColour_actionPerformed(ActionEvent e)
1995 changeColour(new PIDColourScheme());
2001 * @param e DOCUMENT ME!
2003 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2005 changeColour(new Blosum62ColourScheme());
2011 * @param e DOCUMENT ME!
2013 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2015 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,
2017 AlignmentSorter.sortByPID(viewport.getAlignment(),
2018 viewport.getAlignment().getSequenceAt(0));
2019 alignPanel.repaint();
2025 * @param e DOCUMENT ME!
2027 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2029 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,
2031 AlignmentSorter.sortByID(viewport.getAlignment());
2032 alignPanel.repaint();
2038 * @param e DOCUMENT ME!
2040 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2042 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,
2045 AlignmentSorter.sortByGroup(viewport.getAlignment());
2046 alignPanel.repaint();
2052 * @param e DOCUMENT ME!
2054 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2056 new RedundancyPanel(alignPanel, this);
2063 * @param e DOCUMENT ME!
2065 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2067 if ( (viewport.getSelectionGroup() == null) ||
2068 (viewport.getSelectionGroup().getSize(false) < 2))
2070 JOptionPane.showInternalMessageDialog(this,
2071 "You must select at least 2 sequences.",
2072 "Invalid Selection",
2073 JOptionPane.WARNING_MESSAGE);
2077 JInternalFrame frame = new JInternalFrame();
2078 frame.setContentPane(new PairwiseAlignPanel(viewport));
2079 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2086 * @param e DOCUMENT ME!
2088 public void PCAMenuItem_actionPerformed(ActionEvent e)
2090 if ( ( (viewport.getSelectionGroup() != null) &&
2091 (viewport.getSelectionGroup().getSize(false) < 4) &&
2092 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2093 (viewport.getAlignment().getHeight() < 4))
2095 JOptionPane.showInternalMessageDialog(this,
2096 "Principal component analysis must take\n" +
2097 "at least 4 input sequences.",
2098 "Sequence selection insufficient",
2099 JOptionPane.WARNING_MESSAGE);
2104 new PCAPanel(viewport);
2108 public void autoCalculate_actionPerformed(ActionEvent e)
2110 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2111 if(viewport.autoCalculateConsensus)
2121 * @param e DOCUMENT ME!
2123 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2125 NewTreePanel("AV", "PID", "Average distance tree using PID");
2131 * @param e DOCUMENT ME!
2133 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2135 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2141 * @param e DOCUMENT ME!
2143 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2145 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2151 * @param e DOCUMENT ME!
2153 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2155 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2161 * @param type DOCUMENT ME!
2162 * @param pwType DOCUMENT ME!
2163 * @param title DOCUMENT ME!
2165 void NewTreePanel(String type, String pwType, String title)
2169 if (viewport.getSelectionGroup() != null) {
2170 if (viewport.getSelectionGroup().getSize(false) < 3) {
2171 JOptionPane.showMessageDialog(Desktop.desktop,
2172 "You need to have more than two sequences selected to build a tree!",
2173 "Not enough sequences",
2174 JOptionPane.WARNING_MESSAGE);
2179 SequenceGroup sg = viewport.getSelectionGroup();
2181 /* Decide if the selection is a column region */
2182 while (s < sg.getSize(false))
2184 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2187 JOptionPane.showMessageDialog(Desktop.desktop,
2188 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2189 "Try using the Pad function in the edit menu,\n" +
2190 "or one of the multiple sequence alignment web services.",
2191 "Sequences in selection are not aligned",
2192 JOptionPane.WARNING_MESSAGE);
2198 title = title + " on region";
2199 tp = new TreePanel(viewport, type, pwType);
2203 //are the sequences aligned?
2204 if (!viewport.alignment.isAligned())
2206 JOptionPane.showMessageDialog(Desktop.desktop,
2207 "The sequences must be aligned before creating a tree.\n" +
2208 "Try using the Pad function in the edit menu,\n" +
2209 "or one of the multiple sequence alignment web services.",
2210 "Sequences not aligned",
2211 JOptionPane.WARNING_MESSAGE);
2216 if(viewport.alignment.getHeight()<2)
2219 tp = new TreePanel(viewport, type, pwType);
2222 addTreeMenuItem(tp, title);
2224 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2230 * @param title DOCUMENT ME!
2231 * @param order DOCUMENT ME!
2233 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2235 final JMenuItem item = new JMenuItem("by " + title);
2237 item.addActionListener(new java.awt.event.ActionListener()
2239 public void actionPerformed(ActionEvent e)
2241 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2244 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2245 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2246 alignPanel.repaint();
2252 * Maintain the Order by->Displayed Tree menu.
2253 * Creates a new menu item for a TreePanel with an appropriate
2254 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2255 * to remove the menu item when the treePanel is closed, and adjust
2256 * the tree leaf to sequence mapping when the alignment is modified.
2257 * @param treePanel Displayed tree window.
2258 * @param title SortBy menu item title.
2260 void addTreeMenuItem(final TreePanel treePanel, String title)
2262 final JMenuItem item = new JMenuItem(title);
2268 sort.add(sortByTreeMenu);
2271 sortByTreeMenu.add(item);
2272 item.addActionListener(new java.awt.event.ActionListener()
2274 public void actionPerformed(ActionEvent e)
2276 addHistoryItem(new HistoryItem("Tree Sort",
2277 viewport.alignment, HistoryItem.SORT));
2278 AlignmentSorter.sortByTree(viewport.getAlignment(),
2279 treePanel.getTree());
2280 alignPanel.repaint();
2284 treePanel.addInternalFrameListener(new javax.swing.event.
2285 InternalFrameAdapter()
2287 public void internalFrameClosed(
2288 javax.swing.event.InternalFrameEvent evt)
2291 sortByTreeMenu.remove(item);
2295 sort.remove(sortByTreeMenu);
2303 * Work out whether the whole set of sequences
2304 * or just the selected set will be submitted for multiple alignment.
2307 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2309 // Now, check we have enough sequences
2310 AlignmentView msa = null;
2312 if ( (viewport.getSelectionGroup() != null) &&
2313 (viewport.getSelectionGroup().getSize(false) > 1))
2315 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2316 /*SequenceGroup seqs = viewport.getSelectionGroup();
2318 msa = new SequenceI[sz = seqs.getSize(false)];
2320 for (int i = 0; i < sz; i++)
2322 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2324 msa = viewport.getAlignmentView(true);
2328 /*Vector seqs = viewport.getAlignment().getSequences();
2330 if (seqs.size() > 1)
2332 msa = new SequenceI[seqs.size()];
2334 for (int i = 0; i < seqs.size(); i++)
2336 msa[i] = (SequenceI) seqs.elementAt(i);
2339 msa = viewport.getAlignmentView(false);
2345 * Decides what is submitted to a secondary structure prediction service,
2346 * the currently selected sequence, or the currently selected alignment
2347 * (where the first sequence in the set is the one that the prediction
2350 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2352 AlignmentView seqs = null;
2354 if ( (viewport.getSelectionGroup() != null) &&
2355 (viewport.getSelectionGroup().getSize(false) > 0))
2357 seqs = viewport.getAlignmentView(true);
2361 seqs = viewport.getAlignmentView(false);
2363 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2364 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2365 if (!viewport.alignment.isAligned())
2367 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2374 * @param e DOCUMENT ME!
2376 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2378 // Pick the tree file
2379 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2382 chooser.setFileView(new JalviewFileView());
2383 chooser.setDialogTitle("Select a newick-like tree file");
2384 chooser.setToolTipText("Load a tree file");
2386 int value = chooser.showOpenDialog(null);
2388 if (value == JalviewFileChooser.APPROVE_OPTION)
2390 String choice = chooser.getSelectedFile().getPath();
2391 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2395 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2397 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2399 catch (Exception ex)
2401 JOptionPane.showMessageDialog(Desktop.desktop,
2402 "Problem reading tree file",
2404 JOptionPane.WARNING_MESSAGE);
2405 ex.printStackTrace();
2411 public TreePanel ShowNewickTree(NewickFile nf, String title)
2413 return ShowNewickTree(nf,title,600,500,4,5);
2418 * @param nf DOCUMENT ME!
2419 * @param title DOCUMENT ME!
2421 * @return DOCUMENT ME!
2423 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y)
2425 TreePanel tp = null;
2431 if (nf.getTree() != null)
2433 tp = new TreePanel(viewport,
2441 tp.setLocation(x,y);
2444 Desktop.addInternalFrame(tp, title, w, h);
2445 addTreeMenuItem(tp, title);
2448 catch (Exception ex)
2450 ex.printStackTrace();
2461 PrinterJob printJob = PrinterJob.getPrinterJob();
2462 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2463 printJob.setPrintable(alignPanel, pf);
2465 if (printJob.printDialog())
2471 catch (Exception PrintException)
2473 PrintException.printStackTrace();
2480 * Generates menu items and listener event actions for web service clients
2483 public void BuildWebServiceMenu()
2485 if ( (Discoverer.services != null)
2486 && (Discoverer.services.size() > 0))
2488 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2489 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2490 Vector wsmenu = new Vector();
2491 final AlignFrame af = this;
2494 // Add any Multiple Sequence Alignment Services
2495 final JMenu msawsmenu = new JMenu("Alignment");
2496 for (int i = 0, j = msaws.size(); i < j; i++)
2498 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2500 final JMenuItem method = new JMenuItem(sh.getName());
2501 method.addActionListener(new ActionListener()
2503 public void actionPerformed(ActionEvent e)
2505 AlignmentView msa = gatherSequencesForAlignment();
2506 new jalview.ws.MsaWSClient(sh, title, msa,
2507 false, true, viewport.getAlignment().getDataset(), af);
2512 msawsmenu.add(method);
2513 // Deal with services that we know accept partial alignments.
2514 if (sh.getName().indexOf("lustal") > -1)
2516 // We know that ClustalWS can accept partial alignments for refinement.
2517 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2518 methodR.addActionListener(new ActionListener()
2520 public void actionPerformed(ActionEvent e)
2522 AlignmentView msa = gatherSequencesForAlignment();
2523 new jalview.ws.MsaWSClient(sh, title, msa,
2524 true, true, viewport.getAlignment().getDataset(), af);
2529 msawsmenu.add(methodR);
2533 wsmenu.add(msawsmenu);
2535 if (secstrpr != null)
2537 // Add any secondary structure prediction services
2538 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2539 for (int i = 0, j = secstrpr.size(); i < j; i++)
2541 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2543 final JMenuItem method = new JMenuItem(sh.getName());
2544 method.addActionListener(new ActionListener()
2546 public void actionPerformed(ActionEvent e)
2548 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2549 if (msa.getSequences().length == 1)
2551 // Single Sequence prediction
2552 new jalview.ws.JPredClient(sh, title, false, msa, af);
2556 if (msa.getSequences().length > 1)
2558 // Sequence profile based prediction
2559 new jalview.ws.JPredClient(sh,
2560 title, true, msa, af);
2565 secstrmenu.add(method);
2567 wsmenu.add(secstrmenu);
2569 this.webService.removeAll();
2570 for (int i = 0, j = wsmenu.size(); i < j; i++)
2572 webService.add( (JMenu) wsmenu.get(i));
2577 this.webService.removeAll();
2578 this.webService.add(this.webServiceNoServices);
2580 // TODO: add in rediscovery function
2581 // TODO: reduce code redundancy.
2582 // TODO: group services by location as well as function.
2585 /* public void vamsasStore_actionPerformed(ActionEvent e)
2587 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2588 getProperty("LAST_DIRECTORY"));
2590 chooser.setFileView(new JalviewFileView());
2591 chooser.setDialogTitle("Export to Vamsas file");
2592 chooser.setToolTipText("Export");
2594 int value = chooser.showSaveDialog(this);
2596 if (value == JalviewFileChooser.APPROVE_OPTION)
2598 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
2599 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
2600 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
2607 public void showTranslation_actionPerformed(ActionEvent e)
2609 SequenceI [] selection = viewport.getSelectionAsNewSequence();
2610 String [] seqstring = viewport.getViewAsString(true);
2612 int s, sSize = selection.length;
2613 SequenceI [] newSeq = new SequenceI[sSize];
2616 StringBuffer protein;
2618 for(s=0; s<sSize; s++)
2620 protein = new StringBuffer();
2621 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
2622 resSize = seq.length();
2623 resSize -= resSize%3;
2625 for(res = 0; res < resSize; res+=3)
2627 String codon = seq.substring(res, res+3);
2628 codon = codon.replace('U', 'T');
2629 String aa = ResidueProperties.codonTranslate(codon);
2631 protein.append(viewport.getGapCharacter());
2632 else if(aa.equals("STOP"))
2633 protein.append("X");
2635 protein.append( aa );
2637 newSeq[s] = new Sequence(selection[s].getName(),
2638 protein.toString());
2642 AlignmentI al = new Alignment(newSeq);
2643 al.setDataset(null);
2646 ////////////////////////////////
2647 // Copy annotations across
2648 jalview.datamodel.AlignmentAnnotation[] annotations
2649 = viewport.alignment.getAlignmentAnnotation();
2651 if(annotations!=null)
2653 for (int i = 0; i < annotations.length; i++)
2655 if (annotations[i].label.equals("Quality") ||
2656 annotations[i].label.equals("Conservation") ||
2657 annotations[i].label.equals("Consensus"))
2662 aSize = viewport.alignment.getWidth() / 3;
2663 jalview.datamodel.Annotation[] anots =
2664 new jalview.datamodel.Annotation[aSize];
2666 for (a = 0; a < viewport.alignment.getWidth(); a++)
2668 if (annotations[i].annotations[a] == null
2669 || annotations[i].annotations[a] == null)
2672 anots[a / 3] = new Annotation(
2673 annotations[i].annotations[a].displayCharacter,
2674 annotations[i].annotations[a].description,
2675 annotations[i].annotations[a].secondaryStructure,
2676 annotations[i].annotations[a].value,
2677 annotations[i].annotations[a].colour);
2680 jalview.datamodel.AlignmentAnnotation aa
2681 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
2682 annotations[i].description, anots);
2683 al.addAnnotation(aa);
2687 AlignFrame af = new AlignFrame(al);
2688 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
2693 // AlignViewport newViewport = new AlignViewport(al);
2694 // AlignmentPanel ap = new AlignmentPanel(this, newViewport);
2695 // tabbedPane.add("Protein", ap);
2696 // viewports.add(newViewport);
2697 // alignPanels.add(ap);
2700 /////////////////////////
2702 // AlignViewport ds = new AlignViewport(al.getDataset());
2703 // ds.setDataset(true);
2704 // AlignmentPanel dap = new AlignmentPanel(this, ds);
2705 // tabbedPane.add("Dataset", dap);
2706 // viewports.add(ds);
2707 // alignPanels.add(dap);
2708 /////////////////////////
2713 /*public void tabSelected()
2715 int index = tabbedPane.getSelectedIndex();
2716 viewport = (AlignViewport)viewports.elementAt(index);
2717 alignPanel = (AlignmentPanel)alignPanels.elementAt(index);
2723 * @param String DOCUMENT ME!
2725 public boolean parseFeaturesFile(String file, String type)
2727 boolean featuresFile = false;
2729 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
2730 alignPanel.seqPanel.seqCanvas.
2731 getFeatureRenderer().featureColours,
2736 ex.printStackTrace();
2741 viewport.showSequenceFeatures = true;
2742 showSeqFeatures.setSelected(true);
2743 alignPanel.repaint();
2746 return featuresFile;
2749 public void dragEnter(DropTargetDragEvent evt)
2752 public void dragExit(DropTargetEvent evt)
2755 public void dragOver(DropTargetDragEvent evt)
2758 public void dropActionChanged(DropTargetDragEvent evt)
2761 public void drop(DropTargetDropEvent evt)
2763 Transferable t = evt.getTransferable();
2764 java.util.List files = null;
2768 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
2769 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
2771 //Works on Windows and MacOSX
2772 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
2773 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
2775 else if (t.isDataFlavorSupported(uriListFlavor))
2777 // This is used by Unix drag system
2778 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
2779 String data = (String) t.getTransferData(uriListFlavor);
2780 files = new java.util.ArrayList(1);
2781 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
2784 st.hasMoreTokens(); )
2786 String s = st.nextToken();
2787 if (s.startsWith("#"))
2789 // the line is a comment (as per the RFC 2483)
2793 java.net.URI uri = new java.net.URI(s);
2794 java.io.File file = new java.io.File(uri);
2801 e.printStackTrace();
2808 for (int i = 0; i < files.size(); i++)
2810 loadJalviewDataFile(files.get(i).toString());
2813 catch (Exception ex)
2815 ex.printStackTrace();
2820 // This method will attempt to load a "dropped" file first by testing
2821 // whether its and Annotation file, then features file. If both are
2822 // false then the user may have dropped an alignment file onto this
2824 public void loadJalviewDataFile(String file)
2827 String protocol = "File";
2829 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
2834 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
2839 boolean isGroupsFile = parseFeaturesFile(file,protocol);
2842 String format = new IdentifyFile().Identify(file, protocol);
2844 if(format.equalsIgnoreCase("JnetFile"))
2846 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
2848 new JnetAnnotationMaker().add_annotation(predictions,
2849 viewport.getAlignment(),
2851 alignPanel.adjustAnnotationHeight();
2852 alignPanel.repaint();
2855 new FileLoader().LoadFile(viewport, file, protocol, format);
2861 alignPanel.adjustAnnotationHeight();
2864 }catch(Exception ex)
2866 ex.printStackTrace();