X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=e64b8e4cafec2f737d840b1df7d0f733d6c5f0d1;hb=442b6bc246ee877d5e977baf80fd96299e0e05c4;hp=7efd90031064528903a0405b536c9cd915ad93fe;hpb=0180bdb7d844cd1119a885dc42329ccc6deeacd5;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 7efd900..e64b8e4 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -45,7 +45,7 @@ import jalview.ws.*; * @version $Revision$ */ public class AlignFrame - extends GAlignFrame implements DropTargetListener + extends GAlignFrame implements DropTargetListener, IProgressIndicator { /** DOCUMENT ME!! */ public static final int DEFAULT_WIDTH = 700; @@ -68,6 +68,8 @@ public class AlignFrame */ String fileName = null; + + /** * Creates a new AlignFrame object. @@ -160,7 +162,12 @@ public class AlignFrame addKeyListener(); } - + /** + * Change the filename and format for the alignment, and + * enable the 'reload' button functionality. + * @param file valid filename + * @param format format of file + */ public void setFileName(String file, String format) { fileName = file; @@ -526,6 +533,7 @@ public class AlignFrame conservationMenuItem.setSelected(av.getConservationSelected()); seqLimits.setSelected(av.getShowJVSuffix()); idRightAlign.setSelected(av.rightAlignIds); + centreColumnLabelsMenuItem.setState(av.centreColumnLabels); renderGapsMenuItem.setSelected(av.renderGaps); wrapMenuItem.setSelected(av.wrapAlignment); scaleAbove.setVisible(av.wrapAlignment); @@ -547,6 +555,9 @@ public class AlignFrame Hashtable progressBars; + /* (non-Javadoc) + * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) + */ public void setProgressBar(String message, long id) { if(progressBars == null) @@ -587,10 +598,18 @@ public class AlignFrame validate(); } - - - - + /** + * + * @return true if any progress bars are still active + */ + public boolean operationInProgress() + { + if (progressBars!=null && progressBars.size()>0) + { + return true; + } + return false; + } /* Added so Castor Mapping file can obtain Jalview Version */ @@ -675,7 +694,7 @@ public class AlignFrame public void save_actionPerformed(ActionEvent e) { if(fileName==null - || currentFileFormat==null + || (currentFileFormat==null || jalview.io.AppletFormatAdapter.isValidFormat(currentFileFormat, true)) || fileName.startsWith("http") ) { @@ -757,8 +776,18 @@ public class AlignFrame } else - { - + { + if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true)) + { + // JBPNote need to have a raise_gui flag here + JOptionPane.showInternalMessageDialog( + this, "Cannot save file " + fileName + " using format "+format, + "Alignment output format not supported", + JOptionPane.WARNING_MESSAGE); + saveAs_actionPerformed(null); + return false; + } + String[] omitHidden = null; if (viewport.hasHiddenColumns) @@ -775,7 +804,6 @@ public class AlignFrame } } FormatAdapter f = new FormatAdapter(); - String output = f.formatSequences( format, (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future @@ -1434,9 +1462,9 @@ public class AlignFrame } /** - * DOCUMENT ME! + * Paste contents of Jalview clipboard * - * @param newAlignment DOCUMENT ME! + * @param newAlignment true to paste to a new alignment, otherwise add to this. */ void paste(boolean newAlignment) { @@ -2165,6 +2193,12 @@ public class AlignFrame alignPanel.paintAlignment(true); } + public void centreColumnLabels_actionPerformed(ActionEvent e) + { + viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState(); + alignPanel.paintAlignment(true); + } + /** @@ -2858,7 +2892,7 @@ public class AlignFrame { SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByPID(viewport.getAlignment(), - viewport.getAlignment().getSequenceAt(0)); + viewport.getAlignment().getSequenceAt(0), null); addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment)); alignPanel.paintAlignment(true); @@ -3121,7 +3155,7 @@ public class AlignFrame public void actionPerformed(ActionEvent e) { SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray(); - AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment()); + AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());//,viewport.getSelectionGroup()); addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment)); alignPanel.paintAlignment(true); } @@ -3239,7 +3273,7 @@ public class AlignFrame * or just the selected set will be submitted for multiple alignment. * */ - private jalview.datamodel.AlignmentView gatherSequencesForAlignment() + public jalview.datamodel.AlignmentView gatherSequencesForAlignment() { // Now, check we have enough sequences AlignmentView msa = null; @@ -3277,12 +3311,14 @@ public class AlignFrame } /** - * Decides what is submitted to a secondary structure prediction service, - * the currently selected sequence, or the currently selected alignment + * Decides what is submitted to a secondary structure prediction service: + * the first sequence in the alignment, or in the current selection, + * or, if the alignment is 'aligned' (ie padded with gaps), then the + * currently selected region or the whole alignment. * (where the first sequence in the set is the one that the prediction * will be for). */ - AlignmentView gatherSeqOrMsaForSecStrPrediction() + public AlignmentView gatherSeqOrMsaForSecStrPrediction() { AlignmentView seqs = null; @@ -3422,13 +3458,20 @@ public class AlignFrame */ public void BuildWebServiceMenu() { + // TODO: add support for context dependent disabling of services based on alignment and current selection + // TODO: add additional serviceHandle parameter to specify abstract handler class independently of AbstractName + // TODO: add in rediscovery GUI function to restart discoverer + // TODO: group services by location as well as function and/or introduce object broker mechanism. if ( (Discoverer.services != null) && (Discoverer.services.size() > 0)) { + // TODO: refactor to allow list of AbstractName/Handler bindings to be stored or retrieved from elsewhere Vector msaws = (Vector) Discoverer.services.get("MsaWS"); Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred"); + Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch"); + // TODO: move GUI generation code onto service implementation - so a client instance attaches itself to the GUI with method call like jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance, alignframe) Vector wsmenu = new Vector(); - final AlignFrame af = this; + final IProgressIndicator af = this; if (msaws != null) { // Add any Multiple Sequence Alignment Services @@ -3437,42 +3480,9 @@ public class AlignFrame { 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) - { - AlignmentView msa = gatherSequencesForAlignment(); - new jalview.ws.MsaWSClient(sh, title, msa, - false, true, - viewport.getAlignment().getDataset(), - af); - - } - - }); - 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) - { - AlignmentView msa = gatherSequencesForAlignment(); - new jalview.ws.MsaWSClient(sh, title, msa, - true, true, - viewport.getAlignment().getDataset(), - af); - - } - - }); - msawsmenu.add(methodR); - - } + jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh); + impl.attachWSMenuEntry(msawsmenu, this); + } wsmenu.add(msawsmenu); } @@ -3484,32 +3494,25 @@ public class AlignFrame { 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) - { - AlignmentView msa = gatherSeqOrMsaForSecStrPrediction(); - if (msa.getSequences().length == 1) - { - // Single Sequence prediction - new jalview.ws.JPredClient(sh, title, false, msa, af, true); - } - else - { - if (msa.getSequences().length > 1) - { - // Sequence profile based prediction - new jalview.ws.JPredClient(sh, - title, true, msa, af, true); - } - } - } - }); - secstrmenu.add(method); + jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh); + impl.attachWSMenuEntry(secstrmenu, this); } wsmenu.add(secstrmenu); } + if (seqsrch!=null) + { + // Add any sequence search services + final JMenu seqsrchmenu = new JMenu("Sequence Database Search"); + for (int i = 0, j = seqsrch.size(); i < j; i++) + { + final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) + seqsrch.elementAt(i); + jalview.ws.WSClient impl = jalview.ws.Discoverer.getServiceClient(sh); + impl.attachWSMenuEntry(seqsrchmenu, this); + } + // finally, add the whole shebang onto the webservices menu + wsmenu.add(seqsrchmenu); + } resetWebServiceMenu(); for (int i = 0, j = wsmenu.size(); i < j; i++) { @@ -3521,9 +3524,6 @@ public class AlignFrame resetWebServiceMenu(); this.webService.add(this.webServiceNoServices); } - // TODO: add in rediscovery function - // TODO: reduce code redundancy. - // TODO: group services by location as well as function. } @@ -3759,9 +3759,10 @@ public void showTranslation_actionPerformed(ActionEvent e) } /** - * DOCUMENT ME! - * - * @param String DOCUMENT ME! + * Try to load a features file onto the alignment. + * @param file contents or path to retrieve file + * @param type access mode of file (see jalview.io.AlignFile) + * @return true if features file was parsed corectly. */ public boolean parseFeaturesFile(String file, String type) { @@ -3862,12 +3863,15 @@ public void drop(DropTargetDropEvent evt) } } - // This method will attempt to load a "dropped" file first by testing - // whether its and Annotation file, then features file. If both are - // false then the user may have dropped an alignment file onto this - // AlignFrame + /** + * Attempt to load a "dropped" file: First by testing + * whether it's and Annotation file, then a JNet file, and finally a features file. If all are + * false then the user may have dropped an alignment file onto this + * AlignFrame. + * @param file either a filename or a URL string. + */ public void loadJalviewDataFile(String file) - { + { try { String protocol = "File"; @@ -3882,34 +3886,38 @@ public void drop(DropTargetDropEvent evt) if (!isAnnotation) { - boolean isGroupsFile = parseFeaturesFile(file,protocol); - if (!isGroupsFile) + // try to see if its a JNet 'concise' style annotation file *before* we try to parse it as a features file + String format = new IdentifyFile().Identify(file, protocol); + if(format.equalsIgnoreCase("JnetFile")) { - String format = new IdentifyFile().Identify(file, protocol); - - if(format.equalsIgnoreCase("JnetFile")) - { - jalview.io.JPredFile predictions = new jalview.io.JPredFile( - file, protocol); - new JnetAnnotationMaker().add_annotation(predictions, + jalview.io.JPredFile predictions = new jalview.io.JPredFile( + file, protocol); + new JnetAnnotationMaker().add_annotation(predictions, viewport.getAlignment(), 0, false); - alignPanel.adjustAnnotationHeight(); - alignPanel.paintAlignment(true); - } - else + isAnnotation=true; + } + else + { + // try to parse it as a features file + boolean isGroupsFile = parseFeaturesFile(file,protocol); + // if it wasn't a features file then we just treat it as a general alignment file to load into the current view. + if (!isGroupsFile) { new FileLoader().LoadFile(viewport, file, protocol, format); + } else { + alignPanel.paintAlignment(true); + } } } - } - else + if (isAnnotation) { - // (isAnnotation) + alignPanel.adjustAnnotationHeight(); + viewport.updateSequenceIdColours(); buildSortByAnnotationScoresMenu(); + alignPanel.paintAlignment(true); } - } catch (Exception ex) { @@ -3957,7 +3965,7 @@ public void drop(DropTargetDropEvent evt) protected void extractScores_actionPerformed(ActionEvent e) { ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment); - if (pp.getScoresFromDescription("col", "score column ", "\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)")>0) + if (pp.getScoresFromDescription("col", "score column ", "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)", true)>0) { buildSortByAnnotationScoresMenu(); }