X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=8cb12d1be365795241d1fd1b761bcdbfb477d92e;hb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;hp=b504538d2cb0e45363a4d6fa1f2c656b4b75ec2a;hpb=14767e3e26b0c18a90566e02ab945426de6b847d;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b504538..8cb12d1 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1,674 +1,1388 @@ -/******************** - * 2004 Jalview Reengineered - * Barton Group - * Dundee University - * - * AM Waterhouse - *******************/ - - - - -package jalview.gui; - -import jalview.jbgui.GAlignFrame; -import jalview.schemes.*; -import jalview.datamodel.*; -import jalview.analysis.*; -import jalview.io.*; -import java.awt.event.*; -import java.awt.*; -import javax.swing.*; -import java.util.*; - -public class AlignFrame extends GAlignFrame -{ - final AlignmentPanel alignPanel; - final AlignViewport viewport; - public AlignFrame(AlignmentI al) - { - super(); - viewport = new AlignViewport(al,true,true,true,false); - alignPanel = new AlignmentPanel(this, viewport); - getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); - fontNameMenuItem.setText(viewport.getFont().getName()); - fontSizeMenuItem.setText(viewport.getFont().getSize()+""); - } - - protected void saveAs_actionPerformed(ActionEvent e) - { - JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY); - chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format."); - chooser.setToolTipText("Save"); - int value = chooser.showSaveDialog(this); - if(value == JFileChooser.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 ) ); - out.println(output); - out.close(); - } - 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())); - } - - protected void htmlMenuItem_actionPerformed(ActionEvent e) - { - HTMLOutput htmlOutput = new HTMLOutput(viewport.getAlignment(), alignPanel.seqPanel.getColourScheme()); - htmlOutput = null; - } - - public void saveAsPostscriptMenuItem_actionPerformed(ActionEvent e) - { - - } - - public void closeMenuItem_actionPerformed(ActionEvent e) - { - try{ - this.setClosed(true); - }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]); - } - 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]); - } - else - { - redoMenuItem.setEnabled(false); - redoMenuItem.setText("Redo"); - } - } - - public void addHistoryItem(String type) - { - // 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; i500) - newHeight=500; - Desktop.addInternalFrame(af, "Copied sequences", 700,newHeight); - } - - public void deselectAllColumnsMenuItem_actionPerformed(ActionEvent e) - { - viewport.getColumnSelection().clear(); - repaint(); - } - - public void remove2LeftMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("delete columns"); - ColumnSelection colSel = viewport.getColumnSelection(); - if (colSel.size() > 0) - { - int min = colSel.getMin(); - viewport.getAlignment().trimLeft(min); - colSel.compensateForEdit(0,min); - alignPanel.RefreshPanels(); - } - } - - public void remove2RightMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("delete columns"); - ColumnSelection colSel = viewport.getColumnSelection(); - if (colSel.size() > 0) - { - int max = colSel.getMax(); - if(max>1) - viewport.getAlignment().trimRight(max); - - alignPanel.RefreshPanels(); - } - - } - - public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("delete gapped columns"); - viewport.getAlignment().removeGaps(); - alignPanel.RefreshPanels(); - } - - public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("delete all gaps"); - 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 (current.getCharAt(j)=='-' || current.getCharAt(j)=='.' || current.getCharAt(j)==' ') - { - current.deleteCharAt(j); - j--; - jSize--; - } - } - - alignPanel.RefreshPanels(); - } - - public void setGapCharMenuItem_actionPerformed(ActionEvent e) - { - String thisChar = "-"; - String nextChar = "."; - if(viewport.getGapCharacter().equals("-")) - { - thisChar = "."; - nextChar = "-"; - } - setGapCharMenuItem.setText("Set gap character to \""+nextChar+"\""); - viewport.setGapCharacter(thisChar); - } - - - public void fontNameMenuItem_actionPerformed(ActionEvent e) - { - String fonts[] = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); - - - String selection = JOptionPane.showInputDialog(this, - "Select font", - "Font selection", - JOptionPane.QUESTION_MESSAGE, - null,fonts - ,fontNameMenuItem.getText()).toString(); - if(selection!=null) - { - fontNameMenuItem.setText(selection); - SetFont(); - } - - } - - public void fontSizeMenuItem_actionPerformed(ActionEvent e) - { - String selection = JOptionPane.showInputDialog(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(); - } - } - - public void fontStyleMenuItem_actionPerformed(ActionEvent e) - { - String selection = JOptionPane.showInputDialog(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(); - } - - } - - protected void colourTextMenuItem_actionPerformed(ActionEvent e) - { - viewport.setColourText( colourTextMenuItem.isSelected() ); - alignPanel.RefreshPanels(); - } - - void SetFont() - { - 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(); - - } - - protected void wrapMenuItem_actionPerformed(ActionEvent e) - { - viewport.setWrapAlignment( wrapMenuItem.isSelected() ); - alignPanel.setWrapAlignment( wrapMenuItem.isSelected() ); - } - - - public void viewBoxesMenuItem_actionPerformed(ActionEvent e) - { - viewport.setShowBoxes( viewBoxesMenuItem.isSelected() ); - alignPanel.RefreshPanels(); - } - - public void viewTextMenuItem_actionPerformed(ActionEvent e) - { - viewport.setShowText( viewTextMenuItem.isSelected() ); - alignPanel.RefreshPanels(); - } - - - public void consensusGraphMenuItem_actionPerformed(ActionEvent e) - { - alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() ); - } - - public void overviewMenuItem_actionPerformed(ActionEvent e) - { - - 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) - { - alignPanel.setOverviewPanel(null); - }; - }); - alignPanel.setOverviewPanel( overview ); - - }catch(java.lang.OutOfMemoryError ex) - { - JOptionPane.showMessageDialog(this, "Sequence alignment too large to\nproduce overview image!!" - +"\nTry reducing the font size.", - "Out of memory", JOptionPane.WARNING_MESSAGE); - } - - - } - - protected void noColourmenuItem_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme(null, false); - } - - - public void clustalColour_actionPerformed(ActionEvent e) - { - // alignPanel.setColourScheme( new ClustalxColourScheme() ); - } - - public void zappoColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new ZappoColourScheme(), conservationMenuItem.isSelected() ); - } - - public void taylorColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new TaylorColourScheme(),conservationMenuItem.isSelected() ); - } - - - public void hydrophobicityColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new HydrophobicColourScheme(),conservationMenuItem.isSelected() ); - } - - public void helixColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new HelixColourScheme(),conservationMenuItem.isSelected() ); - } - - - public void strandColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new StrandColourScheme() ,conservationMenuItem.isSelected() ); - } - - - public void turnColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new TurnColourScheme() ,conservationMenuItem.isSelected() ); - } - - - public void buriedColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new BuriedColourScheme() ,conservationMenuItem.isSelected() ); - } - - - protected void conservationMenuItem_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme ( alignPanel.seqPanel.getColourScheme(),conservationMenuItem.isSelected() ); - conservationColourIncMenuItem.setEnabled( conservationMenuItem.isSelected() ); - } - - - - public void conservationColourIncMenuItem_actionPerformed(ActionEvent e) - { - ConservationIncrementPanel cip = new ConservationIncrementPanel(viewport, alignPanel); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(cip); - Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400,90); - frame.setMaximizable(false); - } - - - public void abovePIDColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new PIDColourScheme() ,conservationMenuItem.isSelected() ); - } - - - public void userDefinedColour_actionPerformed(ActionEvent e) - { - JInternalFrame frame = new JInternalFrame(); - UserDefinedColours chooser = new UserDefinedColours( frame, alignPanel.seqPanel ); - frame.setContentPane(chooser); - Desktop.addInternalFrame(frame,"User defined colours", 450,540 ); - frame.setResizable(false); - frame.setIconifiable(false); - frame.setMaximizable(false); - } - - public void PIDColour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new PIDColourScheme(),conservationMenuItem.isSelected() ); - } - - - public void BLOSUM62Colour_actionPerformed(ActionEvent e) - { - alignPanel.setColourScheme( new Blosum62ColourScheme(viewport) ,conservationMenuItem.isSelected() ); - } - - - - protected void schemeKeyMenuItem_actionPerformed(ActionEvent e) - { - ColourKey colourKey = new ColourKey( alignPanel.seqPanel.getColourScheme() ); - Desktop.addInternalFrame(colourKey, "Colour scheme key", 400, 320); - } - - - public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("sort"); - AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0)); - alignPanel.RefreshPanels(); - } - - public void sortIDMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("sort"); - AlignmentSorter.sortByID( viewport.getAlignment() ); - alignPanel.RefreshPanels(); - } - - public void sortGroupMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("sort"); - AlignmentSorter.sortGroups(viewport.getAlignment()); - AlignmentSorter.sortGroups(viewport.getAlignment()); - alignPanel.RefreshPanels(); - } - - public void sortTreeOrderMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem("sort"); - if(viewport.getCurrentTree()==null) - return; - - AlignmentSorter.sortByTree(viewport.getAlignment(), viewport.getCurrentTree()); - alignPanel.RefreshPanels(); - } - - public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) - { - - } - - public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) - { - if(viewport.getSelection().size()<2) - JOptionPane.showMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE); - else - { - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(new PairwiseAlignPanel(viewport)); - Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500); - } - } - - public void PCAMenuItem_actionPerformed(ActionEvent e) - { - if( (viewport.getSelection().size()<4 && viewport.getSelection().size()>0) - || viewport.getAlignment().getHeight()<4) - { - JOptionPane.showMessageDialog(this, "Principal component analysis must take\n" - +"at least 4 input sequences.", - "Sequence selection insufficient", - JOptionPane.WARNING_MESSAGE); - return; - } - - 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.showMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!", - "Out of memory", JOptionPane.WARNING_MESSAGE); - } - - - } - - public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("AV", "PID", "Average distance tree using PID"); - } - - public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); - } - - - protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); - } - - protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID"); - } - - 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()); - } - - frame.setContentPane(tp); - Desktop.addInternalFrame(frame, title, 600, 500); - } - - - - public void clustalAlignMenuItem_actionPerformed(ActionEvent e) - { - JOptionPane.showMessageDialog(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); - } - -} +/* +* Jalview - A Sequence Alignment Editor and Viewer +* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* +* 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 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 jalview.analysis.*; +import jalview.datamodel.*; +import jalview.io.*; +import jalview.jbgui.*; +import jalview.schemes.*; +import jalview.ws.*; +import java.beans.PropertyChangeEvent; + +public class AlignFrame extends GAlignFrame +{ + final AlignmentPanel alignPanel; + final AlignViewport viewport; + public static final int NEW_WINDOW_WIDTH = 700; + public static final int NEW_WINDOW_HEIGHT = 500; + public String currentFileFormat = "Jalview"; + + public AlignFrame(AlignmentI al) + { + 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); + + addInternalFrameListener(new InternalFrameAdapter() + { + public void internalFrameActivated(InternalFrameEvent evt) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { alignPanel.requestFocus(); } + }); + + } + }); + + } + + public void saveAlignmentMenu_actionPerformed(ActionEvent e) + { + 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 == JalviewFileChooser.APPROVE_OPTION) + { + 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){} + } + + } + + protected void outputText_actionPerformed(ActionEvent e) + { + 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) + { + new HTMLOutput(viewport); + } + + protected void createPNG_actionPerformed(ActionEvent e) + { + alignPanel.makePNG(); + } + + protected void epsFile_actionPerformed(ActionEvent e) + { + alignPanel.makeEPS(); + } + + + public void printMenuItem_actionPerformed(ActionEvent e) + { + //Putting in a thread avoids Swing painting problems + PrintThread thread = new PrintThread(); + thread.start(); + } + + 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(); + } + } + } + + } + + + + + public void closeMenuItem_actionPerformed(ActionEvent e) + { + try{ + this.setClosed(true); + }catch(Exception ex){} + } + + Stack historyList = new Stack(); + Stack redoList = new Stack(); + private int treeCount = 0; + + void updateEditMenuBar() + { + 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); + HistoryItem hi = (HistoryItem)redoList.peek(); + redoMenuItem.setText("Redo "+hi.getDescription()); + } + else + { + redoMenuItem.setEnabled(false); + redoMenuItem.setText("Redo"); + } + } + + public void addHistoryItem(HistoryItem hi) + { + historyList.push(hi); + updateEditMenuBar(); + } + + protected void undoMenuItem_actionPerformed(ActionEvent e) + { + HistoryItem hi = (HistoryItem)historyList.pop(); + redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, HistoryItem.HIDE)); + restoreHistoryItem(hi); + } + + + protected void redoMenuItem_actionPerformed(ActionEvent e) + { + HistoryItem hi = (HistoryItem)redoList.pop(); + restoreHistoryItem(hi); + updateEditMenuBar(); + viewport.updateConsensus(); + alignPanel.repaint(); + alignPanel.repaint(); + } + + + // used by undo and redo + void restoreHistoryItem(HistoryItem hi) + { + if(hi.getType()== HistoryItem.SORT) + { + for(int i=0; ihi.getSequences().size()-1; i--) + viewport.alignment.deleteSequence(i); + } + } + updateEditMenuBar(); + + viewport.updateConsensus(); + viewport.updateConservation(); + alignPanel.repaint(); + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); + } + + public void moveSelectedSequences(boolean up) + { + SequenceGroup sg = viewport.getSelectionGroup(); + if (sg == null) + return; + + if (up) + { + for (int i = 1; i < viewport.alignment.getHeight(); i++) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); + if (!sg.sequences.contains(seq)) + 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); + } + } + else + { + for (int i = viewport.alignment.getHeight() - 2; i > -1; i--) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); + if (!sg.sequences.contains(seq)) + 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.repaint(); + } + + + + protected void copy_actionPerformed(ActionEvent e) + { + if(viewport.getSelectionGroup()==null) + return; + + SequenceGroup sg = viewport.getSelectionGroup(); + + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer buffer= new StringBuffer(); + + Hashtable orderedSeqs = new Hashtable(); + for(int i=0; i 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 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; i0) + || viewport.getAlignment().getHeight()<4) + { + JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n" + +"at least 4 input sequences.", + "Sequence selection insufficient", + JOptionPane.WARNING_MESSAGE); + return; + } + + 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); + } + + + } + + public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) + { + NewTreePanel("AV", "PID", "Average distance tree using PID"); + } + + public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) + { + NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); + } + + + protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) + { + NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); + } + + protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) + { + NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62"); + } + + void NewTreePanel(String type, String pwType, String title) + { + 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 (s1) + { + // 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); + } + } + + + protected void jpred_actionPerformed(ActionEvent e) +{ + 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()]; + for (int i = 0; i < sz; i++) + { + msa[i] = (SequenceI) seqs.getSequenceAt(i); + } + } + } + else + { + Vector seqs = viewport.getAlignment().getSequences(); + + if (seqs.size() == 1 || !viewport.alignment.isAligned()) + { + seq = (SequenceI) seqs.elementAt(0); + } + else + { + msa = new SequenceI[seqs.size()]; + 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); + } + } + 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(); + } + } + } + + 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();} + } + +}