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, System.currentTimeMillis(), shortName,
87 // USE Jalview2XML to save this file
91 String choice = chooser.getSelectedFile().getPath();
92 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
93 String output = FormatAdapter.formatSequences(currentFileFormat, viewport.getAlignment().getSequences());
95 java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) );
104 protected void outputText_actionPerformed(ActionEvent e)
106 CutAndPasteTransfer cap = new CutAndPasteTransfer(false);
107 JInternalFrame frame = new JInternalFrame();
108 cap.formatForOutput();
109 frame.setContentPane(cap);
110 Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500);
111 cap.setText( FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences()));
114 protected void htmlMenuItem_actionPerformed(ActionEvent e)
116 HTMLOutput htmlOutput = new HTMLOutput(viewport);
120 protected void createPNG_actionPerformed(ActionEvent e)
122 alignPanel.makePNG();
125 protected void epsFile_actionPerformed(ActionEvent e)
127 alignPanel.makeEPS();
131 public void printMenuItem_actionPerformed(ActionEvent e)
133 //Putting in a thread avoids Swing painting problems
134 PrintThread thread = new PrintThread();
138 class PrintThread extends Thread
142 PrinterJob printJob = PrinterJob.getPrinterJob();
143 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
144 printJob.setPrintable(alignPanel, pf);
145 if (printJob.printDialog())
151 catch (Exception PrintException)
153 PrintException.printStackTrace();
163 public void closeMenuItem_actionPerformed(ActionEvent e)
166 this.setClosed(true);
167 }catch(Exception ex){}
170 Stack historyList = new Stack();
171 Stack redoList = new Stack();
173 void updateEditMenuBar()
175 if(historyList.size()>0)
177 undoMenuItem.setEnabled(true);
178 HistoryItem hi = (HistoryItem)historyList.peek();
179 undoMenuItem.setText("Undo "+hi.getDescription());
183 undoMenuItem.setEnabled(false);
184 undoMenuItem.setText("Undo");
187 if(redoList.size()>0)
189 redoMenuItem.setEnabled(true);
190 HistoryItem hi = (HistoryItem)redoList.peek();
191 redoMenuItem.setText("Redo "+hi.getDescription());
195 redoMenuItem.setEnabled(false);
196 redoMenuItem.setText("Redo");
200 public void addHistoryItem(HistoryItem hi)
202 historyList.push(hi);
206 protected void undoMenuItem_actionPerformed(ActionEvent e)
208 HistoryItem hi = (HistoryItem)historyList.pop();
209 redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, HistoryItem.HIDE));
210 restoreHistoryItem(hi);
214 protected void redoMenuItem_actionPerformed(ActionEvent e)
216 HistoryItem hi = (HistoryItem)redoList.pop();
217 restoreHistoryItem(hi);
219 viewport.updateConsensus();
220 alignPanel.repaint();
221 alignPanel.repaint();
225 // used by undo and redo
226 void restoreHistoryItem(HistoryItem hi)
228 if(hi.getType()== HistoryItem.SORT)
230 for(int i=0; i<hi.getSequences().size(); i++)
231 viewport.alignment.getSequences().setElementAt(hi.getSequences().elementAt(i), i);
235 for (int i = 0; i < hi.getSequences().size(); i++)
237 SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);
238 if(restore.getLength()==0)
240 System.out.println(hi.getHidden().elementAt(i));
241 restore.setSequence(hi.getHidden().elementAt(i).toString());
242 viewport.alignment.getSequences().insertElementAt(
244 hi.getAlignIndex(i));
247 restore.setSequence(hi.getHidden().elementAt(i).toString());
249 if(hi.getType()==HistoryItem.PASTE)
251 for(int i=viewport.alignment.getHeight()-1;i>hi.getSequences().size()-1; i--)
252 viewport.alignment.deleteSequence(i);
258 viewport.updateConsensus();
259 viewport.updateConservation();
260 alignPanel.repaint();
263 public void moveSelectedSequences(boolean up)
265 SequenceGroup sg = viewport.getSelectionGroup();
271 for (int i = 1; i < viewport.alignment.getHeight(); i++)
273 SequenceI seq = viewport.alignment.getSequenceAt(i);
274 if (!sg.sequences.contains(seq))
277 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
278 if (sg.sequences.contains(temp))
281 viewport.alignment.getSequences().setElementAt(temp, i);
282 viewport.alignment.getSequences().setElementAt(seq, i - 1);
287 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
289 SequenceI seq = viewport.alignment.getSequenceAt(i);
290 if (!sg.sequences.contains(seq))
293 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
294 if (sg.sequences.contains(temp))
297 viewport.alignment.getSequences().setElementAt(temp, i);
298 viewport.alignment.getSequences().setElementAt(seq, i + 1);
302 alignPanel.repaint();
307 protected void copy_actionPerformed(ActionEvent e)
309 if(viewport.getSelectionGroup()==null)
312 SequenceGroup sg = viewport.getSelectionGroup();
314 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
315 StringBuffer buffer= new StringBuffer();
317 Hashtable orderedSeqs = new Hashtable();
318 for(int i=0; i<sg.getSize(); i++)
320 SequenceI seq = sg.getSequenceAt(i);
321 int index = viewport.alignment.findIndex(seq);
322 orderedSeqs.put(index+"", seq);
326 for(int i=0; i<sg.getSize(); i++)
328 SequenceI seq = null;
331 if(orderedSeqs.containsKey(index+""))
333 seq = (SequenceI) orderedSeqs.get(index + "");
341 buffer.append( seq.getName()+"\t"+seq.findPosition( sg.getStartRes() ) +"\t"
342 +seq.findPosition( sg.getEndRes() )+ "\t"
343 +sg.getSequenceAt(i).getSequence(sg.getStartRes(), sg.getEndRes()+1)+"\n");
345 c.setContents( new StringSelection( buffer.toString()) , null ) ;
350 protected void pasteNew_actionPerformed(ActionEvent e)
355 protected void pasteThis_actionPerformed(ActionEvent e)
357 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, HistoryItem.PASTE));
361 void paste(boolean newAlignment)
364 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
365 Transferable contents = c.getContents(this);
366 if (contents == null)
369 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
370 StringTokenizer st = new StringTokenizer(str);
371 ArrayList seqs = new ArrayList();
372 while (st.hasMoreElements())
374 String name = st.nextToken();
375 int start = Integer.parseInt(st.nextToken());
376 int end = Integer.parseInt(st.nextToken());
377 Sequence sequence = new Sequence(name,st.nextToken(), start, end);
380 viewport.alignment.addSequence(sequence);
387 SequenceI[] newSeqs = new SequenceI[seqs.size()];
388 seqs.toArray(newSeqs);
389 AlignFrame af = new AlignFrame(new Alignment(newSeqs));
390 String newtitle = new String("Copied sequences");
391 if( title.startsWith("Copied sequences"))
394 newtitle = newtitle.concat("- from "+title);
396 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);
400 viewport.setEndSeq(viewport.alignment.getHeight());
401 viewport.alignment.getWidth();
402 viewport.updateConservation();
403 viewport.updateConsensus();
404 alignPanel.repaint();
407 }catch(Exception ex){}// could be anything being pasted in here
412 protected void cut_actionPerformed(ActionEvent e)
414 copy_actionPerformed(null);
415 delete_actionPerformed(null);
418 protected void delete_actionPerformed(ActionEvent e)
420 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
422 if (viewport.getSelectionGroup() == null)
425 SequenceGroup sg = viewport.getSelectionGroup();
426 for (int i=0;i < sg.sequences.size(); i++)
428 SequenceI seq = sg.getSequenceAt(i);
429 int index = viewport.getAlignment().findIndex(seq);
430 seq.deleteChars(sg.getStartRes(), sg.getEndRes()+1);
432 if(seq.getSequence().length()<1)
433 viewport.getAlignment().deleteSequence(seq);
435 viewport.getAlignment().getSequences().setElementAt(seq, index);
438 viewport.setSelectionGroup(null);
439 viewport.alignment.deleteGroup(sg);
440 viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight());
441 if(viewport.getAlignment().getHeight()<1)
444 this.setClosed(true);
445 }catch(Exception ex){}
446 viewport.updateConservation();
447 viewport.updateConsensus();
448 alignPanel.repaint();
453 protected void deleteGroups_actionPerformed(ActionEvent e)
455 viewport.alignment.deleteAllGroups();
456 viewport.setSelectionGroup(null);
457 alignPanel.repaint();
462 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
464 SequenceGroup sg = new SequenceGroup();
465 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
466 sg.addSequence( viewport.getAlignment().getSequenceAt(i));
467 sg.setEndRes(viewport.alignment.getWidth());
468 viewport.setSelectionGroup(sg);
469 PaintRefresher.Refresh(null);
472 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
474 viewport.setSelectionGroup(null);
475 viewport.getColumnSelection().clear();
476 viewport.setSelectionGroup(null);
477 PaintRefresher.Refresh(null);
480 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
482 SequenceGroup sg = viewport.getSelectionGroup();
483 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
484 sg.addOrRemove (viewport.getAlignment().getSequenceAt(i));
486 PaintRefresher.Refresh(null);
489 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
491 ColumnSelection colSel = viewport.getColumnSelection();
492 if (colSel.size() > 0)
494 addHistoryItem(new HistoryItem("Remove Left",viewport.alignment,
496 int min = colSel.getMin();
497 viewport.getAlignment().trimLeft(min);
498 colSel.compensateForEdit(0,min);
500 if(viewport.getSelectionGroup()!=null)
501 viewport.getSelectionGroup().adjustForRemoveLeft(min);
503 Vector groups = viewport.alignment.getGroups();
504 for(int i=0; i<groups.size(); i++)
506 SequenceGroup sg = (SequenceGroup) groups.get(i);
507 if(!sg.adjustForRemoveLeft(min))
508 viewport.alignment.deleteGroup(sg);
511 alignPanel.repaint();
515 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
517 ColumnSelection colSel = viewport.getColumnSelection();
518 if (colSel.size() > 0)
520 addHistoryItem(new HistoryItem("Remove Right",viewport.alignment,
523 int max = colSel.getMax();
524 viewport.getAlignment().trimRight(max);
525 if(viewport.getSelectionGroup()!=null)
526 viewport.getSelectionGroup().adjustForRemoveRight(max);
528 Vector groups = viewport.alignment.getGroups();
529 for(int i=0; i<groups.size(); i++)
531 SequenceGroup sg = (SequenceGroup) groups.get(i);
532 if(!sg.adjustForRemoveRight(max))
533 viewport.alignment.deleteGroup(sg);
538 alignPanel.repaint();
543 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
545 addHistoryItem(new HistoryItem("Remove Gapped Columns",
548 viewport.getAlignment().removeGaps();
549 viewport.updateConservation();
550 viewport.updateConsensus();
551 alignPanel.repaint();
554 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
556 addHistoryItem(new HistoryItem("Remove Gaps",
561 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
563 current = viewport.getAlignment().getSequenceAt(i);
564 jSize = current.getLength();
565 for (int j=0; j < jSize; j++)
566 if(jalview.util.Comparison.isGap(current.getCharAt(j)))
568 current.deleteCharAt(j);
573 viewport.updateConservation();
574 viewport.updateConsensus();
575 alignPanel.repaint();
579 public void findMenuItem_actionPerformed(ActionEvent e)
581 JInternalFrame frame = new JInternalFrame();
582 Finder finder = new Finder(viewport, alignPanel, frame);
583 frame.setContentPane(finder);
584 Desktop.addInternalFrame(frame, "Find", 340,110);
585 frame.setLayer(JLayeredPane.PALETTE_LAYER);
590 public void font_actionPerformed(ActionEvent e)
592 FontChooser fc = new FontChooser( alignPanel );
595 protected void fullSeqId_actionPerformed(ActionEvent e)
597 viewport.setShowFullId( fullSeqId.isSelected() );
599 alignPanel.idPanel.idCanvas.setPreferredSize( alignPanel.calculateIdWidth() );
600 alignPanel.repaint();
603 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
605 viewport.setColourText( colourTextMenuItem.isSelected() );
606 alignPanel.repaint();
609 protected void wrapMenuItem_actionPerformed(ActionEvent e)
611 viewport.setWrapAlignment( wrapMenuItem.isSelected() );
612 alignPanel.setWrapAlignment( wrapMenuItem.isSelected() );
613 scaleAbove.setVisible( wrapMenuItem.isSelected() );
614 scaleLeft.setVisible( wrapMenuItem.isSelected() );
615 scaleRight.setVisible( wrapMenuItem.isSelected() );
616 alignPanel.repaint();
619 protected void scaleAbove_actionPerformed(ActionEvent e)
621 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
622 alignPanel.repaint();
625 protected void scaleLeft_actionPerformed(ActionEvent e)
627 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
628 alignPanel.repaint();
631 protected void scaleRight_actionPerformed(ActionEvent e)
633 viewport.setScaleRightWrapped(scaleRight.isSelected());
634 alignPanel.repaint();
639 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
641 viewport.setShowBoxes( viewBoxesMenuItem.isSelected() );
642 alignPanel.repaint();
645 public void viewTextMenuItem_actionPerformed(ActionEvent e)
647 viewport.setShowText( viewTextMenuItem.isSelected() );
648 alignPanel.repaint();
652 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
654 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
655 alignPanel.repaint();
658 public void sequenceFeatures_actionPerformed(ActionEvent evt)
660 viewport.showSequenceFeatures(sequenceFeatures.isSelected());
661 if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded)
663 SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.alignment, alignPanel);
664 ((Alignment)viewport.alignment).featuresAdded = true;
666 alignPanel.repaint();
669 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
671 if(annotationPanelMenuItem.isSelected() && viewport.getWrapAlignment())
673 annotationPanelMenuItem.setSelected(false);
676 viewport.setShowAnnotation( annotationPanelMenuItem.isSelected() );
677 alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() );
680 public void overviewMenuItem_actionPerformed(ActionEvent e)
682 if (alignPanel.overviewPanel != null)
685 JInternalFrame frame = new JInternalFrame();
686 OverviewPanel overview = new OverviewPanel(alignPanel);
687 frame.setContentPane(overview);
688 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
689 frame.getWidth(), frame.getHeight());
691 frame.setLayer(JLayeredPane.PALETTE_LAYER);
692 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
693 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
695 alignPanel.setOverviewPanel(null);
699 alignPanel.setOverviewPanel( overview );
704 protected void noColourmenuItem_actionPerformed(ActionEvent e)
706 changeColour( null );
710 public void clustalColour_actionPerformed(ActionEvent e)
712 abovePIDThreshold.setSelected(false);
713 changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth()));
716 public void zappoColour_actionPerformed(ActionEvent e)
718 changeColour(new ZappoColourScheme());
721 public void taylorColour_actionPerformed(ActionEvent e)
723 changeColour(new TaylorColourScheme());
727 public void hydrophobicityColour_actionPerformed(ActionEvent e)
729 changeColour( new HydrophobicColourScheme() );
732 public void helixColour_actionPerformed(ActionEvent e)
734 changeColour(new HelixColourScheme() );
738 public void strandColour_actionPerformed(ActionEvent e)
740 changeColour(new StrandColourScheme());
744 public void turnColour_actionPerformed(ActionEvent e)
746 changeColour(new TurnColourScheme());
750 public void buriedColour_actionPerformed(ActionEvent e)
752 changeColour(new BuriedColourScheme() );
755 public void nucleotideColour_actionPerformed(ActionEvent e)
757 changeColour(new NucleotideColourScheme());
761 protected void applyToAllGroups_actionPerformed(ActionEvent e)
763 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
768 void changeColour(ColourSchemeI cs)
772 if ( viewport.getAbovePIDThreshold() )
774 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background");
776 if (cs instanceof ResidueColourScheme)
777 ( (ResidueColourScheme) cs).setThreshold(threshold);
778 else if (cs instanceof ScoreColourScheme)
779 ( (ScoreColourScheme) cs).setThreshold(threshold);
781 viewport.setGlobalColourScheme(cs);
783 else if (cs instanceof ResidueColourScheme)
784 ( (ResidueColourScheme) cs).setThreshold(0);
785 else if (cs instanceof ScoreColourScheme)
786 ( (ScoreColourScheme) cs).setThreshold(0);
790 if (viewport.getConservationSelected())
792 ConservationColourScheme ccs = null;
794 Alignment al = (Alignment) viewport.alignment;
795 Conservation c = new Conservation("All",
796 ResidueProperties.propHash, 3,
797 al.getSequences(), 0,
801 c.verdict(false, viewport.ConsPercGaps);
803 ccs = new ConservationColourScheme(c, cs);
805 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
806 ccs.setConsensus( viewport.vconsensus );
807 viewport.setGlobalColourScheme(ccs);
809 SliderPanel.setConservationSlider(alignPanel, ccs, "Background");
814 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
816 cs.setConsensus(viewport.vconsensus);
817 viewport.setGlobalColourScheme(cs);
821 if(viewport.getColourAppliesToAllGroups())
823 Vector groups = viewport.alignment.getGroups();
824 for(int i=0; i<groups.size(); i++)
826 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
828 if (cs instanceof ClustalxColourScheme)
830 sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());
835 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
836 }catch(Exception ex){ex.printStackTrace();}
839 if(viewport.getAbovePIDThreshold())
841 if (sg.cs instanceof ResidueColourScheme)
842 ( (ResidueColourScheme) sg.cs).setThreshold(threshold);
843 else if (sg.cs instanceof ScoreColourScheme)
844 ( (ScoreColourScheme) sg.cs).setThreshold(threshold);
846 sg.cs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()) );
849 if( viewport.getConservationSelected() )
851 Conservation c = new Conservation("Group",
852 ResidueProperties.propHash, 3,
853 sg.sequences, 0, viewport.alignment.getWidth()-1);
855 c.verdict(false, viewport.ConsPercGaps);
856 ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs);
858 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
859 ccs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
864 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
865 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
871 if(alignPanel.getOverviewPanel()!=null)
872 alignPanel.getOverviewPanel().updateOverviewImage();
873 alignPanel.repaint();
876 protected void modifyPID_actionPerformed(ActionEvent e)
878 if(viewport.getAbovePIDThreshold())
880 SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(),
882 SliderPanel.showPIDSlider();
886 protected void modifyConservation_actionPerformed(ActionEvent e)
888 if(viewport.getConservationSelected())
890 SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme,
892 SliderPanel.showConservationSlider();
897 protected void conservationMenuItem_actionPerformed(ActionEvent e)
899 viewport.setConservationSelected(conservationMenuItem.isSelected());
901 viewport.setAbovePIDThreshold(false);
902 abovePIDThreshold.setSelected(false);
904 ColourSchemeI cs = viewport.getGlobalColourScheme();
905 if(cs instanceof ConservationColourScheme )
906 changeColour( ((ConservationColourScheme)cs).cs );
910 modifyConservation_actionPerformed(null);
913 public void abovePIDThreshold_actionPerformed(ActionEvent e)
915 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
917 conservationMenuItem.setSelected(false);
918 viewport.setConservationSelected(false);
920 ColourSchemeI cs = viewport.getGlobalColourScheme();
922 if(cs instanceof ConservationColourScheme )
923 changeColour( ((ConservationColourScheme)cs).cs );
927 modifyPID_actionPerformed(null);
932 public void userDefinedColour_actionPerformed(ActionEvent e)
934 UserDefinedColours chooser = new UserDefinedColours( alignPanel, null);
937 public void PIDColour_actionPerformed(ActionEvent e)
939 changeColour( new PIDColourScheme() );
943 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
945 changeColour(new Blosum62ColourScheme() );
950 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
952 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, HistoryItem.SORT));
953 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0));
954 alignPanel.repaint();
957 public void sortIDMenuItem_actionPerformed(ActionEvent e)
959 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, HistoryItem.SORT));
960 AlignmentSorter.sortByID( viewport.getAlignment() );
961 alignPanel.repaint();
964 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
966 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, HistoryItem.SORT));
967 AlignmentSorter.sortByGroup(viewport.getAlignment());
968 AlignmentSorter.sortGroups(viewport.getAlignment());
969 alignPanel.repaint();
972 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
974 RedundancyPanel sp = new RedundancyPanel(alignPanel);
975 JInternalFrame frame = new JInternalFrame();
976 frame.setContentPane(sp);
977 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100, false);
981 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
983 if(viewport.getSelectionGroup().getSize()<2)
984 JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);
987 JInternalFrame frame = new JInternalFrame();
988 frame.setContentPane(new PairwiseAlignPanel(viewport));
989 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
993 public void PCAMenuItem_actionPerformed(ActionEvent e)
996 if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0)
997 || viewport.getAlignment().getHeight()<4)
999 JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"
1000 +"at least 4 input sequences.",
1001 "Sequence selection insufficient",
1002 JOptionPane.WARNING_MESSAGE);
1007 PCAPanel pcaPanel = new PCAPanel(viewport, null);
1008 JInternalFrame frame = new JInternalFrame();
1009 frame.setContentPane(pcaPanel);
1010 Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400);
1011 }catch(java.lang.OutOfMemoryError ex)
1013 JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!",
1014 "Out of memory", JOptionPane.WARNING_MESSAGE);
1020 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
1022 NewTreePanel("AV", "PID", "Average distance tree using PID");
1025 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
1027 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
1031 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1033 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
1036 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1038 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID");
1041 void NewTreePanel(String type, String pwType, String title)
1043 //are the sequences aligned?
1044 if(!viewport.alignment.isAligned())
1046 JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.",
1047 "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
1052 if (viewport.getSelectionGroup() != null &&
1053 viewport.getSelectionGroup().getSize() > 3)
1055 tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
1057 0, viewport.alignment.getWidth());
1061 tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
1062 type, pwType, 0, viewport.alignment.getWidth());
1065 addTreeMenuItem(tp, title);
1067 Desktop.addInternalFrame(tp, title, 600, 500);
1070 public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
1071 final JMenuItem item = new JMenuItem(title);
1072 sortByTreeMenu.add(item);
1073 item.addActionListener(new java.awt.event.ActionListener()
1075 public void actionPerformed(ActionEvent e)
1077 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
1079 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
1080 AlignmentSorter.sortBy(viewport.getAlignment(), order);
1081 alignPanel.repaint();
1086 void addTreeMenuItem(final TreePanel treePanel, String title)
1088 final JMenuItem item = new JMenuItem(title);
1089 sortByTreeMenu.add(item);
1090 item.addActionListener(new java.awt.event.ActionListener()
1092 public void actionPerformed(ActionEvent e)
1094 addHistoryItem(new HistoryItem("Tree Sort", viewport.alignment,
1096 AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());
1097 alignPanel.repaint();
1101 treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1103 public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
1105 sortByTreeMenu.remove(item);
1112 public void clustalAlignMenuItem_actionPerformed(ActionEvent e)
1114 // TODO:resolve which menu item was actually selected
1115 // Now, check we have enough sequences
1116 SequenceI[] msa=null;
1117 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1119 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1120 SequenceGroup seqs = viewport.getSelectionGroup();
1122 msa = new SequenceI[sz=seqs.getSize()];
1123 for (int i = 0; i < sz; i++)
1125 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1131 Vector seqs = viewport.getAlignment().getSequences();
1133 if (seqs.size() > 1) {
1134 msa = new SequenceI[seqs.size()];
1135 for (int i = 0; i < seqs.size(); i++)
1137 msa[i] = (SequenceI) seqs.elementAt(i);
1144 jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, true, true);
1148 protected void jpred_actionPerformed(ActionEvent e)
1151 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>0)
1153 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1154 SequenceGroup seqs = viewport.getSelectionGroup();
1155 if (seqs.getSize() == 1 || !viewport.alignment.isAligned())
1157 JPredClient ct = new JPredClient( (SequenceI)seqs.getSequenceAt(0));
1162 SequenceI[] msa = new SequenceI[sz=seqs.getSize()];
1163 for (int i = 0; i < sz; i++)
1165 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1168 JPredClient ct = new JPredClient(msa);
1174 Vector seqs = viewport.getAlignment().getSequences();
1176 if (seqs.size() == 1 || !viewport.alignment.isAligned())
1178 JPredClient ct = new JPredClient( (SequenceI)
1183 SequenceI[] msa = new SequenceI[seqs.size()];
1184 for (int i = 0; i < seqs.size(); i++)
1186 msa[i] = (SequenceI) seqs.elementAt(i);
1189 JPredClient ct = new JPredClient(msa);
1194 protected void msaAlignMenuItem_actionPerformed(ActionEvent e)
1196 // TODO:resolve which menu item was actually selected
1197 // Now, check we have enough sequences
1198 SequenceI[] msa=null;
1199 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1201 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1202 SequenceGroup seqs = viewport.getSelectionGroup();
1204 msa = new SequenceI[sz=seqs.getSize()];
1205 for (int i = 0; i < sz; i++)
1207 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1214 Vector seqs = viewport.getAlignment().getSequences();
1216 if (seqs.size() > 1) {
1217 msa = new SequenceI[seqs.size()];
1218 for (int i = 0; i < seqs.size(); i++)
1220 msa[i] = (SequenceI) seqs.elementAt(i);
1227 MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, true, true);
1230 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {
1231 // Pick the tree file
1232 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1233 getProperty("LAST_DIRECTORY"));
1234 chooser.setFileView(new JalviewFileView());
1235 chooser.setDialogTitle("Select a newick-like tree file");
1236 chooser.setToolTipText("Load a tree file");
1237 int value = chooser.showOpenDialog(null);
1238 if (value == JalviewFileChooser.APPROVE_OPTION)
1240 String choice = chooser.getSelectedFile().getPath();
1241 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1244 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File");
1245 ShowNewickTree(fin, choice);
1247 catch (Exception ex)
1249 JOptionPane.showMessageDialog(Desktop.desktop,
1250 "Problem reading tree file",
1252 JOptionPane.WARNING_MESSAGE);
1253 ex.printStackTrace();
1258 public void ShowNewickTree(NewickFile nf, String title)
1262 if (nf.getTree() != null)
1264 TreePanel tp = new TreePanel(viewport,
1265 viewport.getAlignment().getSequences(),
1266 nf, "FromFile", title);
1267 Desktop.addInternalFrame(tp, title, 600, 500);
1268 addTreeMenuItem(tp, title);
1269 viewport.setCurrentTree(tp.getTree());
1271 }catch(Exception ex){ex.printStackTrace();}