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;
58 // Vector viewports = new Vector();
59 // Vector alignPanels = new Vector();
61 public String currentFileFormat = null;
62 Stack historyList = new Stack();
63 Stack redoList = new Stack();
64 private int treeCount = 0;
67 * new alignment window with hidden columns
68 * @param al AlignmentI
69 * @param hiddenColumns ColumnSelection or null
71 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns) {
73 viewport = new AlignViewport(al, hiddenColumns);
75 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
77 if(viewport.vconsensus==null)
79 //Out of memory calculating consensus.
80 BLOSUM62Colour.setEnabled(false);
81 PIDColour.setEnabled(false);
82 conservationMenuItem.setEnabled(false);
83 modifyConservation.setEnabled(false);
84 abovePIDThreshold.setEnabled(false);
85 modifyPID.setEnabled(false);
88 alignPanel = new AlignmentPanel(this, viewport);
90 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
92 if(sortby.equals("Id"))
93 sortIDMenuItem_actionPerformed(null);
94 else if(sortby.equals("Pairwise Identity"))
95 sortPairwiseMenuItem_actionPerformed(null);
97 // remove(tabbedPane);
98 getContentPane().add(alignPanel, BorderLayout.CENTER);
102 // tabbedPane.add(al.isNucleotide() ? "DNA":"Protein", alignPanel);
105 /////////////////////////
106 if(al.getDataset()==null)
110 // AlignViewport ds = new AlignViewport(al.getDataset(), true);
111 // AlignmentPanel dap = new AlignmentPanel(this, ds);
112 // tabbedPane.add("Dataset", dap);
113 // viewports.add(ds);
114 // alignPanels.add(dap);
115 /////////////////////////
118 viewport.addPropertyChangeListener(new PropertyChangeListener()
120 public void propertyChange(PropertyChangeEvent evt)
122 if (evt.getPropertyName().equals("alignment"))
130 if (Desktop.desktop != null)
132 addServiceListeners();
133 setGUINucleotide(al.isNucleotide());
137 if (jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false))
139 wrapMenuItem.setSelected(true);
140 wrapMenuItem_actionPerformed(null);
147 * Creates a new AlignFrame object.
149 * @param al DOCUMENT ME!
151 public AlignFrame(AlignmentI al)
156 public AlignViewport getViewport()
161 /* Set up intrinsic listeners for dynamically generated GUI bits. */
162 private void addServiceListeners()
164 final java.beans.PropertyChangeListener thisListener;
165 // Do this once to get current state
166 BuildWebServiceMenu();
167 Desktop.discoverer.addPropertyChangeListener(
168 thisListener = new java.beans.PropertyChangeListener()
170 public void propertyChange(PropertyChangeEvent evt)
172 // System.out.println("Discoverer property change.");
173 if (evt.getPropertyName().equals("services"))
175 // System.out.println("Rebuilding web service menu");
176 BuildWebServiceMenu();
180 addInternalFrameListener(new javax.swing.event.
181 InternalFrameAdapter()
183 public void internalFrameClosed(
184 javax.swing.event.InternalFrameEvent evt)
186 // System.out.println("deregistering discoverer listener");
187 Desktop.discoverer.removePropertyChangeListener(thisListener);
188 closeMenuItem_actionPerformed(null);
194 public void setGUINucleotide(boolean nucleotide)
196 showTranslation.setVisible( nucleotide );
197 //sequenceFeatures.setVisible(!nucleotide );
198 //featureSettings.setVisible( !nucleotide );
199 conservationMenuItem.setVisible( !nucleotide );
200 modifyConservation.setVisible( !nucleotide );
202 //Remember AlignFrame always starts as protein
205 calculateMenu.remove(calculateMenu.getItemCount()-2);
209 public void comeBackLater(FeatureEvent evt)
212 public void newFeatures(FeatureEvent evt)
214 if (evt.getFeatures().length > 0)
216 alignPanel.seqPanel.seqCanvas.fr.featuresAdded();
217 alignPanel.repaint();
221 Hashtable progressBars;
222 public void setProgressBar(String message, long id)
224 if(progressBars == null)
225 progressBars = new Hashtable();
227 JPanel progressPanel;
228 GridLayout layout = (GridLayout) statusPanel.getLayout();
229 if(progressBars.get( new Long(id) )!=null)
231 progressPanel = (JPanel)progressBars.get( new Long(id) );
232 statusPanel.remove(progressPanel);
233 progressBars.remove( progressPanel );
234 progressPanel = null;
236 statusBar.setText(message);
238 layout.setRows(layout.getRows() - 1);
242 progressPanel = new JPanel(new BorderLayout(10, 5));
244 JProgressBar progressBar = new JProgressBar();
245 progressBar.setIndeterminate(true);
247 progressPanel.add(new JLabel(message), BorderLayout.WEST);
248 progressPanel.add(progressBar, BorderLayout.CENTER);
250 layout.setRows(layout.getRows() + 1);
251 statusPanel.add(progressPanel);
253 progressBars.put(new Long(id), progressPanel);
261 Added so Castor Mapping file can obtain Jalview Version
263 public String getVersion()
265 return jalview.bin.Cache.getProperty("VERSION");
268 public FeatureRenderer getFeatureRenderer()
270 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
274 public void fetchSequence_actionPerformed(ActionEvent e)
276 new SequenceFetcher(this);
279 public void addFromFile_actionPerformed(ActionEvent e)
281 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
284 public void addFromText_actionPerformed(ActionEvent e)
286 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
289 public void addFromURL_actionPerformed(ActionEvent e)
291 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
297 * @param e DOCUMENT ME!
299 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
301 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
302 getProperty( "LAST_DIRECTORY"),
304 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
306 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
311 chooser.setFileView(new JalviewFileView());
312 chooser.setDialogTitle("Save Alignment to file");
313 chooser.setToolTipText("Save");
315 int value = chooser.showSaveDialog(this);
317 if (value == JalviewFileChooser.APPROVE_OPTION)
319 currentFileFormat = chooser.getSelectedFormat();
321 if (currentFileFormat == null)
323 JOptionPane.showInternalMessageDialog(Desktop.desktop,
324 "You must select a file format before saving!",
325 "File format not specified",
326 JOptionPane.WARNING_MESSAGE);
327 value = chooser.showSaveDialog(this);
331 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
334 String choice = chooser.getSelectedFile().getPath();
335 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
337 saveAlignment(choice, currentFileFormat);
341 public boolean saveAlignment(String file, String format)
343 if (format.equalsIgnoreCase("Jalview"))
345 String shortName = title;
347 if (shortName.indexOf(java.io.File.separatorChar) > -1)
349 shortName = shortName.substring(shortName.lastIndexOf(
350 java.io.File.separatorChar) + 1);
353 new Jalview2XML().SaveAlignment(this, file, shortName);
355 // USE Jalview2XML to save this file
361 String[] omitHidden = null;
363 if (viewport.hasHiddenColumns)
365 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
366 "The Alignment contains hidden columns."
367 + "\nDo you want to save only the visible alignment?",
368 "Save / Omit Hidden Columns",
369 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
371 if (reply == JOptionPane.YES_OPTION)
372 omitHidden = viewport.getViewAsString(false);
375 String output = new FormatAdapter().formatSequences(
377 viewport.alignment.getSequencesArray(),
387 java.io.PrintWriter out = new java.io.PrintWriter(
388 new java.io.FileWriter(file));
397 ex.printStackTrace();
406 * @param e DOCUMENT ME!
408 protected void outputText_actionPerformed(ActionEvent e)
410 String [] omitHidden = null;
412 if(viewport.hasHiddenColumns)
414 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
415 "The Alignment contains hidden columns."
416 +"\nDo you want to output only the visible alignment?",
417 "Save / Omit Hidden Columns",
418 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
420 if(reply==JOptionPane.YES_OPTION)
422 omitHidden = viewport.getViewAsString(false);
426 CutAndPasteTransfer cap = new CutAndPasteTransfer();
427 Desktop.addInternalFrame(cap,
428 "Alignment output - " + e.getActionCommand(), 600,
432 cap.setText(new FormatAdapter().formatSequences(
433 e.getActionCommand(),
434 viewport.alignment.getSequencesArray(),
441 * @param e DOCUMENT ME!
443 protected void htmlMenuItem_actionPerformed(ActionEvent e)
445 new HTMLOutput(viewport,
446 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
447 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
450 public void createImageMap(File file, String image)
452 alignPanel.makePNGImageMap(file, image);
458 * @param e DOCUMENT ME!
460 public void createPNG(File f)
462 alignPanel.makePNG(f);
468 * @param e DOCUMENT ME!
470 public void createEPS(File f)
472 alignPanel.makeEPS(f);
478 * @param e DOCUMENT ME!
480 public void printMenuItem_actionPerformed(ActionEvent e)
482 //Putting in a thread avoids Swing painting problems
483 PrintThread thread = new PrintThread();
487 public void exportFeatures_actionPerformed(ActionEvent e)
489 new AnnotationExporter().exportFeatures(alignPanel);
493 public void exportAnnotations_actionPerformed(ActionEvent e)
495 new AnnotationExporter().exportAnnotations(
497 viewport.alignment.getAlignmentAnnotation()
502 public void associatedData_actionPerformed(ActionEvent e)
504 // Pick the tree file
505 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
508 chooser.setFileView(new JalviewFileView());
509 chooser.setDialogTitle("Load Jalview Annotations or Features File");
510 chooser.setToolTipText("Load Jalview Annotations / Features file");
512 int value = chooser.showOpenDialog(null);
514 if (value == JalviewFileChooser.APPROVE_OPTION)
516 String choice = chooser.getSelectedFile().getPath();
517 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
518 loadJalviewDataFile(choice);
526 * @param e DOCUMENT ME!
528 public void closeMenuItem_actionPerformed(ActionEvent e)
532 PaintRefresher.components.remove(viewport.alignment);
533 this.setClosed(true);
543 void updateEditMenuBar()
545 if (historyList.size() > 0)
547 undoMenuItem.setEnabled(true);
549 HistoryItem hi = (HistoryItem) historyList.peek();
550 undoMenuItem.setText("Undo " + hi.getDescription());
554 undoMenuItem.setEnabled(false);
555 undoMenuItem.setText("Undo");
558 if (redoList.size() > 0)
560 redoMenuItem.setEnabled(true);
562 HistoryItem hi = (HistoryItem) redoList.peek();
563 redoMenuItem.setText("Redo " + hi.getDescription());
567 redoMenuItem.setEnabled(false);
568 redoMenuItem.setText("Redo");
575 * @param hi DOCUMENT ME!
577 public void addHistoryItem(HistoryItem hi)
579 historyList.push(hi);
587 * @param e DOCUMENT ME!
589 protected void undoMenuItem_actionPerformed(ActionEvent e)
591 HistoryItem nh,hi = (HistoryItem) historyList.pop();
592 redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
594 if (hi.alColumnChanges!=null)
595 nh.alColumnChanges = hi.alColumnChanges.getInverse();
596 restoreHistoryItem(hi);
597 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
603 * @param e DOCUMENT ME!
605 protected void redoMenuItem_actionPerformed(ActionEvent e)
607 HistoryItem nh,hi = (HistoryItem) redoList.pop();
608 historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
610 if (hi.alColumnChanges!=null)
611 nh.alColumnChanges=hi.alColumnChanges.getInverse();
612 restoreHistoryItem(hi);
614 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
617 // used by undo and redo
618 void restoreHistoryItem(HistoryItem hi)
621 hi.restore(viewport.getColumnSelection());
625 viewport.firePropertyChange("alignment", null,
626 viewport.getAlignment().getSequences());
632 * @param up DOCUMENT ME!
634 public void moveSelectedSequences(boolean up)
636 SequenceGroup sg = viewport.getSelectionGroup();
645 for (int i = 1; i < viewport.alignment.getHeight(); i++)
647 SequenceI seq = viewport.alignment.getSequenceAt(i);
649 if (!sg.getSequences(false).contains(seq))
654 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
656 if (sg.getSequences(false).contains(temp))
661 viewport.alignment.getSequences().setElementAt(temp, i);
662 viewport.alignment.getSequences().setElementAt(seq, i - 1);
667 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
669 SequenceI seq = viewport.alignment.getSequenceAt(i);
671 if (!sg.getSequences(false).contains(seq))
676 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
678 if (sg.getSequences(false).contains(temp))
683 viewport.alignment.getSequences().setElementAt(temp, i);
684 viewport.alignment.getSequences().setElementAt(seq, i + 1);
688 alignPanel.repaint();
696 * @param e DOCUMENT ME!
698 protected void copy_actionPerformed(ActionEvent e)
700 if (viewport.getSelectionGroup() == null)
705 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
706 String[] omitHidden = null;
708 if (viewport.hasHiddenColumns)
710 omitHidden = viewport.getViewAsString(true);
713 String output = new FormatAdapter().formatSequences(
719 Toolkit.getDefaultToolkit().getSystemClipboard()
720 .setContents(new StringSelection(output), Desktop.instance);
722 Vector hiddenColumns = null;
723 if(viewport.hasHiddenColumns)
725 hiddenColumns =new Vector();
726 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
727 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
729 int[] region = (int[])
730 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
732 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
733 region[1]-hiddenOffset});
737 Desktop.jalviewClipboard = new Object[]{ seqs,
738 viewport.alignment.getDataset(),
745 * @param e DOCUMENT ME!
747 protected void pasteNew_actionPerformed(ActionEvent e)
755 * @param e DOCUMENT ME!
757 protected void pasteThis_actionPerformed(ActionEvent e)
759 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
767 * @param newAlignment DOCUMENT ME!
769 void paste(boolean newAlignment)
773 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
774 Transferable contents = c.getContents(this);
776 if (contents == null)
781 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
785 String format = new IdentifyFile().Identify(str, "Paste");
786 SequenceI[] sequences;
789 if(Desktop.jalviewClipboard!=null)
791 // The clipboard was filled from within Jalview, we must use the sequences
792 // And dataset from the copied alignment
793 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
797 sequences = new FormatAdapter().readFile(str, "Paste", format);
800 AlignmentI alignment = null;
804 alignment = new Alignment(sequences);
806 if(Desktop.jalviewClipboard!=null)
807 alignment.setDataset( (Alignment)Desktop.jalviewClipboard[1] );
809 alignment.setDataset( null );
814 alignment = viewport.getAlignment();
817 for (int i = 0; i < sequences.length; i++)
819 Sequence newseq = new Sequence(sequences[i].getName(),
820 sequences[i].getSequence(), sequences[i].getStart(),
821 sequences[i].getEnd());
823 alignment.addSequence(newseq);
827 viewport.setEndSeq(alignment.getHeight());
828 alignment.getWidth();
829 viewport.firePropertyChange("alignment", null, alignment.getSequences());
836 // Add any annotations attached to sequences
837 for (int i = 0; i < sequences.length; i++)
839 if (sequences[i].getAnnotation() != null)
841 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
843 AlignmentAnnotation newAnnot =
844 new AlignmentAnnotation(
845 sequences[i].getAnnotation()[a].label,
846 sequences[i].getAnnotation()[a].description,
847 sequences[i].getAnnotation()[a].annotations,
848 sequences[i].getAnnotation()[a].graphMin,
849 sequences[i].getAnnotation()[a].graphMax,
850 sequences[i].getAnnotation()[a].graph);
852 sequences[i].getAnnotation()[a] = newAnnot;
853 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
855 newAnnot.sequenceRef = sequences[i];
856 newAnnot.adjustForAlignment();
857 alignment.addAnnotation(newAnnot);
858 alignment.setAnnotationIndex(newAnnot, a);
861 alignPanel.annotationPanel.adjustPanelHeight();
867 AlignFrame af = new AlignFrame(alignment);
868 String newtitle = new String("Copied sequences");
870 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
872 Vector hc = (Vector)Desktop.jalviewClipboard[2];
873 for(int i=0; i<hc.size(); i++)
875 int [] region = (int[]) hc.elementAt(i);
876 af.viewport.hideColumns(region[0], region[1]);
881 //>>>This is a fix for the moment, until a better solution is found!!<<<
882 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
883 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
886 if (title.startsWith("Copied sequences"))
892 newtitle = newtitle.concat("- from " + title);
895 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH,
904 ex.printStackTrace();
905 System.out.println("Exception whilst pasting: "+ex);
906 // could be anything being pasted in here
915 * @param e DOCUMENT ME!
917 protected void cut_actionPerformed(ActionEvent e)
919 copy_actionPerformed(null);
920 delete_actionPerformed(null);
926 * @param e DOCUMENT ME!
928 protected void delete_actionPerformed(ActionEvent e)
931 if (viewport.getSelectionGroup() == null)
937 SequenceGroup sg = viewport.getSelectionGroup();
941 //Jalview no longer allows deletion of residues.
942 //Check here whether any residues are in selection area
943 /* if( sg.getEndRes()-sg.getStartRes() < viewport.alignment.getWidth()-1)
945 for (int i = 0; i < sg.sequences.size(); i++)
947 SequenceI seq = sg.getSequenceAt(i);
948 int j = sg.getStartRes();
951 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
953 JOptionPane.showInternalMessageDialog(
954 Desktop.desktop, "Cannot delete residues from alignment!\n"
955 + "Try hiding columns instead.",
956 "Deletion of residues not permitted",
957 JOptionPane.WARNING_MESSAGE);
962 }while(j<=sg.getEndRes());
967 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
971 for (int i = 0; i < sg.getSize(false); i++)
973 SequenceI seq = sg.getSequenceAt(i);
974 int index = viewport.getAlignment().findIndex(seq);
976 seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);
978 // If the cut affects all sequences, remove highlighted columns
979 if (sg.getSize(false) == viewport.alignment.getHeight())
981 viewport.getColumnSelection().removeElements(sg.getStartRes(),
985 if (seq.getSequence().length() < 1)
987 viewport.getAlignment().deleteSequence(seq);
991 viewport.getAlignment().getSequences().setElementAt(seq, index);
995 viewport.setSelectionGroup(null);
996 viewport.alignment.deleteGroup(sg);
998 viewport.firePropertyChange("alignment", null,
999 viewport.getAlignment().getSequences());
1003 if (viewport.getAlignment().getHeight() < 1)
1007 this.setClosed(true);
1009 catch (Exception ex)
1018 * @param e DOCUMENT ME!
1020 protected void deleteGroups_actionPerformed(ActionEvent e)
1022 viewport.alignment.deleteAllGroups();
1023 viewport.setSelectionGroup(null);
1024 alignPanel.repaint();
1030 * @param e DOCUMENT ME!
1032 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1034 SequenceGroup sg = new SequenceGroup();
1036 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1039 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1042 sg.setEndRes(viewport.alignment.getWidth() - 1);
1043 viewport.setSelectionGroup(sg);
1044 PaintRefresher.Refresh(null, viewport.alignment);
1050 * @param e DOCUMENT ME!
1052 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1054 if(viewport.cursorMode)
1056 alignPanel.seqPanel.keyboardNo1 = null;
1057 alignPanel.seqPanel.keyboardNo2 = null;
1059 viewport.setSelectionGroup(null);
1060 viewport.getColumnSelection().clear();
1061 viewport.setSelectionGroup(null);
1062 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1063 alignPanel.idPanel.idCanvas.searchResults = null;
1064 alignPanel.repaint();
1065 PaintRefresher.Refresh(null, viewport.alignment);
1071 * @param e DOCUMENT ME!
1073 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1075 SequenceGroup sg = viewport.getSelectionGroup();
1079 selectAllSequenceMenuItem_actionPerformed(null);
1084 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1087 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1090 PaintRefresher.Refresh(null, viewport.alignment);
1093 public void invertColSel_actionPerformed(ActionEvent e)
1095 viewport.invertColumnSelection();
1096 alignPanel.repaint();
1103 * @param e DOCUMENT ME!
1105 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1107 ColumnSelection colSel = viewport.getColumnSelection();
1109 if (colSel.size() > 0)
1112 addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,
1115 int min = colSel.getMin();
1116 viewport.getAlignment().trimLeft(min);
1117 colSel.compensateForEdit(0, min);
1118 edit.addShift(0,min);
1119 if (viewport.getSelectionGroup() != null)
1121 viewport.getSelectionGroup().adjustForRemoveLeft(min);
1124 Vector groups = viewport.alignment.getGroups();
1126 for (int i = 0; i < groups.size(); i++)
1128 SequenceGroup sg = (SequenceGroup) groups.get(i);
1130 if (!sg.adjustForRemoveLeft(min))
1132 viewport.alignment.deleteGroup(sg);
1136 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1143 * @param e DOCUMENT ME!
1145 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1147 ColumnSelection colSel = viewport.getColumnSelection();
1149 if (colSel.size() > 0)
1151 addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
1154 int max = colSel.getMax();
1155 viewport.getAlignment().trimRight(max);
1156 // TODO: delete hidden column entries in colSel to right of max
1157 // TODO: record hidden columns in history for undo.
1158 if (viewport.getSelectionGroup() != null)
1160 viewport.getSelectionGroup().adjustForRemoveRight(max);
1163 Vector groups = viewport.alignment.getGroups();
1165 for (int i = 0; i < groups.size(); i++)
1167 SequenceGroup sg = (SequenceGroup) groups.get(i);
1169 if (!sg.adjustForRemoveRight(max))
1171 viewport.alignment.deleteGroup(sg);
1175 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1182 * @param e DOCUMENT ME!
1184 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1187 addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",
1188 viewport.alignment, HistoryItem.HIDE));
1190 //This is to maintain viewport position on first residue
1192 SequenceI seq = viewport.alignment.getSequenceAt(0);
1193 int startRes = seq.findPosition(viewport.startRes);
1195 viewport.getAlignment().removeGaps(shifts=new ShiftList());
1196 edit.alColumnChanges=shifts.getInverse();
1197 if (viewport.hasHiddenColumns)
1198 viewport.getColumnSelection().compensateForEdits(shifts);
1199 viewport.setStartRes(seq.findIndex(startRes)-1);
1200 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1206 * @param e DOCUMENT ME!
1208 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1210 // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences
1211 // TODO: columnSelection.compensateforedits should be called (and passed to history item)
1212 addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
1215 //This is to maintain viewport position on first residue
1217 SequenceI seq = viewport.alignment.getSequenceAt(0);
1218 int startRes = seq.findPosition(viewport.startRes);
1227 int end = viewport.alignment.getWidth();
1229 if (viewport.getSelectionGroup() != null
1230 && viewport.getSelectionGroup().getSequences(true) != null
1231 && viewport.getSelectionGroup().getSize(true) > 0)
1233 seqs = viewport.getSelectionGroup().getSequences(true);
1234 start = viewport.getSelectionGroup().getStartRes();
1235 end = viewport.getSelectionGroup().getEndRes()+1;
1239 seqs = viewport.alignment.getSequences();
1241 /* Commented out regions below are partial implementation of todo above.
1242 * divide start,end into visible chunks, and for each:
1243 int diff=end-start+1;
1245 int dr[] = new int[seqs.size()];
1247 for (int i = 0; i < seqs.size(); i++)
1249 current = (SequenceI) seqs.elementAt(i);
1251 current.removeGaps(start, end);
1252 /*if (d<diff) // can only shift
1258 /* // after the end of each chunk -
1260 // record shift for history.
1261 editgaps.addShift(start, diff);
1262 if (viewport.hasHiddenColumns && diffmax>diff) {
1264 StringBuffer gaps=new StringBuffer(diffmax);
1265 for (int i=0,j=diffmax-diff; i<j; i++)
1266 gaps.append(viewport.getGapCharacter());
1267 for (int i=0, j=seqs.size(); i<j; i++) {
1268 current = (SequenceI) seqs.elementAt(i);
1270 String sq = current.getSequence();
1271 current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());
1277 viewport.setStartRes(seq.findIndex(startRes)-1);
1279 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1282 public void alignmentChanged()
1284 if(viewport.padGaps)
1285 viewport.getAlignment().padGaps();
1287 if(viewport.vconsensus!=null && viewport.autoCalculateConsensus)
1289 viewport.updateConsensus();
1290 viewport.updateConservation();
1293 resetAllColourSchemes();
1294 if(alignPanel.overviewPanel!=null)
1295 alignPanel.overviewPanel.updateOverviewImage();
1297 viewport.alignment.adjustSequenceAnnotations();
1299 if(alignPanel.overviewPanel!=null)
1300 alignPanel.overviewPanel.updateOverviewImage();
1301 // JBPNote: could push a vamsas document update here.
1302 alignPanel.repaint();
1305 void resetAllColourSchemes()
1307 ColourSchemeI cs = viewport.globalColourScheme;
1310 if (cs instanceof ClustalxColourScheme)
1312 ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
1313 resetClustalX(viewport.alignment.getSequences(),
1314 viewport.alignment.getWidth());
1317 cs.setConsensus(viewport.vconsensus);
1318 if (cs.conservationApplied())
1320 Alignment al = (Alignment) viewport.alignment;
1321 Conservation c = new Conservation("All",
1322 ResidueProperties.propHash, 3,
1323 al.getSequences(), 0,
1326 c.verdict(false, viewport.ConsPercGaps);
1328 cs.setConservation(c);
1332 int s, sSize = viewport.alignment.getGroups().size();
1333 for(s=0; s<sSize; s++)
1335 SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);
1336 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1338 ((ClustalxColourScheme)sg.cs).resetClustalX(
1339 sg.getSequences(true), sg.getWidth());
1341 sg.recalcConservation();
1348 * @param e DOCUMENT ME!
1350 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1352 addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,
1355 viewport.padGaps = padGapsMenuitem.isSelected();
1357 // if (viewport.padGaps)
1364 * @param e DOCUMENT ME!
1366 public void findMenuItem_actionPerformed(ActionEvent e)
1368 JInternalFrame frame = new JInternalFrame();
1369 Finder finder = new Finder(viewport, alignPanel, frame);
1370 frame.setContentPane(finder);
1371 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1372 Desktop.addInternalFrame(frame, "Find", 340, 110);
1378 * @param e DOCUMENT ME!
1380 public void font_actionPerformed(ActionEvent e)
1382 new FontChooser(alignPanel);
1385 public void smoothFont_actionPerformed(ActionEvent e)
1387 viewport.antiAlias = smoothFont.isSelected();
1388 alignPanel.annotationPanel.image = null;
1389 alignPanel.repaint();
1396 * @param e DOCUMENT ME!
1398 protected void seqLimit_actionPerformed(ActionEvent e)
1400 viewport.setShowJVSuffix(seqLimits.isSelected());
1402 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1403 alignPanel.repaint();
1410 * @param e DOCUMENT ME!
1412 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1414 viewport.setColourText(colourTextMenuItem.isSelected());
1415 alignPanel.repaint();
1421 * @param e DOCUMENT ME!
1423 public void wrapMenuItem_actionPerformed(ActionEvent e)
1425 scaleAbove.setVisible(wrapMenuItem.isSelected());
1426 scaleLeft.setVisible(wrapMenuItem.isSelected());
1427 scaleRight.setVisible(wrapMenuItem.isSelected());
1428 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1429 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1432 public void showAllSeqs_actionPerformed(ActionEvent e)
1434 viewport.showAllHiddenSeqs();
1437 public void showAllColumns_actionPerformed(ActionEvent e)
1439 viewport.showAllHiddenColumns();
1443 public void hideSelSequences_actionPerformed(ActionEvent e)
1445 viewport.hideAllSelectedSeqs();
1448 public void hideSelColumns_actionPerformed(ActionEvent e)
1450 viewport.hideSelectedColumns();
1451 alignPanel.repaint();
1454 public void hiddenMarkers_actionPerformed(ActionEvent e)
1456 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1463 * @param e DOCUMENT ME!
1465 protected void scaleAbove_actionPerformed(ActionEvent e)
1467 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1468 alignPanel.repaint();
1474 * @param e DOCUMENT ME!
1476 protected void scaleLeft_actionPerformed(ActionEvent e)
1478 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1479 alignPanel.repaint();
1485 * @param e DOCUMENT ME!
1487 protected void scaleRight_actionPerformed(ActionEvent e)
1489 viewport.setScaleRightWrapped(scaleRight.isSelected());
1490 alignPanel.repaint();
1496 * @param e DOCUMENT ME!
1498 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1500 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1501 alignPanel.repaint();
1507 * @param e DOCUMENT ME!
1509 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1511 viewport.setShowText(viewTextMenuItem.isSelected());
1512 alignPanel.repaint();
1518 * @param e DOCUMENT ME!
1520 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1522 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1523 alignPanel.repaint();
1527 public FeatureSettings featureSettings;
1528 public void featureSettings_actionPerformed(ActionEvent e)
1530 if(featureSettings !=null )
1532 featureSettings.close();
1533 featureSettings = null;
1535 featureSettings = new FeatureSettings(this);
1541 * @param evt DOCUMENT ME!
1543 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1545 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1546 alignPanel.repaint();
1547 if (alignPanel.getOverviewPanel() != null)
1549 alignPanel.getOverviewPanel().updateOverviewImage();
1556 * @param e DOCUMENT ME!
1558 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1560 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1561 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1567 * @param e DOCUMENT ME!
1569 public void overviewMenuItem_actionPerformed(ActionEvent e)
1571 if (alignPanel.overviewPanel != null)
1576 JInternalFrame frame = new JInternalFrame();
1577 OverviewPanel overview = new OverviewPanel(alignPanel);
1578 frame.setContentPane(overview);
1579 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1580 frame.getWidth(), frame.getHeight());
1582 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1583 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1585 public void internalFrameClosed(
1586 javax.swing.event.InternalFrameEvent evt)
1588 alignPanel.setOverviewPanel(null);
1593 alignPanel.setOverviewPanel(overview);
1599 * @param e DOCUMENT ME!
1601 protected void noColourmenuItem_actionPerformed(ActionEvent e)
1609 * @param e DOCUMENT ME!
1611 public void clustalColour_actionPerformed(ActionEvent e)
1613 changeColour(new ClustalxColourScheme(
1614 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
1620 * @param e DOCUMENT ME!
1622 public void zappoColour_actionPerformed(ActionEvent e)
1624 changeColour(new ZappoColourScheme());
1630 * @param e DOCUMENT ME!
1632 public void taylorColour_actionPerformed(ActionEvent e)
1634 changeColour(new TaylorColourScheme());
1640 * @param e DOCUMENT ME!
1642 public void hydrophobicityColour_actionPerformed(ActionEvent e)
1644 changeColour(new HydrophobicColourScheme());
1650 * @param e DOCUMENT ME!
1652 public void helixColour_actionPerformed(ActionEvent e)
1654 changeColour(new HelixColourScheme());
1660 * @param e DOCUMENT ME!
1662 public void strandColour_actionPerformed(ActionEvent e)
1664 changeColour(new StrandColourScheme());
1670 * @param e DOCUMENT ME!
1672 public void turnColour_actionPerformed(ActionEvent e)
1674 changeColour(new TurnColourScheme());
1680 * @param e DOCUMENT ME!
1682 public void buriedColour_actionPerformed(ActionEvent e)
1684 changeColour(new BuriedColourScheme());
1690 * @param e DOCUMENT ME!
1692 public void nucleotideColour_actionPerformed(ActionEvent e)
1694 changeColour(new NucleotideColourScheme());
1697 public void annotationColour_actionPerformed(ActionEvent e)
1699 new AnnotationColourChooser(viewport, alignPanel);
1706 * @param e DOCUMENT ME!
1708 protected void applyToAllGroups_actionPerformed(ActionEvent e)
1710 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
1716 * @param cs DOCUMENT ME!
1718 public void changeColour(ColourSchemeI cs)
1724 if (viewport.getAbovePIDThreshold())
1726 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
1729 cs.setThreshold(threshold,
1730 viewport.getIgnoreGapsConsensus());
1732 viewport.setGlobalColourScheme(cs);
1736 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
1739 if (viewport.getConservationSelected())
1742 Alignment al = (Alignment) viewport.alignment;
1743 Conservation c = new Conservation("All",
1744 ResidueProperties.propHash, 3,
1745 al.getSequences(), 0,
1749 c.verdict(false, viewport.ConsPercGaps);
1751 cs.setConservation(c);
1753 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
1758 cs.setConservation(null);
1761 cs.setConsensus(viewport.vconsensus);
1764 viewport.setGlobalColourScheme(cs);
1766 if (viewport.getColourAppliesToAllGroups())
1768 Vector groups = viewport.alignment.getGroups();
1770 for (int i = 0; i < groups.size(); i++)
1772 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1780 if (cs instanceof ClustalxColourScheme)
1782 sg.cs = new ClustalxColourScheme(
1783 sg.getSequences(true), sg.getWidth());
1785 else if (cs instanceof UserColourScheme)
1787 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
1793 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
1795 catch (Exception ex)
1800 if (viewport.getAbovePIDThreshold()
1801 || cs instanceof PIDColourScheme
1802 || cs instanceof Blosum62ColourScheme)
1804 sg.cs.setThreshold(threshold,
1805 viewport.getIgnoreGapsConsensus());
1807 sg.cs.setConsensus(AAFrequency.calculate(
1808 sg.getSequences(true), 0,
1812 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
1815 if (viewport.getConservationSelected())
1817 Conservation c = new Conservation("Group",
1818 ResidueProperties.propHash, 3,
1819 sg.getSequences(true), 0,
1820 viewport.alignment.getWidth() - 1);
1822 c.verdict(false, viewport.ConsPercGaps);
1823 sg.cs.setConservation(c);
1826 sg.cs.setConservation(null);
1830 if (alignPanel.getOverviewPanel() != null)
1832 alignPanel.getOverviewPanel().updateOverviewImage();
1835 alignPanel.repaint();
1841 * @param e DOCUMENT ME!
1843 protected void modifyPID_actionPerformed(ActionEvent e)
1845 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
1847 SliderPanel.setPIDSliderSource(alignPanel,
1848 viewport.getGlobalColourScheme(),
1850 SliderPanel.showPIDSlider();
1857 * @param e DOCUMENT ME!
1859 protected void modifyConservation_actionPerformed(ActionEvent e)
1861 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
1863 SliderPanel.setConservationSlider(alignPanel,
1864 viewport.globalColourScheme,
1866 SliderPanel.showConservationSlider();
1873 * @param e DOCUMENT ME!
1875 protected void conservationMenuItem_actionPerformed(ActionEvent e)
1877 viewport.setConservationSelected(conservationMenuItem.isSelected());
1879 viewport.setAbovePIDThreshold(false);
1880 abovePIDThreshold.setSelected(false);
1882 changeColour(viewport.getGlobalColourScheme());
1884 modifyConservation_actionPerformed(null);
1890 * @param e DOCUMENT ME!
1892 public void abovePIDThreshold_actionPerformed(ActionEvent e)
1894 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
1896 conservationMenuItem.setSelected(false);
1897 viewport.setConservationSelected(false);
1899 changeColour(viewport.getGlobalColourScheme());
1901 modifyPID_actionPerformed(null);
1907 * @param e DOCUMENT ME!
1909 public void userDefinedColour_actionPerformed(ActionEvent e)
1911 if (e.getActionCommand().equals("User Defined..."))
1913 new UserDefinedColours(alignPanel, null);
1917 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
1918 getUserColourSchemes().get(e.getActionCommand());
1924 public void updateUserColourMenu()
1927 Component[] menuItems = colourMenu.getMenuComponents();
1928 int i, iSize = menuItems.length;
1929 for (i = 0; i < iSize; i++)
1931 if (menuItems[i].getName() != null &&
1932 menuItems[i].getName().equals("USER_DEFINED"))
1934 colourMenu.remove(menuItems[i]);
1938 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
1940 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
1941 getUserColourSchemes().keys();
1943 while (userColours.hasMoreElements())
1945 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
1946 nextElement().toString());
1947 radioItem.setName("USER_DEFINED");
1948 radioItem.addMouseListener(new MouseAdapter()
1950 public void mousePressed(MouseEvent evt)
1952 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
1954 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
1956 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
1957 "Remove from default list?",
1958 "Remove user defined colour",
1959 JOptionPane.YES_NO_OPTION);
1960 if(option == JOptionPane.YES_OPTION)
1962 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
1963 colourMenu.remove(radioItem);
1966 radioItem.addActionListener(new ActionListener()
1968 public void actionPerformed(ActionEvent evt)
1970 userDefinedColour_actionPerformed(evt);
1976 radioItem.addActionListener(new ActionListener()
1978 public void actionPerformed(ActionEvent evt)
1980 userDefinedColour_actionPerformed(evt);
1984 colourMenu.insert(radioItem, 15);
1985 colours.add(radioItem);
1993 * @param e DOCUMENT ME!
1995 public void PIDColour_actionPerformed(ActionEvent e)
1997 changeColour(new PIDColourScheme());
2003 * @param e DOCUMENT ME!
2005 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2007 changeColour(new Blosum62ColourScheme());
2013 * @param e DOCUMENT ME!
2015 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2017 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,
2019 AlignmentSorter.sortByPID(viewport.getAlignment(),
2020 viewport.getAlignment().getSequenceAt(0));
2021 alignPanel.repaint();
2027 * @param e DOCUMENT ME!
2029 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2031 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,
2033 AlignmentSorter.sortByID(viewport.getAlignment());
2034 alignPanel.repaint();
2040 * @param e DOCUMENT ME!
2042 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2044 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,
2047 AlignmentSorter.sortByGroup(viewport.getAlignment());
2048 alignPanel.repaint();
2054 * @param e DOCUMENT ME!
2056 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2058 new RedundancyPanel(alignPanel, this);
2065 * @param e DOCUMENT ME!
2067 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2069 if ( (viewport.getSelectionGroup() == null) ||
2070 (viewport.getSelectionGroup().getSize(false) < 2))
2072 JOptionPane.showInternalMessageDialog(this,
2073 "You must select at least 2 sequences.",
2074 "Invalid Selection",
2075 JOptionPane.WARNING_MESSAGE);
2079 JInternalFrame frame = new JInternalFrame();
2080 frame.setContentPane(new PairwiseAlignPanel(viewport));
2081 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2088 * @param e DOCUMENT ME!
2090 public void PCAMenuItem_actionPerformed(ActionEvent e)
2092 if ( ( (viewport.getSelectionGroup() != null) &&
2093 (viewport.getSelectionGroup().getSize(false) < 4) &&
2094 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2095 (viewport.getAlignment().getHeight() < 4))
2097 JOptionPane.showInternalMessageDialog(this,
2098 "Principal component analysis must take\n" +
2099 "at least 4 input sequences.",
2100 "Sequence selection insufficient",
2101 JOptionPane.WARNING_MESSAGE);
2106 new PCAPanel(viewport);
2110 public void autoCalculate_actionPerformed(ActionEvent e)
2112 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2113 if(viewport.autoCalculateConsensus)
2123 * @param e DOCUMENT ME!
2125 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2127 NewTreePanel("AV", "PID", "Average distance tree using PID");
2133 * @param e DOCUMENT ME!
2135 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2137 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2143 * @param e DOCUMENT ME!
2145 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2147 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2153 * @param e DOCUMENT ME!
2155 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2157 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2163 * @param type DOCUMENT ME!
2164 * @param pwType DOCUMENT ME!
2165 * @param title DOCUMENT ME!
2167 void NewTreePanel(String type, String pwType, String title)
2171 if ( (viewport.getSelectionGroup() != null) &&
2172 (viewport.getSelectionGroup().getSize(false) > 3))
2175 SequenceGroup sg = viewport.getSelectionGroup();
2177 /* Decide if the selection is a column region */
2178 while (s < sg.getSize(false))
2180 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2183 JOptionPane.showMessageDialog(Desktop.desktop,
2184 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2185 "Try using the Pad function in the edit menu,\n" +
2186 "or one of the multiple sequence alignment web services.",
2187 "Sequences in selection are not aligned",
2188 JOptionPane.WARNING_MESSAGE);
2194 title = title + " on region";
2195 tp = new TreePanel(viewport, type, pwType);
2199 //are the sequences aligned?
2200 if (!viewport.alignment.isAligned())
2202 JOptionPane.showMessageDialog(Desktop.desktop,
2203 "The sequences must be aligned before creating a tree.\n" +
2204 "Try using the Pad function in the edit menu,\n" +
2205 "or one of the multiple sequence alignment web services.",
2206 "Sequences not aligned",
2207 JOptionPane.WARNING_MESSAGE);
2212 if(viewport.alignment.getHeight()<2)
2215 tp = new TreePanel(viewport, type, pwType);
2218 addTreeMenuItem(tp, title);
2220 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2226 * @param title DOCUMENT ME!
2227 * @param order DOCUMENT ME!
2229 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2231 final JMenuItem item = new JMenuItem("by " + title);
2233 item.addActionListener(new java.awt.event.ActionListener()
2235 public void actionPerformed(ActionEvent e)
2237 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2240 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2241 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2242 alignPanel.repaint();
2248 * Maintain the Order by->Displayed Tree menu.
2249 * Creates a new menu item for a TreePanel with an appropriate
2250 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2251 * to remove the menu item when the treePanel is closed, and adjust
2252 * the tree leaf to sequence mapping when the alignment is modified.
2253 * @param treePanel Displayed tree window.
2254 * @param title SortBy menu item title.
2256 void addTreeMenuItem(final TreePanel treePanel, String title)
2258 final JMenuItem item = new JMenuItem(title);
2264 sort.add(sortByTreeMenu);
2267 sortByTreeMenu.add(item);
2268 item.addActionListener(new java.awt.event.ActionListener()
2270 public void actionPerformed(ActionEvent e)
2272 addHistoryItem(new HistoryItem("Tree Sort",
2273 viewport.alignment, HistoryItem.SORT));
2274 AlignmentSorter.sortByTree(viewport.getAlignment(),
2275 treePanel.getTree());
2276 alignPanel.repaint();
2280 treePanel.addInternalFrameListener(new javax.swing.event.
2281 InternalFrameAdapter()
2283 public void internalFrameClosed(
2284 javax.swing.event.InternalFrameEvent evt)
2287 sortByTreeMenu.remove(item);
2291 sort.remove(sortByTreeMenu);
2299 * Work out whether the whole set of sequences
2300 * or just the selected set will be submitted for multiple alignment.
2303 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2305 // Now, check we have enough sequences
2306 AlignmentView msa = null;
2308 if ( (viewport.getSelectionGroup() != null) &&
2309 (viewport.getSelectionGroup().getSize(false) > 1))
2311 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2312 /*SequenceGroup seqs = viewport.getSelectionGroup();
2314 msa = new SequenceI[sz = seqs.getSize(false)];
2316 for (int i = 0; i < sz; i++)
2318 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2320 msa = viewport.getAlignmentView(true);
2324 /*Vector seqs = viewport.getAlignment().getSequences();
2326 if (seqs.size() > 1)
2328 msa = new SequenceI[seqs.size()];
2330 for (int i = 0; i < seqs.size(); i++)
2332 msa[i] = (SequenceI) seqs.elementAt(i);
2335 msa = viewport.getAlignmentView(false);
2341 * Decides what is submitted to a secondary structure prediction service,
2342 * the currently selected sequence, or the currently selected alignment
2343 * (where the first sequence in the set is the one that the prediction
2346 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2348 AlignmentView seqs = null;
2350 if ( (viewport.getSelectionGroup() != null) &&
2351 (viewport.getSelectionGroup().getSize(false) > 0))
2353 seqs = viewport.getAlignmentView(true);
2357 seqs = viewport.getAlignmentView(false);
2359 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2360 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2361 if (!viewport.alignment.isAligned())
2363 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2370 * @param e DOCUMENT ME!
2372 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2374 // Pick the tree file
2375 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2378 chooser.setFileView(new JalviewFileView());
2379 chooser.setDialogTitle("Select a newick-like tree file");
2380 chooser.setToolTipText("Load a tree file");
2382 int value = chooser.showOpenDialog(null);
2384 if (value == JalviewFileChooser.APPROVE_OPTION)
2386 String choice = chooser.getSelectedFile().getPath();
2387 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2391 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2393 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2395 catch (Exception ex)
2397 JOptionPane.showMessageDialog(Desktop.desktop,
2398 "Problem reading tree file",
2400 JOptionPane.WARNING_MESSAGE);
2401 ex.printStackTrace();
2407 public TreePanel ShowNewickTree(NewickFile nf, String title)
2409 return ShowNewickTree(nf,title,600,500,4,5);
2414 * @param nf DOCUMENT ME!
2415 * @param title DOCUMENT ME!
2417 * @return DOCUMENT ME!
2419 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y)
2421 TreePanel tp = null;
2427 if (nf.getTree() != null)
2429 tp = new TreePanel(viewport,
2437 tp.setLocation(x,y);
2440 Desktop.addInternalFrame(tp, title, w, h);
2441 addTreeMenuItem(tp, title);
2444 catch (Exception ex)
2446 ex.printStackTrace();
2457 PrinterJob printJob = PrinterJob.getPrinterJob();
2458 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2459 printJob.setPrintable(alignPanel, pf);
2461 if (printJob.printDialog())
2467 catch (Exception PrintException)
2469 PrintException.printStackTrace();
2476 * Generates menu items and listener event actions for web service clients
2479 public void BuildWebServiceMenu()
2481 if ( (Discoverer.services != null)
2482 && (Discoverer.services.size() > 0))
2484 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2485 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2486 Vector wsmenu = new Vector();
2487 final AlignFrame af = this;
2490 // Add any Multiple Sequence Alignment Services
2491 final JMenu msawsmenu = new JMenu("Alignment");
2492 for (int i = 0, j = msaws.size(); i < j; i++)
2494 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2496 final JMenuItem method = new JMenuItem(sh.getName());
2497 method.addActionListener(new ActionListener()
2499 public void actionPerformed(ActionEvent e)
2501 AlignmentView msa = gatherSequencesForAlignment();
2502 new jalview.ws.MsaWSClient(sh, title, msa,
2503 false, true, viewport.getAlignment().getDataset(), af);
2508 msawsmenu.add(method);
2509 // Deal with services that we know accept partial alignments.
2510 if (sh.getName().indexOf("lustal") > -1)
2512 // We know that ClustalWS can accept partial alignments for refinement.
2513 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2514 methodR.addActionListener(new ActionListener()
2516 public void actionPerformed(ActionEvent e)
2518 AlignmentView msa = gatherSequencesForAlignment();
2519 new jalview.ws.MsaWSClient(sh, title, msa,
2520 true, true, viewport.getAlignment().getDataset(), af);
2525 msawsmenu.add(methodR);
2529 wsmenu.add(msawsmenu);
2531 if (secstrpr != null)
2533 // Add any secondary structure prediction services
2534 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2535 for (int i = 0, j = secstrpr.size(); i < j; i++)
2537 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2539 final JMenuItem method = new JMenuItem(sh.getName());
2540 method.addActionListener(new ActionListener()
2542 public void actionPerformed(ActionEvent e)
2544 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2545 if (msa.getSequences().length == 1)
2547 // Single Sequence prediction
2548 new jalview.ws.JPredClient(sh, title, false, msa, af);
2552 if (msa.getSequences().length > 1)
2554 // Sequence profile based prediction
2555 new jalview.ws.JPredClient(sh,
2556 title, true, msa, af);
2561 secstrmenu.add(method);
2563 wsmenu.add(secstrmenu);
2565 this.webService.removeAll();
2566 for (int i = 0, j = wsmenu.size(); i < j; i++)
2568 webService.add( (JMenu) wsmenu.get(i));
2573 this.webService.removeAll();
2574 this.webService.add(this.webServiceNoServices);
2576 // TODO: add in rediscovery function
2577 // TODO: reduce code redundancy.
2578 // TODO: group services by location as well as function.
2581 /* public void vamsasStore_actionPerformed(ActionEvent e)
2583 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2584 getProperty("LAST_DIRECTORY"));
2586 chooser.setFileView(new JalviewFileView());
2587 chooser.setDialogTitle("Export to Vamsas file");
2588 chooser.setToolTipText("Export");
2590 int value = chooser.showSaveDialog(this);
2592 if (value == JalviewFileChooser.APPROVE_OPTION)
2594 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
2595 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
2596 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
2603 public void showTranslation_actionPerformed(ActionEvent e)
2605 SequenceI [] selection = viewport.getSelectionAsNewSequence();
2606 String [] seqstring = viewport.getViewAsString(true);
2608 int s, sSize = selection.length;
2609 SequenceI [] newSeq = new SequenceI[sSize];
2612 StringBuffer protein;
2614 for(s=0; s<sSize; s++)
2616 protein = new StringBuffer();
2617 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
2618 resSize = seq.length();
2619 resSize -= resSize%3;
2621 for(res = 0; res < resSize; res+=3)
2623 String codon = seq.substring(res, res+3);
2624 codon = codon.replace('U', 'T');
2625 String aa = ResidueProperties.codonTranslate(codon);
2627 protein.append(viewport.getGapCharacter());
2628 else if(aa.equals("STOP"))
2629 protein.append("X");
2631 protein.append( aa );
2633 newSeq[s] = new Sequence(selection[s].getName(),
2634 protein.toString());
2638 AlignmentI al = new Alignment(newSeq);
2639 al.setDataset(null);
2642 ////////////////////////////////
2643 // Copy annotations across
2644 jalview.datamodel.AlignmentAnnotation[] annotations
2645 = viewport.alignment.getAlignmentAnnotation();
2647 if(annotations!=null)
2649 for (int i = 0; i < annotations.length; i++)
2651 if (annotations[i].label.equals("Quality") ||
2652 annotations[i].label.equals("Conservation") ||
2653 annotations[i].label.equals("Consensus"))
2658 aSize = viewport.alignment.getWidth() / 3;
2659 jalview.datamodel.Annotation[] anots =
2660 new jalview.datamodel.Annotation[aSize];
2662 for (a = 0; a < viewport.alignment.getWidth(); a++)
2664 if (annotations[i].annotations[a] == null
2665 || annotations[i].annotations[a] == null)
2668 anots[a / 3] = new Annotation(
2669 annotations[i].annotations[a].displayCharacter,
2670 annotations[i].annotations[a].description,
2671 annotations[i].annotations[a].secondaryStructure,
2672 annotations[i].annotations[a].value,
2673 annotations[i].annotations[a].colour);
2676 jalview.datamodel.AlignmentAnnotation aa
2677 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
2678 annotations[i].description, anots);
2679 al.addAnnotation(aa);
2683 AlignFrame af = new AlignFrame(al);
2684 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
2689 // AlignViewport newViewport = new AlignViewport(al);
2690 // AlignmentPanel ap = new AlignmentPanel(this, newViewport);
2691 // tabbedPane.add("Protein", ap);
2692 // viewports.add(newViewport);
2693 // alignPanels.add(ap);
2696 /////////////////////////
2698 // AlignViewport ds = new AlignViewport(al.getDataset());
2699 // ds.setDataset(true);
2700 // AlignmentPanel dap = new AlignmentPanel(this, ds);
2701 // tabbedPane.add("Dataset", dap);
2702 // viewports.add(ds);
2703 // alignPanels.add(dap);
2704 /////////////////////////
2709 /*public void tabSelected()
2711 int index = tabbedPane.getSelectedIndex();
2712 viewport = (AlignViewport)viewports.elementAt(index);
2713 alignPanel = (AlignmentPanel)alignPanels.elementAt(index);
2719 * @param String DOCUMENT ME!
2721 public boolean parseFeaturesFile(String file, String type)
2723 boolean featuresFile = false;
2725 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
2726 alignPanel.seqPanel.seqCanvas.
2727 getFeatureRenderer().featureColours,
2732 ex.printStackTrace();
2737 viewport.showSequenceFeatures = true;
2738 showSeqFeatures.setSelected(true);
2739 alignPanel.repaint();
2742 return featuresFile;
2745 public void dragEnter(DropTargetDragEvent evt)
2748 public void dragExit(DropTargetEvent evt)
2751 public void dragOver(DropTargetDragEvent evt)
2754 public void dropActionChanged(DropTargetDragEvent evt)
2757 public void drop(DropTargetDropEvent evt)
2759 Transferable t = evt.getTransferable();
2760 java.util.List files = null;
2764 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
2765 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
2767 //Works on Windows and MacOSX
2768 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
2769 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
2771 else if (t.isDataFlavorSupported(uriListFlavor))
2773 // This is used by Unix drag system
2774 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
2775 String data = (String) t.getTransferData(uriListFlavor);
2776 files = new java.util.ArrayList(1);
2777 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
2780 st.hasMoreTokens(); )
2782 String s = st.nextToken();
2783 if (s.startsWith("#"))
2785 // the line is a comment (as per the RFC 2483)
2789 java.net.URI uri = new java.net.URI(s);
2790 java.io.File file = new java.io.File(uri);
2797 e.printStackTrace();
2804 for (int i = 0; i < files.size(); i++)
2806 loadJalviewDataFile(files.get(i).toString());
2809 catch (Exception ex)
2811 ex.printStackTrace();
2816 // This method will attempt to load a "dropped" file first by testing
2817 // whether its and Annotation file, then features file. If both are
2818 // false then the user may have dropped an alignment file onto this
2820 public void loadJalviewDataFile(String file)
2823 String protocol = "File";
2825 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
2830 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
2835 boolean isGroupsFile = parseFeaturesFile(file,protocol);
2838 String format = new IdentifyFile().Identify(file, protocol);
2840 if(format.equalsIgnoreCase("JnetFile"))
2842 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
2844 new JnetAnnotationMaker().add_annotation(predictions,
2845 viewport.getAlignment(),
2847 alignPanel.adjustAnnotationHeight();
2848 alignPanel.repaint();
2851 new FileLoader().LoadFile(viewport, file, protocol, format);
2857 alignPanel.adjustAnnotationHeight();
2860 }catch(Exception ex)
2862 ex.printStackTrace();