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.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();
109 Desktop.addInternalFrame(cap, "Alignment output - "+e.getActionCommand(), 600, 500);
110 cap.setText( FormatAdapter.formatSequences(e.getActionCommand(), viewport.getAlignment().getSequences()));
113 protected void htmlMenuItem_actionPerformed(ActionEvent e)
115 new HTMLOutput(viewport);
118 protected void createPNG_actionPerformed(ActionEvent e)
120 alignPanel.makePNG();
123 protected void epsFile_actionPerformed(ActionEvent e)
125 alignPanel.makeEPS();
129 public void printMenuItem_actionPerformed(ActionEvent e)
131 //Putting in a thread avoids Swing painting problems
132 PrintThread thread = new PrintThread();
136 class PrintThread extends Thread
140 PrinterJob printJob = PrinterJob.getPrinterJob();
141 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
142 printJob.setPrintable(alignPanel, pf);
143 if (printJob.printDialog())
149 catch (Exception PrintException)
151 PrintException.printStackTrace();
161 public void closeMenuItem_actionPerformed(ActionEvent e)
164 this.setClosed(true);
165 }catch(Exception ex){}
168 Stack historyList = new Stack();
169 Stack redoList = new Stack();
170 private int treeCount = 0;
172 void updateEditMenuBar()
174 if(historyList.size()>0)
176 undoMenuItem.setEnabled(true);
177 HistoryItem hi = (HistoryItem)historyList.peek();
178 undoMenuItem.setText("Undo "+hi.getDescription());
182 undoMenuItem.setEnabled(false);
183 undoMenuItem.setText("Undo");
186 if(redoList.size()>0)
188 redoMenuItem.setEnabled(true);
189 HistoryItem hi = (HistoryItem)redoList.peek();
190 redoMenuItem.setText("Redo "+hi.getDescription());
194 redoMenuItem.setEnabled(false);
195 redoMenuItem.setText("Redo");
199 public void addHistoryItem(HistoryItem hi)
201 historyList.push(hi);
205 protected void undoMenuItem_actionPerformed(ActionEvent e)
207 HistoryItem hi = (HistoryItem)historyList.pop();
208 redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, HistoryItem.HIDE));
209 restoreHistoryItem(hi);
213 protected void redoMenuItem_actionPerformed(ActionEvent e)
215 HistoryItem hi = (HistoryItem)redoList.pop();
216 restoreHistoryItem(hi);
218 viewport.updateConsensus();
219 alignPanel.repaint();
220 alignPanel.repaint();
224 // used by undo and redo
225 void restoreHistoryItem(HistoryItem hi)
227 if(hi.getType()== HistoryItem.SORT)
229 for(int i=0; i<hi.getSequences().size(); i++)
230 viewport.alignment.getSequences().setElementAt(hi.getSequences().elementAt(i), i);
234 for (int i = 0; i < hi.getSequences().size(); i++)
236 SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);
237 if(restore.getLength()==0)
239 restore.setSequence(hi.getHidden().elementAt(i).toString());
240 viewport.alignment.getSequences().insertElementAt(
242 hi.getAlignIndex(i));
245 restore.setSequence(hi.getHidden().elementAt(i).toString());
247 if(hi.getType()==HistoryItem.PASTE)
249 for(int i=viewport.alignment.getHeight()-1;i>hi.getSequences().size()-1; i--)
250 viewport.alignment.deleteSequence(i);
253 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
256 viewport.updateConsensus();
257 viewport.updateConservation();
258 alignPanel.repaint();
261 public void moveSelectedSequences(boolean up)
263 SequenceGroup sg = viewport.getSelectionGroup();
269 for (int i = 1; i < viewport.alignment.getHeight(); i++)
271 SequenceI seq = viewport.alignment.getSequenceAt(i);
272 if (!sg.sequences.contains(seq))
275 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
276 if (sg.sequences.contains(temp))
279 viewport.alignment.getSequences().setElementAt(temp, i);
280 viewport.alignment.getSequences().setElementAt(seq, i - 1);
285 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
287 SequenceI seq = viewport.alignment.getSequenceAt(i);
288 if (!sg.sequences.contains(seq))
291 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
292 if (sg.sequences.contains(temp))
295 viewport.alignment.getSequences().setElementAt(temp, i);
296 viewport.alignment.getSequences().setElementAt(seq, i + 1);
300 alignPanel.repaint();
305 protected void copy_actionPerformed(ActionEvent e)
307 if(viewport.getSelectionGroup()==null)
310 SequenceGroup sg = viewport.getSelectionGroup();
312 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
313 StringBuffer buffer= new StringBuffer();
315 Hashtable orderedSeqs = new Hashtable();
316 for(int i=0; i<sg.getSize(); i++)
318 SequenceI seq = sg.getSequenceAt(i);
319 int index = viewport.alignment.findIndex(seq);
320 orderedSeqs.put(index+"", seq);
324 for(int i=0; i<sg.getSize(); i++)
326 SequenceI seq = null;
329 if(orderedSeqs.containsKey(index+""))
331 seq = (SequenceI) orderedSeqs.get(index + "");
339 buffer.append( seq.getName()+"\t"+seq.findPosition( sg.getStartRes() ) +"\t"
340 +seq.findPosition( sg.getEndRes() )+ "\t"
341 +sg.getSequenceAt(i).getSequence(sg.getStartRes(), sg.getEndRes()+1)+"\n");
343 c.setContents( new StringSelection( buffer.toString()) , null ) ;
348 protected void pasteNew_actionPerformed(ActionEvent e)
353 protected void pasteThis_actionPerformed(ActionEvent e)
355 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, HistoryItem.PASTE));
359 void paste(boolean newAlignment)
362 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
363 Transferable contents = c.getContents(this);
364 if (contents == null)
367 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
368 StringTokenizer st = new StringTokenizer(str);
369 ArrayList seqs = new ArrayList();
370 while (st.hasMoreElements())
372 String name = st.nextToken();
373 int start = Integer.parseInt(st.nextToken());
374 int end = Integer.parseInt(st.nextToken());
375 Sequence sequence = new Sequence(name,st.nextToken(), start, end);
378 viewport.alignment.addSequence(sequence);
385 SequenceI[] newSeqs = new SequenceI[seqs.size()];
386 seqs.toArray(newSeqs);
387 AlignFrame af = new AlignFrame(new Alignment(newSeqs));
388 String newtitle = new String("Copied sequences");
389 if( title.startsWith("Copied sequences"))
392 newtitle = newtitle.concat("- from "+title);
394 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT);
398 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
399 viewport.setEndSeq(viewport.alignment.getHeight());
400 viewport.alignment.getWidth();
401 viewport.updateConservation();
402 viewport.updateConsensus();
403 alignPanel.repaint();
406 }catch(Exception ex){}// could be anything being pasted in here
411 protected void cut_actionPerformed(ActionEvent e)
413 copy_actionPerformed(null);
414 delete_actionPerformed(null);
417 protected void delete_actionPerformed(ActionEvent e)
419 boolean seqsdeleted=false;
421 if (viewport.getSelectionGroup() == null)
424 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
426 SequenceGroup sg = viewport.getSelectionGroup();
427 for (int i=0;i < sg.sequences.size(); i++)
429 SequenceI seq = sg.getSequenceAt(i);
430 int index = viewport.getAlignment().findIndex(seq);
431 seq.deleteChars(sg.getStartRes(),sg.getEndRes()+1);
433 if(seq.getSequence().length()<1) {
435 viewport.getAlignment().deleteSequence(seq);
437 viewport.getAlignment().getSequences().setElementAt(seq, index);
441 viewport.setSelectionGroup(null);
442 viewport.alignment.deleteGroup(sg);
444 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
445 viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight());
446 if(viewport.getAlignment().getHeight()<1)
449 this.setClosed(true);
450 }catch(Exception ex){}
451 viewport.updateConservation();
452 viewport.updateConsensus();
453 alignPanel.repaint();
457 protected void deleteGroups_actionPerformed(ActionEvent e)
459 viewport.alignment.deleteAllGroups();
460 viewport.setSelectionGroup(null);
461 alignPanel.repaint();
466 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
468 SequenceGroup sg = new SequenceGroup();
469 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
470 sg.addSequence( viewport.getAlignment().getSequenceAt(i));
471 sg.setEndRes(viewport.alignment.getWidth());
472 viewport.setSelectionGroup(sg);
473 PaintRefresher.Refresh(null);
476 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
478 viewport.setSelectionGroup(null);
479 viewport.getColumnSelection().clear();
480 viewport.setSelectionGroup(null);
481 PaintRefresher.Refresh(null);
484 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
486 SequenceGroup sg = viewport.getSelectionGroup();
487 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
488 sg.addOrRemove (viewport.getAlignment().getSequenceAt(i));
490 PaintRefresher.Refresh(null);
493 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
495 ColumnSelection colSel = viewport.getColumnSelection();
496 if (colSel.size() > 0)
498 addHistoryItem(new HistoryItem("Remove Left",viewport.alignment,
500 int min = colSel.getMin();
501 viewport.getAlignment().trimLeft(min);
502 colSel.compensateForEdit(0,min);
504 if(viewport.getSelectionGroup()!=null)
505 viewport.getSelectionGroup().adjustForRemoveLeft(min);
507 Vector groups = viewport.alignment.getGroups();
508 for(int i=0; i<groups.size(); i++)
510 SequenceGroup sg = (SequenceGroup) groups.get(i);
511 if(!sg.adjustForRemoveLeft(min))
512 viewport.alignment.deleteGroup(sg);
515 alignPanel.repaint();
519 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
521 ColumnSelection colSel = viewport.getColumnSelection();
522 if (colSel.size() > 0)
524 addHistoryItem(new HistoryItem("Remove Right",viewport.alignment,
527 int max = colSel.getMax();
528 viewport.getAlignment().trimRight(max);
529 if(viewport.getSelectionGroup()!=null)
530 viewport.getSelectionGroup().adjustForRemoveRight(max);
532 Vector groups = viewport.alignment.getGroups();
533 for(int i=0; i<groups.size(); i++)
535 SequenceGroup sg = (SequenceGroup) groups.get(i);
536 if(!sg.adjustForRemoveRight(max))
537 viewport.alignment.deleteGroup(sg);
542 alignPanel.repaint();
547 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
549 addHistoryItem(new HistoryItem("Remove Gapped Columns",
553 viewport.getAlignment().removeGaps();
554 viewport.updateConservation();
555 viewport.updateConsensus();
556 alignPanel.repaint();
559 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
561 addHistoryItem(new HistoryItem("Remove Gaps",
566 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
568 current = viewport.getAlignment().getSequenceAt(i);
569 jSize = current.getLength();
570 for (int j=0; j < jSize; j++)
571 if(jalview.util.Comparison.isGap(current.getCharAt(j)))
573 current.deleteCharAt(j);
578 viewport.updateConservation();
579 viewport.updateConsensus();
580 alignPanel.repaint();
584 public void padGapsMenuitem_actionPerformed(ActionEvent e)
586 addHistoryItem(new HistoryItem("Pad Gaps",
590 int Width = viewport.getAlignment().getWidth()-1;
591 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
593 current = viewport.getAlignment().getSequenceAt(i);
595 if (current.getLength()<Width)
596 current.insertCharAt(Width, viewport.getGapCharacter());
598 viewport.updateConservation();
599 viewport.updateConsensus();
600 alignPanel.repaint();
604 public void findMenuItem_actionPerformed(ActionEvent e)
606 JInternalFrame frame = new JInternalFrame();
607 Finder finder = new Finder(viewport, alignPanel, frame);
608 frame.setContentPane(finder);
609 Desktop.addInternalFrame(frame, "Find", 340,110);
610 frame.setLayer(JLayeredPane.PALETTE_LAYER);
615 public void font_actionPerformed(ActionEvent e)
617 FontChooser fc = new FontChooser( alignPanel );
620 protected void fullSeqId_actionPerformed(ActionEvent e)
622 viewport.setShowFullId( fullSeqId.isSelected() );
624 alignPanel.idPanel.idCanvas.setPreferredSize( alignPanel.calculateIdWidth() );
625 alignPanel.repaint();
628 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
630 viewport.setColourText( colourTextMenuItem.isSelected() );
631 alignPanel.repaint();
634 protected void wrapMenuItem_actionPerformed(ActionEvent e)
636 viewport.setWrapAlignment( wrapMenuItem.isSelected() );
637 alignPanel.setWrapAlignment( wrapMenuItem.isSelected() );
638 scaleAbove.setVisible( wrapMenuItem.isSelected() );
639 scaleLeft.setVisible( wrapMenuItem.isSelected() );
640 scaleRight.setVisible( wrapMenuItem.isSelected() );
641 alignPanel.repaint();
644 protected void scaleAbove_actionPerformed(ActionEvent e)
646 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
647 alignPanel.repaint();
650 protected void scaleLeft_actionPerformed(ActionEvent e)
652 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
653 alignPanel.repaint();
656 protected void scaleRight_actionPerformed(ActionEvent e)
658 viewport.setScaleRightWrapped(scaleRight.isSelected());
659 alignPanel.repaint();
664 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
666 viewport.setShowBoxes( viewBoxesMenuItem.isSelected() );
667 alignPanel.repaint();
670 public void viewTextMenuItem_actionPerformed(ActionEvent e)
672 viewport.setShowText( viewTextMenuItem.isSelected() );
673 alignPanel.repaint();
677 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
679 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
680 alignPanel.repaint();
683 public void sequenceFeatures_actionPerformed(ActionEvent evt)
685 viewport.showSequenceFeatures(sequenceFeatures.isSelected());
686 if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded)
688 SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.alignment, alignPanel);
689 ((Alignment)viewport.alignment).featuresAdded = true;
691 alignPanel.repaint();
694 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
696 if(annotationPanelMenuItem.isSelected() && viewport.getWrapAlignment())
698 annotationPanelMenuItem.setSelected(false);
701 viewport.setShowAnnotation( annotationPanelMenuItem.isSelected() );
702 alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() );
705 public void overviewMenuItem_actionPerformed(ActionEvent e)
707 if (alignPanel.overviewPanel != null)
710 JInternalFrame frame = new JInternalFrame();
711 OverviewPanel overview = new OverviewPanel(alignPanel);
712 frame.setContentPane(overview);
713 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
714 frame.getWidth(), frame.getHeight());
716 frame.setLayer(JLayeredPane.PALETTE_LAYER);
717 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
718 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
720 alignPanel.setOverviewPanel(null);
724 alignPanel.setOverviewPanel( overview );
729 protected void noColourmenuItem_actionPerformed(ActionEvent e)
731 changeColour( null );
735 public void clustalColour_actionPerformed(ActionEvent e)
737 changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth()));
740 public void zappoColour_actionPerformed(ActionEvent e)
742 changeColour(new ZappoColourScheme());
745 public void taylorColour_actionPerformed(ActionEvent e)
747 changeColour(new TaylorColourScheme());
751 public void hydrophobicityColour_actionPerformed(ActionEvent e)
753 changeColour( new HydrophobicColourScheme() );
756 public void helixColour_actionPerformed(ActionEvent e)
758 changeColour(new HelixColourScheme() );
762 public void strandColour_actionPerformed(ActionEvent e)
764 changeColour(new StrandColourScheme());
768 public void turnColour_actionPerformed(ActionEvent e)
770 changeColour(new TurnColourScheme());
774 public void buriedColour_actionPerformed(ActionEvent e)
776 changeColour(new BuriedColourScheme() );
779 public void nucleotideColour_actionPerformed(ActionEvent e)
781 changeColour(new NucleotideColourScheme());
785 protected void applyToAllGroups_actionPerformed(ActionEvent e)
787 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
792 void changeColour(ColourSchemeI cs)
796 if ( viewport.getAbovePIDThreshold() )
798 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background");
800 if (cs instanceof ResidueColourScheme)
801 ( (ResidueColourScheme) cs).setThreshold(threshold);
802 else if (cs instanceof ScoreColourScheme)
803 ( (ScoreColourScheme) cs).setThreshold(threshold);
805 viewport.setGlobalColourScheme(cs);
807 else if (cs instanceof ResidueColourScheme)
808 ( (ResidueColourScheme) cs).setThreshold(0);
809 else if (cs instanceof ScoreColourScheme)
810 ( (ScoreColourScheme) cs).setThreshold(0);
814 if (viewport.getConservationSelected())
816 ConservationColourScheme ccs = null;
818 Alignment al = (Alignment) viewport.alignment;
819 Conservation c = new Conservation("All",
820 ResidueProperties.propHash, 3,
821 al.getSequences(), 0,
825 c.verdict(false, viewport.ConsPercGaps);
827 ccs = new ConservationColourScheme(c, cs);
829 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
830 ccs.setConsensus( viewport.vconsensus );
831 viewport.setGlobalColourScheme(ccs);
833 ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs, "Background");
838 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
840 cs.setConsensus(viewport.vconsensus);
841 viewport.setGlobalColourScheme(cs);
845 if(viewport.getColourAppliesToAllGroups())
847 Vector groups = viewport.alignment.getGroups();
848 for(int i=0; i<groups.size(); i++)
850 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
854 else if (cs instanceof ClustalxColourScheme)
855 sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());
856 else if (cs instanceof UserColourScheme)
857 sg.cs = new UserColourScheme( ((UserColourScheme)cs).getColours());
860 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
861 }catch(Exception ex){}
863 if(viewport.getAbovePIDThreshold())
865 if (sg.cs instanceof ResidueColourScheme)
866 ( (ResidueColourScheme) sg.cs).setThreshold(threshold);
867 else if (sg.cs instanceof ScoreColourScheme)
868 ( (ScoreColourScheme) sg.cs).setThreshold(threshold);
870 sg.cs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()) );
873 if( viewport.getConservationSelected() )
875 Conservation c = new Conservation("Group",
876 ResidueProperties.propHash, 3,
877 sg.sequences, 0, viewport.alignment.getWidth()-1);
879 c.verdict(false, viewport.ConsPercGaps);
880 ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs);
882 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
883 ccs.setConsensus( AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
888 // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!
889 sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, sg.getWidth()));
895 if(alignPanel.getOverviewPanel()!=null)
896 alignPanel.getOverviewPanel().updateOverviewImage();
897 alignPanel.repaint();
900 protected void modifyPID_actionPerformed(ActionEvent e)
902 if(viewport.getAbovePIDThreshold())
904 SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(),
906 SliderPanel.showPIDSlider();
910 protected void modifyConservation_actionPerformed(ActionEvent e)
912 if(viewport.getConservationSelected())
914 SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme,
916 SliderPanel.showConservationSlider();
921 protected void conservationMenuItem_actionPerformed(ActionEvent e)
923 viewport.setConservationSelected(conservationMenuItem.isSelected());
925 viewport.setAbovePIDThreshold(false);
926 abovePIDThreshold.setSelected(false);
928 ColourSchemeI cs = viewport.getGlobalColourScheme();
929 if(cs instanceof ConservationColourScheme )
930 changeColour( ((ConservationColourScheme)cs).cs );
934 modifyConservation_actionPerformed(null);
937 public void abovePIDThreshold_actionPerformed(ActionEvent e)
939 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
941 conservationMenuItem.setSelected(false);
942 viewport.setConservationSelected(false);
944 ColourSchemeI cs = viewport.getGlobalColourScheme();
946 if(cs instanceof ConservationColourScheme )
947 changeColour( ((ConservationColourScheme)cs).cs );
951 modifyPID_actionPerformed(null);
956 public void userDefinedColour_actionPerformed(ActionEvent e)
958 new UserDefinedColours( alignPanel, null);
961 public void PIDColour_actionPerformed(ActionEvent e)
963 changeColour( new PIDColourScheme() );
967 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
969 changeColour(new Blosum62ColourScheme() );
974 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
976 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, HistoryItem.SORT));
977 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0));
978 alignPanel.repaint();
981 public void sortIDMenuItem_actionPerformed(ActionEvent e)
983 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, HistoryItem.SORT));
984 AlignmentSorter.sortByID( viewport.getAlignment() );
985 alignPanel.repaint();
988 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
990 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, HistoryItem.SORT));
991 AlignmentSorter.sortByGroup(viewport.getAlignment());
992 AlignmentSorter.sortGroups(viewport.getAlignment());
993 alignPanel.repaint();
996 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
998 RedundancyPanel sp = new RedundancyPanel(alignPanel,this);
999 JInternalFrame frame = new JInternalFrame();
1000 frame.setContentPane(sp);
1001 Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100, false);
1005 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
1007 if((viewport.getSelectionGroup()==null) ||
1008 viewport.getSelectionGroup().getSize()<2)
1009 JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);
1012 JInternalFrame frame = new JInternalFrame();
1013 frame.setContentPane(new PairwiseAlignPanel(viewport));
1014 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
1018 public void PCAMenuItem_actionPerformed(ActionEvent e)
1021 if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0)
1022 || viewport.getAlignment().getHeight()<4)
1024 JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"
1025 +"at least 4 input sequences.",
1026 "Sequence selection insufficient",
1027 JOptionPane.WARNING_MESSAGE);
1032 PCAPanel pcaPanel = new PCAPanel(viewport, null);
1033 JInternalFrame frame = new JInternalFrame();
1034 frame.setContentPane(pcaPanel);
1035 Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400);
1036 }catch(java.lang.OutOfMemoryError ex)
1038 JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!",
1039 "Out of memory", JOptionPane.WARNING_MESSAGE);
1045 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
1047 NewTreePanel("AV", "PID", "Average distance tree using PID");
1050 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
1052 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
1056 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1058 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
1061 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1063 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
1066 void NewTreePanel(String type, String pwType, String title)
1068 //are the sequences aligned?
1069 if(!viewport.alignment.isAligned())
1071 JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.\n"
1072 +"Try using the Pad function in the edit menu,\n"
1073 +"or one of the multiple sequence alignment web services.",
1074 "Sequences not aligned", JOptionPane.WARNING_MESSAGE);
1079 if (viewport.getSelectionGroup() != null &&
1080 viewport.getSelectionGroup().getSize() > 3)
1082 tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type,
1084 0, viewport.alignment.getWidth());
1088 tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),
1089 type, pwType, 0, viewport.alignment.getWidth());
1092 addTreeMenuItem(tp, title);
1094 Desktop.addInternalFrame(tp, title, 600, 500);
1097 public void addSortByOrderMenuItem(String title, final AlignmentOrder order) {
1098 final JMenuItem item = new JMenuItem("by "+title);
1100 item.addActionListener(new java.awt.event.ActionListener()
1102 public void actionPerformed(ActionEvent e)
1104 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
1106 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
1107 AlignmentSorter.sortBy(viewport.getAlignment(), order);
1108 alignPanel.repaint();
1113 void addTreeMenuItem(final TreePanel treePanel, String title)
1115 final JMenuItem item = new JMenuItem(title);
1120 sort.add(sortByTreeMenu);
1122 sortByTreeMenu.add(item);
1123 item.addActionListener(new java.awt.event.ActionListener()
1125 public void actionPerformed(ActionEvent e)
1127 addHistoryItem(new HistoryItem("Tree Sort", viewport.alignment,
1129 AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());
1130 alignPanel.repaint();
1134 treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1136 public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
1139 sortByTreeMenu.remove(item);
1141 sort.remove(sortByTreeMenu);
1144 viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
1145 public void propertyChange(PropertyChangeEvent evt)
1147 if (evt.getPropertyName().equals("alignment")) {
1148 treePanel.getTree().UpdatePlaceHolders( (Vector) evt.getNewValue());
1149 treePanel.repaint();
1158 public void clustalAlignMenuItem_actionPerformed(ActionEvent e)
1160 // TODO:resolve which menu item was actually selected
1161 // Now, check we have enough sequences
1162 SequenceI[] msa=null;
1163 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1165 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1166 SequenceGroup seqs = viewport.getSelectionGroup();
1168 msa = new SequenceI[sz=seqs.getSize()];
1169 for (int i = 0; i < sz; i++)
1171 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1177 Vector seqs = viewport.getAlignment().getSequences();
1179 if (seqs.size() > 1) {
1180 msa = new SequenceI[seqs.size()];
1181 for (int i = 0; i < seqs.size(); i++)
1183 msa[i] = (SequenceI) seqs.elementAt(i);
1190 jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", title, msa, true, true);
1194 protected void jpred_actionPerformed(ActionEvent e)
1197 SequenceI[] msa=null;
1199 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>0)
1201 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1202 SequenceGroup seqs = viewport.getSelectionGroup();
1203 if (seqs.getSize() == 1 || !viewport.alignment.isAligned())
1205 seq = (SequenceI)seqs.getSequenceAt(0);
1210 msa = new SequenceI[sz=seqs.getSize()];
1211 for (int i = 0; i < sz; i++)
1213 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1219 Vector seqs = viewport.getAlignment().getSequences();
1221 if (seqs.size() == 1 || !viewport.alignment.isAligned())
1223 seq = (SequenceI) seqs.elementAt(0);
1227 msa = new SequenceI[seqs.size()];
1228 for (int i = 0; i < seqs.size(); i++)
1230 msa[i] = (SequenceI) seqs.elementAt(i);
1235 JPredClient ct = new JPredClient(title, msa);
1238 JPredClient ct = new JPredClient(title, seq);
1240 System.err.print("JALVIEW ERROR! - Unexpected JPred selection state!\n");
1243 protected void msaAlignMenuItem_actionPerformed(ActionEvent e)
1245 // TODO:resolve which menu item was actually selected
1246 // Now, check we have enough sequences
1247 SequenceI[] msa=null;
1248 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1250 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1251 SequenceGroup seqs = viewport.getSelectionGroup();
1253 msa = new SequenceI[sz=seqs.getSize()];
1254 for (int i = 0; i < sz; i++)
1256 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1263 Vector seqs = viewport.getAlignment().getSequences();
1265 if (seqs.size() > 1) {
1266 msa = new SequenceI[seqs.size()];
1267 for (int i = 0; i < seqs.size(); i++)
1269 msa[i] = (SequenceI) seqs.elementAt(i);
1276 MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, true, true);
1279 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {
1280 // Pick the tree file
1281 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1282 getProperty("LAST_DIRECTORY"));
1283 chooser.setFileView(new JalviewFileView());
1284 chooser.setDialogTitle("Select a newick-like tree file");
1285 chooser.setToolTipText("Load a tree file");
1286 int value = chooser.showOpenDialog(null);
1287 if (value == JalviewFileChooser.APPROVE_OPTION)
1289 String choice = chooser.getSelectedFile().getPath();
1290 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1293 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File");
1294 ShowNewickTree(fin, choice);
1296 catch (Exception ex)
1298 JOptionPane.showMessageDialog(Desktop.desktop,
1299 "Problem reading tree file",
1301 JOptionPane.WARNING_MESSAGE);
1302 ex.printStackTrace();
1307 public void ShowNewickTree(NewickFile nf, String title)
1311 if (nf.getTree() != null)
1313 TreePanel tp = new TreePanel(viewport,
1314 viewport.getAlignment().getSequences(),
1315 nf, "FromFile", title);
1316 Desktop.addInternalFrame(tp, title, 600, 500);
1317 addTreeMenuItem(tp, title);
1318 viewport.setCurrentTree(tp.getTree());
1320 }catch(Exception ex){ex.printStackTrace();}