2 * 2004 Jalview Reengineered
17 import java.awt.datatransfer.*;
18 import java.awt.event.*;
19 import java.awt.print.*;
21 import javax.swing.event.*;
23 import jalview.analysis.*;
24 import jalview.datamodel.*;
26 import jalview.jbgui.*;
27 import jalview.schemes.*;
29 import java.beans.PropertyChangeEvent;
31 public class AlignFrame extends GAlignFrame
33 final AlignmentPanel alignPanel;
34 final AlignViewport viewport;
35 public static final int NEW_WINDOW_WIDTH = 700;
36 public static final int NEW_WINDOW_HEIGHT = 500;
37 public String currentFileFormat = "Jalview";
39 public AlignFrame(AlignmentI al)
41 viewport = new AlignViewport(al);
43 alignPanel = new AlignmentPanel(this, viewport);
44 alignPanel.annotationPanel.adjustPanelHeight();
45 alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel.annotationPanel.getPreferredSize());
46 alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel.getPreferredSize());
47 alignPanel.setAnnotationVisible( viewport.getShowAnnotation() );
49 getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER);
51 addInternalFrameListener(new InternalFrameAdapter()
53 public void internalFrameActivated(InternalFrameEvent evt)
55 javax.swing.SwingUtilities.invokeLater(new Runnable()
58 { alignPanel.requestFocus(); }
66 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
68 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY")
69 , new String[]{"fa, fasta, fastq", "aln", "pfam", "msf", "pir","blc","jar"},
70 new String[]{"Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"},
73 chooser.setAcceptAllFileFilterUsed(false);
74 chooser.setFileView(new JalviewFileView());
75 chooser.setDialogTitle("Save Alignment to file");
76 chooser.setToolTipText("Save");
77 int value = chooser.showSaveDialog(this);
78 if(value == JalviewFileChooser.APPROVE_OPTION)
80 currentFileFormat = chooser.getSelectedFormat();
81 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat);
83 if (currentFileFormat.equals("Jalview"))
85 String shortName = title;
86 if(shortName.indexOf(java.io.File.separatorChar)>-1)
87 shortName = shortName.substring(
88 shortName.lastIndexOf(java.io.File.separatorChar)+1);
90 String choice = chooser.getSelectedFile().getPath();
91 Jalview2XML.SaveState(this, choice, shortName);
92 // USE Jalview2XML to save this file
96 String choice = chooser.getSelectedFile().getPath();
97 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
98 String output = FormatAdapter.formatSequences(currentFileFormat, viewport.getAlignment().getSequences());
100 java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) );
104 catch(Exception ex){}
109 protected void outputText_actionPerformed(ActionEvent e)
111 CutAndPasteTransfer cap = new CutAndPasteTransfer();
112 Desktop.addInternalFrame(cap, "Alignment output - "+e.getActionCommand(), 600, 500);
113 cap.setText( FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences()));
116 protected void htmlMenuItem_actionPerformed(ActionEvent e)
118 new HTMLOutput(viewport);
121 protected void createPNG_actionPerformed(ActionEvent e)
123 alignPanel.makePNG();
126 protected void epsFile_actionPerformed(ActionEvent e)
128 alignPanel.makeEPS();
132 public void printMenuItem_actionPerformed(ActionEvent e)
134 //Putting in a thread avoids Swing painting problems
135 PrintThread thread = new PrintThread();
139 class PrintThread extends Thread
143 PrinterJob printJob = PrinterJob.getPrinterJob();
144 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
145 printJob.setPrintable(alignPanel, pf);
146 if (printJob.printDialog())
152 catch (Exception PrintException)
154 PrintException.printStackTrace();
164 public void closeMenuItem_actionPerformed(ActionEvent e)
167 this.setClosed(true);
168 }catch(Exception ex){}
171 Stack historyList = new Stack();
172 Stack redoList = new Stack();
173 private int treeCount = 0;
175 void updateEditMenuBar()
177 if(historyList.size()>0)
179 undoMenuItem.setEnabled(true);
180 HistoryItem hi = (HistoryItem)historyList.peek();
181 undoMenuItem.setText("Undo "+hi.getDescription());
185 undoMenuItem.setEnabled(false);
186 undoMenuItem.setText("Undo");
189 if(redoList.size()>0)
191 redoMenuItem.setEnabled(true);
192 HistoryItem hi = (HistoryItem)redoList.peek();
193 redoMenuItem.setText("Redo "+hi.getDescription());
197 redoMenuItem.setEnabled(false);
198 redoMenuItem.setText("Redo");
202 public void addHistoryItem(HistoryItem hi)
204 historyList.push(hi);
208 protected void undoMenuItem_actionPerformed(ActionEvent e)
210 HistoryItem hi = (HistoryItem)historyList.pop();
211 redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, HistoryItem.HIDE));
212 restoreHistoryItem(hi);
216 protected void redoMenuItem_actionPerformed(ActionEvent e)
218 HistoryItem hi = (HistoryItem)redoList.pop();
219 restoreHistoryItem(hi);
221 viewport.updateConsensus();
222 alignPanel.repaint();
223 alignPanel.repaint();
227 // used by undo and redo
228 void restoreHistoryItem(HistoryItem hi)
230 if(hi.getType()== HistoryItem.SORT)
232 for(int i=0; i<hi.getSequences().size(); i++)
233 viewport.alignment.getSequences().setElementAt(hi.getSequences().elementAt(i), i);
237 for (int i = 0; i < hi.getSequences().size(); i++)
239 SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);
240 if(restore.getLength()==0)
242 restore.setSequence(hi.getHidden().elementAt(i).toString());
243 viewport.alignment.getSequences().insertElementAt(
245 hi.getAlignIndex(i));
248 restore.setSequence(hi.getHidden().elementAt(i).toString());
250 if(hi.getType()==HistoryItem.PASTE)
252 for(int i=viewport.alignment.getHeight()-1;i>hi.getSequences().size()-1; i--)
253 viewport.alignment.deleteSequence(i);
258 viewport.updateConsensus();
259 viewport.updateConservation();
260 alignPanel.repaint();
261 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
264 public void moveSelectedSequences(boolean up)
266 SequenceGroup sg = viewport.getSelectionGroup();
272 for (int i = 1; i < viewport.alignment.getHeight(); i++)
274 SequenceI seq = viewport.alignment.getSequenceAt(i);
275 if (!sg.sequences.contains(seq))
278 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
279 if (sg.sequences.contains(temp))
282 viewport.alignment.getSequences().setElementAt(temp, i);
283 viewport.alignment.getSequences().setElementAt(seq, i - 1);
288 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
290 SequenceI seq = viewport.alignment.getSequenceAt(i);
291 if (!sg.sequences.contains(seq))
294 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
295 if (sg.sequences.contains(temp))
298 viewport.alignment.getSequences().setElementAt(temp, i);
299 viewport.alignment.getSequences().setElementAt(seq, i + 1);
303 alignPanel.repaint();
308 protected void copy_actionPerformed(ActionEvent e)
310 if(viewport.getSelectionGroup()==null)
313 SequenceGroup sg = viewport.getSelectionGroup();
315 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
316 StringBuffer buffer= new StringBuffer();
318 Hashtable orderedSeqs = new Hashtable();
319 for(int i=0; i<sg.getSize(); i++)
321 SequenceI seq = sg.getSequenceAt(i);
322 int index = viewport.alignment.findIndex(seq);
323 orderedSeqs.put(index+"", seq);
327 for(int i=0; i<sg.getSize(); i++)
329 SequenceI seq = null;
332 if(orderedSeqs.containsKey(index+""))
334 seq = (SequenceI) orderedSeqs.get(index + "");
342 buffer.append( seq.getName()+"\t"+seq.findPosition( sg.getStartRes() ) +"\t"
343 +seq.findPosition( sg.getEndRes() )+ "\t"
344 +sg.getSequenceAt(i).getSequence(sg.getStartRes(), sg.getEndRes()+1)+"\n");
346 c.setContents( new StringSelection( buffer.toString()) , null ) ;
351 protected void pasteNew_actionPerformed(ActionEvent e)
356 protected void pasteThis_actionPerformed(ActionEvent e)
358 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, HistoryItem.PASTE));
362 void paste(boolean newAlignment)
365 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
366 Transferable contents = c.getContents(this);
367 if (contents == null)
370 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
371 StringTokenizer st = new StringTokenizer(str);
372 ArrayList seqs = new ArrayList();
373 while (st.hasMoreElements())
375 String name = st.nextToken();
376 int start = Integer.parseInt(st.nextToken());
377 int end = Integer.parseInt(st.nextToken());
378 Sequence sequence = new Sequence(name,st.nextToken(), start, end);
381 viewport.alignment.addSequence(sequence);
388 SequenceI[] newSeqs = new SequenceI[seqs.size()];
389 seqs.toArray(newSeqs);
390 AlignFrame af = new AlignFrame(new Alignment(newSeqs));
391 String newtitle = new String("Copied sequences");
392 if( title.startsWith("Copied sequences"))
395 newtitle = newtitle.concat("- from "+title);
397 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);
401 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
402 viewport.setEndSeq(viewport.alignment.getHeight());
403 viewport.alignment.getWidth();
404 viewport.updateConservation();
405 viewport.updateConsensus();
406 alignPanel.repaint();
409 }catch(Exception ex){}// could be anything being pasted in here
414 protected void cut_actionPerformed(ActionEvent e)
416 copy_actionPerformed(null);
417 delete_actionPerformed(null);
420 protected void delete_actionPerformed(ActionEvent e)
422 boolean seqsdeleted=false;
424 if (viewport.getSelectionGroup() == null)
427 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
429 SequenceGroup sg = viewport.getSelectionGroup();
430 for (int i=0;i < sg.sequences.size(); i++)
432 SequenceI seq = sg.getSequenceAt(i);
433 int index = viewport.getAlignment().findIndex(seq);
434 seq.deleteChars(sg.getStartRes(),sg.getEndRes()+1);
436 if(seq.getSequence().length()<1) {
438 viewport.getAlignment().deleteSequence(seq);
440 viewport.getAlignment().getSequences().setElementAt(seq, index);
444 viewport.setSelectionGroup(null);
445 viewport.alignment.deleteGroup(sg);
447 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
448 viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight());
449 if(viewport.getAlignment().getHeight()<1)
452 this.setClosed(true);
453 }catch(Exception ex){}
454 viewport.updateConservation();
455 viewport.updateConsensus();
456 alignPanel.repaint();
460 protected void deleteGroups_actionPerformed(ActionEvent e)
462 viewport.alignment.deleteAllGroups();
463 viewport.setSelectionGroup(null);
464 alignPanel.repaint();
469 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
471 SequenceGroup sg = new SequenceGroup();
472 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
473 sg.addSequence( viewport.getAlignment().getSequenceAt(i));
474 sg.setEndRes(viewport.alignment.getWidth());
475 viewport.setSelectionGroup(sg);
476 PaintRefresher.Refresh(null);
479 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
481 viewport.setSelectionGroup(null);
482 viewport.getColumnSelection().clear();
483 viewport.setSelectionGroup(null);
484 PaintRefresher.Refresh(null);
487 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
489 SequenceGroup sg = viewport.getSelectionGroup();
490 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
491 sg.addOrRemove (viewport.getAlignment().getSequenceAt(i));
493 PaintRefresher.Refresh(null);
496 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
498 ColumnSelection colSel = viewport.getColumnSelection();
499 if (colSel.size() > 0)
501 addHistoryItem(new HistoryItem("Remove Left",viewport.alignment,
503 int min = colSel.getMin();
504 viewport.getAlignment().trimLeft(min);
505 colSel.compensateForEdit(0,min);
507 if(viewport.getSelectionGroup()!=null)
508 viewport.getSelectionGroup().adjustForRemoveLeft(min);
510 Vector groups = viewport.alignment.getGroups();
511 for(int i=0; i<groups.size(); i++)
513 SequenceGroup sg = (SequenceGroup) groups.get(i);
514 if(!sg.adjustForRemoveLeft(min))
515 viewport.alignment.deleteGroup(sg);
518 alignPanel.repaint();
522 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
524 ColumnSelection colSel = viewport.getColumnSelection();
525 if (colSel.size() > 0)
527 addHistoryItem(new HistoryItem("Remove Right",viewport.alignment,
530 int max = colSel.getMax();
531 viewport.getAlignment().trimRight(max);
532 if(viewport.getSelectionGroup()!=null)
533 viewport.getSelectionGroup().adjustForRemoveRight(max);
535 Vector groups = viewport.alignment.getGroups();
536 for(int i=0; i<groups.size(); i++)
538 SequenceGroup sg = (SequenceGroup) groups.get(i);
539 if(!sg.adjustForRemoveRight(max))
540 viewport.alignment.deleteGroup(sg);
545 alignPanel.repaint();
550 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
552 addHistoryItem(new HistoryItem("Remove Gapped Columns",
556 viewport.getAlignment().removeGaps();
557 viewport.updateConservation();
558 viewport.updateConsensus();
559 alignPanel.repaint();
562 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
564 addHistoryItem(new HistoryItem("Remove Gaps",
569 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
571 current = viewport.getAlignment().getSequenceAt(i);
572 jSize = current.getLength();
573 for (int j=0; j < jSize; j++)
574 if(jalview.util.Comparison.isGap(current.getCharAt(j)))
576 current.deleteCharAt(j);
581 viewport.updateConservation();
582 viewport.updateConsensus();
583 alignPanel.repaint();
587 public void padGapsMenuitem_actionPerformed(ActionEvent e)
589 addHistoryItem(new HistoryItem("Pad Gaps",
593 int Width = viewport.getAlignment().getWidth()-1;
594 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
596 current = viewport.getAlignment().getSequenceAt(i);
598 if (current.getLength()<Width)
599 current.insertCharAt(Width, viewport.getGapCharacter());
601 viewport.updateConservation();
602 viewport.updateConsensus();
603 alignPanel.repaint();
607 public void findMenuItem_actionPerformed(ActionEvent e)
609 JInternalFrame frame = new JInternalFrame();
610 Finder finder = new Finder(viewport, alignPanel, frame);
611 frame.setContentPane(finder);
612 Desktop.addInternalFrame(frame, "Find", 340,110);
613 frame.setLayer(JLayeredPane.PALETTE_LAYER);
618 public void font_actionPerformed(ActionEvent e)
620 FontChooser fc = new FontChooser( alignPanel );
623 protected void fullSeqId_actionPerformed(ActionEvent e)
625 viewport.setShowFullId( fullSeqId.isSelected() );
627 alignPanel.idPanel.idCanvas.setPreferredSize( alignPanel.calculateIdWidth() );
628 alignPanel.repaint();
631 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
633 viewport.setColourText( colourTextMenuItem.isSelected() );
634 alignPanel.repaint();
637 protected void wrapMenuItem_actionPerformed(ActionEvent e)
639 viewport.setWrapAlignment( wrapMenuItem.isSelected() );
640 alignPanel.setWrapAlignment( wrapMenuItem.isSelected() );
641 scaleAbove.setVisible( wrapMenuItem.isSelected() );
642 scaleLeft.setVisible( wrapMenuItem.isSelected() );
643 scaleRight.setVisible( wrapMenuItem.isSelected() );
644 alignPanel.repaint();
647 protected void scaleAbove_actionPerformed(ActionEvent e)
649 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
650 alignPanel.repaint();
653 protected void scaleLeft_actionPerformed(ActionEvent e)
655 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
656 alignPanel.repaint();
659 protected void scaleRight_actionPerformed(ActionEvent e)
661 viewport.setScaleRightWrapped(scaleRight.isSelected());
662 alignPanel.repaint();
667 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
669 viewport.setShowBoxes( viewBoxesMenuItem.isSelected() );
670 alignPanel.repaint();
673 public void viewTextMenuItem_actionPerformed(ActionEvent e)
675 viewport.setShowText( viewTextMenuItem.isSelected() );
676 alignPanel.repaint();
680 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
682 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
683 alignPanel.repaint();
686 public void sequenceFeatures_actionPerformed(ActionEvent evt)
688 viewport.showSequenceFeatures(sequenceFeatures.isSelected());
689 if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded)
691 SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.alignment, alignPanel);
692 ((Alignment)viewport.alignment).featuresAdded = true;
694 alignPanel.repaint();
697 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
699 if(annotationPanelMenuItem.isSelected() && viewport.getWrapAlignment())
701 annotationPanelMenuItem.setSelected(false);
704 viewport.setShowAnnotation( annotationPanelMenuItem.isSelected() );
705 alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() );
708 public void overviewMenuItem_actionPerformed(ActionEvent e)
710 if (alignPanel.overviewPanel != null)
713 JInternalFrame frame = new JInternalFrame();
714 OverviewPanel overview = new OverviewPanel(alignPanel);
715 frame.setContentPane(overview);
716 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
717 frame.getWidth(), frame.getHeight());
719 frame.setLayer(JLayeredPane.PALETTE_LAYER);
720 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
721 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
723 alignPanel.setOverviewPanel(null);
727 alignPanel.setOverviewPanel( overview );
732 protected void noColourmenuItem_actionPerformed(ActionEvent e)
734 changeColour( null );
738 public void clustalColour_actionPerformed(ActionEvent e)
740 changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth()));
743 public void zappoColour_actionPerformed(ActionEvent e)
745 changeColour(new ZappoColourScheme());
748 public void taylorColour_actionPerformed(ActionEvent e)
750 changeColour(new TaylorColourScheme());
754 public void hydrophobicityColour_actionPerformed(ActionEvent e)
756 changeColour( new HydrophobicColourScheme() );
759 public void helixColour_actionPerformed(ActionEvent e)
761 changeColour(new HelixColourScheme() );
765 public void strandColour_actionPerformed(ActionEvent e)
767 changeColour(new StrandColourScheme());
771 public void turnColour_actionPerformed(ActionEvent e)
773 changeColour(new TurnColourScheme());
777 public void buriedColour_actionPerformed(ActionEvent e)
779 changeColour(new BuriedColourScheme() );
782 public void nucleotideColour_actionPerformed(ActionEvent e)
784 changeColour(new NucleotideColourScheme());
788 protected void applyToAllGroups_actionPerformed(ActionEvent e)
790 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
795 void changeColour(ColourSchemeI cs)
799 if ( viewport.getAbovePIDThreshold() )
801 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background");
803 if (cs instanceof ResidueColourScheme)
804 ( (ResidueColourScheme) cs).setThreshold(threshold);
805 else if (cs instanceof ScoreColourScheme)
806 ( (ScoreColourScheme) cs).setThreshold(threshold);
808 viewport.setGlobalColourScheme(cs);
810 else if (cs instanceof ResidueColourScheme)
811 ( (ResidueColourScheme) cs).setThreshold(0);
812 else if (cs instanceof ScoreColourScheme)
813 ( (ScoreColourScheme) cs).setThreshold(0);
817 if (viewport.getConservationSelected())
819 ConservationColourScheme ccs = null;
821 Alignment al = (Alignment) viewport.alignment;
822 Conservation c = new Conservation("All",
823 ResidueProperties.propHash, 3,
824 al.getSequences(), 0,
828 c.verdict(false, viewport.ConsPercGaps);
830 ccs = new ConservationColourScheme(c, cs);
832 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
833 ccs.setConsensus( viewport.vconsensus );
834 viewport.setGlobalColourScheme(ccs);
836 ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs, "Background");
841 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
843 cs.setConsensus(viewport.vconsensus);
844 viewport.setGlobalColourScheme(cs);
848 if(viewport.getColourAppliesToAllGroups())
850 Vector groups = viewport.alignment.getGroups();
851 for(int i=0; i<groups.size(); i++)
853 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
857 else if (cs instanceof ClustalxColourScheme)
858 sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());
859 else if (cs instanceof UserColourScheme)
860 sg.cs = new UserColourScheme( ((UserColourScheme)cs).getColours());
863 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
864 }catch(Exception ex){}
866 if(viewport.getAbovePIDThreshold())
868 if (sg.cs instanceof ResidueColourScheme)
869 ( (ResidueColourScheme) sg.cs).setThreshold(threshold);
870 else if (sg.cs instanceof ScoreColourScheme)
871 ( (ScoreColourScheme) sg.cs).setThreshold(threshold);
873 sg.cs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()) );
876 if( viewport.getConservationSelected() )
878 Conservation c = new Conservation("Group",
879 ResidueProperties.propHash, 3,
880 sg.sequences, 0, viewport.alignment.getWidth()-1);
882 c.verdict(false, viewport.ConsPercGaps);
883 ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs);
885 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
886 ccs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
891 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
892 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
898 if(alignPanel.getOverviewPanel()!=null)
899 alignPanel.getOverviewPanel().updateOverviewImage();
900 alignPanel.repaint();
903 protected void modifyPID_actionPerformed(ActionEvent e)
905 if(viewport.getAbovePIDThreshold())
907 SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(),
909 SliderPanel.showPIDSlider();
913 protected void modifyConservation_actionPerformed(ActionEvent e)
915 if(viewport.getConservationSelected())
917 SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme,
919 SliderPanel.showConservationSlider();
924 protected void conservationMenuItem_actionPerformed(ActionEvent e)
926 viewport.setConservationSelected(conservationMenuItem.isSelected());
928 viewport.setAbovePIDThreshold(false);
929 abovePIDThreshold.setSelected(false);
931 ColourSchemeI cs = viewport.getGlobalColourScheme();
932 if(cs instanceof ConservationColourScheme )
933 changeColour( ((ConservationColourScheme)cs).cs );
937 modifyConservation_actionPerformed(null);
940 public void abovePIDThreshold_actionPerformed(ActionEvent e)
942 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
944 conservationMenuItem.setSelected(false);
945 viewport.setConservationSelected(false);
947 ColourSchemeI cs = viewport.getGlobalColourScheme();
949 if(cs instanceof ConservationColourScheme )
950 changeColour( ((ConservationColourScheme)cs).cs );
954 modifyPID_actionPerformed(null);
959 public void userDefinedColour_actionPerformed(ActionEvent e)
961 new UserDefinedColours( alignPanel, null);
964 public void PIDColour_actionPerformed(ActionEvent e)
966 changeColour( new PIDColourScheme() );
970 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
972 changeColour(new Blosum62ColourScheme() );
977 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
979 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, HistoryItem.SORT));
980 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0));
981 alignPanel.repaint();
984 public void sortIDMenuItem_actionPerformed(ActionEvent e)
986 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, HistoryItem.SORT));
987 AlignmentSorter.sortByID( viewport.getAlignment() );
988 alignPanel.repaint();
991 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
993 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, HistoryItem.SORT));
994 AlignmentSorter.sortByGroup(viewport.getAlignment());
995 AlignmentSorter.sortGroups(viewport.getAlignment());
996 alignPanel.repaint();
999 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
1001 RedundancyPanel sp = new RedundancyPanel(alignPanel,this);
1002 JInternalFrame frame = new JInternalFrame();
1003 frame.setContentPane(sp);
1004 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100, false);
1008 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
1010 if((viewport.getSelectionGroup()==null) ||
1011 viewport.getSelectionGroup().getSize()<2)
1012 JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);
1015 JInternalFrame frame = new JInternalFrame();
1016 frame.setContentPane(new PairwiseAlignPanel(viewport));
1017 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
1021 public void PCAMenuItem_actionPerformed(ActionEvent e)
1024 if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0)
1025 || viewport.getAlignment().getHeight()<4)
1027 JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"
1028 +"at least 4 input sequences.",
1029 "Sequence selection insufficient",
1030 JOptionPane.WARNING_MESSAGE);
1035 PCAPanel pcaPanel = new PCAPanel(viewport, null);
1036 JInternalFrame frame = new JInternalFrame();
1037 frame.setContentPane(pcaPanel);
1038 Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400);
1039 }catch(java.lang.OutOfMemoryError ex)
1041 JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!",
1042 "Out of memory", JOptionPane.WARNING_MESSAGE);
1048 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
1050 NewTreePanel("AV", "PID", "Average distance tree using PID");
1053 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
1055 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
1059 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1061 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
1064 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1066 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
1069 void NewTreePanel(String type, String pwType, String title)
1071 //are the sequences aligned?
1072 if(!viewport.alignment.isAligned())
1074 JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
1075 +"Try using the Pad function in the edit menu,\n"
1076 +"or one of the multiple sequence alignment web services.",
1077 "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
1082 if (viewport.getSelectionGroup() != null &&
1083 viewport.getSelectionGroup().getSize() > 3)
1085 tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
1087 0, viewport.alignment.getWidth());
1091 tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
1092 type, pwType, 0, viewport.alignment.getWidth());
1095 addTreeMenuItem(tp, title);
1096 viewport.setCurrentTree(tp.getTree());
1098 Desktop.addInternalFrame(tp, title, 600, 500);
1101 public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
1102 final JMenuItem item = new JMenuItem("by "+title);
1104 item.addActionListener(new java.awt.event.ActionListener()
1106 public void actionPerformed(ActionEvent e)
1108 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
1110 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
1111 AlignmentSorter.sortBy(viewport.getAlignment(), order);
1112 alignPanel.repaint();
1117 void addTreeMenuItem(final TreePanel treePanel, String title)
1119 final JMenuItem item = new JMenuItem(title);
1124 sort.add(sortByTreeMenu);
1126 sortByTreeMenu.add(item);
1127 item.addActionListener(new java.awt.event.ActionListener()
1129 public void actionPerformed(ActionEvent e)
1131 addHistoryItem(new HistoryItem("Tree Sort", viewport.alignment,
1133 AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());
1134 alignPanel.repaint();
1138 treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1140 public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
1143 sortByTreeMenu.remove(item);
1145 sort.remove(sortByTreeMenu);
1148 viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
1149 public void propertyChange(PropertyChangeEvent evt)
1151 if (evt.getPropertyName().equals("alignment")) {
1152 treePanel.getTree().UpdatePlaceHolders( (Vector) evt.getNewValue());
1153 treePanel.repaint();
1162 public void clustalAlignMenuItem_actionPerformed(ActionEvent e)
1164 // TODO:resolve which menu item was actually selected
1165 // Now, check we have enough sequences
1166 SequenceI[] msa=null;
1167 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1169 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1170 SequenceGroup seqs = viewport.getSelectionGroup();
1172 msa = new SequenceI[sz=seqs.getSize()];
1173 for (int i = 0; i < sz; i++)
1175 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1181 Vector seqs = viewport.getAlignment().getSequences();
1183 if (seqs.size() > 1) {
1184 msa = new SequenceI[seqs.size()];
1185 for (int i = 0; i < seqs.size(); i++)
1187 msa[i] = (SequenceI) seqs.elementAt(i);
1194 jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, false, true);
1197 public void ClustalRealign_actionPerformed(ActionEvent e)
1199 // TODO:resolve which menu item was actually selected
1200 // Now, check we have enough sequences
1201 SequenceI[] msa=null;
1202 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1204 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1205 SequenceGroup seqs = viewport.getSelectionGroup();
1207 msa = new SequenceI[sz=seqs.getSize()];
1208 for (int i = 0; i < sz; i++)
1210 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1216 Vector seqs = viewport.getAlignment().getSequences();
1218 if (seqs.size() > 1) {
1219 msa = new SequenceI[seqs.size()];
1220 for (int i = 0; i < seqs.size(); i++)
1222 msa[i] = (SequenceI) seqs.elementAt(i);
1229 jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, true, true);
1234 protected void jpred_actionPerformed(ActionEvent e)
1237 SequenceI[] msa=null;
1239 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>0)
1241 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1242 SequenceGroup seqs = viewport.getSelectionGroup();
1243 if (seqs.getSize() == 1 || !viewport.alignment.isAligned())
1245 seq = (SequenceI)seqs.getSequenceAt(0);
1250 msa = new SequenceI[sz=seqs.getSize()];
1251 for (int i = 0; i < sz; i++)
1253 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1259 Vector seqs = viewport.getAlignment().getSequences();
1261 if (seqs.size() == 1 || !viewport.alignment.isAligned())
1263 seq = (SequenceI) seqs.elementAt(0);
1267 msa = new SequenceI[seqs.size()];
1268 for (int i = 0; i < seqs.size(); i++)
1270 msa[i] = (SequenceI) seqs.elementAt(i);
1275 JPredClient ct = new JPredClient(title, msa);
1278 JPredClient ct = new JPredClient(title, seq);
1280 System.err.print("JALVIEW ERROR! - Unexpected JPred selection state!\n");
1283 protected void msaAlignMenuItem_actionPerformed(ActionEvent e)
1285 // TODO:resolve which menu item was actually selected
1286 // Now, check we have enough sequences
1287 SequenceI[] msa=null;
1288 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1290 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1291 SequenceGroup seqs = viewport.getSelectionGroup();
1293 msa = new SequenceI[sz=seqs.getSize()];
1294 for (int i = 0; i < sz; i++)
1296 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1303 Vector seqs = viewport.getAlignment().getSequences();
1305 if (seqs.size() > 1) {
1306 msa = new SequenceI[seqs.size()];
1307 for (int i = 0; i < seqs.size(); i++)
1309 msa[i] = (SequenceI) seqs.elementAt(i);
1316 MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, false, true);
1319 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {
1320 // Pick the tree file
1321 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1322 getProperty("LAST_DIRECTORY"));
1323 chooser.setFileView(new JalviewFileView());
1324 chooser.setDialogTitle("Select a newick-like tree file");
1325 chooser.setToolTipText("Load a tree file");
1326 int value = chooser.showOpenDialog(null);
1327 if (value == JalviewFileChooser.APPROVE_OPTION)
1329 String choice = chooser.getSelectedFile().getPath();
1330 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1333 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File");
1334 ShowNewickTree(fin, choice);
1336 catch (Exception ex)
1338 JOptionPane.showMessageDialog(Desktop.desktop,
1339 "Problem reading tree file",
1341 JOptionPane.WARNING_MESSAGE);
1342 ex.printStackTrace();
1347 public void ShowNewickTree(NewickFile nf, String title)
1351 if (nf.getTree() != null)
1353 TreePanel tp = new TreePanel(viewport,
1354 viewport.getAlignment().getSequences(),
1355 nf, "FromFile", title);
1356 Desktop.addInternalFrame(tp, title, 600, 500);
1357 addTreeMenuItem(tp, title);
1358 viewport.setCurrentTree(tp.getTree());
1360 }catch(Exception ex){ex.printStackTrace();}