X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=72691cc1577e35261fa48158e7dfd52f674db069;hb=9480f68983a1dbd16d876706ed0c7a51fbaaff01;hp=b27a98e9c5aa8ed9564ddb8ac4572f4423f225ca;hpb=4ab604448cf2d6f3af25ba89aba8e7d576949276;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b27a98e..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)); } /** @@ -1049,8 +1080,28 @@ public class AlignFrame } } - - + /** + * + * @return alignment objects for all views + */ + AlignmentI[] getViewAlignments() + { + if (alignPanels!=null) + { + Enumeration e = alignPanels.elements(); + AlignmentI[] als = new AlignmentI[alignPanels.size()]; + for (int i=0; e.hasMoreElements(); i++) + { + als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment(); + } + return als; + } + if (viewport!=null) + { + return new AlignmentI[] { viewport.alignment }; + } + return null; + } /** * DOCUMENT ME! * @@ -1058,9 +1109,11 @@ public class AlignFrame */ protected void undoMenuItem_actionPerformed(ActionEvent e) { + if (viewport.historyList.empty()) + return; CommandI command = (CommandI)viewport.historyList.pop(); viewport.redoList.push(command); - command.undoCommand(); + command.undoCommand(getViewAlignments()); AlignViewport originalSource = getOriginatingSource(command); updateEditMenuBar(); @@ -1088,7 +1141,7 @@ public class AlignFrame CommandI command = (CommandI) viewport.redoList.pop(); viewport.historyList.push(command); - command.doCommand(); + command.doCommand(getViewAlignments()); AlignViewport originalSource = getOriginatingSource(command); updateEditMenuBar(); @@ -1403,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) { @@ -1582,19 +1635,44 @@ public class AlignFrame alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a); } - - } } if (!newAlignment) { + // propagate alignment changed. viewport.setEndSeq(alignment.getHeight()); if (annotationAdded) { - alignPanel.annotationPanel.adjustPanelHeight(); + // Duplicate sequence annotation in all views. + AlignmentI[] alview = this.getViewAlignments(); + for (int i = 0; i < sequences.length; i++) + { + AlignmentAnnotation sann[] = sequences[i].getAnnotation(); + if (sann == null) + continue; + for (int avnum=0;avnum0); scoreSorts.clear(); + + _annotationScoreVectorHash = + viewport.alignment.getAlignmentAnnotation().hashCode(); } } @@ -3256,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); + } } } @@ -3335,7 +3433,7 @@ public class AlignFrame { ex.printStackTrace(); } - + return tp; } @@ -3346,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)) { @@ -3445,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. } @@ -3467,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); } @@ -3493,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(); }