X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=4b28166e395d450b8cf487c8085a3315a8915d30;hb=8da7acff9214ddaf0e6d28e76219ab51bd38e62d;hp=484b8cd93ea6667b69fad2544c17e7d3fc662838;hpb=e588028667ea7c02f015c9ecc2be2f811e3d761b;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 484b8cd..4b28166 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -13,12 +13,13 @@ * 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 + * along with this program; if not, write to the Free Softwarechang * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.gui; import java.beans.*; +import java.io.*; import java.util.*; import java.awt.*; @@ -35,18 +36,34 @@ import jalview.jbgui.*; import jalview.schemes.*; import jalview.ws.*; +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class AlignFrame extends GAlignFrame { + /** 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; - public String currentFileFormat = "Jalview"; + + /** 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); @@ -59,23 +76,132 @@ public class AlignFrame getPreferredSize()); alignPanel.setAnnotationVisible(viewport.getShowAnnotation()); + String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort"); + + if(sortby.equals("Id")) + sortIDMenuItem_actionPerformed(null); + else if(sortby.equals("Pairwise Identity")) + sortPairwiseMenuItem_actionPerformed(null); + getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); - addInternalFrameListener(new InternalFrameAdapter() + viewport.addPropertyChangeListener(new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals("alignment")) + { + alignmentChanged(); + } + } + }); + + addServiceListeners(); + } + + /* Set up intrinsic listeners for dynamically generated GUI bits. */ + private void addServiceListeners() + { + final java.beans.PropertyChangeListener thisListener; + // Do this once to get current state + BuildWebServiceMenu(); + Desktop.discoverer.addPropertyChangeListener( + thisListener = new java.beans.PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + // System.out.println("Discoverer property change."); + if (evt.getPropertyName().equals("services")) + { + // System.out.println("Rebuilding web service menu"); + BuildWebServiceMenu(); + } + } + }); + addInternalFrameListener(new javax.swing.event. + InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + // System.out.println("deregistering discoverer listener"); + Desktop.discoverer.removePropertyChangeListener(thisListener); + closeMenuItem_actionPerformed(null); + } + ; + }); + + } + + /** + * DOCUMENT ME! + * + * @param String DOCUMENT ME! + */ + + public void parseGroupsFile(String file) + { + try { - public void internalFrameActivated(InternalFrameEvent evt) + 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) { - javax.swing.SwingUtilities.invokeLater(new Runnable() + 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()) { - public void run() + text = st.nextToken(); + token = st.nextToken(); + if (!token.equals("ID_NOT_SPECIFIED")) { - alignPanel.requestFocus(); + 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 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. @@ -104,43 +230,62 @@ public class AlignFrame jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat); - if (currentFileFormat.equals("Jalview")) - { - String shortName = title; + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - if (shortName.indexOf(java.io.File.separatorChar) > -1) - { - shortName = shortName.substring(shortName.lastIndexOf( - java.io.File.separatorChar) + 1); - } + saveAlignment(choice, currentFileFormat); + } + } - String choice = chooser.getSelectedFile().getPath(); - Jalview2XML.SaveAlignment(this, choice, shortName); + public boolean saveAlignment(String file, String format) + { + if (format.equalsIgnoreCase("Jalview")) + { + String shortName = title; - // USE Jalview2XML to save this file - return; + if (shortName.indexOf(java.io.File.separatorChar) > -1) + { + shortName = shortName.substring(shortName.lastIndexOf( + java.io.File.separatorChar) + 1); } - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + Jalview2XML.SaveAlignment(this, file, shortName); - String output = FormatAdapter.formatSequences(currentFileFormat, - viewport.getAlignment().getSequences()); + // USE Jalview2XML to save this file + return true; + } + else + { + String output = FormatAdapter.formatSequences(format, + viewport.getAlignment(). + getSequences()); + if (output == null) + { + return false; + } try { - java.io.PrintWriter out = new java.io.PrintWriter(new java.io. - FileWriter( - choice)); - out.println(output); + java.io.PrintWriter out = new java.io.PrintWriter( + new java.io.FileWriter(file)); + + out.print(output); out.close(); + return true; } catch (Exception ex) { + ex.printStackTrace(); } } + return false; } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void outputText_actionPerformed(ActionEvent e) { CutAndPasteTransfer cap = new CutAndPasteTransfer(); @@ -152,21 +297,46 @@ public class AlignFrame getSequences())); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void htmlMenuItem_actionPerformed(ActionEvent e) { new HTMLOutput(viewport); } - protected void createPNG_actionPerformed(ActionEvent e) + public void createImageMap(File file, String image) { - alignPanel.makePNG(); + alignPanel.makePNGImageMap(file, image); } - protected void epsFile_actionPerformed(ActionEvent e) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void createPNG(File f) { - alignPanel.makeEPS(); + alignPanel.makePNG(f); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void createEPS(File f) + { + alignPanel.makeEPS(f); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void printMenuItem_actionPerformed(ActionEvent e) { //Putting in a thread avoids Swing painting problems @@ -174,10 +344,16 @@ public class AlignFrame thread.start(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void closeMenuItem_actionPerformed(ActionEvent e) { try { + PaintRefresher.components.remove(viewport.alignment); this.setClosed(true); } catch (Exception ex) @@ -185,6 +361,9 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + */ void updateEditMenuBar() { if (historyList.size() > 0) @@ -214,28 +393,42 @@ public class AlignFrame } } + /** + * DOCUMENT ME! + * + * @param hi DOCUMENT ME! + */ public void addHistoryItem(HistoryItem hi) { historyList.push(hi); updateEditMenuBar(); } + /** + * 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.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } + /** + * 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(); + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } // used by undo and redo @@ -280,13 +473,15 @@ public class AlignFrame updateEditMenuBar(); - viewport.updateConsensus(); - viewport.updateConservation(); - alignPanel.repaint(); viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } + /** + * DOCUMENT ME! + * + * @param up DOCUMENT ME! + */ public void moveSelectedSequences(boolean up) { SequenceGroup sg = viewport.getSelectionGroup(); @@ -344,6 +539,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void copy_actionPerformed(ActionEvent e) { if (viewport.getSelectionGroup() == null) @@ -365,7 +565,8 @@ public class AlignFrame orderedSeqs.put(index + "", seq); } - int index = 0; + int index = 0, startRes, endRes; + char ch; for (int i = 0; i < sg.getSize(); i++) { @@ -385,22 +586,53 @@ public class AlignFrame index++; } } + //FIND START RES + //Returns residue following index if gap + startRes = seq.findPosition(sg.getStartRes()); + + //FIND END RES + //Need to find the residue preceeding index if gap + endRes = 0; + + for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++) + { + ch = seq.getCharAt(j); + if (!jalview.util.Comparison.isGap( (ch))) + { + endRes++; + } + } + + if (endRes > 0) + { + endRes += seq.getStart() - 1; + } buffer.append(seq.getName() + "\t" + - seq.findPosition(sg.getStartRes()) + "\t" + - seq.findPosition(sg.getEndRes()) + "\t" + - sg.getSequenceAt(i).getSequence(sg.getStartRes(), - sg.getEndRes() + 1) + "\n"); + startRes + "\t" + + endRes + "\t" + + seq.getSequence(sg.getStartRes(), + sg.getEndRes() + 1) + "\n"); } c.setContents(new StringSelection(buffer.toString()), null); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void pasteNew_actionPerformed(ActionEvent e) { paste(true); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void pasteThis_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, @@ -408,6 +640,11 @@ public class AlignFrame paste(false); } + /** + * DOCUMENT ME! + * + * @param newAlignment DOCUMENT ME! + */ void paste(boolean newAlignment) { try @@ -464,28 +701,35 @@ public class AlignFrame } else { - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); viewport.setEndSeq(viewport.alignment.getHeight()); viewport.alignment.getWidth(); - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } } catch (Exception ex) { + // could be anything being pasted in here } - // could be anything being pasted in here + } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void cut_actionPerformed(ActionEvent e) { copy_actionPerformed(null); delete_actionPerformed(null); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void delete_actionPerformed(ActionEvent e) { boolean seqsdeleted = false; @@ -499,6 +743,11 @@ public class AlignFrame HistoryItem.HIDE)); SequenceGroup sg = viewport.getSelectionGroup(); + boolean allSequences = false; + if (sg.sequences.size() == viewport.alignment.getHeight()) + { + allSequences = true; + } for (int i = 0; i < sg.sequences.size(); i++) { @@ -506,6 +755,13 @@ public class AlignFrame int index = viewport.getAlignment().findIndex(seq); seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); + // If the cut affects all sequences, remove highlighted columns + if (allSequences) + { + viewport.getColumnSelection().removeElements(sg.getStartRes(), + sg.getEndRes() + 1); + } + if (seq.getSequence().length() < 1) { seqsdeleted = true; @@ -526,7 +782,6 @@ public class AlignFrame viewport.getAlignment().getSequences()); } - viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getHeight()); if (viewport.getAlignment().getHeight() < 1) { @@ -538,12 +793,13 @@ public class AlignFrame { } } - - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void deleteGroups_actionPerformed(ActionEvent e) { viewport.alignment.deleteAllGroups(); @@ -551,6 +807,11 @@ public class AlignFrame alignPanel.repaint(); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) { SequenceGroup sg = new SequenceGroup(); @@ -561,26 +822,38 @@ public class AlignFrame sg.addSequence(viewport.getAlignment().getSequenceAt(i), false); } - sg.setEndRes(viewport.alignment.getWidth()); + sg.setEndRes(viewport.alignment.getWidth() - 1); viewport.setSelectionGroup(sg); PaintRefresher.Refresh(null, viewport.alignment); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) { viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); viewport.setSelectionGroup(null); - alignPanel.annotationPanel.activeRes=null; + alignPanel.annotationPanel.activeRes = null; PaintRefresher.Refresh(null, viewport.alignment); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void invertSequenceMenuItem_actionPerformed(ActionEvent e) { SequenceGroup sg = viewport.getSelectionGroup(); - if(sg==null) + + if (sg == null) { selectAllSequenceMenuItem_actionPerformed(null); + return; } @@ -593,6 +866,11 @@ public class AlignFrame PaintRefresher.Refresh(null, viewport.alignment); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void remove2LeftMenuItem_actionPerformed(ActionEvent e) { ColumnSelection colSel = viewport.getColumnSelection(); @@ -623,10 +901,15 @@ public class AlignFrame } } - alignPanel.repaint(); + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void remove2RightMenuItem_actionPerformed(ActionEvent e) { ColumnSelection colSel = viewport.getColumnSelection(); @@ -656,36 +939,77 @@ public class AlignFrame } } - alignPanel.repaint(); + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Remove Gapped Columns", viewport.alignment, HistoryItem.HIDE)); + //This is to maintain viewport position on first residue + //of first sequence + SequenceI seq = viewport.alignment.getSequenceAt(0); + int startRes = seq.findPosition(viewport.startRes); + viewport.getAlignment().removeGaps(); - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); + + viewport.setStartRes(seq.findIndex(startRes)-1); + + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) { addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, HistoryItem.HIDE)); + //This is to maintain viewport position on first residue + //of first sequence + SequenceI seq = viewport.alignment.getSequenceAt(0); + int startRes = seq.findPosition(viewport.startRes); + + SequenceI current; int jSize; - for (int i = 0; i < viewport.getAlignment().getSequences().size(); - i++) + Vector seqs = null; + + int start = 0; + int end = viewport.alignment.getWidth(); + + if (viewport.getSelectionGroup() != null + && viewport.getSelectionGroup().sequences != null + && viewport.getSelectionGroup().sequences.size() > 0) { - current = viewport.getAlignment().getSequenceAt(i); + 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(); - for (int j = 0; j < jSize; j++) + int j = start; + + do { if (jalview.util.Comparison.isGap(current.getCharAt(j))) { @@ -693,14 +1017,69 @@ public class AlignFrame j--; jSize--; } + j++; } + while (j < end && j < jSize); } - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); + viewport.setStartRes(seq.findIndex(startRes)-1); + + + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); } + public void alignmentChanged() + { + viewport.updateConsensus(); + viewport.updateConservation(); + resetAllColourSchemes(); + alignPanel.repaint(); + } + + void resetAllColourSchemes() + { + ColourSchemeI cs = viewport.globalColourScheme; + if(cs!=null) + { + if (cs instanceof ClustalxColourScheme) + { + ( (ClustalxColourScheme) viewport.getGlobalColourScheme()). + resetClustalX(viewport.alignment.getSequences(), + viewport.alignment.getWidth()); + } + + cs.setConsensus(viewport.vconsensus); + if (cs.conservationApplied()) + { + Alignment al = (Alignment) viewport.alignment; + Conservation c = new Conservation("All", + ResidueProperties.propHash, 3, + al.getSequences(), 0, + al.getWidth() - 1); + c.calculate(); + c.verdict(false, viewport.ConsPercGaps); + + cs.setConservation(c); + } + } + + int s, sSize = viewport.alignment.getGroups().size(); + for(s=0; sDisplayed Tree menu. + * Creates a new menu item for a TreePanel with an appropriate + * jalview.analysis.AlignmentSorter call. Listeners are added + * to remove the menu item when the treePanel is closed, and adjust + * the tree leaf to sequence mapping when the alignment is modified. + * @param treePanel Displayed tree window. + * @param title SortBy menu item title. + */ void addTreeMenuItem(final TreePanel treePanel, String title) { final JMenuItem item = new JMenuItem(title); @@ -1370,50 +2019,13 @@ public class AlignFrame }); } - 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)) - { - // 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) + /** + * Work out whether the whole set of sequences + * or just the selected set will be submitted for multiple alignment. + * + */ + private SequenceI[] gatherSequencesForAlignment() { - // TODO:resolve which menu item was actually selected // Now, check we have enough sequences SequenceI[] msa = null; @@ -1444,15 +2056,16 @@ public class AlignFrame } } } - - if (msa != null) - { - jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", - title, msa, true, true); - } + return msa; } - protected void jpred_actionPerformed(ActionEvent e) + /** + * Decides what is submitted to a secondary structure prediction service, + * the currently selected sequence, or the currently selected alignment + * (where the first sequence in the set is the one that the prediction + * will be for). + */ + SequenceI[] gatherSeqOrMsaForSecStrPrediction() { SequenceI seq = null; SequenceI[] msa = null; @@ -1496,63 +2109,26 @@ public class AlignFrame } } } - 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); - } + return msa; } else { - Vector seqs = viewport.getAlignment().getSequences(); - - if (seqs.size() > 1) + if (seq != null) { - msa = new SequenceI[seqs.size()]; - - for (int i = 0; i < seqs.size(); i++) - { - msa[i] = (SequenceI) seqs.elementAt(i); - } + return new SequenceI[] + { + seq}; } } - - if (msa != null) - { - MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS", title, msa, - false, true); - } + return null; } - + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) { // Pick the tree file @@ -1574,7 +2150,7 @@ public class AlignFrame { jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, "File"); - viewport.setCurrentTree( ShowNewickTree(fin, choice).getTree() ); + viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree()); } catch (Exception ex) { @@ -1587,19 +2163,41 @@ public class AlignFrame } } + public TreePanel ShowNewickTree(NewickFile nf, String title) { + return ShowNewickTree(nf,title,600,500,4,5); + } + /** + * DOCUMENT ME! + * + * @param nf DOCUMENT ME! + * @param title DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) + { 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); + viewport.getAlignment().getSequences(), nf, + "FromFile", + title); + + tp.setSize(w,h); + + if(x>0 && y>0) + tp.setLocation(x,y); + + + Desktop.addInternalFrame(tp, title, w, h); addTreeMenuItem(tp, title); } } @@ -1607,6 +2205,7 @@ public class AlignFrame { ex.printStackTrace(); } + return tp; } @@ -1632,4 +2231,111 @@ public class AlignFrame } } } + + /** + * Generates menu items and listener event actions for web service clients + * + */ + public void BuildWebServiceMenu() + { + if ( (Desktop.discoverer.services != null) + && (Desktop.discoverer.services.size() > 0)) + { + Vector msaws = (Vector) Desktop.discoverer.services.get("MsaWS"); + Vector secstrpr = (Vector) Desktop.discoverer.services.get("SecStrPred"); + Vector wsmenu = new Vector(); + if (msaws != null) + { + // Add any Multiple Sequence Alignment Services + final JMenu msawsmenu = new JMenu("Alignment"); + for (int i = 0, j = msaws.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws. + get(i); + final JMenuItem method = new JMenuItem(sh.getName()); + method.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + SequenceI[] msa = gatherSequencesForAlignment(); + MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa, + false, true); + + } + + }); + msawsmenu.add(method); + // Deal with services that we know accept partial alignments. + if (sh.getName().indexOf("lustal") > -1) + { + // We know that ClustalWS can accept partial alignments for refinement. + final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign"); + methodR.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + SequenceI[] msa = gatherSequencesForAlignment(); + MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa, + true, true); + + } + + }); + msawsmenu.add(methodR); + + } + } + wsmenu.add(msawsmenu); + } + if (secstrpr != null) + { + // Add any secondary structure prediction services + final JMenu secstrmenu = new JMenu("Secondary Structure Prediction"); + for (int i = 0, j = secstrpr.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) + secstrpr.get(i); + final JMenuItem method = new JMenuItem(sh.getName()); + method.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + SequenceI[] msa = gatherSeqOrMsaForSecStrPrediction(); + if (msa.length == 1) + { + // Single Sequence prediction + jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh, + title, msa[0]); + } + else + { + if (msa.length > 1) + { + // Single Sequence prediction + jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh, + title, msa); + } + } + } + }); + secstrmenu.add(method); + } + wsmenu.add(secstrmenu); + } + this.webService.removeAll(); + for (int i = 0, j = wsmenu.size(); i < j; i++) + { + webService.add( (JMenu) wsmenu.get(i)); + } + } + else + { + this.webService.removeAll(); + this.webService.add(this.webServiceNoServices); + } + // TODO: add in rediscovery function + // TODO: reduce code redundancy. + // TODO: group services by location as well as function. + } + }