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.*;
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.replace('/', '_');
86 title = title.replace('\\', '_');
87 String choice = chooser.getSelectedFile().getPath();
88 Jalview2XML.SaveState(this, choice, shortName);
89 // USE Jalview2XML to save this file
93 String choice = chooser.getSelectedFile().getPath();
94 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
95 String output = FormatAdapter.formatSequences(currentFileFormat, viewport.getAlignment().getSequences());
97 java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) );
101 catch(Exception ex){}
106 protected void outputText_actionPerformed(ActionEvent e)
108 CutAndPasteTransfer cap = new CutAndPasteTransfer(false);
109 JInternalFrame frame = new JInternalFrame();
110 cap.formatForOutput();
111 frame.setContentPane(cap);
112 Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500);
113 cap.setText( FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences()));
116 protected void htmlMenuItem_actionPerformed(ActionEvent e)
118 HTMLOutput htmlOutput = new HTMLOutput(viewport);
122 protected void createPNG_actionPerformed(ActionEvent e)
124 alignPanel.makePNG();
127 protected void epsFile_actionPerformed(ActionEvent e)
129 alignPanel.makeEPS();
133 public void printMenuItem_actionPerformed(ActionEvent e)
135 //Putting in a thread avoids Swing painting problems
136 PrintThread thread = new PrintThread();
140 class PrintThread extends Thread
144 PrinterJob printJob = PrinterJob.getPrinterJob();
145 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
146 printJob.setPrintable(alignPanel, pf);
147 if (printJob.printDialog())
153 catch (Exception PrintException)
155 PrintException.printStackTrace();
165 public void closeMenuItem_actionPerformed(ActionEvent e)
168 this.setClosed(true);
169 }catch(Exception ex){}
172 Stack historyList = new Stack();
173 Stack redoList = new Stack();
174 private int treeCount = 0;
176 void updateEditMenuBar()
178 if(historyList.size()>0)
180 undoMenuItem.setEnabled(true);
181 HistoryItem hi = (HistoryItem)historyList.peek();
182 undoMenuItem.setText("Undo "+hi.getDescription());
186 undoMenuItem.setEnabled(false);
187 undoMenuItem.setText("Undo");
190 if(redoList.size()>0)
192 redoMenuItem.setEnabled(true);
193 HistoryItem hi = (HistoryItem)redoList.peek();
194 redoMenuItem.setText("Redo "+hi.getDescription());
198 redoMenuItem.setEnabled(false);
199 redoMenuItem.setText("Redo");
203 public void addHistoryItem(HistoryItem hi)
205 historyList.push(hi);
209 protected void undoMenuItem_actionPerformed(ActionEvent e)
211 HistoryItem hi = (HistoryItem)historyList.pop();
212 redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, HistoryItem.HIDE));
213 restoreHistoryItem(hi);
217 protected void redoMenuItem_actionPerformed(ActionEvent e)
219 HistoryItem hi = (HistoryItem)redoList.pop();
220 restoreHistoryItem(hi);
222 viewport.updateConsensus();
223 alignPanel.repaint();
224 alignPanel.repaint();
228 // used by undo and redo
229 void restoreHistoryItem(HistoryItem hi)
231 if(hi.getType()== HistoryItem.SORT)
233 for(int i=0; i<hi.getSequences().size(); i++)
234 viewport.alignment.getSequences().setElementAt(hi.getSequences().elementAt(i), i);
238 for (int i = 0; i < hi.getSequences().size(); i++)
240 SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);
241 if(restore.getLength()==0)
243 restore.setSequence(hi.getHidden().elementAt(i).toString());
244 viewport.alignment.getSequences().insertElementAt(
246 hi.getAlignIndex(i));
249 restore.setSequence(hi.getHidden().elementAt(i).toString());
251 if(hi.getType()==HistoryItem.PASTE)
253 for(int i=viewport.alignment.getHeight()-1;i>hi.getSequences().size()-1; i--)
254 viewport.alignment.deleteSequence(i);
260 viewport.updateConsensus();
261 viewport.updateConservation();
262 alignPanel.repaint();
265 public void moveSelectedSequences(boolean up)
267 SequenceGroup sg = viewport.getSelectionGroup();
273 for (int i = 1; i < viewport.alignment.getHeight(); i++)
275 SequenceI seq = viewport.alignment.getSequenceAt(i);
276 if (!sg.sequences.contains(seq))
279 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
280 if (sg.sequences.contains(temp))
283 viewport.alignment.getSequences().setElementAt(temp, i);
284 viewport.alignment.getSequences().setElementAt(seq, i - 1);
289 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
291 SequenceI seq = viewport.alignment.getSequenceAt(i);
292 if (!sg.sequences.contains(seq))
295 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
296 if (sg.sequences.contains(temp))
299 viewport.alignment.getSequences().setElementAt(temp, i);
300 viewport.alignment.getSequences().setElementAt(seq, i + 1);
304 alignPanel.repaint();
309 protected void copy_actionPerformed(ActionEvent e)
311 if(viewport.getSelectionGroup()==null)
314 SequenceGroup sg = viewport.getSelectionGroup();
316 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
317 StringBuffer buffer= new StringBuffer();
319 Hashtable orderedSeqs = new Hashtable();
320 for(int i=0; i<sg.getSize(); i++)
322 SequenceI seq = sg.getSequenceAt(i);
323 int index = viewport.alignment.findIndex(seq);
324 orderedSeqs.put(index+"", seq);
328 for(int i=0; i<sg.getSize(); i++)
330 SequenceI seq = null;
333 if(orderedSeqs.containsKey(index+""))
335 seq = (SequenceI) orderedSeqs.get(index + "");
343 buffer.append( seq.getName()+"\t"+seq.findPosition( sg.getStartRes() ) +"\t"
344 +seq.findPosition( sg.getEndRes() )+ "\t"
345 +sg.getSequenceAt(i).getSequence(sg.getStartRes(), sg.getEndRes()+1)+"\n");
347 c.setContents( new StringSelection( buffer.toString()) , null ) ;
352 protected void pasteNew_actionPerformed(ActionEvent e)
357 protected void pasteThis_actionPerformed(ActionEvent e)
359 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, HistoryItem.PASTE));
363 void paste(boolean newAlignment)
366 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
367 Transferable contents = c.getContents(this);
368 if (contents == null)
371 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
372 StringTokenizer st = new StringTokenizer(str);
373 ArrayList seqs = new ArrayList();
374 while (st.hasMoreElements())
376 String name = st.nextToken();
377 int start = Integer.parseInt(st.nextToken());
378 int end = Integer.parseInt(st.nextToken());
379 Sequence sequence = new Sequence(name,st.nextToken(), start, end);
382 viewport.alignment.addSequence(sequence);
389 SequenceI[] newSeqs = new SequenceI[seqs.size()];
390 seqs.toArray(newSeqs);
391 AlignFrame af = new AlignFrame(new Alignment(newSeqs));
392 String newtitle = new String("Copied sequences");
393 if( title.startsWith("Copied sequences"))
396 newtitle = newtitle.concat("- from "+title);
398 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);
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 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
424 if (viewport.getSelectionGroup() == null)
427 SequenceGroup sg = viewport.getSelectionGroup();
428 for (int i=0;i < sg.sequences.size(); i++)
430 SequenceI seq = sg.getSequenceAt(i);
431 int index = viewport.getAlignment().findIndex(seq);
432 seq.deleteChars(sg.getStartRes(),sg.getEndRes()+1);
434 if(seq.getSequence().length()<1)
435 viewport.getAlignment().deleteSequence(seq);
437 viewport.getAlignment().getSequences().setElementAt(seq, index);
440 viewport.setSelectionGroup(null);
441 viewport.alignment.deleteGroup(sg);
442 viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight());
443 if(viewport.getAlignment().getHeight()<1)
446 this.setClosed(true);
447 }catch(Exception ex){}
448 viewport.updateConservation();
449 viewport.updateConsensus();
450 alignPanel.repaint();
455 protected void deleteGroups_actionPerformed(ActionEvent e)
457 viewport.alignment.deleteAllGroups();
458 viewport.setSelectionGroup(null);
459 alignPanel.repaint();
464 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
466 SequenceGroup sg = new SequenceGroup();
467 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
468 sg.addSequence( viewport.getAlignment().getSequenceAt(i));
469 sg.setEndRes(viewport.alignment.getWidth());
470 viewport.setSelectionGroup(sg);
471 PaintRefresher.Refresh(null);
474 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
476 viewport.setSelectionGroup(null);
477 viewport.getColumnSelection().clear();
478 viewport.setSelectionGroup(null);
479 PaintRefresher.Refresh(null);
482 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
484 SequenceGroup sg = viewport.getSelectionGroup();
485 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
486 sg.addOrRemove (viewport.getAlignment().getSequenceAt(i));
488 PaintRefresher.Refresh(null);
491 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
493 ColumnSelection colSel = viewport.getColumnSelection();
494 if (colSel.size() > 0)
496 addHistoryItem(new HistoryItem("Remove Left",viewport.alignment,
498 int min = colSel.getMin();
499 viewport.getAlignment().trimLeft(min);
500 colSel.compensateForEdit(0,min);
502 if(viewport.getSelectionGroup()!=null)
503 viewport.getSelectionGroup().adjustForRemoveLeft(min);
505 Vector groups = viewport.alignment.getGroups();
506 for(int i=0; i<groups.size(); i++)
508 SequenceGroup sg = (SequenceGroup) groups.get(i);
509 if(!sg.adjustForRemoveLeft(min))
510 viewport.alignment.deleteGroup(sg);
513 alignPanel.repaint();
517 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
519 ColumnSelection colSel = viewport.getColumnSelection();
520 if (colSel.size() > 0)
522 addHistoryItem(new HistoryItem("Remove Right",viewport.alignment,
525 int max = colSel.getMax();
526 viewport.getAlignment().trimRight(max);
527 if(viewport.getSelectionGroup()!=null)
528 viewport.getSelectionGroup().adjustForRemoveRight(max);
530 Vector groups = viewport.alignment.getGroups();
531 for(int i=0; i<groups.size(); i++)
533 SequenceGroup sg = (SequenceGroup) groups.get(i);
534 if(!sg.adjustForRemoveRight(max))
535 viewport.alignment.deleteGroup(sg);
540 alignPanel.repaint();
545 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
547 addHistoryItem(new HistoryItem("Remove Gapped Columns",
551 viewport.getAlignment().removeGaps();
552 viewport.updateConservation();
553 viewport.updateConsensus();
554 alignPanel.repaint();
557 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
559 addHistoryItem(new HistoryItem("Remove Gaps",
564 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
566 current = viewport.getAlignment().getSequenceAt(i);
567 jSize = current.getLength();
568 for (int j=0; j < jSize; j++)
569 if(jalview.util.Comparison.isGap(current.getCharAt(j)))
571 current.deleteCharAt(j);
576 viewport.updateConservation();
577 viewport.updateConsensus();
578 alignPanel.repaint();
582 public void padGapsMenuitem_actionPerformed(ActionEvent e)
584 addHistoryItem(new HistoryItem("Pad Gaps",
588 int Width = viewport.getAlignment().getWidth()-1;
589 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
591 current = viewport.getAlignment().getSequenceAt(i);
593 if (current.getLength()<Width)
594 current.insertCharAt(Width, viewport.getGapCharacter());
596 viewport.updateConservation();
597 viewport.updateConsensus();
598 alignPanel.repaint();
602 public void findMenuItem_actionPerformed(ActionEvent e)
604 JInternalFrame frame = new JInternalFrame();
605 Finder finder = new Finder(viewport, alignPanel, frame);
606 frame.setContentPane(finder);
607 Desktop.addInternalFrame(frame, "Find", 340,110);
608 frame.setLayer(JLayeredPane.PALETTE_LAYER);
613 public void font_actionPerformed(ActionEvent e)
615 FontChooser fc = new FontChooser( alignPanel );
618 protected void fullSeqId_actionPerformed(ActionEvent e)
620 viewport.setShowFullId( fullSeqId.isSelected() );
622 alignPanel.idPanel.idCanvas.setPreferredSize( alignPanel.calculateIdWidth() );
623 alignPanel.repaint();
626 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
628 viewport.setColourText( colourTextMenuItem.isSelected() );
629 alignPanel.repaint();
632 protected void wrapMenuItem_actionPerformed(ActionEvent e)
634 viewport.setWrapAlignment( wrapMenuItem.isSelected() );
635 alignPanel.setWrapAlignment( wrapMenuItem.isSelected() );
636 scaleAbove.setVisible( wrapMenuItem.isSelected() );
637 scaleLeft.setVisible( wrapMenuItem.isSelected() );
638 scaleRight.setVisible( wrapMenuItem.isSelected() );
639 alignPanel.repaint();
642 protected void scaleAbove_actionPerformed(ActionEvent e)
644 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
645 alignPanel.repaint();
648 protected void scaleLeft_actionPerformed(ActionEvent e)
650 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
651 alignPanel.repaint();
654 protected void scaleRight_actionPerformed(ActionEvent e)
656 viewport.setScaleRightWrapped(scaleRight.isSelected());
657 alignPanel.repaint();
662 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
664 viewport.setShowBoxes( viewBoxesMenuItem.isSelected() );
665 alignPanel.repaint();
668 public void viewTextMenuItem_actionPerformed(ActionEvent e)
670 viewport.setShowText( viewTextMenuItem.isSelected() );
671 alignPanel.repaint();
675 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
677 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
678 alignPanel.repaint();
681 public void sequenceFeatures_actionPerformed(ActionEvent evt)
683 viewport.showSequenceFeatures(sequenceFeatures.isSelected());
684 if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded)
686 SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.alignment, alignPanel);
687 ((Alignment)viewport.alignment).featuresAdded = true;
689 alignPanel.repaint();
692 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
694 if(annotationPanelMenuItem.isSelected() && viewport.getWrapAlignment())
696 annotationPanelMenuItem.setSelected(false);
699 viewport.setShowAnnotation( annotationPanelMenuItem.isSelected() );
700 alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() );
703 public void overviewMenuItem_actionPerformed(ActionEvent e)
705 if (alignPanel.overviewPanel != null)
708 JInternalFrame frame = new JInternalFrame();
709 OverviewPanel overview = new OverviewPanel(alignPanel);
710 frame.setContentPane(overview);
711 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
712 frame.getWidth(), frame.getHeight());
714 frame.setLayer(JLayeredPane.PALETTE_LAYER);
715 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
716 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
718 alignPanel.setOverviewPanel(null);
722 alignPanel.setOverviewPanel( overview );
727 protected void noColourmenuItem_actionPerformed(ActionEvent e)
729 changeColour( null );
733 public void clustalColour_actionPerformed(ActionEvent e)
735 abovePIDThreshold.setSelected(false);
736 changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth()));
739 public void zappoColour_actionPerformed(ActionEvent e)
741 changeColour(new ZappoColourScheme());
744 public void taylorColour_actionPerformed(ActionEvent e)
746 changeColour(new TaylorColourScheme());
750 public void hydrophobicityColour_actionPerformed(ActionEvent e)
752 changeColour( new HydrophobicColourScheme() );
755 public void helixColour_actionPerformed(ActionEvent e)
757 changeColour(new HelixColourScheme() );
761 public void strandColour_actionPerformed(ActionEvent e)
763 changeColour(new StrandColourScheme());
767 public void turnColour_actionPerformed(ActionEvent e)
769 changeColour(new TurnColourScheme());
773 public void buriedColour_actionPerformed(ActionEvent e)
775 changeColour(new BuriedColourScheme() );
778 public void nucleotideColour_actionPerformed(ActionEvent e)
780 changeColour(new NucleotideColourScheme());
784 protected void applyToAllGroups_actionPerformed(ActionEvent e)
786 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
791 void changeColour(ColourSchemeI cs)
795 if ( viewport.getAbovePIDThreshold() )
797 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background");
799 if (cs instanceof ResidueColourScheme)
800 ( (ResidueColourScheme) cs).setThreshold(threshold);
801 else if (cs instanceof ScoreColourScheme)
802 ( (ScoreColourScheme) cs).setThreshold(threshold);
804 viewport.setGlobalColourScheme(cs);
806 else if (cs instanceof ResidueColourScheme)
807 ( (ResidueColourScheme) cs).setThreshold(0);
808 else if (cs instanceof ScoreColourScheme)
809 ( (ScoreColourScheme) cs).setThreshold(0);
813 if (viewport.getConservationSelected())
815 ConservationColourScheme ccs = null;
817 Alignment al = (Alignment) viewport.alignment;
818 Conservation c = new Conservation("All",
819 ResidueProperties.propHash, 3,
820 al.getSequences(), 0,
824 c.verdict(false, viewport.ConsPercGaps);
826 ccs = new ConservationColourScheme(c, cs);
828 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
829 ccs.setConsensus( viewport.vconsensus );
830 viewport.setGlobalColourScheme(ccs);
832 SliderPanel.setConservationSlider(alignPanel, ccs, "Background");
837 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
839 cs.setConsensus(viewport.vconsensus);
840 viewport.setGlobalColourScheme(cs);
844 if(viewport.getColourAppliesToAllGroups())
846 Vector groups = viewport.alignment.getGroups();
847 for(int i=0; i<groups.size(); i++)
849 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
851 if (cs instanceof ClustalxColourScheme)
853 sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());
858 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
859 }catch(Exception ex){ex.printStackTrace();}
862 if(viewport.getAbovePIDThreshold())
864 if (sg.cs instanceof ResidueColourScheme)
865 ( (ResidueColourScheme) sg.cs).setThreshold(threshold);
866 else if (sg.cs instanceof ScoreColourScheme)
867 ( (ScoreColourScheme) sg.cs).setThreshold(threshold);
869 sg.cs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()) );
872 if( viewport.getConservationSelected() )
874 Conservation c = new Conservation("Group",
875 ResidueProperties.propHash, 3,
876 sg.sequences, 0, viewport.alignment.getWidth()-1);
878 c.verdict(false, viewport.ConsPercGaps);
879 ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs);
881 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
882 ccs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
887 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
888 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
894 if(alignPanel.getOverviewPanel()!=null)
895 alignPanel.getOverviewPanel().updateOverviewImage();
896 alignPanel.repaint();
899 protected void modifyPID_actionPerformed(ActionEvent e)
901 if(viewport.getAbovePIDThreshold())
903 SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(),
905 SliderPanel.showPIDSlider();
909 protected void modifyConservation_actionPerformed(ActionEvent e)
911 if(viewport.getConservationSelected())
913 SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme,
915 SliderPanel.showConservationSlider();
920 protected void conservationMenuItem_actionPerformed(ActionEvent e)
922 viewport.setConservationSelected(conservationMenuItem.isSelected());
924 viewport.setAbovePIDThreshold(false);
925 abovePIDThreshold.setSelected(false);
927 ColourSchemeI cs = viewport.getGlobalColourScheme();
928 if(cs instanceof ConservationColourScheme )
929 changeColour( ((ConservationColourScheme)cs).cs );
933 modifyConservation_actionPerformed(null);
936 public void abovePIDThreshold_actionPerformed(ActionEvent e)
938 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
940 conservationMenuItem.setSelected(false);
941 viewport.setConservationSelected(false);
943 ColourSchemeI cs = viewport.getGlobalColourScheme();
945 if(cs instanceof ConservationColourScheme )
946 changeColour( ((ConservationColourScheme)cs).cs );
950 modifyPID_actionPerformed(null);
955 public void userDefinedColour_actionPerformed(ActionEvent e)
957 UserDefinedColours chooser = new UserDefinedColours( alignPanel, null);
960 public void PIDColour_actionPerformed(ActionEvent e)
962 changeColour( new PIDColourScheme() );
966 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
968 changeColour(new Blosum62ColourScheme() );
973 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
975 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, HistoryItem.SORT));
976 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0));
977 alignPanel.repaint();
980 public void sortIDMenuItem_actionPerformed(ActionEvent e)
982 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, HistoryItem.SORT));
983 AlignmentSorter.sortByID( viewport.getAlignment() );
984 alignPanel.repaint();
987 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
989 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, HistoryItem.SORT));
990 AlignmentSorter.sortByGroup(viewport.getAlignment());
991 AlignmentSorter.sortGroups(viewport.getAlignment());
992 alignPanel.repaint();
995 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
997 RedundancyPanel sp = new RedundancyPanel(alignPanel);
998 JInternalFrame frame = new JInternalFrame();
999 frame.setContentPane(sp);
1000 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100, false);
1004 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
1006 if(viewport.getSelectionGroup().getSize()<2)
1007 JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);
1010 JInternalFrame frame = new JInternalFrame();
1011 frame.setContentPane(new PairwiseAlignPanel(viewport));
1012 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
1016 public void PCAMenuItem_actionPerformed(ActionEvent e)
1019 if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0)
1020 || viewport.getAlignment().getHeight()<4)
1022 JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"
1023 +"at least 4 input sequences.",
1024 "Sequence selection insufficient",
1025 JOptionPane.WARNING_MESSAGE);
1030 PCAPanel pcaPanel = new PCAPanel(viewport, null);
1031 JInternalFrame frame = new JInternalFrame();
1032 frame.setContentPane(pcaPanel);
1033 Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400);
1034 }catch(java.lang.OutOfMemoryError ex)
1036 JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!",
1037 "Out of memory", JOptionPane.WARNING_MESSAGE);
1043 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
1045 NewTreePanel("AV", "PID", "Average distance tree using PID");
1048 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
1050 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
1054 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1056 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
1059 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1061 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID");
1064 void NewTreePanel(String type, String pwType, String title)
1066 //are the sequences aligned?
1067 if(!viewport.alignment.isAligned())
1069 JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.",
1070 "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
1075 if (viewport.getSelectionGroup() != null &&
1076 viewport.getSelectionGroup().getSize() > 3)
1078 tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
1080 0, viewport.alignment.getWidth());
1084 tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
1085 type, pwType, 0, viewport.alignment.getWidth());
1088 addTreeMenuItem(tp, title);
1090 Desktop.addInternalFrame(tp, title, 600, 500);
1093 public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
1094 final JMenuItem item = new JMenuItem("by "+title);
1096 item.addActionListener(new java.awt.event.ActionListener()
1098 public void actionPerformed(ActionEvent e)
1100 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
1102 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
1103 AlignmentSorter.sortBy(viewport.getAlignment(), order);
1104 alignPanel.repaint();
1109 void addTreeMenuItem(final TreePanel treePanel, String title)
1111 final JMenuItem item = new JMenuItem(title);
1116 sort.add(sortByTreeMenu);
1118 sortByTreeMenu.add(item);
1119 item.addActionListener(new java.awt.event.ActionListener()
1121 public void actionPerformed(ActionEvent e)
1123 addHistoryItem(new HistoryItem("Tree Sort", viewport.alignment,
1125 AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());
1126 alignPanel.repaint();
1130 treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1132 public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
1135 sortByTreeMenu.remove(item);
1137 sort.remove(sortByTreeMenu);
1144 public void clustalAlignMenuItem_actionPerformed(ActionEvent e)
1146 // TODO:resolve which menu item was actually selected
1147 // Now, check we have enough sequences
1148 SequenceI[] msa=null;
1149 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1151 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1152 SequenceGroup seqs = viewport.getSelectionGroup();
1154 msa = new SequenceI[sz=seqs.getSize()];
1155 for (int i = 0; i < sz; i++)
1157 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1163 Vector seqs = viewport.getAlignment().getSequences();
1165 if (seqs.size() > 1) {
1166 msa = new SequenceI[seqs.size()];
1167 for (int i = 0; i < seqs.size(); i++)
1169 msa[i] = (SequenceI) seqs.elementAt(i);
1176 jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, true, true);
1180 protected void jpred_actionPerformed(ActionEvent e)
1183 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>0)
1185 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1186 SequenceGroup seqs = viewport.getSelectionGroup();
1187 if (seqs.getSize() == 1 || !viewport.alignment.isAligned())
1189 JPredClient ct = new JPredClient( (SequenceI)seqs.getSequenceAt(0));
1194 SequenceI[] msa = new SequenceI[sz=seqs.getSize()];
1195 for (int i = 0; i < sz; i++)
1197 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1200 JPredClient ct = new JPredClient(title, msa);
1206 Vector seqs = viewport.getAlignment().getSequences();
1208 if (seqs.size() == 1 || !viewport.alignment.isAligned())
1210 JPredClient ct = new JPredClient( (SequenceI)
1215 SequenceI[] msa = new SequenceI[seqs.size()];
1216 for (int i = 0; i < seqs.size(); i++)
1218 msa[i] = (SequenceI) seqs.elementAt(i);
1221 JPredClient ct = new JPredClient(title, msa);
1226 protected void msaAlignMenuItem_actionPerformed(ActionEvent e)
1228 // TODO:resolve which menu item was actually selected
1229 // Now, check we have enough sequences
1230 SequenceI[] msa=null;
1231 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1233 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1234 SequenceGroup seqs = viewport.getSelectionGroup();
1236 msa = new SequenceI[sz=seqs.getSize()];
1237 for (int i = 0; i < sz; i++)
1239 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1246 Vector seqs = viewport.getAlignment().getSequences();
1248 if (seqs.size() > 1) {
1249 msa = new SequenceI[seqs.size()];
1250 for (int i = 0; i < seqs.size(); i++)
1252 msa[i] = (SequenceI) seqs.elementAt(i);
1259 MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, true, true);
1262 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {
1263 // Pick the tree file
1264 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1265 getProperty("LAST_DIRECTORY"));
1266 chooser.setFileView(new JalviewFileView());
1267 chooser.setDialogTitle("Select a newick-like tree file");
1268 chooser.setToolTipText("Load a tree file");
1269 int value = chooser.showOpenDialog(null);
1270 if (value == JalviewFileChooser.APPROVE_OPTION)
1272 String choice = chooser.getSelectedFile().getPath();
1273 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1276 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File");
1277 ShowNewickTree(fin, choice);
1279 catch (Exception ex)
1281 JOptionPane.showMessageDialog(Desktop.desktop,
1282 "Problem reading tree file",
1284 JOptionPane.WARNING_MESSAGE);
1285 ex.printStackTrace();
1290 public void ShowNewickTree(NewickFile nf, String title)
1294 if (nf.getTree() != null)
1296 TreePanel tp = new TreePanel(viewport,
1297 viewport.getAlignment().getSequences(),
1298 nf, "FromFile", title);
1299 Desktop.addInternalFrame(tp, title, 600, 500);
1300 addTreeMenuItem(tp, title);
1301 viewport.setCurrentTree(tp.getTree());
1303 }catch(Exception ex){ex.printStackTrace();}