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(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);
257 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
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 boolean seqsdeleted=false;
423 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, HistoryItem.HIDE));
425 if (viewport.getSelectionGroup() == null)
428 SequenceGroup sg = viewport.getSelectionGroup();
429 for (int i=0;i < sg.sequences.size(); i++)
431 SequenceI seq = sg.getSequenceAt(i);
432 int index = viewport.getAlignment().findIndex(seq);
433 seq.deleteChars(sg.getStartRes(),sg.getEndRes()+1);
435 if(seq.getSequence().length()<1) {
437 viewport.getAlignment().deleteSequence(seq);
439 viewport.getAlignment().getSequences().setElementAt(seq, index);
443 viewport.setSelectionGroup(null);
444 viewport.alignment.deleteGroup(sg);
446 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
447 viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight());
448 if(viewport.getAlignment().getHeight()<1)
451 this.setClosed(true);
452 }catch(Exception ex){}
453 viewport.updateConservation();
454 viewport.updateConsensus();
455 alignPanel.repaint();
459 protected void deleteGroups_actionPerformed(ActionEvent e)
461 viewport.alignment.deleteAllGroups();
462 viewport.setSelectionGroup(null);
463 alignPanel.repaint();
468 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
470 SequenceGroup sg = new SequenceGroup();
471 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
472 sg.addSequence( viewport.getAlignment().getSequenceAt(i));
473 sg.setEndRes(viewport.alignment.getWidth());
474 viewport.setSelectionGroup(sg);
475 PaintRefresher.Refresh(null);
478 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
480 viewport.setSelectionGroup(null);
481 viewport.getColumnSelection().clear();
482 viewport.setSelectionGroup(null);
483 PaintRefresher.Refresh(null);
486 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
488 SequenceGroup sg = viewport.getSelectionGroup();
489 for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)
490 sg.addOrRemove (viewport.getAlignment().getSequenceAt(i));
492 PaintRefresher.Refresh(null);
495 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
497 ColumnSelection colSel = viewport.getColumnSelection();
498 if (colSel.size() > 0)
500 addHistoryItem(new HistoryItem("Remove Left",viewport.alignment,
502 int min = colSel.getMin();
503 viewport.getAlignment().trimLeft(min);
504 colSel.compensateForEdit(0,min);
506 if(viewport.getSelectionGroup()!=null)
507 viewport.getSelectionGroup().adjustForRemoveLeft(min);
509 Vector groups = viewport.alignment.getGroups();
510 for(int i=0; i<groups.size(); i++)
512 SequenceGroup sg = (SequenceGroup) groups.get(i);
513 if(!sg.adjustForRemoveLeft(min))
514 viewport.alignment.deleteGroup(sg);
517 alignPanel.repaint();
521 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
523 ColumnSelection colSel = viewport.getColumnSelection();
524 if (colSel.size() > 0)
526 addHistoryItem(new HistoryItem("Remove Right",viewport.alignment,
529 int max = colSel.getMax();
530 viewport.getAlignment().trimRight(max);
531 if(viewport.getSelectionGroup()!=null)
532 viewport.getSelectionGroup().adjustForRemoveRight(max);
534 Vector groups = viewport.alignment.getGroups();
535 for(int i=0; i<groups.size(); i++)
537 SequenceGroup sg = (SequenceGroup) groups.get(i);
538 if(!sg.adjustForRemoveRight(max))
539 viewport.alignment.deleteGroup(sg);
544 alignPanel.repaint();
549 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
551 addHistoryItem(new HistoryItem("Remove Gapped Columns",
555 viewport.getAlignment().removeGaps();
556 viewport.updateConservation();
557 viewport.updateConsensus();
558 alignPanel.repaint();
561 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
563 addHistoryItem(new HistoryItem("Remove Gaps",
568 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
570 current = viewport.getAlignment().getSequenceAt(i);
571 jSize = current.getLength();
572 for (int j=0; j < jSize; j++)
573 if(jalview.util.Comparison.isGap(current.getCharAt(j)))
575 current.deleteCharAt(j);
580 viewport.updateConservation();
581 viewport.updateConsensus();
582 alignPanel.repaint();
586 public void padGapsMenuitem_actionPerformed(ActionEvent e)
588 addHistoryItem(new HistoryItem("Pad Gaps",
592 int Width = viewport.getAlignment().getWidth()-1;
593 for (int i=0; i < viewport.getAlignment().getSequences().size();i++)
595 current = viewport.getAlignment().getSequenceAt(i);
597 if (current.getLength()<Width)
598 current.insertCharAt(Width, viewport.getGapCharacter());
600 viewport.updateConservation();
601 viewport.updateConsensus();
602 alignPanel.repaint();
606 public void findMenuItem_actionPerformed(ActionEvent e)
608 JInternalFrame frame = new JInternalFrame();
609 Finder finder = new Finder(viewport, alignPanel, frame);
610 frame.setContentPane(finder);
611 Desktop.addInternalFrame(frame, "Find", 340,110);
612 frame.setLayer(JLayeredPane.PALETTE_LAYER);
617 public void font_actionPerformed(ActionEvent e)
619 FontChooser fc = new FontChooser( alignPanel );
622 protected void fullSeqId_actionPerformed(ActionEvent e)
624 viewport.setShowFullId( fullSeqId.isSelected() );
626 alignPanel.idPanel.idCanvas.setPreferredSize( alignPanel.calculateIdWidth() );
627 alignPanel.repaint();
630 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
632 viewport.setColourText( colourTextMenuItem.isSelected() );
633 alignPanel.repaint();
636 protected void wrapMenuItem_actionPerformed(ActionEvent e)
638 viewport.setWrapAlignment( wrapMenuItem.isSelected() );
639 alignPanel.setWrapAlignment( wrapMenuItem.isSelected() );
640 scaleAbove.setVisible( wrapMenuItem.isSelected() );
641 scaleLeft.setVisible( wrapMenuItem.isSelected() );
642 scaleRight.setVisible( wrapMenuItem.isSelected() );
643 alignPanel.repaint();
646 protected void scaleAbove_actionPerformed(ActionEvent e)
648 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
649 alignPanel.repaint();
652 protected void scaleLeft_actionPerformed(ActionEvent e)
654 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
655 alignPanel.repaint();
658 protected void scaleRight_actionPerformed(ActionEvent e)
660 viewport.setScaleRightWrapped(scaleRight.isSelected());
661 alignPanel.repaint();
666 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
668 viewport.setShowBoxes( viewBoxesMenuItem.isSelected() );
669 alignPanel.repaint();
672 public void viewTextMenuItem_actionPerformed(ActionEvent e)
674 viewport.setShowText( viewTextMenuItem.isSelected() );
675 alignPanel.repaint();
679 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
681 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
682 alignPanel.repaint();
685 public void sequenceFeatures_actionPerformed(ActionEvent evt)
687 viewport.showSequenceFeatures(sequenceFeatures.isSelected());
688 if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded)
690 SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.alignment, alignPanel);
691 ((Alignment)viewport.alignment).featuresAdded = true;
693 alignPanel.repaint();
696 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
698 if(annotationPanelMenuItem.isSelected() && viewport.getWrapAlignment())
700 annotationPanelMenuItem.setSelected(false);
703 viewport.setShowAnnotation( annotationPanelMenuItem.isSelected() );
704 alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() );
707 public void overviewMenuItem_actionPerformed(ActionEvent e)
709 if (alignPanel.overviewPanel != null)
712 JInternalFrame frame = new JInternalFrame();
713 OverviewPanel overview = new OverviewPanel(alignPanel);
714 frame.setContentPane(overview);
715 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
716 frame.getWidth(), frame.getHeight());
718 frame.setLayer(JLayeredPane.PALETTE_LAYER);
719 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
720 { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)
722 alignPanel.setOverviewPanel(null);
726 alignPanel.setOverviewPanel( overview );
731 protected void noColourmenuItem_actionPerformed(ActionEvent e)
733 changeColour( null );
737 public void clustalColour_actionPerformed(ActionEvent e)
739 abovePIDThreshold.setSelected(false);
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 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);
855 if (cs instanceof ClustalxColourScheme)
857 sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());
862 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
863 }catch(Exception ex){ex.printStackTrace();}
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 UserDefinedColours chooser = 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);
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().getSize()<2)
1011 JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);
1014 JInternalFrame frame = new JInternalFrame();
1015 frame.setContentPane(new PairwiseAlignPanel(viewport));
1016 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
1020 public void PCAMenuItem_actionPerformed(ActionEvent e)
1023 if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0)
1024 || viewport.getAlignment().getHeight()<4)
1026 JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"
1027 +"at least 4 input sequences.",
1028 "Sequence selection insufficient",
1029 JOptionPane.WARNING_MESSAGE);
1034 PCAPanel pcaPanel = new PCAPanel(viewport, null);
1035 JInternalFrame frame = new JInternalFrame();
1036 frame.setContentPane(pcaPanel);
1037 Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400);
1038 }catch(java.lang.OutOfMemoryError ex)
1040 JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!",
1041 "Out of memory", JOptionPane.WARNING_MESSAGE);
1047 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
1049 NewTreePanel("AV", "PID", "Average distance tree using PID");
1052 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
1054 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
1058 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1060 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
1063 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
1065 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID");
1068 void NewTreePanel(String type, String pwType, String title)
1070 //are the sequences aligned?
1071 if(!viewport.alignment.isAligned())
1073 JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.",
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 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>0)
1199 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1200 SequenceGroup seqs = viewport.getSelectionGroup();
1201 if (seqs.getSize() == 1 || !viewport.alignment.isAligned())
1203 JPredClient ct = new JPredClient( (SequenceI)seqs.getSequenceAt(0));
1208 SequenceI[] msa = new SequenceI[sz=seqs.getSize()];
1209 for (int i = 0; i < sz; i++)
1211 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1214 JPredClient ct = new JPredClient(title, msa);
1220 Vector seqs = viewport.getAlignment().getSequences();
1222 if (seqs.size() == 1 || !viewport.alignment.isAligned())
1224 JPredClient ct = new JPredClient( (SequenceI)
1229 SequenceI[] msa = new SequenceI[seqs.size()];
1230 for (int i = 0; i < seqs.size(); i++)
1232 msa[i] = (SequenceI) seqs.elementAt(i);
1235 JPredClient ct = new JPredClient(title, msa);
1240 protected void msaAlignMenuItem_actionPerformed(ActionEvent e)
1242 // TODO:resolve which menu item was actually selected
1243 // Now, check we have enough sequences
1244 SequenceI[] msa=null;
1245 if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>1)
1247 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
1248 SequenceGroup seqs = viewport.getSelectionGroup();
1250 msa = new SequenceI[sz=seqs.getSize()];
1251 for (int i = 0; i < sz; i++)
1253 msa[i] = (SequenceI) seqs.getSequenceAt(i);
1260 Vector seqs = viewport.getAlignment().getSequences();
1262 if (seqs.size() > 1) {
1263 msa = new SequenceI[seqs.size()];
1264 for (int i = 0; i < seqs.size(); i++)
1266 msa[i] = (SequenceI) seqs.elementAt(i);
1273 MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS",title, msa, true, true);
1276 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) {
1277 // Pick the tree file
1278 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
1279 getProperty("LAST_DIRECTORY"));
1280 chooser.setFileView(new JalviewFileView());
1281 chooser.setDialogTitle("Select a newick-like tree file");
1282 chooser.setToolTipText("Load a tree file");
1283 int value = chooser.showOpenDialog(null);
1284 if (value == JalviewFileChooser.APPROVE_OPTION)
1286 String choice = chooser.getSelectedFile().getPath();
1287 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1290 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File");
1291 ShowNewickTree(fin, choice);
1293 catch (Exception ex)
1295 JOptionPane.showMessageDialog(Desktop.desktop,
1296 "Problem reading tree file",
1298 JOptionPane.WARNING_MESSAGE);
1299 ex.printStackTrace();
1304 public void ShowNewickTree(NewickFile nf, String title)
1308 if (nf.getTree() != null)
1310 TreePanel tp = new TreePanel(viewport,
1311 viewport.getAlignment().getSequences(),
1312 nf, "FromFile", title);
1313 Desktop.addInternalFrame(tp, title, 600, 500);
1314 addTreeMenuItem(tp, title);
1315 viewport.setCurrentTree(tp.getTree());
1317 }catch(Exception ex){ex.printStackTrace();}