2 * 2004 Jalview Reengineered
14 import jalview.jbgui.GAlignFrame;
15 import jalview.schemes.*;
16 import jalview.datamodel.*;
17 import jalview.analysis.*;
21 import java.awt.event.*;
22 import java.awt.print.*;
24 import javax.swing.event.*;
26 import java.awt.datatransfer.*;
29 public class AlignFrame extends GAlignFrame
31 final AlignmentPanel alignPanel;
32 final AlignViewport viewport;
33 public static final int NEW_WINDOW_WIDTH = 700;
34 public static final int NEW_WINDOW_HEIGHT = 500;
35 public String currentFileFormat = "Jalview";
37 public AlignFrame(AlignmentI al)
39 viewport = new AlignViewport(al);
41 alignPanel = new AlignmentPanel(this, viewport);
42 alignPanel.annotationPanel.adjustPanelHeight();
43 alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel.annotationPanel.getPreferredSize());
44 alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel.getPreferredSize());
45 alignPanel.setAnnotationVisible( viewport.getShowAnnotation() );
47 getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER);
49 addInternalFrameListener(new InternalFrameAdapter()
51 public void internalFrameActivated(InternalFrameEvent evt)
53 javax.swing.SwingUtilities.invokeLater(new Runnable()
56 { alignPanel.requestFocus(); }
64 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
66 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY")
67 , new String[]{"fa, fasta, fastq", "aln", "pfam", "msf", "pir","blc","jar"},
68 new String[]{"Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"},
71 chooser.setAcceptAllFileFilterUsed(false);
72 chooser.setFileView(new JalviewFileView());
73 chooser.setDialogTitle("Save Alignment to file");
74 chooser.setToolTipText("Save");
75 int value = chooser.showSaveDialog(this);
76 if(value == JalviewFileChooser.APPROVE_OPTION)
78 currentFileFormat = chooser.getSelectedFormat();
80 if (currentFileFormat.equals("Jalview"))
82 String shortName = title.replace('/', '_');
83 title = title.replace('\\', '_');
84 String choice = chooser.getSelectedFile().getPath();
85 Jalview2XML.SaveState(this, choice, shortName);
86 // USE Jalview2XML to save this file
90 String choice = chooser.getSelectedFile().getPath();
91 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
92 String output = FormatAdapter.formatSequences(currentFileFormat, viewport.getAlignment().getSequences());
94 java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) );
103 protected void outputText_actionPerformed(ActionEvent e)
105 CutAndPasteTransfer cap = new CutAndPasteTransfer(false);
106 JInternalFrame frame = new JInternalFrame();
107 cap.formatForOutput();
108 frame.setContentPane(cap);
109 Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500);
110 cap.setText( FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences()));
113 protected void htmlMenuItem_actionPerformed(ActionEvent e)
115 HTMLOutput htmlOutput = new HTMLOutput(viewport);
119 protected void createPNG_actionPerformed(ActionEvent e)
121 alignPanel.makePNG();
124 protected void epsFile_actionPerformed(ActionEvent e)
126 alignPanel.makeEPS();
130 public void printMenuItem_actionPerformed(ActionEvent e)
132 //Putting in a thread avoids Swing painting problems
133 PrintThread thread = new PrintThread();
137 class PrintThread extends Thread
141 PrinterJob printJob = PrinterJob.getPrinterJob();
142 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
143 printJob.setPrintable(alignPanel, pf);
144 if (printJob.printDialog())
150 catch (Exception PrintException)
152 PrintException.printStackTrace();
162 public void closeMenuItem_actionPerformed(ActionEvent e)
165 this.setClosed(true);
166 }catch(Exception ex){}
169 Stack historyList = new Stack();
170 Stack redoList = new Stack();
172 void updateEditMenuBar()
174 if(historyList.size()>0)
176 undoMenuItem.setEnabled(true);
177 HistoryItem hi = (HistoryItem)historyList.peek();
178 undoMenuItem.setText("Undo "+hi.getDescription());
182 undoMenuItem.setEnabled(false);
183 undoMenuItem.setText("Undo");
186 if(redoList.size()>0)
188 redoMenuItem.setEnabled(true);
189 HistoryItem hi = (HistoryItem)redoList.peek();
190 redoMenuItem.setText("Redo "+hi.getDescription());
194 redoMenuItem.setEnabled(false);
195 redoMenuItem.setText("Redo");
199 public void addHistoryItem(HistoryItem hi)
201 historyList.push(hi);
205 protected void undoMenuItem_actionPerformed(ActionEvent e)
207 HistoryItem hi = (HistoryItem)historyList.pop();
208 redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, HistoryItem.HIDE));
209 restoreHistoryItem(hi);
213 protected void redoMenuItem_actionPerformed(ActionEvent e)
215 HistoryItem hi = (HistoryItem)redoList.pop();
216 restoreHistoryItem(hi);
218 viewport.updateConsensus();
219 alignPanel.repaint();
220 alignPanel.repaint();
224 // used by undo and redo
225 void restoreHistoryItem(HistoryItem hi)
227 if(hi.getType()== HistoryItem.SORT)
229 for(int i=0; i<hi.getSequences().size(); i++)
230 viewport.alignment.getSequences().setElementAt(hi.getSequences().elementAt(i), i);
234 for (int i = 0; i < hi.getSequences().size(); i++)
236 SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);
237 if(restore.getLength()==0)
239 restore.setSequence(hi.getHidden().elementAt(i).toString());
240 viewport.alignment.getSequences().insertElementAt(
242 hi.getAlignIndex(i));
245 restore.setSequence(hi.getHidden().elementAt(i).toString());
247 if(hi.getType()==HistoryItem.PASTE)
249 for(int i=viewport.alignment.getHeight()-1;i>hi.getSequences().size()-1; i--)
250 viewport.alignment.deleteSequence(i);
256 viewport.updateConsensus();
257 viewport.updateConservation();
258 alignPanel.repaint();
261 public void moveSelectedSequences(boolean up)
263 SequenceGroup sg = viewport.getSelectionGroup();
269 for (int i = 1; i < viewport.alignment.getHeight(); i++)
271 SequenceI seq = viewport.alignment.getSequenceAt(i);
272 if (!sg.sequences.contains(seq))
275 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
276 if (sg.sequences.contains(temp))
279 viewport.alignment.getSequences().setElementAt(temp, i);
280 viewport.alignment.getSequences().setElementAt(seq, i - 1);
285 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
287 SequenceI seq = viewport.alignment.getSequenceAt(i);
288 if (!sg.sequences.contains(seq))
291 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
292 if (sg.sequences.contains(temp))
295 viewport.alignment.getSequences().setElementAt(temp, i);
296 viewport.alignment.getSequences().setElementAt(seq, i + 1);
300 alignPanel.repaint();
305 protected void copy_actionPerformed(ActionEvent e)
307 if(viewport.getSelectionGroup()==null)
310 SequenceGroup sg = viewport.getSelectionGroup();
312 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
313 StringBuffer buffer= new StringBuffer();
315 Hashtable orderedSeqs = new Hashtable();
316 for(int i=0; i<sg.getSize(); i++)
318 SequenceI seq = sg.getSequenceAt(i);
319 int index = viewport.alignment.findIndex(seq);
320 orderedSeqs.put(index+"", seq);
324 for(int i=0; i<sg.getSize(); i++)
326 SequenceI seq = null;
329 if(orderedSeqs.containsKey(index+""))
331 seq = (SequenceI) orderedSeqs.get(index + "");
339 buffer.append( seq.getName()+"\t"+seq.findPosition( sg.getStartRes() ) +"\t"
340 +seq.findPosition( sg.getEndRes() )+ "\t"
341 +sg.getSequenceAt(i).getSequence(sg.getStartRes(), sg.getEndRes()+1)+"\n");
343 c.setContents( new StringSelection( buffer.toString()) , null ) ;
348 protected void pasteNew_actionPerformed(ActionEvent e)
353 protected void pasteThis_actionPerformed(ActionEvent e)
355 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, HistoryItem.PASTE));
359 void paste(boolean newAlignment)
362 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
363 Transferable contents = c.getContents(this);
364 if (contents == null)
367 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
368 StringTokenizer st = new StringTokenizer(str);
369 ArrayList seqs = new ArrayList();
370 while (st.hasMoreElements())
372 String name = st.nextToken();
373 int start = Integer.parseInt(st.nextToken());
374 int end = Integer.parseInt(st.nextToken());
375 Sequence sequence = new Sequence(name,st.nextToken(), start, end);
378 viewport.alignment.addSequence(sequence);
385 SequenceI[] newSeqs = new SequenceI[seqs.size()];
386 seqs.toArray(newSeqs);
387 AlignFrame af = new AlignFrame(new Alignment(newSeqs));
388 String newtitle = new String("Copied sequences");
389 if( title.startsWith("Copied sequences"))
392 newtitle = newtitle.concat("- from "+title);
394 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);
398 viewport.setEndSeq(viewport.alignment.getHeight());
399 viewport.alignment.getWidth();
400 viewport.updateConservation();
401 viewport.updateConsensus();
402 alignPanel.repaint();
405 }catch(Exception ex){}// could be anything being pasted in here
410 protected void cut_actionPerformed(ActionEvent e)
412 copy_actionPerformed(null);
413 delete_actionPerformed(null);
416 protected void delete_actionPerformed(ActionEvent e)
418 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
420 if (viewport.getSelectionGroup() == null)
423 SequenceGroup sg = viewport.getSelectionGroup();
424 for (int i=0;i < sg.sequences.size(); i++)
426 SequenceI seq = sg.getSequenceAt(i);
427 int index = viewport.getAlignment().findIndex(seq);
428 seq.deleteChars(sg.getStartRes(), sg.getEndRes()+1);
430 if(seq.getSequence().length()<1)
431 viewport.getAlignment().deleteSequence(seq);
433 viewport.getAlignment().getSequences().setElementAt(seq, index);
436 viewport.setSelectionGroup(null);
437 viewport.alignment.deleteGroup(sg);
438 viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight());
439 if(viewport.getAlignment().getHeight()<1)
442 this.setClosed(true);
443 }catch(Exception ex){}
444 viewport.updateConservation();
445 viewport.updateConsensus();
446 alignPanel.repaint();
451 protected void deleteGroups_actionPerformed(ActionEvent e)
453 viewport.alignment.deleteAllGroups();
454 viewport.setSelectionGroup(null);
455 alignPanel.repaint();
460 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
462 SequenceGroup sg = new SequenceGroup();
463 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
464 sg.addSequence( viewport.getAlignment().getSequenceAt(i));
465 sg.setEndRes(viewport.alignment.getWidth());
466 viewport.setSelectionGroup(sg);
467 PaintRefresher.Refresh(null);
470 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
472 viewport.setSelectionGroup(null);
473 viewport.getColumnSelection().clear();
474 viewport.setSelectionGroup(null);
475 PaintRefresher.Refresh(null);
478 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
480 SequenceGroup sg = viewport.getSelectionGroup();
481 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
482 sg.addOrRemove (viewport.getAlignment().getSequenceAt(i));
484 PaintRefresher.Refresh(null);
487 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
489 ColumnSelection colSel = viewport.getColumnSelection();
490 if (colSel.size() > 0)
492 addHistoryItem(new HistoryItem("Remove Left",viewport.alignment,
494 int min = colSel.getMin();
495 viewport.getAlignment().trimLeft(min);
496 colSel.compensateForEdit(0,min);
498 if(viewport.getSelectionGroup()!=null)
499 viewport.getSelectionGroup().adjustForRemoveLeft(min);
501 Vector groups = viewport.alignment.getGroups();
502 for(int i=0; i<groups.size(); i++)
504 SequenceGroup sg = (SequenceGroup) groups.get(i);
505 if(!sg.adjustForRemoveLeft(min))
506 viewport.alignment.deleteGroup(sg);
509 alignPanel.repaint();
513 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
515 ColumnSelection colSel = viewport.getColumnSelection();
516 if (colSel.size() > 0)
518 addHistoryItem(new HistoryItem("Remove Right",viewport.alignment,
521 int max = colSel.getMax();
522 viewport.getAlignment().trimRight(max);
523 if(viewport.getSelectionGroup()!=null)
524 viewport.getSelectionGroup().adjustForRemoveRight(max);
526 Vector groups = viewport.alignment.getGroups();
527 for(int i=0; i<groups.size(); i++)
529 SequenceGroup sg = (SequenceGroup) groups.get(i);
530 if(!sg.adjustForRemoveRight(max))
531 viewport.alignment.deleteGroup(sg);
536 alignPanel.repaint();
541 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
543 addHistoryItem(new HistoryItem("Remove Gapped Columns",
547 viewport.getAlignment().removeGaps();
548 viewport.updateConservation();
549 viewport.updateConsensus();
550 alignPanel.repaint();
553 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
555 addHistoryItem(new HistoryItem("Remove Gaps",
560 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
562 current = viewport.getAlignment().getSequenceAt(i);
563 jSize = current.getLength();
564 for (int j=0; j < jSize; j++)
565 if(jalview.util.Comparison.isGap(current.getCharAt(j)))
567 current.deleteCharAt(j);
572 viewport.updateConservation();
573 viewport.updateConsensus();
574 alignPanel.repaint();
578 public void findMenuItem_actionPerformed(ActionEvent e)
580 JInternalFrame frame = new JInternalFrame();
581 Finder finder = new Finder(viewport, alignPanel, frame);
582 frame.setContentPane(finder);
583 Desktop.addInternalFrame(frame, "Find", 340,110);
584 frame.setLayer(JLayeredPane.PALETTE_LAYER);
589 public void font_actionPerformed(ActionEvent e)
591 FontChooser fc = new FontChooser( alignPanel );
594 protected void fullSeqId_actionPerformed(ActionEvent e)
596 viewport.setShowFullId( fullSeqId.isSelected() );
598 alignPanel.idPanel.idCanvas.setPreferredSize( alignPanel.calculateIdWidth() );
599 alignPanel.repaint();
602 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
604 viewport.setColourText( colourTextMenuItem.isSelected() );
605 alignPanel.repaint();
608 protected void wrapMenuItem_actionPerformed(ActionEvent e)
610 viewport.setWrapAlignment( wrapMenuItem.isSelected() );
611 alignPanel.setWrapAlignment( wrapMenuItem.isSelected() );
612 scaleAbove.setVisible( wrapMenuItem.isSelected() );
613 scaleLeft.setVisible( wrapMenuItem.isSelected() );
614 scaleRight.setVisible( wrapMenuItem.isSelected() );
615 alignPanel.repaint();
618 protected void scaleAbove_actionPerformed(ActionEvent e)
620 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
621 alignPanel.repaint();
624 protected void scaleLeft_actionPerformed(ActionEvent e)
626 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
627 alignPanel.repaint();
630 protected void scaleRight_actionPerformed(ActionEvent e)
632 viewport.setScaleRightWrapped(scaleRight.isSelected());
633 alignPanel.repaint();
638 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
640 viewport.setShowBoxes( viewBoxesMenuItem.isSelected() );
641 alignPanel.repaint();
644 public void viewTextMenuItem_actionPerformed(ActionEvent e)
646 viewport.setShowText( viewTextMenuItem.isSelected() );
647 alignPanel.repaint();
651 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
653 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
654 alignPanel.repaint();
657 public void sequenceFeatures_actionPerformed(ActionEvent evt)
659 viewport.showSequenceFeatures(sequenceFeatures.isSelected());
660 if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded)
662 SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.alignment, alignPanel);
663 ((Alignment)viewport.alignment).featuresAdded = true;
665 alignPanel.repaint();
668 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
670 if(annotationPanelMenuItem.isSelected() && viewport.getWrapAlignment())
672 annotationPanelMenuItem.setSelected(false);
675 viewport.setShowAnnotation( annotationPanelMenuItem.isSelected() );
676 alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() );
679 public void overviewMenuItem_actionPerformed(ActionEvent e)
681 if (alignPanel.overviewPanel != null)
684 JInternalFrame frame = new JInternalFrame();
685 OverviewPanel overview = new OverviewPanel(alignPanel);
686 frame.setContentPane(overview);
687 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
688 frame.getWidth(), frame.getHeight());
690 frame.setLayer(JLayeredPane.PALETTE_LAYER);
691 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
692 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
694 alignPanel.setOverviewPanel(null);
698 alignPanel.setOverviewPanel( overview );
703 protected void noColourmenuItem_actionPerformed(ActionEvent e)
705 changeColour( null );
709 public void clustalColour_actionPerformed(ActionEvent e)
711 abovePIDThreshold.setSelected(false);
712 changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth()));
715 public void zappoColour_actionPerformed(ActionEvent e)
717 changeColour(new ZappoColourScheme());
720 public void taylorColour_actionPerformed(ActionEvent e)
722 changeColour(new TaylorColourScheme());
726 public void hydrophobicityColour_actionPerformed(ActionEvent e)
728 changeColour( new HydrophobicColourScheme() );
731 public void helixColour_actionPerformed(ActionEvent e)
733 changeColour(new HelixColourScheme() );
737 public void strandColour_actionPerformed(ActionEvent e)
739 changeColour(new StrandColourScheme());
743 public void turnColour_actionPerformed(ActionEvent e)
745 changeColour(new TurnColourScheme());
749 public void buriedColour_actionPerformed(ActionEvent e)
751 changeColour(new BuriedColourScheme() );
754 public void nucleotideColour_actionPerformed(ActionEvent e)
756 changeColour(new NucleotideColourScheme());
760 protected void applyToAllGroups_actionPerformed(ActionEvent e)
762 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
767 void changeColour(ColourSchemeI cs)
771 if ( viewport.getAbovePIDThreshold() )
773 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background");
775 if (cs instanceof ResidueColourScheme)
776 ( (ResidueColourScheme) cs).setThreshold(threshold);
777 else if (cs instanceof ScoreColourScheme)
778 ( (ScoreColourScheme) cs).setThreshold(threshold);
780 viewport.setGlobalColourScheme(cs);
782 else if (cs instanceof ResidueColourScheme)
783 ( (ResidueColourScheme) cs).setThreshold(0);
784 else if (cs instanceof ScoreColourScheme)
785 ( (ScoreColourScheme) cs).setThreshold(0);
789 if (viewport.getConservationSelected())
791 ConservationColourScheme ccs = null;
793 Alignment al = (Alignment) viewport.alignment;
794 Conservation c = new Conservation("All",
795 ResidueProperties.propHash, 3,
796 al.getSequences(), 0,
800 c.verdict(false, viewport.ConsPercGaps);
802 ccs = new ConservationColourScheme(c, cs);
804 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
805 ccs.setConsensus( viewport.vconsensus );
806 viewport.setGlobalColourScheme(ccs);
808 SliderPanel.setConservationSlider(alignPanel, ccs, "Background");
813 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
815 cs.setConsensus(viewport.vconsensus);
816 viewport.setGlobalColourScheme(cs);
820 if(viewport.getColourAppliesToAllGroups())
822 Vector groups = viewport.alignment.getGroups();
823 for(int i=0; i<groups.size(); i++)
825 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
827 if (cs instanceof ClustalxColourScheme)
829 sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());
834 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
835 }catch(Exception ex){ex.printStackTrace();}
838 if(viewport.getAbovePIDThreshold())
840 if (sg.cs instanceof ResidueColourScheme)
841 ( (ResidueColourScheme) sg.cs).setThreshold(threshold);
842 else if (sg.cs instanceof ScoreColourScheme)
843 ( (ScoreColourScheme) sg.cs).setThreshold(threshold);
845 sg.cs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()) );
848 if( viewport.getConservationSelected() )
850 Conservation c = new Conservation("Group",
851 ResidueProperties.propHash, 3,
852 sg.sequences, 0, viewport.alignment.getWidth()-1);
854 c.verdict(false, viewport.ConsPercGaps);
855 ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs);
857 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
858 ccs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
863 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
864 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
870 if(alignPanel.getOverviewPanel()!=null)
871 alignPanel.getOverviewPanel().updateOverviewImage();
872 alignPanel.repaint();
875 protected void modifyPID_actionPerformed(ActionEvent e)
877 if(viewport.getAbovePIDThreshold())
879 SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(),
881 SliderPanel.showPIDSlider();
885 protected void modifyConservation_actionPerformed(ActionEvent e)
887 if(viewport.getConservationSelected())
889 SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme,
891 SliderPanel.showConservationSlider();
896 protected void conservationMenuItem_actionPerformed(ActionEvent e)
898 viewport.setConservationSelected(conservationMenuItem.isSelected());
900 viewport.setAbovePIDThreshold(false);
901 abovePIDThreshold.setSelected(false);
903 ColourSchemeI cs = viewport.getGlobalColourScheme();
904 if(cs instanceof ConservationColourScheme )
905 changeColour( ((ConservationColourScheme)cs).cs );
909 modifyConservation_actionPerformed(null);
912 public void abovePIDThreshold_actionPerformed(ActionEvent e)
914 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
916 conservationMenuItem.setSelected(false);
917 viewport.setConservationSelected(false);
919 ColourSchemeI cs = viewport.getGlobalColourScheme();
921 if(cs instanceof ConservationColourScheme )
922 changeColour( ((ConservationColourScheme)cs).cs );
926 modifyPID_actionPerformed(null);
931 public void userDefinedColour_actionPerformed(ActionEvent e)
933 UserDefinedColours chooser = new UserDefinedColours( alignPanel, null);
936 public void PIDColour_actionPerformed(ActionEvent e)
938 changeColour( new PIDColourScheme() );
942 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
944 changeColour(new Blosum62ColourScheme() );
949 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
951 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, HistoryItem.SORT));
952 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0));
953 alignPanel.repaint();
956 public void sortIDMenuItem_actionPerformed(ActionEvent e)
958 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, HistoryItem.SORT));
959 AlignmentSorter.sortByID( viewport.getAlignment() );
960 alignPanel.repaint();
963 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
965 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, HistoryItem.SORT));
966 AlignmentSorter.sortByGroup(viewport.getAlignment());
967 AlignmentSorter.sortGroups(viewport.getAlignment());
968 alignPanel.repaint();
971 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
973 RedundancyPanel sp = new RedundancyPanel(alignPanel);
974 JInternalFrame frame = new JInternalFrame();
975 frame.setContentPane(sp);
976 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100, false);
980 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
982 if(viewport.getSelectionGroup().getSize()<2)
983 JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);
986 JInternalFrame frame = new JInternalFrame();
987 frame.setContentPane(new PairwiseAlignPanel(viewport));
988 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
992 public void PCAMenuItem_actionPerformed(ActionEvent e)
995 if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0)
996 || viewport.getAlignment().getHeight()<4)
998 JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"
999 +"at least 4 input sequences.",
1000 "Sequence selection insufficient",
1001 JOptionPane.WARNING_MESSAGE);
1006 PCAPanel pcaPanel = new PCAPanel(viewport, null);
1007 JInternalFrame frame = new JInternalFrame();
1008 frame.setContentPane(pcaPanel);
1009 Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400);
1010 }catch(java.lang.OutOfMemoryError ex)
1012 JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!",
1013 "Out of memory", JOptionPane.WARNING_MESSAGE);
1019 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
1021 NewTreePanel("AV", "PID", "Average distance tree using PID");
1024 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
1026 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
1030 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1032 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
1035 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1037 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID");
1040 void NewTreePanel(String type, String pwType, String title)
1042 //are the sequences aligned?
1043 if(!viewport.alignment.isAligned())
1045 JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.",
1046 "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
1051 if (viewport.getSelectionGroup() != null &&
1052 viewport.getSelectionGroup().getSize() > 3)
1054 tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
1056 0, viewport.alignment.getWidth());
1060 tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
1061 type, pwType, 0, viewport.alignment.getWidth());
1064 addTreeMenuItem(tp, title);
1066 Desktop.addInternalFrame(tp, title, 600, 500);
1069 public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
1070 final JMenuItem item = new JMenuItem(title);
1071 sortByTreeMenu.add(item);
1072 item.addActionListener(new java.awt.event.ActionListener()
1074 public void actionPerformed(ActionEvent e)
1076 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
1078 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
1079 AlignmentSorter.sortBy(viewport.getAlignment(), order);
1080 alignPanel.repaint();
1085 void addTreeMenuItem(final TreePanel treePanel, String title)
1087 final JMenuItem item = new JMenuItem(title);
1088 sortByTreeMenu.add(item);
1089 item.addActionListener(new java.awt.event.ActionListener()
1091 public void actionPerformed(ActionEvent e)
1093 addHistoryItem(new HistoryItem("Tree Sort", viewport.alignment,
1095 AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());
1096 alignPanel.repaint();
1100 treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1102 public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
1104 sortByTreeMenu.remove(item);
1111 public void clustalAlignMenuItem_actionPerformed(ActionEvent e)
1113 // TODO:resolve which menu item was actually selected
1114 // Now, check we have enough sequences
1115 SequenceI[] msa=null;
1116 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1118 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1119 SequenceGroup seqs = viewport.getSelectionGroup();
1121 msa = new SequenceI[sz=seqs.getSize()];
1122 for (int i = 0; i < sz; i++)
1124 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1130 Vector seqs = viewport.getAlignment().getSequences();
1132 if (seqs.size() > 1) {
1133 msa = new SequenceI[seqs.size()];
1134 for (int i = 0; i < seqs.size(); i++)
1136 msa[i] = (SequenceI) seqs.elementAt(i);
1143 jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, true, true);
1147 protected void jpred_actionPerformed(ActionEvent e)
1150 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>0)
1152 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1153 SequenceGroup seqs = viewport.getSelectionGroup();
1154 if (seqs.getSize() == 1 || !viewport.alignment.isAligned())
1156 JPredClient ct = new JPredClient( (SequenceI)seqs.getSequenceAt(0));
1161 SequenceI[] msa = new SequenceI[sz=seqs.getSize()];
1162 for (int i = 0; i < sz; i++)
1164 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1167 JPredClient ct = new JPredClient(msa);
1173 Vector seqs = viewport.getAlignment().getSequences();
1175 if (seqs.size() == 1 || !viewport.alignment.isAligned())
1177 JPredClient ct = new JPredClient( (SequenceI)
1182 SequenceI[] msa = new SequenceI[seqs.size()];
1183 for (int i = 0; i < seqs.size(); i++)
1185 msa[i] = (SequenceI) seqs.elementAt(i);
1188 JPredClient ct = new JPredClient(msa);
1193 protected void msaAlignMenuItem_actionPerformed(ActionEvent e)
1195 // TODO:resolve which menu item was actually selected
1196 // Now, check we have enough sequences
1197 SequenceI[] msa=null;
1198 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1200 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1201 SequenceGroup seqs = viewport.getSelectionGroup();
1203 msa = new SequenceI[sz=seqs.getSize()];
1204 for (int i = 0; i < sz; i++)
1206 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1213 Vector seqs = viewport.getAlignment().getSequences();
1215 if (seqs.size() > 1) {
1216 msa = new SequenceI[seqs.size()];
1217 for (int i = 0; i < seqs.size(); i++)
1219 msa[i] = (SequenceI) seqs.elementAt(i);
1226 MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, true, true);
1229 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {
1230 // Pick the tree file
1231 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1232 getProperty("LAST_DIRECTORY"));
1233 chooser.setFileView(new JalviewFileView());
1234 chooser.setDialogTitle("Select a newick-like tree file");
1235 chooser.setToolTipText("Load a tree file");
1236 int value = chooser.showOpenDialog(null);
1237 if (value == JalviewFileChooser.APPROVE_OPTION)
1239 String choice = chooser.getSelectedFile().getPath();
1240 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1243 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File");
1244 ShowNewickTree(fin, choice);
1246 catch (Exception ex)
1248 JOptionPane.showMessageDialog(Desktop.desktop,
1249 "Problem reading tree file",
1251 JOptionPane.WARNING_MESSAGE);
1252 ex.printStackTrace();
1257 public void ShowNewickTree(NewickFile nf, String title)
1261 if (nf.getTree() != null)
1263 TreePanel tp = new TreePanel(viewport,
1264 viewport.getAlignment().getSequences(),
1265 nf, "FromFile", title);
1266 Desktop.addInternalFrame(tp, title, 600, 500);
1267 addTreeMenuItem(tp, title);
1268 viewport.setCurrentTree(tp.getTree());
1270 }catch(Exception ex){ex.printStackTrace();}