X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=72691cc1577e35261fa48158e7dfd52f674db069;hb=9480f68983a1dbd16d876706ed0c7a51fbaaff01;hp=c7887da9c92e55cab3fccba11f0a9e3f8799c9e4;hpb=c8a5e53fe8b07e36f805fd7e21568064c20922f0;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index c7887da..72691cc 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -59,9 +59,13 @@ public class AlignFrame Vector alignPanels = new Vector(); - /** DOCUMENT ME!! */ + /** + * Last format used to load or save alignments in this window + */ String currentFileFormat = null; - + /** + * Current filename for this alignment + */ String fileName = null; @@ -156,7 +160,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; @@ -498,14 +507,17 @@ public class AlignFrame showTranslation.setVisible( nucleotide ); conservationMenuItem.setEnabled( !nucleotide ); modifyConservation.setEnabled( !nucleotide ); - + //Remember AlignFrame always starts as protein if(!nucleotide) { calculateMenu.remove(calculateMenu.getItemCount()-2); } + setShowProductsEnabled(); } + + /** * Need to call this method when tabs are selected for multiple views, * or when loading from Jalview2XML.java @@ -580,10 +592,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 */ @@ -668,7 +688,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") ) { @@ -689,10 +709,8 @@ public class AlignFrame { 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" }, + jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS, + jalview.io.AppletFormatAdapter.WRITABLE_FNAMES, currentFileFormat, false); @@ -722,7 +740,10 @@ public class AlignFrame currentFileFormat); jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName); - + if (currentFileFormat.indexOf(" ")>-1) + { + currentFileFormat = currentFileFormat.substring(0, currentFileFormat.indexOf(" ")); + } saveAlignment(fileName, currentFileFormat); } } @@ -749,8 +770,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) @@ -766,11 +797,11 @@ public class AlignFrame omitHidden = viewport.getViewAsString(false); } } - - String output = new FormatAdapter().formatSequences( + FormatAdapter f = new FormatAdapter(); + String output = f.formatSequences( format, - viewport.alignment.getSequencesArray(), - omitHidden); + (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future + omitHidden, f.getCacheSuffixDefault(format), viewport.colSel); if (output == null) { @@ -841,8 +872,8 @@ public class AlignFrame cap.setText(new FormatAdapter().formatSequences( e.getActionCommand(), - viewport.alignment.getSequencesArray(), - omitHidden)); + viewport.alignment, + omitHidden, viewport.colSel)); } /** @@ -1425,9 +1456,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) { @@ -2849,7 +2880,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); @@ -3112,7 +3143,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); } @@ -3316,21 +3347,28 @@ public class AlignFrame { String choice = chooser.getSelectedFile().getPath(); jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - + jalview.io.NewickFile fin = null; try { - jalview.io.NewickFile fin = new jalview.io.NewickFile(choice, + 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(), + "Problem reading tree file", JOptionPane.WARNING_MESSAGE); ex.printStackTrace(); } + if (fin!=null && fin.hasWarningMessage()) + { + JOptionPane.showMessageDialog(Desktop.desktop, + fin.getWarningMessage(), + "Possible problem with tree file", + JOptionPane.WARNING_MESSAGE); + } } } @@ -3395,7 +3433,7 @@ public class AlignFrame { ex.printStackTrace(); } - + return tp; } @@ -3406,6 +3444,11 @@ public class AlignFrame */ public void BuildWebServiceMenu() { + // TODO: add support for context dependent disabling of services based on alignment and current selection + // TODO: refactor to allow list of AbstractName/Handler bindings to be stored or retrieved from elsewhere + // 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)) { @@ -3505,9 +3548,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. } @@ -3527,7 +3567,7 @@ public class AlignFrame public void actionPerformed(ActionEvent e) { - new jalview.io.DBRefFetcher( + new jalview.ws.DBRefFetcher( alignPanel.av.getSequenceSelection(), alignPanel.alignFrame).fetchDBRefs(false); } @@ -3553,8 +3593,164 @@ public class AlignFrame vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this); } }*/ + /** + * prototype of an automatically enabled/disabled analysis function + * + */ + protected void setShowProductsEnabled() + { + SequenceI [] selection = viewport.getSequenceSelection(); + if (canShowProducts(selection, viewport.getSelectionGroup()!=null, viewport.getAlignment().getDataset())) + { + showProducts.setEnabled(true); + + } else { + showProducts.setEnabled(false); + } + } + /** + * search selection for sequence xRef products and build the + * show products menu. + * @param selection + * @param dataset + * @return true if showProducts menu should be enabled. + */ + public boolean canShowProducts(SequenceI[] selection, boolean isRegionSelection, Alignment dataset) + { + boolean showp=false; + try { + showProducts.removeAll(); + final boolean dna = viewport.getAlignment().isNucleotide(); + final Alignment ds = dataset; + String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection, dataset); + //Object[] prods = CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(), selection, dataset, true); + final SequenceI[] sel = selection; + for (int t=0; ptypes!=null && t0) + if (pp.getScoresFromDescription("col", "score column ", "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)", true)>0) { buildSortByAnnotationScoresMenu(); }