X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=5c3193127c60acead39d4e40653eeaf7ef148ae3;hb=1d6ae39a6442c455d362b933f1da89b0a481e5f5;hp=ede7eacef9ffee2eccb72c6d5aef132f89d62ffc;hpb=9eaa1ff9aac185a7094b5e82516a7f675b3a5890;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index ede7eac..5c31931 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1,142 +1,212 @@ -/******************** - * 2004 Jalview Reengineered - * Barton Group - * Dundee University +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * - * AM Waterhouse - *******************/ - - - - + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.gui; -import jalview.jbgui.GAlignFrame; -import jalview.schemes.*; -import jalview.datamodel.*; -import jalview.analysis.*; -import jalview.io.*; -import MCview.*; +import java.beans.*; +import java.util.*; + import java.awt.*; +import java.awt.datatransfer.*; import java.awt.event.*; import java.awt.print.*; import javax.swing.*; import javax.swing.event.*; -import java.util.*; -public class AlignFrame extends GAlignFrame +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.io.*; +import jalview.jbgui.*; +import jalview.schemes.*; +import jalview.ws.*; + +public class AlignFrame + extends GAlignFrame { + public static final int NEW_WINDOW_WIDTH = 700; + public static final int NEW_WINDOW_HEIGHT = 500; final AlignmentPanel alignPanel; final AlignViewport viewport; + public String currentFileFormat = "Jalview"; + Stack historyList = new Stack(); + Stack redoList = new Stack(); + private int treeCount = 0; + public AlignFrame(AlignmentI al) { - super(); - viewport = new AlignViewport(al,true,true,true,false); + viewport = new AlignViewport(al); + alignPanel = new AlignmentPanel(this, viewport); + alignPanel.annotationPanel.adjustPanelHeight(); + alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel. + annotationPanel.getPreferredSize()); + alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel. + getPreferredSize()); + alignPanel.setAnnotationVisible(viewport.getShowAnnotation()); + getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); - fontNameMenuItem.setText(viewport.getFont().getName()); - fontSizeMenuItem.setText(viewport.getFont().getSize()+""); + + addInternalFrameListener(new InternalFrameAdapter() + { + public void internalFrameActivated(InternalFrameEvent evt) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + alignPanel.requestFocus(); + } + }); + } + }); } - protected void saveAs_actionPerformed(ActionEvent e) + public void saveAlignmentMenu_actionPerformed(ActionEvent e) { - JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY); - chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format."); + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty( + "LAST_DIRECTORY"), + new String[] + { + "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", + "jar" + }, + new String[] + { + "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" + }, currentFileFormat); + + chooser.setAcceptAllFileFilterUsed(false); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Save Alignment to file"); chooser.setToolTipText("Save"); + int value = chooser.showSaveDialog(this); - if(value == JFileChooser.APPROVE_OPTION) + + if (value == JalviewFileChooser.APPROVE_OPTION) { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.LAST_DIRECTORY = choice; - String output = FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences()); - try{ - java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) ); + currentFileFormat = chooser.getSelectedFormat(); + jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", + currentFileFormat); + + if (currentFileFormat.equals("Jalview")) + { + String shortName = title; + + if (shortName.indexOf(java.io.File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + java.io.File.separatorChar) + 1); + } + + String choice = chooser.getSelectedFile().getPath(); + Jalview2XML.SaveState(this, choice, shortName); + + // USE Jalview2XML to save this file + return; + } + + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + + String output = FormatAdapter.formatSequences(currentFileFormat, + viewport.getAlignment().getSequences()); + + try + { + java.io.PrintWriter out = new java.io.PrintWriter(new java.io. + FileWriter( + choice)); out.println(output); out.close(); } - catch(Exception ex){} + catch (Exception ex) + { + } } - } protected void outputText_actionPerformed(ActionEvent e) { - CutAndPasteTransfer cap = new CutAndPasteTransfer(false); - JInternalFrame frame = new JInternalFrame(); - cap.formatForOutput(); - frame.setContentPane(cap); - Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500); - cap.setText( FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences())); + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + Desktop.addInternalFrame(cap, + "Alignment output - " + e.getActionCommand(), 600, + 500); + cap.setText(FormatAdapter.formatSequences(e.getActionCommand(), + viewport.getAlignment(). + getSequences())); } protected void htmlMenuItem_actionPerformed(ActionEvent e) { - HTMLOutput htmlOutput = new HTMLOutput(viewport); - htmlOutput = null; + new HTMLOutput(viewport); } - public void printMenuItem_actionPerformed(ActionEvent e) + protected void createPNG_actionPerformed(ActionEvent e) { - //Putting in a thread avoids Swing painting problems - PrintThread thread = new PrintThread(); - thread.start(); + alignPanel.makePNG(); } - class PrintThread extends Thread + protected void epsFile_actionPerformed(ActionEvent e) { - public void run() - { - PrinterJob printJob = PrinterJob.getPrinterJob(); - PageFormat pf = printJob.pageDialog(printJob.defaultPage()); - printJob.setPrintable(alignPanel, pf); - if (printJob.printDialog()) - { - try - { - printJob.print(); - } - catch (Exception PrintException) - { - PrintException.printStackTrace(); - } - } - } - + alignPanel.makeEPS(); } - - + public void printMenuItem_actionPerformed(ActionEvent e) + { + //Putting in a thread avoids Swing painting problems + PrintThread thread = new PrintThread(); + thread.start(); + } public void closeMenuItem_actionPerformed(ActionEvent e) { - try{ + try + { this.setClosed(true); - }catch(Exception ex){} + } + catch (Exception ex) + { + } } - ArrayList historyList = new ArrayList(); - ArrayList redoList = new ArrayList(); - void updateEditMenuBar() { - if(historyList.size()>0) - { - undoMenuItem.setEnabled(true); - Object [] history = (Object[])historyList.get(0); - undoMenuItem.setText("Undo "+history[0]); - } + if (historyList.size() > 0) + { + undoMenuItem.setEnabled(true); + + HistoryItem hi = (HistoryItem) historyList.peek(); + undoMenuItem.setText("Undo " + hi.getDescription()); + } else { undoMenuItem.setEnabled(false); undoMenuItem.setText("Undo"); } - if(redoList.size()>0) - { - redoMenuItem.setEnabled(true); - Object [] history = (Object[])redoList.get(0); - redoMenuItem.setText("Redo "+history[0]); - } + if (redoList.size() > 0) + { + redoMenuItem.setEnabled(true); + + HistoryItem hi = (HistoryItem) redoList.peek(); + redoMenuItem.setText("Redo " + hi.getDescription()); + } else { redoMenuItem.setEnabled(false); @@ -144,561 +214,965 @@ public class AlignFrame extends GAlignFrame } } - public void addHistoryItem(String type) + public void addHistoryItem(HistoryItem hi) { - // must make sure we add new sequence objects her, not refs to the existing sequences - redoList.clear(); - SequenceI[] seq = new SequenceI[viewport.getAlignment().getHeight()]; - for(int i=0; i (hi.getSequences().size() - 1); i--) + { + viewport.alignment.deleteSequence(i); + } + } } - PaintRefresher.Refresh(null); - } + updateEditMenuBar(); - public void deselectAllColumnsMenuItem_actionPerformed(ActionEvent e) - { - viewport.getColumnSelection().clear(); - repaint(); + viewport.updateConsensus(); + viewport.updateConservation(); + alignPanel.repaint(); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } - public void remove2LeftMenuItem_actionPerformed(ActionEvent e) + public void moveSelectedSequences(boolean up) { - addHistoryItem("delete columns"); - ColumnSelection colSel = viewport.getColumnSelection(); - if (colSel.size() > 0) + SequenceGroup sg = viewport.getSelectionGroup(); + + if (sg == null) { - int min = colSel.getMin(); - viewport.getAlignment().trimLeft(min); - colSel.compensateForEdit(0,min); - alignPanel.RefreshPanels(); + return; } - } - public void remove2RightMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("delete columns"); - ColumnSelection colSel = viewport.getColumnSelection(); - if (colSel.size() > 0) + if (up) { - int max = colSel.getMax(); - if(max>1) - viewport.getAlignment().trimRight(max); + for (int i = 1; i < viewport.alignment.getHeight(); i++) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); - alignPanel.RefreshPanels(); - } + if (!sg.sequences.contains(seq)) + { + continue; + } - } + SequenceI temp = viewport.alignment.getSequenceAt(i - 1); - public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("delete gapped columns"); - viewport.getAlignment().removeGaps(); - alignPanel.RefreshPanels(); - } + if (sg.sequences.contains(temp)) + { + continue; + } - public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("delete all gaps"); - SequenceI current; - int jSize; - for (int i=0; i < viewport.getAlignment().getSequences().size();i++) + viewport.alignment.getSequences().setElementAt(temp, i); + viewport.alignment.getSequences().setElementAt(seq, i - 1); + } + } + else { - current = viewport.getAlignment().getSequenceAt(i); - jSize = current.getLength(); - for (int j=0; j < jSize; j++) - if(jalview.util.Comparison.isGap(current.getCharAt(j))) + for (int i = viewport.alignment.getHeight() - 2; i > -1; i--) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); + + if (!sg.sequences.contains(seq)) { - current.deleteCharAt(j); - j--; - jSize--; + continue; + } + + SequenceI temp = viewport.alignment.getSequenceAt(i + 1); + + if (sg.sequences.contains(temp)) + { + continue; } + + viewport.alignment.getSequences().setElementAt(temp, i); + viewport.alignment.getSequences().setElementAt(seq, i + 1); + } } - alignPanel.RefreshPanels(); + alignPanel.repaint(); } - public void setGapCharMenuItem_actionPerformed(ActionEvent e) + protected void copy_actionPerformed(ActionEvent e) { - char thisChar = '-'; - char nextChar = '.'; - if(viewport.getGapCharacter()=='-') + if (viewport.getSelectionGroup() == null) { - thisChar = '.'; - nextChar = '-'; + return; } - setGapCharMenuItem.setText("Set gap character to \""+nextChar+"\""); - viewport.setGapCharacter(thisChar); - alignPanel.RefreshPanels(); - } - public void findMenuItem_actionPerformed(ActionEvent e) - { - JOptionPane op = new JOptionPane(); - JInternalFrame frame = op.createInternalFrame(this, "Find"); - Finder finder = new Finder(viewport, alignPanel, frame); - frame.setContentPane(finder); - frame.setSize(300,110); - frame.setVisible(true); - } + SequenceGroup sg = viewport.getSelectionGroup(); + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer buffer = new StringBuffer(); + Hashtable orderedSeqs = new Hashtable(); - public void fontNameMenuItem_actionPerformed(ActionEvent e) - { - String fonts[] = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); + for (int i = 0; i < sg.getSize(); i++) + { + SequenceI seq = sg.getSequenceAt(i); + int index = viewport.alignment.findIndex(seq); + orderedSeqs.put(index + "", seq); + } + int index = 0; - String selection = JOptionPane.showInternalInputDialog(this, - "Select font", - "Font selection", - JOptionPane.QUESTION_MESSAGE, - null,fonts - ,fontNameMenuItem.getText()).toString(); - if(selection!=null) + for (int i = 0; i < sg.getSize(); i++) { - fontNameMenuItem.setText(selection); - SetFont(); - } + SequenceI seq = null; - } + while (seq == null) + { + if (orderedSeqs.containsKey(index + "")) + { + seq = (SequenceI) orderedSeqs.get(index + ""); + index++; - public void fontSizeMenuItem_actionPerformed(ActionEvent e) - { - String selection = JOptionPane.showInternalInputDialog(this, - "Select font size", - "Font size", - JOptionPane.QUESTION_MESSAGE, - null, new String[]{"1","2","4","6","8","10","12","14","16","18","20"} - ,fontSizeMenuItem.getText()).toString(); - if(selection!=null) - { - fontSizeMenuItem.setText(selection); - SetFont(); - } - } + break; + } + else + { + index++; + } + } - public void fontStyleMenuItem_actionPerformed(ActionEvent e) - { - String selection = JOptionPane.showInternalInputDialog(this, - "Select font style", - "Font style", - JOptionPane.QUESTION_MESSAGE, - null, new String[]{"plain", "bold", "italic"} - ,fontStyleMenuItem.getText()).toString(); - if(selection!=null) - { - fontStyleMenuItem.setText(selection); - SetFont(); + buffer.append(seq.getName() + "\t" + + seq.findPosition(sg.getStartRes()) + "\t" + + seq.findPosition(sg.getEndRes()) + "\t" + + sg.getSequenceAt(i).getSequence(sg.getStartRes(), + sg.getEndRes() + 1) + "\n"); } + c.setContents(new StringSelection(buffer.toString()), null); } - protected void colourTextMenuItem_actionPerformed(ActionEvent e) + protected void pasteNew_actionPerformed(ActionEvent e) { - viewport.setColourText( colourTextMenuItem.isSelected() ); - alignPanel.RefreshPanels(); + paste(true); } - void SetFont() + protected void pasteThis_actionPerformed(ActionEvent e) { - int style = java.awt.Font.PLAIN; - if(fontStyleMenuItem.getText().equals("bold")) - style = java.awt.Font.BOLD; - else if(fontStyleMenuItem.getText().equals("italic")) - style = java.awt.Font.ITALIC; - - viewport.setFont(new java.awt.Font(fontNameMenuItem.getText(), - style, - Integer.parseInt(fontSizeMenuItem.getText()))); - alignPanel.RefreshPanels(); - + addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, + HistoryItem.PASTE)); + paste(false); } - protected void wrapMenuItem_actionPerformed(ActionEvent e) + void paste(boolean newAlignment) { - viewport.setWrapAlignment( wrapMenuItem.isSelected() ); - alignPanel.RefreshPanels(); - } - + try + { + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable contents = c.getContents(this); - public void viewBoxesMenuItem_actionPerformed(ActionEvent e) - { - viewport.setShowBoxes( viewBoxesMenuItem.isSelected() ); - alignPanel.RefreshPanels(); - } + if (contents == null) + { + return; + } - public void viewTextMenuItem_actionPerformed(ActionEvent e) - { - viewport.setShowText( viewTextMenuItem.isSelected() ); - alignPanel.RefreshPanels(); - } + String str = (String) contents.getTransferData(DataFlavor.stringFlavor); + StringTokenizer st = new StringTokenizer(str); + ArrayList seqs = new ArrayList(); + while (st.hasMoreElements()) + { + String name = st.nextToken(); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + Sequence sequence = new Sequence(name, st.nextToken(), start, + end); - protected void renderGapsMenuItem_actionPerformed(ActionEvent e) - { - viewport.setRenderGaps(renderGapsMenuItem.isSelected()); - alignPanel.RefreshPanels(); - } + if (!newAlignment) + { + viewport.alignment.addSequence(sequence); + } + else + { + seqs.add(sequence); + } + } + if (newAlignment) + { + SequenceI[] newSeqs = new SequenceI[seqs.size()]; + seqs.toArray(newSeqs); - public void consensusGraphMenuItem_actionPerformed(ActionEvent e) - { - alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() ); - } + AlignFrame af = new AlignFrame(new Alignment(newSeqs)); + String newtitle = new String("Copied sequences"); - public void overviewMenuItem_actionPerformed(ActionEvent e) - { + if (title.startsWith("Copied sequences")) + { + newtitle = title; + } + else + { + newtitle = newtitle.concat("- from " + title); + } - JInternalFrame frame = new JInternalFrame(); - OverviewPanel overview = alignPanel.getOverviewPanel(); - try{ - overview = new OverviewPanel(alignPanel, viewport); - frame.setContentPane(overview); - Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), - frame.getWidth(), frame.getHeight()); - frame.pack(); - frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() - { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) + Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, + NEW_WINDOW_HEIGHT); + } + else { - alignPanel.setOverviewPanel(null); - }; - }); - alignPanel.setOverviewPanel( overview ); - - }catch(java.lang.OutOfMemoryError ex) - { - JOptionPane.showInternalMessageDialog(this, "Sequence alignment too large to\nproduce overview image!!" - +"\nTry reducing the font size.", - "Out of memory", JOptionPane.WARNING_MESSAGE); - } - + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + viewport.setEndSeq(viewport.alignment.getHeight()); + viewport.alignment.getWidth(); + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } + } + catch (Exception ex) + { + } + // could be anything being pasted in here } - protected void noColourmenuItem_actionPerformed(ActionEvent e) + protected void cut_actionPerformed(ActionEvent e) { - viewport.setGlobalColourScheme( null ); - changeColour(); + copy_actionPerformed(null); + delete_actionPerformed(null); } - - public void clustalColour_actionPerformed(ActionEvent e) + protected void delete_actionPerformed(ActionEvent e) { - viewport.setGlobalColourScheme(new ClustalxColourScheme( )); - changeColour(); - } + boolean seqsdeleted = false; - public void zappoColour_actionPerformed(ActionEvent e) - { - viewport.setGlobalColourScheme(new ZappoColourScheme() ); - changeColour(); + if (viewport.getSelectionGroup() == null) + { + return; + } + + addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, + HistoryItem.HIDE)); + + SequenceGroup sg = viewport.getSelectionGroup(); + + for (int i = 0; i < sg.sequences.size(); i++) + { + SequenceI seq = sg.getSequenceAt(i); + int index = viewport.getAlignment().findIndex(seq); + seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); + + if (seq.getSequence().length() < 1) + { + seqsdeleted = true; + viewport.getAlignment().deleteSequence(seq); + } + else + { + viewport.getAlignment().getSequences().setElementAt(seq, index); + } + } + + viewport.setSelectionGroup(null); + viewport.alignment.deleteGroup(sg); + + if (seqsdeleted) + { + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + } + + viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getHeight()); + + if (viewport.getAlignment().getHeight() < 1) + { + try + { + this.setClosed(true); + } + catch (Exception ex) + { + } + } + + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); } - public void taylorColour_actionPerformed(ActionEvent e) + protected void deleteGroups_actionPerformed(ActionEvent e) + { + viewport.alignment.deleteAllGroups(); + viewport.setSelectionGroup(null); + alignPanel.repaint(); + } + + public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) + { + SequenceGroup sg = new SequenceGroup(); + + for (int i = 0; i < viewport.getAlignment().getSequences().size(); + i++) + { + sg.addSequence(viewport.getAlignment().getSequenceAt(i), false); + } + + sg.setEndRes(viewport.alignment.getWidth()); + viewport.setSelectionGroup(sg); + PaintRefresher.Refresh(null); + } + + public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) + { + viewport.setSelectionGroup(null); + viewport.getColumnSelection().clear(); + viewport.setSelectionGroup(null); + PaintRefresher.Refresh(null); + } + + public void invertSequenceMenuItem_actionPerformed(ActionEvent e) + { + SequenceGroup sg = viewport.getSelectionGroup(); + + for (int i = 0; i < viewport.getAlignment().getSequences().size(); + i++) + { + sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false); + } + + PaintRefresher.Refresh(null); + } + + public void remove2LeftMenuItem_actionPerformed(ActionEvent e) + { + ColumnSelection colSel = viewport.getColumnSelection(); + + if (colSel.size() > 0) + { + addHistoryItem(new HistoryItem("Remove Left", viewport.alignment, + HistoryItem.HIDE)); + + int min = colSel.getMin(); + viewport.getAlignment().trimLeft(min); + colSel.compensateForEdit(0, min); + + if (viewport.getSelectionGroup() != null) + { + viewport.getSelectionGroup().adjustForRemoveLeft(min); + } + + Vector groups = viewport.alignment.getGroups(); + + for (int i = 0; i < groups.size(); i++) + { + SequenceGroup sg = (SequenceGroup) groups.get(i); + + if (!sg.adjustForRemoveLeft(min)) + { + viewport.alignment.deleteGroup(sg); + } + } + + alignPanel.repaint(); + } + } + + public void remove2RightMenuItem_actionPerformed(ActionEvent e) { - viewport.setGlobalColourScheme(new TaylorColourScheme() ); - changeColour(); + ColumnSelection colSel = viewport.getColumnSelection(); + + if (colSel.size() > 0) + { + addHistoryItem(new HistoryItem("Remove Right", viewport.alignment, + HistoryItem.HIDE)); + + int max = colSel.getMax(); + viewport.getAlignment().trimRight(max); + + if (viewport.getSelectionGroup() != null) + { + viewport.getSelectionGroup().adjustForRemoveRight(max); + } + + Vector groups = viewport.alignment.getGroups(); + + for (int i = 0; i < groups.size(); i++) + { + SequenceGroup sg = (SequenceGroup) groups.get(i); + + if (!sg.adjustForRemoveRight(max)) + { + viewport.alignment.deleteGroup(sg); + } + } + + alignPanel.repaint(); + } + } + + public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Remove Gapped Columns", + viewport.alignment, HistoryItem.HIDE)); + + viewport.getAlignment().removeGaps(); + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); } + public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, + HistoryItem.HIDE)); + + SequenceI current; + int jSize; + + for (int i = 0; i < viewport.getAlignment().getSequences().size(); + i++) + { + current = viewport.getAlignment().getSequenceAt(i); + jSize = current.getLength(); + + for (int j = 0; j < jSize; j++) + { + if (jalview.util.Comparison.isGap(current.getCharAt(j))) + { + current.deleteCharAt(j); + j--; + jSize--; + } + } + } + + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } + + public void padGapsMenuitem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, + HistoryItem.HIDE)); + + SequenceI current; + int Width = viewport.getAlignment().getWidth() - 1; + + for (int i = 0; i < viewport.getAlignment().getSequences().size(); + i++) + { + current = viewport.getAlignment().getSequenceAt(i); + + if (current.getLength() < Width) + { + current.insertCharAt(Width, viewport.getGapCharacter()); + } + } + + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } + + public void findMenuItem_actionPerformed(ActionEvent e) + { + JInternalFrame frame = new JInternalFrame(); + Finder finder = new Finder(viewport, alignPanel, frame); + frame.setContentPane(finder); + Desktop.addInternalFrame(frame, "Find", 340, 110); + frame.setLayer(JLayeredPane.PALETTE_LAYER); + } + + public void font_actionPerformed(ActionEvent e) + { + FontChooser fc = new FontChooser(alignPanel); + } + + protected void fullSeqId_actionPerformed(ActionEvent e) + { + viewport.setShowFullId(fullSeqId.isSelected()); + + alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth()); + alignPanel.repaint(); + } + + protected void colourTextMenuItem_actionPerformed(ActionEvent e) + { + viewport.setColourText(colourTextMenuItem.isSelected()); + alignPanel.repaint(); + } + + protected void wrapMenuItem_actionPerformed(ActionEvent e) + { + viewport.setWrapAlignment(wrapMenuItem.isSelected()); + alignPanel.setWrapAlignment(wrapMenuItem.isSelected()); + scaleAbove.setVisible(wrapMenuItem.isSelected()); + scaleLeft.setVisible(wrapMenuItem.isSelected()); + scaleRight.setVisible(wrapMenuItem.isSelected()); + alignPanel.repaint(); + } + + protected void scaleAbove_actionPerformed(ActionEvent e) + { + viewport.setScaleAboveWrapped(scaleAbove.isSelected()); + alignPanel.repaint(); + } + + protected void scaleLeft_actionPerformed(ActionEvent e) + { + viewport.setScaleLeftWrapped(scaleLeft.isSelected()); + alignPanel.repaint(); + } + + protected void scaleRight_actionPerformed(ActionEvent e) + { + viewport.setScaleRightWrapped(scaleRight.isSelected()); + alignPanel.repaint(); + } + + public void viewBoxesMenuItem_actionPerformed(ActionEvent e) + { + viewport.setShowBoxes(viewBoxesMenuItem.isSelected()); + alignPanel.repaint(); + } + + public void viewTextMenuItem_actionPerformed(ActionEvent e) + { + viewport.setShowText(viewTextMenuItem.isSelected()); + alignPanel.repaint(); + } + + protected void renderGapsMenuItem_actionPerformed(ActionEvent e) + { + viewport.setRenderGaps(renderGapsMenuItem.isSelected()); + alignPanel.repaint(); + } + + public void sequenceFeatures_actionPerformed(ActionEvent evt) + { + viewport.showSequenceFeatures(sequenceFeatures.isSelected()); + + if (viewport.showSequenceFeatures && + ! ( (Alignment) viewport.alignment).featuresAdded) + { + SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport. + alignment, + alignPanel); + ( (Alignment) viewport.alignment).featuresAdded = true; + } + + alignPanel.repaint(); + } + + public void annotationPanelMenuItem_actionPerformed(ActionEvent e) + { + if (annotationPanelMenuItem.isSelected() && + viewport.getWrapAlignment()) + { + annotationPanelMenuItem.setSelected(false); + + return; + } + + viewport.setShowAnnotation(annotationPanelMenuItem.isSelected()); + alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected()); + } + + public void overviewMenuItem_actionPerformed(ActionEvent e) + { + if (alignPanel.overviewPanel != null) + { + return; + } + + JInternalFrame frame = new JInternalFrame(); + OverviewPanel overview = new OverviewPanel(alignPanel); + frame.setContentPane(overview); + Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), + frame.getWidth(), frame.getHeight()); + frame.pack(); + frame.setLayer(JLayeredPane.PALETTE_LAYER); + frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + alignPanel.setOverviewPanel(null); + } + ; + }); + + alignPanel.setOverviewPanel(overview); + } + + protected void noColourmenuItem_actionPerformed(ActionEvent e) + { + changeColour(null); + } + + public void clustalColour_actionPerformed(ActionEvent e) + { + changeColour(new ClustalxColourScheme( + viewport.alignment.getSequences(), viewport.alignment.getWidth())); + } + + public void zappoColour_actionPerformed(ActionEvent e) + { + changeColour(new ZappoColourScheme()); + } + + public void taylorColour_actionPerformed(ActionEvent e) + { + changeColour(new TaylorColourScheme()); + } public void hydrophobicityColour_actionPerformed(ActionEvent e) { - viewport.setGlobalColourScheme( new HydrophobicColourScheme() ); - changeColour(); + changeColour(new HydrophobicColourScheme()); + } + + public void helixColour_actionPerformed(ActionEvent e) + { + changeColour(new HelixColourScheme()); + } + + public void strandColour_actionPerformed(ActionEvent e) + { + changeColour(new StrandColourScheme()); } - public void helixColour_actionPerformed(ActionEvent e) - { - viewport.setGlobalColourScheme( new HelixColourScheme() ); - changeColour(); - } + public void turnColour_actionPerformed(ActionEvent e) + { + changeColour(new TurnColourScheme()); + } + + public void buriedColour_actionPerformed(ActionEvent e) + { + changeColour(new BuriedColourScheme()); + } + + public void nucleotideColour_actionPerformed(ActionEvent e) + { + changeColour(new NucleotideColourScheme()); + } + + protected void applyToAllGroups_actionPerformed(ActionEvent e) + { + viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected()); + } + + void changeColour(ColourSchemeI cs) + { + int threshold = 0; + + if (viewport.getAbovePIDThreshold()) + { + threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, + "Background"); + + if (cs instanceof ResidueColourScheme) + { + ( (ResidueColourScheme) cs).setThreshold(threshold); + } + else if (cs instanceof ScoreColourScheme) + { + ( (ScoreColourScheme) cs).setThreshold(threshold); + } + + viewport.setGlobalColourScheme(cs); + } + else if (cs instanceof ResidueColourScheme) + { + ( (ResidueColourScheme) cs).setThreshold(0); + } + else if (cs instanceof ScoreColourScheme) + { + ( (ScoreColourScheme) cs).setThreshold(0); + } + + if (viewport.getConservationSelected()) + { + ConservationColourScheme ccs = null; + + Alignment al = (Alignment) viewport.alignment; + Conservation c = new Conservation("All", + ResidueProperties.propHash, 3, + al.getSequences(), 0, + al.getWidth() - 1); + + c.calculate(); + c.verdict(false, viewport.ConsPercGaps); + + ccs = new ConservationColourScheme(c, cs); + + // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! + ccs.setConsensus(viewport.vconsensus); + viewport.setGlobalColourScheme(ccs); + + ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs, + "Background"); + } + else + { + // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! + if (cs != null) + { + cs.setConsensus(viewport.vconsensus); + } + + viewport.setGlobalColourScheme(cs); + } + + if (viewport.getColourAppliesToAllGroups()) + { + Vector groups = viewport.alignment.getGroups(); + + for (int i = 0; i < groups.size(); i++) + { + SequenceGroup sg = (SequenceGroup) groups.elementAt(i); + + if (cs == null) + { + sg.cs = null; + } + else if (cs instanceof ClustalxColourScheme) + { + sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth()); + } + else if (cs instanceof UserColourScheme) + { + sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours()); + } + else + { + try + { + sg.cs = (ColourSchemeI) cs.getClass().newInstance(); + } + catch (Exception ex) + { + } + } + + if (viewport.getAbovePIDThreshold()) + { + if (sg.cs instanceof ResidueColourScheme) + { + ( (ResidueColourScheme) sg.cs).setThreshold(threshold); + } + else if (sg.cs instanceof ScoreColourScheme) + { + ( (ScoreColourScheme) sg.cs).setThreshold(threshold); + } + sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, + sg.getWidth())); + } - public void strandColour_actionPerformed(ActionEvent e) - { - viewport.setGlobalColourScheme(new StrandColourScheme() ); - changeColour(); - } + if (viewport.getConservationSelected()) + { + Conservation c = new Conservation("Group", + ResidueProperties.propHash, 3, + sg.sequences, 0, + viewport.alignment.getWidth() - 1); + c.calculate(); + c.verdict(false, viewport.ConsPercGaps); + + ConservationColourScheme ccs = new ConservationColourScheme(c, + sg.cs); + + // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! + ccs.setConsensus(AAFrequency.calculate(sg.sequences, 0, + sg.getWidth())); + sg.cs = ccs; + } + else if (cs != null) + { + // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! + sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, + sg.getWidth())); + } + } + } + if (alignPanel.getOverviewPanel() != null) + { + alignPanel.getOverviewPanel().updateOverviewImage(); + } - public void turnColour_actionPerformed(ActionEvent e) - { - viewport.setGlobalColourScheme(new TurnColourScheme() ); - changeColour(); + alignPanel.repaint(); } - - public void buriedColour_actionPerformed(ActionEvent e) + protected void modifyPID_actionPerformed(ActionEvent e) { - viewport.setGlobalColourScheme( new BuriedColourScheme() ); - changeColour(); + if (viewport.getAbovePIDThreshold()) + { + SliderPanel.setPIDSliderSource(alignPanel, + viewport.getGlobalColourScheme(), + "Background"); + SliderPanel.showPIDSlider(); + } } - void changeColour() + protected void modifyConservation_actionPerformed(ActionEvent e) { - if(abovePIDThreshold.isSelected()) + if (viewport.getConservationSelected()) { - abovePIDThreshold_actionPerformed(null); - alignPanel.setColourScheme( ); + SliderPanel.setConservationSlider(alignPanel, + viewport.globalColourScheme, + "Background"); + SliderPanel.showConservationSlider(); } - else if(conservationMenuItem.isSelected()) - conservationMenuItem_actionPerformed(null); - else - alignPanel.setColourScheme( ); - } - protected void conservationMenuItem_actionPerformed(ActionEvent e) + protected void conservationMenuItem_actionPerformed(ActionEvent e) { viewport.setConservationSelected(conservationMenuItem.isSelected()); - alignPanel.setColourScheme(); - ColourSchemeI oldCs = viewport.getGlobalColourScheme(); + viewport.setAbovePIDThreshold(false); + abovePIDThreshold.setSelected(false); - if(conservationMenuItem.isSelected()) - { - if(sliderPanel!=null) - { - sliderPanel.cs = oldCs; - } + ColourSchemeI cs = viewport.getGlobalColourScheme(); - else - { - sliderPanel = new SliderPanel(alignPanel, 30, true, - viewport.getGlobalColourScheme()); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(sliderPanel); - Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400, - 90); - frame.setMaximizable(false); - frame.setResizable(false); - frame.addInternalFrameListener(new javax.swing.event. - InternalFrameAdapter() - { - public void internalFrameClosed(javax.swing.event.InternalFrameEvent - evt) - { - sliderPanel = null; - }; - }); - } + if (cs instanceof ConservationColourScheme) + { + changeColour( ( (ConservationColourScheme) cs).cs); } else { - if(oldCs instanceof ConservationColourScheme) - { - ConservationColourScheme ccs = (ConservationColourScheme)oldCs; - viewport.setGlobalColourScheme( ccs.cs ); - } - alignPanel.setColourScheme(); + changeColour(cs); } + modifyConservation_actionPerformed(null); } - SliderPanel sliderPanel; public void abovePIDThreshold_actionPerformed(ActionEvent e) { - ColourSchemeI oldCs = viewport.getGlobalColourScheme(); - int threshold = 0; - - if(abovePIDThreshold.isSelected()) - { - if(sliderPanel!=null) - sliderPanel.cs = oldCs; - - else - { - sliderPanel = new SliderPanel(alignPanel, 70, false, oldCs); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(sliderPanel); - Desktop.addInternalFrame(frame, "Percentage Identity Threshold", 400, - 90); - frame.setMaximizable(false); - frame.setResizable(false); - frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() - { - public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) - { - sliderPanel = null; - }; - }); + viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected()); - } + conservationMenuItem.setSelected(false); + viewport.setConservationSelected(false); - threshold = sliderPanel.getValue(); - } + ColourSchemeI cs = viewport.getGlobalColourScheme(); - if (oldCs instanceof ResidueColourScheme) + if (cs instanceof ConservationColourScheme) { - ResidueColourScheme rcs = (ResidueColourScheme) oldCs; - rcs.setThreshold(threshold); + changeColour( ( (ConservationColourScheme) cs).cs); } - else if (oldCs instanceof ScoreColourScheme) + else { - ScoreColourScheme scs = (ScoreColourScheme) oldCs; - scs.setThreshold(threshold); + changeColour(cs); } - alignPanel.setColourScheme(); - + modifyPID_actionPerformed(null); } - - public void userDefinedColour_actionPerformed(ActionEvent e) { - JInternalFrame frame = new JInternalFrame(); - UserDefinedColours chooser = new UserDefinedColours( frame, alignPanel, null); - frame.setContentPane(chooser); - Desktop.addInternalFrame(frame,"User defined colours", 450,540 ); - frame.setResizable(false); - frame.setIconifiable(false); - frame.setMaximizable(false); + new UserDefinedColours(alignPanel, null); } public void PIDColour_actionPerformed(ActionEvent e) { - viewport.setGlobalColourScheme( new PIDColourScheme() ); - alignPanel.setColourScheme( ); + changeColour(new PIDColourScheme()); } - public void BLOSUM62Colour_actionPerformed(ActionEvent e) { - viewport.setGlobalColourScheme( new Blosum62ColourScheme(viewport) ); - alignPanel.setColourScheme(); - } - - - - protected void schemeKeyMenuItem_actionPerformed(ActionEvent e) - { - ColourKey colourKey = new ColourKey( viewport.getGlobalColourScheme() ); - Desktop.addInternalFrame(colourKey, "Colour scheme key", 400, 320); + changeColour(new Blosum62ColourScheme()); } - public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) { - addHistoryItem("sort"); - AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0)); - alignPanel.RefreshPanels(); + addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, + HistoryItem.SORT)); + AlignmentSorter.sortByPID(viewport.getAlignment(), + viewport.getAlignment().getSequenceAt(0)); + alignPanel.repaint(); } public void sortIDMenuItem_actionPerformed(ActionEvent e) { - addHistoryItem("sort"); - AlignmentSorter.sortByID( viewport.getAlignment() ); - alignPanel.RefreshPanels(); + addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, + HistoryItem.SORT)); + AlignmentSorter.sortByID(viewport.getAlignment()); + alignPanel.repaint(); } public void sortGroupMenuItem_actionPerformed(ActionEvent e) { - addHistoryItem("sort"); - AlignmentSorter.sortByGroup(viewport.getAlignment()); - AlignmentSorter.sortGroups(viewport.getAlignment()); - alignPanel.RefreshPanels(); - } - - public void sortTreeOrderMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("sort"); - if(viewport.getCurrentTree()==null) - return; + addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, + HistoryItem.SORT)); - AlignmentSorter.sortByTree(viewport.getAlignment(), viewport.getCurrentTree()); - alignPanel.RefreshPanels(); + // AlignmentSorter.sortByGroup(viewport.getAlignment()); + AlignmentSorter.sortGroups(viewport.getAlignment()); + alignPanel.repaint(); } public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) { - RedundancyPanel sp = new RedundancyPanel(alignPanel); + RedundancyPanel sp = new RedundancyPanel(alignPanel, this); JInternalFrame frame = new JInternalFrame(); frame.setContentPane(sp); - Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, 100); - frame.setMaximizable(false); - frame.setResizable(false); - + Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, + 100, false); } public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) { - if(viewport.getSelection().size()<2) - JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE); + if ( (viewport.getSelectionGroup() == null) || + (viewport.getSelectionGroup().getSize() < 2)) + { + JOptionPane.showInternalMessageDialog(this, + "You must select at least 2 sequences.", + "Invalid Selection", + JOptionPane.WARNING_MESSAGE); + } else { JInternalFrame frame = new JInternalFrame(); @@ -709,28 +1183,35 @@ public class AlignFrame extends GAlignFrame public void PCAMenuItem_actionPerformed(ActionEvent e) { - if( (viewport.getSelection().size()<4 && viewport.getSelection().size()>0) - || viewport.getAlignment().getHeight()<4) + if ( ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() < 4) && + (viewport.getSelectionGroup().getSize() > 0)) || + (viewport.getAlignment().getHeight() < 4)) { - JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n" - +"at least 4 input sequences.", - "Sequence selection insufficient", - JOptionPane.WARNING_MESSAGE); + JOptionPane.showInternalMessageDialog(this, + "Principal component analysis must take\n" + + "at least 4 input sequences.", + "Sequence selection insufficient", + JOptionPane.WARNING_MESSAGE); + return; } - try{ + try + { PCAPanel pcaPanel = new PCAPanel(viewport, null); JInternalFrame frame = new JInternalFrame(); frame.setContentPane(pcaPanel); - Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400); - }catch(java.lang.OutOfMemoryError ex) - { - JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!", - "Out of memory", JOptionPane.WARNING_MESSAGE); - } - - + Desktop.addInternalFrame(frame, "Principal component analysis", + 400, 400); + } + catch (java.lang.OutOfMemoryError ex) + { + JOptionPane.showInternalMessageDialog(this, + "Too many sequences selected\nfor Principal Component Analysis!!", + "Out of memory", + JOptionPane.WARNING_MESSAGE); + } } public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) @@ -743,7 +1224,6 @@ public class AlignFrame extends GAlignFrame NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); } - protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) { NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); @@ -751,78 +1231,400 @@ public class AlignFrame extends GAlignFrame protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) { - NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID"); + NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62"); } void NewTreePanel(String type, String pwType, String title) { - JInternalFrame frame = new javax.swing.JInternalFrame(); - TreePanel tp=null; - if (viewport.getSelection() != null && viewport.getSelection().size() > 3) - { - tp = new TreePanel(viewport, viewport.getSelection().asVector(),type, pwType, - viewport.getStartRes(), viewport.getEndRes()); - } - else - { - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - type, pwType, viewport.getStartRes(), - viewport.getEndRes()); - } + String ltitle; + final TreePanel tp; + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 3)) + { + int s = 0; + SequenceGroup sg = viewport.getSelectionGroup(); + + /* Decide if the selection is a column region */ + while (s < sg.sequences.size()) + { + if ( ( (SequenceI) sg.sequences.elementAt(s++)).getLength() < + sg.getEndRes()) + { + JOptionPane.showMessageDialog(Desktop.desktop, + "The selected region to create a tree may\nonly contain residues or gaps.\n" + + "Try using the Pad function in the edit menu,\n" + + "or one of the multiple sequence alignment web services.", + "Sequences in selection are not aligned", + JOptionPane.WARNING_MESSAGE); + + return; + } + } + + title = title + " on region"; + tp = new TreePanel(viewport, + viewport.getSelectionGroup().sequences, type, pwType, + sg.getStartRes(), sg.getEndRes()); + } + else + { + //are the sequences aligned? + if (!viewport.alignment.isAligned()) + { + JOptionPane.showMessageDialog(Desktop.desktop, + "The sequences must be aligned before creating a tree.\n" + + "Try using the Pad function in the edit menu,\n" + + "or one of the multiple sequence alignment web services.", + "Sequences not aligned", + JOptionPane.WARNING_MESSAGE); + + return; + } + + tp = new TreePanel(viewport, + viewport.getAlignment().getSequences(), type, pwType, + 0, + viewport.alignment.getWidth()); + } + + addTreeMenuItem(tp, title); + viewport.setCurrentTree(tp.getTree()); + + Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500); + } + + public void addSortByOrderMenuItem(String title, final AlignmentOrder order) + { + final JMenuItem item = new JMenuItem("by " + title); + sort.add(item); + item.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Sort", viewport.alignment, + HistoryItem.SORT)); - frame.setContentPane(tp); - Desktop.addInternalFrame(frame, title, 600, 500); + // TODO: JBPNote - have to map order entries to curent SequenceI pointers + AlignmentSorter.sortBy(viewport.getAlignment(), order); + alignPanel.repaint(); + } + }); } + void addTreeMenuItem(final TreePanel treePanel, String title) + { + final JMenuItem item = new JMenuItem(title); + + treeCount++; + + if (treeCount == 1) + { + sort.add(sortByTreeMenu); + } + + sortByTreeMenu.add(item); + item.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Tree Sort", + viewport.alignment, HistoryItem.SORT)); + AlignmentSorter.sortByTree(viewport.getAlignment(), + treePanel.getTree()); + alignPanel.repaint(); + } + }); + + treePanel.addInternalFrameListener(new javax.swing.event. + InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + treeCount--; + sortByTreeMenu.remove(item); + if (treeCount == 0) + { + sort.remove(sortByTreeMenu); + } + } + ; + }); + viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals("alignment")) + { + treePanel.getTree().UpdatePlaceHolders( (Vector) evt.getNewValue()); + treePanel.repaint(); + } + } + }); + } public void clustalAlignMenuItem_actionPerformed(ActionEvent e) { - JOptionPane.showInternalMessageDialog(this, "Jalview is currently being reengineered" - +"\nwithin the Barton Group, Dundee University." - +"\nThis will be available as a web service 2005", - "Web service", JOptionPane.INFORMATION_MESSAGE); + // TODO:resolve which menu item was actually selected + // Now, check we have enough sequences + SequenceI[] msa = null; + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 1)) + { + // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! + SequenceGroup seqs = viewport.getSelectionGroup(); + int sz; + msa = new SequenceI[sz = seqs.getSize()]; + + for (int i = 0; i < sz; i++) + { + msa[i] = (SequenceI) seqs.getSequenceAt(i); + } + } + else + { + Vector seqs = viewport.getAlignment().getSequences(); + + if (seqs.size() > 1) + { + msa = new SequenceI[seqs.size()]; + + for (int i = 0; i < seqs.size(); i++) + { + msa[i] = (SequenceI) seqs.elementAt(i); + } + } + } + + if (msa != null) + { + jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", + title, msa, false, true); + } + } + + public void ClustalRealign_actionPerformed(ActionEvent e) + { + // TODO:resolve which menu item was actually selected + // Now, check we have enough sequences + SequenceI[] msa = null; + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 1)) + { + // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! + SequenceGroup seqs = viewport.getSelectionGroup(); + int sz; + msa = new SequenceI[sz = seqs.getSize()]; + + for (int i = 0; i < sz; i++) + { + msa[i] = (SequenceI) seqs.getSequenceAt(i); + } + } + else + { + Vector seqs = viewport.getAlignment().getSequences(); + + if (seqs.size() > 1) + { + msa = new SequenceI[seqs.size()]; + + for (int i = 0; i < seqs.size(); i++) + { + msa[i] = (SequenceI) seqs.elementAt(i); + } + } + } + + if (msa != null) + { + jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", + title, msa, true, true); + } } - public void pdbTest_actionPerformed(ActionEvent e) + protected void jpred_actionPerformed(ActionEvent e) { - String reply = JOptionPane.showInternalInputDialog(this, "Enter pdb code", "PDB test viewer", JOptionPane.QUESTION_MESSAGE); + SequenceI seq = null; + SequenceI[] msa = null; + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 0)) + { + // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! + SequenceGroup seqs = viewport.getSelectionGroup(); + + if ( (seqs.getSize() == 1) || !viewport.alignment.isAligned()) + { + seq = (SequenceI) seqs.getSequenceAt(0); + } + else + { + int sz; + msa = new SequenceI[sz = seqs.getSize()]; - String url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id=1a4u"; - if (reply.length()>1) - url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id="+reply; + for (int i = 0; i < sz; i++) + { + msa[i] = (SequenceI) seqs.getSequenceAt(i); + } + } + } + else + { + Vector seqs = viewport.getAlignment().getSequences(); - try - { - PDBfile pdb = new PDBfile(url, - "URL"); - Sequence seq = (Sequence)viewport.getAlignment().getSequenceAt(0); - seq.setPDBfile(pdb); - ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).isVisible = true; - ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).sequence = seq; - // ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).colourBySequence(); + if ( (seqs.size() == 1) || !viewport.alignment.isAligned()) + { + seq = (SequenceI) seqs.elementAt(0); + } + else + { + msa = new SequenceI[seqs.size()]; - rotCanvas rc = new rotCanvas(pdb); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(rc); - Desktop.addInternalFrame(frame, url, 400,400); - } - catch (Exception ex) - { - ex.printStackTrace(); - } + for (int i = 0; i < seqs.size(); i++) + { + msa[i] = (SequenceI) seqs.elementAt(i); + } + } + } + if (msa != null) + { + JPredClient ct = new JPredClient(title, msa); + } + else if (seq != null) + { + JPredClient ct = new JPredClient(title, seq); + } + else + { + System.err.print( + "JALVIEW ERROR! - Unexpected JPred selection state!\n"); + } } + protected void msaAlignMenuItem_actionPerformed(ActionEvent e) + { + // TODO:resolve which menu item was actually selected + // Now, check we have enough sequences + SequenceI[] msa = null; + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 1)) + { + // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! + SequenceGroup seqs = viewport.getSelectionGroup(); + int sz; + msa = new SequenceI[sz = seqs.getSize()]; + + for (int i = 0; i < sz; i++) + { + msa[i] = (SequenceI) seqs.getSequenceAt(i); + } + } + else + { + Vector seqs = viewport.getAlignment().getSequences(); + + if (seqs.size() > 1) + { + msa = new SequenceI[seqs.size()]; + + for (int i = 0; i < seqs.size(); i++) + { + msa[i] = (SequenceI) seqs.elementAt(i); + } + } + } + + if (msa != null) + { + MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS", title, msa, + false, true); + } + } - public void doKeyPressed(KeyEvent evt) + protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) { + // Pick the tree file + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty( + "LAST_DIRECTORY")); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Select a newick-like tree file"); + chooser.setToolTipText("Load a tree file"); + + int value = chooser.showOpenDialog(null); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + + try + { + jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, + "File"); + ShowNewickTree(fin, choice); + } + catch (Exception ex) + { + JOptionPane.showMessageDialog(Desktop.desktop, + "Problem reading tree file", + ex.getMessage(), + JOptionPane.WARNING_MESSAGE); + ex.printStackTrace(); + } + } + } - System.out.println(evt.getKeyChar()); - if(evt.isControlDown() && evt.getKeyChar()=='f') - findMenuItem_actionPerformed(null); + public void ShowNewickTree(NewickFile nf, String title) + { + try + { + nf.parse(); + if (nf.getTree() != null) + { + TreePanel tp = new TreePanel(viewport, + viewport.getAlignment().getSequences(), nf, + "FromFile", + title); + Desktop.addInternalFrame(tp, title, 600, 500); + addTreeMenuItem(tp, title); + viewport.setCurrentTree(tp.getTree()); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } } + class PrintThread + extends Thread + { + public void run() + { + PrinterJob printJob = PrinterJob.getPrinterJob(); + PageFormat pf = printJob.pageDialog(printJob.defaultPage()); + printJob.setPrintable(alignPanel, pf); + if (printJob.printDialog()) + { + try + { + printJob.print(); + } + catch (Exception PrintException) + { + PrintException.printStackTrace(); + } + } + } + } }