X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=8cb12d1be365795241d1fd1b761bcdbfb477d92e;hb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;hp=42094550da539211cfc9eaf91002ff01d5cb9977;hpb=798a8f1eda50a57b71e21df22e015da1364ffd1c;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 4209455..8cb12d1 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1,1062 +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 jalview.ws.*; -import java.awt.*; -import java.awt.event.*; -import java.awt.print.*; -import javax.swing.*; -import javax.swing.event.*; -import java.util.*; -import java.awt.datatransfer.*; - - -public class AlignFrame extends GAlignFrame -{ - final AlignmentPanel alignPanel; - final AlignViewport viewport; - public AlignFrame(AlignmentI al) - { - super(); - viewport = new AlignViewport(al,true,true,true,false); - - String fontName = jalview.bin.Cache.getProperty("FONT_NAME"); - String fontStyle= jalview.bin.Cache.getProperty("FONT_STYLE"); - String fontSize = jalview.bin.Cache.getProperty("FONT_SIZE"); - if(fontName!=null && fontStyle!=null && fontSize!=null) - viewport.setFont( new Font(fontName,Integer.parseInt(fontStyle),Integer.parseInt(fontSize)) ); - - - - alignPanel = new AlignmentPanel(this, viewport); - 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(); } - }); - - } - }); - - } - - protected void saveAs_actionPerformed(ActionEvent e) - { - JFileChooser chooser = new JFileChooser(jalview.bin.Cache.getProperty("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.setProperty("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); - htmlOutput = null; - } - - protected void createJPG_actionPerformed(ActionEvent e) - { - - int height = (viewport.alignment.getWidth() / viewport.getChunkWidth() +1) * viewport.chunkHeight; - int width = alignPanel.seqPanel.getWidth() + alignPanel.idPanel.getWidth(); - - - if(!viewport.getWrapAlignment()) - { - height = viewport.alignment.getHeight() * viewport.charHeight; - width = alignPanel.idPanel.getWidth() + viewport.alignment.getWidth() * viewport.charWidth; - } - - alignPanel.makeJPG( width, height); - } - - - 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(); - - 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; 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.RefreshPanels(); - } - - - - protected void copy_actionPerformed(ActionEvent e) - { - if(viewport.getRubberbandGroup()==null) - return; - - SequenceGroup sg = viewport.getRubberbandGroup(); - - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - StringBuffer buffer= new StringBuffer(); - - for(int i=0; i 500) - newHeight = 500; - Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight); - } - else - { - viewport.setEndSeq(viewport.alignment.getHeight()); - viewport.alignment.getWidth(); - alignPanel.RefreshPanels(); - } - - }catch(Exception ex){}// could be anything being pasted in here - - } - - - protected void cut_actionPerformed(ActionEvent e) - { - copy_actionPerformed(null); - delete_actionPerformed(null); - } - - protected void delete_actionPerformed(ActionEvent e) - { - addHistoryItem("Delete"); - if (viewport.getRubberbandGroup() == null) - return; - - SequenceGroup sg = viewport.getRubberbandGroup(); - 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) - viewport.getAlignment().deleteSequence(seq); - else - viewport.getAlignment().getSequences().setElementAt(seq, index); - } - - viewport.setRubberbandGroup(null); - viewport.alignment.deleteGroup(sg); - viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight()); - if(viewport.getAlignment().getHeight()<1) - try - { - this.setClosed(true); - }catch(Exception ex){} - alignPanel.RefreshPanels(); - - } - - - - protected void redoMenuItem_actionPerformed(ActionEvent e) - { - Object [] history = (Object[])redoList.remove(0); - SequenceI[] seq = (SequenceI[]) history[1]; - viewport.setAlignment( new Alignment(seq) ); - updateEditMenuBar(); - alignPanel.RefreshPanels(); - } - - - public void groupsMenuItem_actionPerformed(ActionEvent e) - { - GroupEditor geditor = new GroupEditor(viewport, alignPanel); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(geditor); - Desktop.addInternalFrame(frame, "Group editor", 710, 410); - frame.setResizable(false); - } - - protected void deleteGroups_actionPerformed(ActionEvent e) - { - viewport.alignment.deleteAllGroups(); - viewport.getSelection().clear(); - - alignPanel.RefreshPanels(); - } - - - - public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) - { - Selection sel = viewport.getSelection(); - for (int i=0; i 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(jalview.util.Comparison.isGap(current.getCharAt(j))) - { - current.deleteCharAt(j); - j--; - jSize--; - } - } - - alignPanel.RefreshPanels(); - } - - public void setGapCharMenuItem_actionPerformed(ActionEvent e) - { - char thisChar = '-'; - char nextChar = '.'; - if(viewport.getGapCharacter()=='-') - { - thisChar = '.'; - nextChar = '-'; - } - setGapCharMenuItem.setText("Set gap character to \""+nextChar+"\""); - viewport.setGapCharacter(thisChar); - alignPanel.RefreshPanels(); - } - - 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); - - } - - - public void font_actionPerformed(ActionEvent e) - { - // JOptionPane op = new JOptionPane(); - JInternalFrame frame = new JInternalFrame(); - FontChooser fc = new FontChooser( alignPanel, frame ); - frame.setContentPane(fc); - Desktop.addInternalFrame(frame, "Change Font", 480,100); - } - - protected void colourTextMenuItem_actionPerformed(ActionEvent e) - { - viewport.setColourText( colourTextMenuItem.isSelected() ); - 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(); - } - - - protected void renderGapsMenuItem_actionPerformed(ActionEvent e) - { - viewport.setRenderGaps(renderGapsMenuItem.isSelected()); - alignPanel.RefreshPanels(); - } - - public void sequenceFeatures_actionPerformed(ActionEvent evt) - { - viewport.showSequenceFeatures(sequenceFeatures.isSelected()); - if(viewport.showSequenceFeatures && !((Alignment)viewport.alignment).featuresAdded) - { - AlignmentUtil.fetchSequenceFeatures( viewport.alignment , alignPanel); - ((Alignment)viewport.alignment).featuresAdded = true; - } - alignPanel.RefreshPanels(); - } - - public void consensusGraphMenuItem_actionPerformed(ActionEvent e) - { - alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() ); - } - - public void overviewMenuItem_actionPerformed(ActionEvent e) - { - if (alignPanel.overviewPanel != null) - return; - - 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.showInternalMessageDialog(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) - { - changeColour( null ); - } - - - public void clustalColour_actionPerformed(ActionEvent e) - { - abovePIDThreshold.setSelected(false); - 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) - { - changeColour( new HydrophobicColourScheme() ); - } - - public void helixColour_actionPerformed(ActionEvent e) - { - changeColour(new HelixColourScheme() ); - } - - - public void strandColour_actionPerformed(ActionEvent e) - { - changeColour(new StrandColourScheme()); - } - - - 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) - { - - if(viewport.getColourAppliesToAllGroups()) - { - 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 BLOSUM62PID"); - } - - void NewTreePanel(String type, String pwType, String title) - { - //are the sequences aligned? - if(!viewport.alignment.isAligned()) - { - JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.", - "Sequences not aligned", JOptionPane.WARNING_MESSAGE); - return; - } - - TreePanel tp=null; - if (viewport.getSelection() != null && viewport.getSelection().size() > 3) - { - tp = new TreePanel(viewport, viewport.getSelection().asVector(),type, pwType, - 0, viewport.alignment.getWidth()); - } - else - { - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - type, pwType, 0, viewport.alignment.getWidth()); - } - - Desktop.addInternalFrame(tp, title, 600, 500); - } - - - - - public void clustalAlignMenuItem_actionPerformed(ActionEvent e) - { - JInternalFrame frame = new JInternalFrame(); - ClustalThread ct = new ClustalThread(frame); - Thread t = new Thread(ct); - t.start(); - frame.setContentPane(ct); - Desktop.addInternalFrame(frame, title, 300, 80); - - } - - class ClustalThread extends JPanel implements Runnable - { - Image [] image; - int imageIndex = 0; - boolean webServiceRunning = false; - JInternalFrame frame; - public ClustalThread(JInternalFrame frame) - { - this.frame = frame; - image = new Image[9]; - for(int i=0; i<9; i++) - { - java.net.URL url = getClass().getResource("/images/dna" + (i+1) + ".gif"); - if (url != null) - { - image[i] = java.awt.Toolkit.getDefaultToolkit().createImage(url); - MediaTracker mt = new MediaTracker(this); - mt.addImage(image[i], i); - try{mt.waitForID(i);} - catch(Exception ex){} - } - } - DNATwirler twirler = new DNATwirler(); - twirler.start(); - webServiceRunning = true; - } - - class DNATwirler extends Thread - { - public void run() - { - while(webServiceRunning) - { - try{ - Thread.sleep(100); - imageIndex++; - imageIndex %=9; - repaint(); - } - catch(Exception ex){} - } - } - } - - // JBPNote - // Should check to see if the server settings are valid - // Need visual-delay indication here. - public void run() - { - jalview.ws.Jemboss jemboss = new jalview.ws.Jemboss(); - Vector sv = viewport.getAlignment().getSequences(); - SequenceI[] seqs = new SequenceI[sv.size()]; - - int i = 0; - do - { - seqs[i] = (SequenceI) sv.elementAt(i); - } - while (++i < sv.size()); - - SequenceI[] alignment = jemboss.clustalW(seqs); // gaps removed within method - - if (alignment != null) - { - AlignFrame af = new AlignFrame(new Alignment(alignment)); - af.clustalColour.setSelected(true); - af.clustalColour_actionPerformed(null); - Desktop.addInternalFrame(af, getTitle().concat(" - ClustalW Alignment"), - 700, 500); // JBPNote - is there a new window geom. property ? - } - else - JOptionPane.showMessageDialog(Desktop.desktop, "Problem obtaining clustal alignment", "Web service error", - JOptionPane.WARNING_MESSAGE); - - webServiceRunning = false; - try{ - frame.setClosed(true); - }catch(Exception ex){} - } - - public void paintComponent(Graphics g) - { - g.setColor(Color.white); - g.fillRect(0,0,getWidth(), getHeight()); - if(image!=null) - { - g.drawImage(image[imageIndex],10,10,this); - } - g.setFont(new Font("Arial", Font.BOLD, 12)); - g.setColor(Color.black); - g.drawString("Clustal Alignment Web Service running", 30,30); - } - } -} +/* +* 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();} + } + +}