X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=d154e2ea4f905796517af33d169c69a3589c55aa;hb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;hp=a21aabe7c25ca3a54071fba19ce810cf97ca2949;hpb=affd24332b831acf0ffe4697dc1efafe8e414b31;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index a21aabe..d154e2e 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1,1230 +1,2136 @@ -/******************** - * 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.analysis.*; +import jalview.datamodel.*; +import jalview.io.*; -package jalview.gui; +import jalview.jbgui.*; -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.datatransfer.*; import java.awt.event.*; import java.awt.print.*; + +import java.io.*; + +import java.beans.*; + +import java.util.*; + import javax.swing.*; import javax.swing.event.*; -import java.util.*; -import java.awt.datatransfer.*; +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ 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 AlignFrame(AlignmentI al) - { - try{ - String ip = java.net.InetAddress.getLocalHost().getHostAddress(); - if( !ip.startsWith("10.")) - webService.setVisible(false); - } - catch(java.net.UnknownHostException e){} - 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(); } - }); - - } - }); - - } - - protected void saveAs_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") - , suffix, e.getActionCommand()+" file"); - chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format."); - chooser.setToolTipText("Save"); - int value = chooser.showSaveDialog(this); - if(value == JalviewFileChooser.APPROVE_OPTION) - { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - String output = FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences()); + /** DOCUMENT ME!! */ + public static final int NEW_WINDOW_WIDTH = 700; + + /** DOCUMENT ME!! */ + public static final int NEW_WINDOW_HEIGHT = 500; + final AlignmentPanel alignPanel; + final AlignViewport viewport; + + /** DOCUMENT ME!! */ + public String currentFileFormat = null; + Stack historyList = new Stack(); + Stack redoList = new Stack(); + private int treeCount = 0; + + /** + * Creates a new AlignFrame object. + * + * @param al DOCUMENT ME! + */ + 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(); + } + }); + } + }); + } + + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void parseGroupsFile(String file) + { 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 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 + BufferedReader in = new BufferedReader(new FileReader(file)); + SequenceI seq=null; + String line, text, token; + UserColourScheme ucs; + int index, start, end; + StringTokenizer st; + SequenceGroup sg; + while( (line = in.readLine())!=null) { - printJob.print(); + st = new StringTokenizer(line, "\t"); + if(st.countTokens()!=6) + { + System.out.println("Groups file "+file+" is invalid. Read help file."); + System.exit(1); + } + + while(st.hasMoreElements()) + { + text = st.nextToken(); + token = st.nextToken(); + if(!token.equals("ID_NOT_SPECIFIED")) + { + index = viewport.alignment.findIndex(viewport.alignment.findName( + token)); + st.nextToken(); + } + else + index = Integer.parseInt( st.nextToken() ); + + start=Integer.parseInt( st.nextToken() ); + end = Integer.parseInt( st.nextToken() ); + ucs = new UserColourScheme(st.nextToken()); + + seq = viewport.alignment.getSequenceAt(index); + start = seq.findIndex(start)-1; + end = seq.findIndex(end)-1; + + sg = new SequenceGroup(text,ucs,true,true,false,start,end); + sg.addSequence( seq,true); + + viewport.alignment.addGroup(sg); + } } - catch (Exception PrintException) + + }catch(Exception ex){System.out.println("Error parsing groups file: "+ex);} + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + 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) { - PrintException.printStackTrace(); + currentFileFormat = chooser.getSelectedFormat(); + jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", + currentFileFormat); + + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + + saveAlignment(choice, currentFileFormat); } - } } - } + public boolean saveAlignment(String file, String format) + { + if (format.equalsIgnoreCase("Jalview")) + { + String shortName = title; + if (shortName.indexOf(java.io.File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + java.io.File.separatorChar) + 1); + } + Jalview2XML.SaveAlignment(this, file, shortName); + // USE Jalview2XML to save this file + return true; + } + else + { + String output = FormatAdapter.formatSequences(format, + viewport.getAlignment(). + getSequences()); + if(output==null) + return false; - public void closeMenuItem_actionPerformed(ActionEvent e) - { - try{ - this.setClosed(true); - }catch(Exception ex){} - } + try + { + java.io.PrintWriter out = new java.io.PrintWriter( + new java.io.FileWriter(file)); + out.println(output); + out.close(); + return true; + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + return false; + } - 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 + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void outputText_actionPerformed(ActionEvent e) { - undoMenuItem.setEnabled(false); - undoMenuItem.setText("Undo"); + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + Desktop.addInternalFrame(cap, + "Alignment output - " + e.getActionCommand(), 600, 500); + cap.setText(FormatAdapter.formatSequences(e.getActionCommand(), + viewport.getAlignment().getSequences())); } - if(redoList.size()>0) - { - redoMenuItem.setEnabled(true); - Object [] history = (Object[])redoList.get(0); - redoMenuItem.setText("Redo "+history[0]); - } - else + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void htmlMenuItem_actionPerformed(ActionEvent e) { - redoMenuItem.setEnabled(false); - redoMenuItem.setText("Redo"); + new HTMLOutput(viewport); } - } - 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 0) + { + undoMenuItem.setEnabled(true); - SequenceI temp = viewport.alignment.getSequenceAt(i - 1); - if (sg.sequences.contains(temp)) - continue; + HistoryItem hi = (HistoryItem) historyList.peek(); + undoMenuItem.setText("Undo " + hi.getDescription()); + } + else + { + undoMenuItem.setEnabled(false); + undoMenuItem.setText("Undo"); + } - viewport.alignment.getSequences().setElementAt(temp, i); - viewport.alignment.getSequences().setElementAt(seq, i - 1); - } + if (redoList.size() > 0) + { + redoMenuItem.setEnabled(true); + + HistoryItem hi = (HistoryItem) redoList.peek(); + redoMenuItem.setText("Redo " + hi.getDescription()); + } + else + { + redoMenuItem.setEnabled(false); + redoMenuItem.setText("Redo"); + } } - else + + /** + * DOCUMENT ME! + * + * @param hi DOCUMENT ME! + */ + public void addHistoryItem(HistoryItem hi) { - for (int i = viewport.alignment.getHeight() - 2; i > -1; i--) - { - SequenceI seq = viewport.alignment.getSequenceAt(i); - if (!sg.sequences.contains(seq)) - continue; + historyList.push(hi); + updateEditMenuBar(); + } - SequenceI temp = viewport.alignment.getSequenceAt(i + 1); - if (sg.sequences.contains(temp)) - continue; + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void undoMenuItem_actionPerformed(ActionEvent e) + { + HistoryItem hi = (HistoryItem) historyList.pop(); + redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, + HistoryItem.HIDE)); + restoreHistoryItem(hi); + } - viewport.alignment.getSequences().setElementAt(temp, i); - viewport.alignment.getSequences().setElementAt(seq, i + 1); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void redoMenuItem_actionPerformed(ActionEvent e) + { + HistoryItem hi = (HistoryItem) redoList.pop(); + restoreHistoryItem(hi); + updateEditMenuBar(); + viewport.updateConsensus(); + alignPanel.repaint(); + alignPanel.repaint(); } - alignPanel.repaint(); - } + // used by undo and redo + void restoreHistoryItem(HistoryItem hi) + { + if (hi.getType() == HistoryItem.SORT) + { + for (int i = 0; i < hi.getSequences().size(); i++) + { + viewport.alignment.getSequences().setElementAt(hi.getSequences() + .elementAt(i), + i); + } + } + else + { + for (int i = 0; i < hi.getSequences().size(); i++) + { + SequenceI restore = (SequenceI) hi.getSequences().elementAt(i); + + if (restore.getLength() == 0) + { + restore.setSequence(hi.getHidden().elementAt(i).toString()); + viewport.alignment.getSequences().insertElementAt(restore, + hi.getAlignIndex(i)); + } + else + { + restore.setSequence(hi.getHidden().elementAt(i).toString()); + } + } + + if (hi.getType() == HistoryItem.PASTE) + { + for (int i = viewport.alignment.getHeight() - 1; + i > (hi.getSequences().size() - 1); i--) + { + viewport.alignment.deleteSequence(i); + } + } + } + updateEditMenuBar(); + viewport.updateConsensus(); + viewport.updateConservation(); + alignPanel.repaint(); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + } - protected void copy_actionPerformed(ActionEvent e) - { - if(viewport.getSelectionGroup()==null) - return; + /** + * DOCUMENT ME! + * + * @param up DOCUMENT ME! + */ + public void moveSelectedSequences(boolean up) + { + SequenceGroup sg = viewport.getSelectionGroup(); - SequenceGroup sg = viewport.getSelectionGroup(); + if (sg == null) + { + return; + } - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - StringBuffer buffer= new StringBuffer(); + if (up) + { + for (int i = 1; i < viewport.alignment.getHeight(); i++) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); - for(int i=0; i -1; i--) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); - protected void pasteThis_actionPerformed(ActionEvent e) - { - addHistoryItem("Paste"); - paste(false); - } + if (!sg.sequences.contains(seq)) + { + continue; + } - void paste(boolean newAlignment) - { - try{ - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - Transferable contents = c.getContents(this); - if (contents == null) - return; + SequenceI temp = viewport.alignment.getSequenceAt(i + 1); - String str = (String) contents.getTransferData(DataFlavor.stringFlavor); - StringTokenizer st = new StringTokenizer(str); - ArrayList seqs = new ArrayList(); - while (st.hasMoreElements()) - { - String name = st.nextToken(); - int start = Integer.parseInt(st.nextToken()); - int end = Integer.parseInt(st.nextToken()); - Sequence sequence = new Sequence(name,st.nextToken(), start, end); + if (sg.sequences.contains(temp)) + { + continue; + } - if(!newAlignment) - viewport.alignment.addSequence(sequence); - else - seqs.add(sequence); - } + viewport.alignment.getSequences().setElementAt(temp, i); + viewport.alignment.getSequences().setElementAt(seq, i + 1); + } + } - if(newAlignment) - { - SequenceI[] newSeqs = new SequenceI[seqs.size()]; - seqs.toArray(newSeqs); - AlignFrame af = new AlignFrame(new Alignment(newSeqs)); - Desktop.addInternalFrame(af, "Copied sequences", NEW_WINDOW_WIDTH, NEW_WINDOW_HEIGHT); - } - else - { - viewport.setEndSeq(viewport.alignment.getHeight()); - viewport.alignment.getWidth(); - viewport.updateConservation(); - viewport.updateConsensus(); alignPanel.repaint(); - } + } - }catch(Exception ex){}// could be anything being pasted in here + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void copy_actionPerformed(ActionEvent e) + { + if (viewport.getSelectionGroup() == null) + { + return; + } - } + SequenceGroup sg = viewport.getSelectionGroup(); + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer buffer = new StringBuffer(); - protected void cut_actionPerformed(ActionEvent e) - { - copy_actionPerformed(null); - delete_actionPerformed(null); - } + Hashtable orderedSeqs = new Hashtable(); - protected void delete_actionPerformed(ActionEvent e) - { - addHistoryItem("Delete"); - if (viewport.getSelectionGroup() == null) - return; + for (int i = 0; i < sg.getSize(); i++) + { + SequenceI seq = sg.getSequenceAt(i); + int index = viewport.alignment.findIndex(seq); + orderedSeqs.put(index + "", seq); + } - SequenceGroup sg = viewport.getSelectionGroup(); - for (int i=0;i < sg.sequences.size(); i++) - { - SequenceI seq = sg.getSequenceAt(i); - int index = viewport.getAlignment().findIndex(seq); - seq.deleteChars(sg.getStartRes(), sg.getEndRes()+1); + int index = 0; - if(seq.getSequence().length()<1) - viewport.getAlignment().deleteSequence(seq); - else - viewport.getAlignment().getSequences().setElementAt(seq, index); - } - - viewport.setSelectionGroup(null); - viewport.alignment.deleteGroup(sg); - viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight()); - if(viewport.getAlignment().getHeight()<1) - try - { - this.setClosed(true); - }catch(Exception ex){} - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); - - } - - - - protected void redoMenuItem_actionPerformed(ActionEvent e) - { - Object [] history = (Object[])redoList.remove(0); - SequenceI[] seq = (SequenceI[]) history[1]; - viewport.setAlignment( new Alignment(seq) ); - updateEditMenuBar(); - viewport.updateConsensus(); - alignPanel.repaint(); - alignPanel.repaint(); - } - - - protected void deleteGroups_actionPerformed(ActionEvent e) - { - viewport.alignment.deleteAllGroups(); - viewport.setSelectionGroup(null); - - alignPanel.repaint(); - } - - - - public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) - { - SequenceGroup sg = new SequenceGroup(); - for (int i=0; i 0) - { - 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) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void pasteNew_actionPerformed(ActionEvent e) { - int max = colSel.getMax(); - viewport.getAlignment().trimRight(max); - if(viewport.getSelectionGroup()!=null) - viewport.getSelectionGroup().adjustForRemoveRight(max); + paste(true); + } - Vector groups = viewport.alignment.getGroups(); - for(int i=0; i 0) + { + addHistoryItem(new HistoryItem("Remove Left", viewport.alignment, + HistoryItem.HIDE)); - protected void noColourmenuItem_actionPerformed(ActionEvent e) - { - changeColour( null ); - } + int min = colSel.getMin(); + viewport.getAlignment().trimLeft(min); + colSel.compensateForEdit(0, min); + if (viewport.getSelectionGroup() != null) + { + viewport.getSelectionGroup().adjustForRemoveLeft(min); + } - public void clustalColour_actionPerformed(ActionEvent e) - { - abovePIDThreshold.setSelected(false); - changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth())); - } + Vector groups = viewport.alignment.getGroups(); - public void zappoColour_actionPerformed(ActionEvent e) - { - changeColour(new ZappoColourScheme()); - } + for (int i = 0; i < groups.size(); i++) + { + SequenceGroup sg = (SequenceGroup) groups.get(i); - public void taylorColour_actionPerformed(ActionEvent e) - { - changeColour(new TaylorColourScheme()); - } + if (!sg.adjustForRemoveLeft(min)) + { + viewport.alignment.deleteGroup(sg); + } + } + alignPanel.repaint(); + } + } - public void hydrophobicityColour_actionPerformed(ActionEvent e) - { - changeColour( new HydrophobicColourScheme() ); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void remove2RightMenuItem_actionPerformed(ActionEvent e) + { + ColumnSelection colSel = viewport.getColumnSelection(); - public void helixColour_actionPerformed(ActionEvent e) - { - changeColour(new HelixColourScheme() ); - } + if (colSel.size() > 0) + { + addHistoryItem(new HistoryItem("Remove Right", viewport.alignment, + HistoryItem.HIDE)); + int max = colSel.getMax(); + viewport.getAlignment().trimRight(max); - public void strandColour_actionPerformed(ActionEvent e) - { - changeColour(new StrandColourScheme()); - } + if (viewport.getSelectionGroup() != null) + { + viewport.getSelectionGroup().adjustForRemoveRight(max); + } + Vector groups = viewport.alignment.getGroups(); - public void turnColour_actionPerformed(ActionEvent e) - { - changeColour(new TurnColourScheme()); - } + for (int i = 0; i < groups.size(); i++) + { + SequenceGroup sg = (SequenceGroup) groups.get(i); + if (!sg.adjustForRemoveRight(max)) + { + viewport.alignment.deleteGroup(sg); + } + } - public void buriedColour_actionPerformed(ActionEvent e) - { - changeColour(new BuriedColourScheme() ); - } + alignPanel.repaint(); + } + } - public void nucleotideColour_actionPerformed(ActionEvent e) - { - changeColour(new NucleotideColourScheme()); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Remove Gapped Columns", + viewport.alignment, HistoryItem.HIDE)); + viewport.getAlignment().removeGaps(); + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } - protected void applyToAllGroups_actionPerformed(ActionEvent e) - { - viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected()); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, + HistoryItem.HIDE)); + SequenceI current; + int jSize; + Vector seqs = null; - void changeColour(ColourSchemeI cs) - { - int threshold = 0; + int start = 0; + int end = viewport.alignment.getWidth(); - if ( viewport.getAbovePIDThreshold() ) + if (viewport.getSelectionGroup() != null) + { + seqs = viewport.getSelectionGroup().sequences; + start = viewport.getSelectionGroup().getStartRes(); + end = viewport.getSelectionGroup().getEndRes(); + } + else + { + seqs = viewport.alignment.getSequences(); + } + + for (int i = 0; i < seqs.size(); i++) + { + current = (SequenceI) seqs.elementAt(i); + jSize = current.getLength(); + + int j = start; + + do + { + if (jalview.util.Comparison.isGap(current.getCharAt(j))) + { + current.deleteCharAt(j); + j--; + jSize--; + } + + j++; + } + while (j < end); + } + + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void padGapsMenuitem_actionPerformed(ActionEvent e) { - threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background"); + addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, + HistoryItem.HIDE)); + + SequenceI current; + int Width = viewport.getAlignment().getWidth(); - if (cs instanceof ResidueColourScheme) - ( (ResidueColourScheme) cs).setThreshold(threshold); - else if (cs instanceof ScoreColourScheme) - ( (ScoreColourScheme) cs).setThreshold(threshold); + for (int i = 0; i < viewport.getAlignment().getSequences().size(); + i++) + { + current = viewport.getAlignment().getSequenceAt(i); + + if (current.getLength() < Width) + { + current.insertCharAt(Width - 1, viewport.getGapCharacter()); + } + } - viewport.setGlobalColourScheme(cs); + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); } - else if (cs instanceof ResidueColourScheme) - ( (ResidueColourScheme) cs).setThreshold(0); - else if (cs instanceof ScoreColourScheme) - ( (ScoreColourScheme) cs).setThreshold(0); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void findMenuItem_actionPerformed(ActionEvent e) + { + JInternalFrame frame = new JInternalFrame(); + Finder finder = new Finder(viewport, alignPanel, frame); + frame.setContentPane(finder); + Desktop.addInternalFrame(frame, "Find", 340, 110); + frame.setLayer(JLayeredPane.PALETTE_LAYER); + } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void font_actionPerformed(ActionEvent e) + { + FontChooser fc = new FontChooser(alignPanel); + } - if (viewport.getConservationSelected()) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void fullSeqId_actionPerformed(ActionEvent e) { - ConservationColourScheme ccs = null; + viewport.setShowFullId(fullSeqId.isSelected()); - Alignment al = (Alignment) viewport.alignment; - Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, - al.getSequences(), 0, - al.getWidth() - 1); + alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth()); + alignPanel.repaint(); + } - c.calculate(); - c.verdict(false, viewport.ConsPercGaps); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void colourTextMenuItem_actionPerformed(ActionEvent e) + { + viewport.setColourText(colourTextMenuItem.isSelected()); + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void wrapMenuItem_actionPerformed(ActionEvent e) + { + viewport.setWrapAlignment(wrapMenuItem.isSelected()); + alignPanel.setWrapAlignment(wrapMenuItem.isSelected()); + scaleAbove.setVisible(wrapMenuItem.isSelected()); + scaleLeft.setVisible(wrapMenuItem.isSelected()); + scaleRight.setVisible(wrapMenuItem.isSelected()); + alignPanel.repaint(); + } - ccs = new ConservationColourScheme(c, cs); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void scaleAbove_actionPerformed(ActionEvent e) + { + viewport.setScaleAboveWrapped(scaleAbove.isSelected()); + alignPanel.repaint(); + } - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - ccs.setConsensus( viewport.vconsensus ); - viewport.setGlobalColourScheme(ccs); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void scaleLeft_actionPerformed(ActionEvent e) + { + viewport.setScaleLeftWrapped(scaleLeft.isSelected()); + alignPanel.repaint(); + } - SliderPanel.setConservationSlider(alignPanel, ccs, "Background"); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void scaleRight_actionPerformed(ActionEvent e) + { + viewport.setScaleRightWrapped(scaleRight.isSelected()); + alignPanel.repaint(); + } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void viewBoxesMenuItem_actionPerformed(ActionEvent e) + { + viewport.setShowBoxes(viewBoxesMenuItem.isSelected()); + alignPanel.repaint(); } - else + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void viewTextMenuItem_actionPerformed(ActionEvent e) { - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - if (cs != null) - cs.setConsensus(viewport.vconsensus); - viewport.setGlobalColourScheme(cs); + viewport.setShowText(viewTextMenuItem.isSelected()); + alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void renderGapsMenuItem_actionPerformed(ActionEvent e) + { + viewport.setRenderGaps(renderGapsMenuItem.isSelected()); + alignPanel.repaint(); + } - if(viewport.getColourAppliesToAllGroups()) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void sequenceFeatures_actionPerformed(ActionEvent evt) { - Vector groups = viewport.alignment.getGroups(); - for(int i=0; i0) - || viewport.getAlignment().getHeight()<4) + viewport.setAbovePIDThreshold(false); + abovePIDThreshold.setSelected(false); + + ColourSchemeI cs = viewport.getGlobalColourScheme(); + + if (cs instanceof ConservationColourScheme) + { + changeColour(((ConservationColourScheme) cs).cs); + } + else + { + changeColour(cs); + } + + modifyConservation_actionPerformed(null); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void abovePIDThreshold_actionPerformed(ActionEvent e) { - JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n" - +"at least 4 input sequences.", - "Sequence selection insufficient", - JOptionPane.WARNING_MESSAGE); - return; + viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected()); + + conservationMenuItem.setSelected(false); + viewport.setConservationSelected(false); + + ColourSchemeI cs = viewport.getGlobalColourScheme(); + + if (cs instanceof ConservationColourScheme) + { + changeColour(((ConservationColourScheme) cs).cs); + } + else + { + changeColour(cs); + } + + modifyPID_actionPerformed(null); } - 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); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void userDefinedColour_actionPerformed(ActionEvent e) + { + new UserDefinedColours(alignPanel, null); + } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void PIDColour_actionPerformed(ActionEvent e) + { + changeColour(new PIDColourScheme()); + } - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void BLOSUM62Colour_actionPerformed(ActionEvent e) + { + changeColour(new Blosum62ColourScheme()); + } - public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("AV", "PID", "Average distance tree using PID"); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, + HistoryItem.SORT)); + AlignmentSorter.sortByPID(viewport.getAlignment(), + viewport.getAlignment().getSequenceAt(0)); + alignPanel.repaint(); + } - public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void sortIDMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, + HistoryItem.SORT)); + AlignmentSorter.sortByID(viewport.getAlignment()); + alignPanel.repaint(); + } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void sortGroupMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, + HistoryItem.SORT)); - protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); - } + AlignmentSorter.sortByGroup(viewport.getAlignment()); + alignPanel.repaint(); + } - protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID"); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) + { + RedundancyPanel sp = new RedundancyPanel(alignPanel, this); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(sp); + Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, + 100, false); + } - void NewTreePanel(String type, String pwType, String title) - { - //are the sequences aligned? - if(!viewport.alignment.isAligned()) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e) { - JOptionPane.showMessageDialog(Desktop.desktop, "The sequences must be aligned before creating a tree.", - "Sequences not aligned", JOptionPane.WARNING_MESSAGE); - return; + if ((viewport.getSelectionGroup() == null) || + (viewport.getSelectionGroup().getSize() < 2)) + { + JOptionPane.showInternalMessageDialog(this, + "You must select at least 2 sequences.", "Invalid Selection", + JOptionPane.WARNING_MESSAGE); + } + else + { + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(new PairwiseAlignPanel(viewport)); + Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500); + } } - final TreePanel tp; - if (viewport.getSelectionGroup() != null && - viewport.getSelectionGroup().getSize() > 3) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void PCAMenuItem_actionPerformed(ActionEvent e) { - tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences, type, - pwType, - 0, viewport.alignment.getWidth()); + 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); + + 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); + } } - else + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) { - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - type, pwType, 0, viewport.alignment.getWidth()); + NewTreePanel("AV", "PID", "Average distance tree using PID"); } - addTreeMenuItem(tp, title); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) + { + NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); + } - Desktop.addInternalFrame(tp, title, 600, 500); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) + { + NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); + } - void addTreeMenuItem(final TreePanel treePanel, String title) - { - final JMenuItem item = new JMenuItem(title); - sortByTreeMenu.add(item); - item.addActionListener(new java.awt.event.ActionListener() + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) { - public void actionPerformed(ActionEvent e) - { - addHistoryItem("sort"); - AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree()); - alignPanel.repaint(); - } - }); + NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62"); + } - treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + /** + * DOCUMENT ME! + * + * @param type DOCUMENT ME! + * @param pwType DOCUMENT ME! + * @param title DOCUMENT ME! + */ + void NewTreePanel(String type, String pwType, String title) { - public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) - { - sortByTreeMenu.remove(item); - }; - }); + final TreePanel tp; - } + if ((viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 3)) + { + int s = 0; + SequenceGroup sg = viewport.getSelectionGroup(); + + /* Decide if the selection is a column region */ + while (s < sg.sequences.size()) + { + if (((SequenceI) sg.sequences.elementAt(s++)).getLength() < sg.getEndRes()) + { + JOptionPane.showMessageDialog(Desktop.desktop, + "The selected region to create a tree may\nonly contain residues or gaps.\n" + + "Try using the Pad function in the edit menu,\n" + + "or one of the multiple sequence alignment web services.", + "Sequences in selection are not aligned", + JOptionPane.WARNING_MESSAGE); + + return; + } + } + + title = title + " on region"; + tp = new TreePanel(viewport, + viewport.getSelectionGroup().sequences, type, pwType, + sg.getStartRes(), sg.getEndRes()); + } + else + { + //are the sequences aligned? + if (!viewport.alignment.isAligned()) + { + JOptionPane.showMessageDialog(Desktop.desktop, + "The sequences must be aligned before creating a tree.\n" + + "Try using the Pad function in the edit menu,\n" + + "or one of the multiple sequence alignment web services.", + "Sequences not aligned", JOptionPane.WARNING_MESSAGE); + + return; + } + + tp = new TreePanel(viewport, + viewport.getAlignment().getSequences(), type, pwType, 0, + viewport.alignment.getWidth()); + } + addTreeMenuItem(tp, title); + viewport.setCurrentTree(tp.getTree()); - 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); + Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500); + } - ClustalThread thread = new ClustalThread(info); - thread.start(); - } + /** + * DOCUMENT ME! + * + * @param title DOCUMENT ME! + * @param order DOCUMENT ME! + */ + 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(); + } + }); + } - class ClustalThread extends Thread + /** + * DOCUMENT ME! + * + * @param treePanel DOCUMENT ME! + * @param title DOCUMENT ME! + */ + void addTreeMenuItem(final TreePanel treePanel, String title) { - WebserviceInfo info; - public ClustalThread(WebserviceInfo info) - {this.info = info; } + final JMenuItem item = new JMenuItem(title); - public void run() - { - info.setStatus(WebserviceInfo.STATE_RUNNING); - jalview.ws.Jemboss jemboss = new jalview.ws.Jemboss(); - Vector sv = viewport.getAlignment().getSequences(); - SequenceI[] seqs = new SequenceI[sv.size()]; + treeCount++; - int i = 0; - do + if (treeCount == 1) { - seqs[i] = (SequenceI) sv.elementAt(i); + sort.add(sortByTreeMenu); } - while (++i < sv.size()); - SequenceI[] alignment = jemboss.clustalW(seqs); // gaps removed within method - if (alignment != null) + sortByTreeMenu.add(item); + item.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Tree Sort", + viewport.alignment, HistoryItem.SORT)); + AlignmentSorter.sortByTree(viewport.getAlignment(), + treePanel.getTree()); + alignPanel.repaint(); + } + }); + + treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + treeCount--; + sortByTreeMenu.remove(item); + + if (treeCount == 0) + { + sort.remove(sortByTreeMenu); + } + } + ; + }); + viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals("alignment")) + { + treePanel.getTree().UpdatePlaceHolders((Vector) evt.getNewValue()); + treePanel.repaint(); + } + } + }); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void clustalAlignMenuItem_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)) { - 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); + // 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 { - info.setStatus(WebserviceInfo.STATE_STOPPED_ERROR); - info.appendProgressText("Problem obtaining clustal alignment"); + 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); } - } } - protected void jpred_actionPerformed(ActionEvent e) -{ - - if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize()>0) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void ClustalRealign_actionPerformed(ActionEvent e) { - // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! - SequenceGroup seqs = viewport.getSelectionGroup(); - if (seqs.getSize() == 1 || !viewport.alignment.isAligned()) - { - JPredClient ct = new JPredClient( (SequenceI)seqs.getSequenceAt(0)); - } - else - { - int sz; - SequenceI[] msa = new SequenceI[sz=seqs.getSize()]; - for (int i = 0; i < sz; i++) + // 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)) { - msa[i] = (SequenceI) seqs.getSequenceAt(i); + // 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) + { + jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", + title, msa, true, true); + } } - else + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void jpred_actionPerformed(ActionEvent e) { - Vector seqs = viewport.getAlignment().getSequences(); + SequenceI seq = null; + SequenceI[] msa = null; - if (seqs.size() == 1 || !viewport.alignment.isAligned()) - { - JPredClient ct = new JPredClient( (SequenceI) - seqs.elementAt(0)); - } - else - { - SequenceI[] msa = new SequenceI[seqs.size()]; - for (int i = 0; i < seqs.size(); i++) + if ((viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 0)) { - msa[i] = (SequenceI) seqs.elementAt(i); + // 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); + } + } } - JPredClient ct = new JPredClient(msa); - } - + 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 - 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; - SequenceI[] msa = new SequenceI[sz=seqs.getSize()]; - for (int i = 0; i < sz; i++) + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + 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)) { - msa[i] = (SequenceI) seqs.getSequenceAt(i); + // 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(); - MsaWSClient ct = new jalview.ws.MsaWSClient(msa); - } - else - { - Vector seqs = viewport.getAlignment().getSequences(); + if (seqs.size() > 1) + { + msa = new SequenceI[seqs.size()]; - if (seqs.size() > 1) { - SequenceI[] msa = new SequenceI[seqs.size()]; - for (int i = 0; i < seqs.size(); i++) - { - msa[i] = (SequenceI) seqs.elementAt(i); - } + for (int i = 0; i < seqs.size(); i++) + { + msa[i] = (SequenceI) seqs.elementAt(i); + } + } + } - MsaWSClient ct = new MsaWSClient(msa); + if (msa != null) + { + MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS", title, msa, + false, true); } + } - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + 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"); + viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree()); + } + catch (Exception ex) + { + JOptionPane.showMessageDialog(Desktop.desktop, + "Problem reading tree file", ex.getMessage(), + JOptionPane.WARNING_MESSAGE); + ex.printStackTrace(); + } + } } - 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); - TreePanel treepanel = null; - try - { - jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File"); - fin.parse(); + /** + * DOCUMENT ME! + * + * @param nf DOCUMENT ME! + * @param title DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public TreePanel ShowNewickTree(NewickFile nf, String title) + { + TreePanel tp = null; - if (fin.getTree() != null) + try { - TreePanel tp = null; - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - fin, "FromFile", choice); - Desktop.addInternalFrame(tp, title, 600, 500); - addTreeMenuItem(tp, title); + 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) - { - JOptionPane.showMessageDialog(Desktop.desktop, - "Problem reading tree file", - ex.getMessage(), - JOptionPane.WARNING_MESSAGE); - ex.printStackTrace(); - } + 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(); + } + } + } + } }