X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=7499b4eb0b5b33c73f301d6badf7dccb4e45d760;hb=085727a32930d9a05becd66686ed001f50331bc6;hp=b00a584baa6de294244da59889262f0905eb39fc;hpb=dbfdb02d549e91942095e39c2a50259b1c54c256;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b00a584..7499b4e 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1,135 +1,160 @@ -/******************** - * 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 jalview.ws.*; +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.*; -import java.awt.datatransfer.*; +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.io.*; +import jalview.jbgui.*; +import jalview.schemes.*; +import jalview.ws.*; -public class AlignFrame extends GAlignFrame +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; + 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) { - try{ - String ip = java.net.InetAddress.getLocalHost().getHostAddress(); - if( !ip.startsWith("10.")) - alignMenu.setVisible(false); - } - catch(java.net.UnknownHostException e){} - viewport = new AlignViewport(al,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)) ); - - // add conservation graph to alignment - viewport.updateConservation(); - viewport.updateConsensus(); - + 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.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 internalFrameActivated(InternalFrameEvent evt) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() { - public void run() - { alignPanel.requestFocus(); } - }); - - } - }); - + alignPanel.requestFocus(); + } + }); + } + }); } - protected void saveAs_actionPerformed(ActionEvent e) + public void saveAlignmentMenu_actionPerformed(ActionEvent e) { - String suffix [] = null; - if(e.getActionCommand().equals("FASTA")) - suffix = new String[]{"fa", "fasta"}; - else if(e.getActionCommand().equals("MSF")) - suffix = new String[]{"msf"}; - else if(e.getActionCommand().equals("CLUSTAL")) - suffix = new String[]{"aln"}; - else if(e.getActionCommand().equals("BLC")) - suffix = new String[]{"blc"}; - else if(e.getActionCommand().equals("PIR")) - suffix = new String[]{"pir"}; - else if(e.getActionCommand().equals("PFAM")) - suffix = new String[]{"pfam"}; - + 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); - JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY") - , suffix, e.getActionCommand()+" file"); + chooser.setAcceptAllFileFilterUsed(false); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format."); + chooser.setDialogTitle("Save Alignment to file"); chooser.setToolTipText("Save"); + int value = chooser.showSaveDialog(this); - if(value == JalviewFileChooser.APPROVE_OPTION) + + if (value == JalviewFileChooser.APPROVE_OPTION) { - String choice = chooser.getSelectedFile().getPath(); + 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.SaveAlignment(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.get(e.getActionCommand(), viewport.getAlignment().getSequences()); - try{ - java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( 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); } protected void createPNG_actionPerformed(ActionEvent e) @@ -142,7 +167,6 @@ public class AlignFrame extends GAlignFrame alignPanel.makeEPS(); } - public void printMenuItem_actionPerformed(ActionEvent e) { //Putting in a thread avoids Swing painting problems @@ -150,62 +174,39 @@ public class AlignFrame extends GAlignFrame 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{ + try + { this.setClosed(true); - }catch(Exception ex){} + } + catch (Exception ex) + { + } } - Stack historyList = new Stack(); - Stack redoList = new Stack(); - JMenuBar jMenuBar1 = new JMenuBar(); - 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); @@ -213,61 +214,105 @@ 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); + } + } } - ///////// - redoList.add(0, new Object[] {history[0], seq}); + updateEditMenuBar(); - seq = (SequenceI[]) history[1]; - viewport.setAlignment( new Alignment(seq) ); - updateEditMenuBar(); - viewport.updateConsensus(); - alignPanel.RefreshPanels(); - alignPanel.RefreshPanels(); + 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); @@ -278,44 +323,78 @@ public class AlignFrame extends GAlignFrame 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.RefreshPanels(); + alignPanel.repaint(); } - - protected void copy_actionPerformed(ActionEvent e) { - if(viewport.getSelectionGroup()==null) - return; + if (viewport.getSelectionGroup() == null) + { + return; + } - SequenceGroup sg = viewport.getSelectionGroup(); + SequenceGroup sg = viewport.getSelectionGroup(); - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - StringBuffer buffer= new StringBuffer(); + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer buffer = new StringBuffer(); - 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); + colSel.compensateForEdit(0, min); - if(viewport.getSelectionGroup()!=null) + 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) + + if (viewport.getSelectionGroup() != null) + { viewport.getSelectionGroup().adjustForRemoveRight(max); + } Vector groups = viewport.alignment.getGroups(); - for(int i=0; i0) - || 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) @@ -1018,7 +1244,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"); @@ -1026,186 +1251,344 @@ 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) { - //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; - } - final TreePanel tp; - if (viewport.getSelectionGroup() != null && - viewport.getSelectionGroup().getSize() > 3) + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 3)) { - tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type, - pwType, - 0, viewport.alignment.getWidth()); + 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 { - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - type, pwType, 0, viewport.alignment.getWidth()); + //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); + addTreeMenuItem(tp, title); + viewport.setCurrentTree(tp.getTree()); - Desktop.addInternalFrame(tp, title, 600, 500); + 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)); + + // 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("sort"); - AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree()); - alignPanel.RefreshPanels(); + addHistoryItem(new HistoryItem("Tree Sort", + viewport.alignment, HistoryItem.SORT)); + AlignmentSorter.sortByTree(viewport.getAlignment(), + treePanel.getTree()); + alignPanel.repaint(); } }); - treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + treePanel.addInternalFrameListener(new javax.swing.event. + InternalFrameAdapter() { - public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) + 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) { - WebserviceInfo info = new WebserviceInfo("Clustal web service", - "\"Thompson, J.D., Higgins, D.G. and Gibson, T.J. (1994) CLUSTAL W: improving the sensitivity of progressive multiple"+ - " sequence alignment through sequence weighting, position specific gap penalties and weight matrix choice." - +" Nucleic Acids Research, submitted, June 1994.", - 450, 150); + // TODO:resolve which menu item was actually selected + // Now, check we have enough sequences + SequenceI[] msa = null; - ClustalThread thread = new ClustalThread(info); - thread.start(); - } + 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()]; - class ClustalThread extends Thread + for (int i = 0; i < sz; i++) + { + msa[i] = (SequenceI) seqs.getSequenceAt(i); + } + } + else { - WebserviceInfo info; - public ClustalThread(WebserviceInfo info) - {this.info = info; } + Vector seqs = viewport.getAlignment().getSequences(); - public void run() + if (seqs.size() > 1) { - info.setStatus(WebserviceInfo.STATE_RUNNING); - jalview.ws.Jemboss jemboss = new jalview.ws.Jemboss(); - Vector sv = viewport.getAlignment().getSequences(); - SequenceI[] seqs = new SequenceI[sv.size()]; + msa = new SequenceI[seqs.size()]; - int i = 0; - do + for (int i = 0; i < seqs.size(); i++) { - seqs[i] = (SequenceI) sv.elementAt(i); + msa[i] = (SequenceI) seqs.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)); - Desktop.addInternalFrame(af, title.concat(" - ClustalW Alignment"), - NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT); - af.clustalColour_actionPerformed(null); - af.clustalColour.setSelected(true); - info.setStatus(WebserviceInfo.STATE_STOPPED_OK); - } - else + 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++) { - info.setStatus(WebserviceInfo.STATE_STOPPED_ERROR); - info.appendProgressText("Problem obtaining clustal alignment"); + 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) + 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()) + + if ( (seqs.getSize() == 1) || !viewport.alignment.isAligned()) { - JPredClient ct = new JPredClient( (SequenceI)seqs.getSequenceAt(0)); + seq = (SequenceI) seqs.getSequenceAt(0); } else { int sz; - SequenceI[] msa = new SequenceI[sz=seqs.getSize()]; + msa = new SequenceI[sz = seqs.getSize()]; + for (int i = 0; i < sz; i++) { msa[i] = (SequenceI) seqs.getSequenceAt(i); } - - JPredClient ct = new JPredClient(msa); } - } else { Vector seqs = viewport.getAlignment().getSequences(); - if (seqs.size() == 1 || !viewport.alignment.isAligned()) + if ( (seqs.size() == 1) || !viewport.alignment.isAligned()) { - JPredClient ct = new JPredClient( (SequenceI) - seqs.elementAt(0)); + seq = (SequenceI) seqs.elementAt(0); } else { - SequenceI[] msa = new SequenceI[seqs.size()]; + 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(); - JPredClient ct = new JPredClient(msa); + 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) { + protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) + { // Pick the tree file JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. - getProperty("LAST_DIRECTORY")); + 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); - TreePanel treepanel = null; + try { - jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File"); - fin.parse(); - - if (fin.getTree() != null) - { - TreePanel tp = null; - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - fin, "FromFile", choice); - Desktop.addInternalFrame(tp, title, 600, 500); - addTreeMenuItem(tp, title); - } + jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, + "File"); + viewport.setCurrentTree( ShowNewickTree(fin, choice).getTree() ); } catch (Exception ex) { @@ -1218,4 +1601,49 @@ public class AlignFrame extends GAlignFrame } } + public TreePanel ShowNewickTree(NewickFile nf, String title) + { + TreePanel tp = null; + try + { + nf.parse(); + if (nf.getTree() != null) + { + tp = new TreePanel(viewport, + viewport.getAlignment().getSequences(), nf, + "FromFile", + title); + Desktop.addInternalFrame(tp, title, 600, 500); + addTreeMenuItem(tp, title); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + return tp; + } + + 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(); + } + } + } + } }