X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=fc145edc2776179d37d0ef472d6aad4caf543ef9;hb=364f1cf36d12a069be963ec0166c9170e8b6f365;hp=5ff7c6cb239edda0b3e9fd73f05c8e54ef3ca8f1;hpb=a6b324e3f5edac3df0b968f0037b1cc8b651598e;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 5ff7c6c..fc145ed 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -32,6 +32,7 @@ import jalview.api.AlignViewControllerI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsControllerI; +import jalview.api.FeatureSettingsModelI; import jalview.api.SplitContainerI; import jalview.api.ViewStyleI; import jalview.api.analysis.ScoreModelI; @@ -53,6 +54,7 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.DBRefSource; import jalview.datamodel.HiddenSequences; import jalview.datamodel.PDBEntry; import jalview.datamodel.SeqCigar; @@ -94,9 +96,13 @@ import jalview.schemes.ZappoColourScheme; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import jalview.ws.DBRefFetcher; +import jalview.ws.DBRefFetcher.FetchFinishedListenerI; +import jalview.ws.SequenceFetcher; import jalview.ws.jws1.Discoverer; import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.jabaws2.Jws2Instance; +import jalview.ws.seqfetcher.ASequenceFetcher; import jalview.ws.seqfetcher.DbSourceProxy; import java.awt.BorderLayout; @@ -904,7 +910,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure()); rnahelicesColour .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour); - setShowProductsEnabled(); + + showProducts.setEnabled(canShowProducts()); + updateEditMenuBar(); } @@ -960,7 +968,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void fetchSequence_actionPerformed(ActionEvent e) { - new SequenceFetcher(this); + new jalview.gui.SequenceFetcher(this); } @Override @@ -1370,7 +1378,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void bioJSMenuItem_actionPerformed(ActionEvent e) { - BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel); + BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this); bjs.exportJalviewAlignmentAsBioJsHtmlFile(); } @@ -4652,67 +4660,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } - /* - * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser - * chooser = new JalviewFileChooser(jalview.bin.Cache. - * getProperty("LAST_DIRECTORY")); - * - * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export - * to Vamsas file"); chooser.setToolTipText("Export"); - * - * int value = chooser.showSaveDialog(this); - * - * if (value == JalviewFileChooser.APPROVE_OPTION) { - * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport); - * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview( - * chooser.getSelectedFile().getAbsolutePath(), this); } } - */ /** - * prototype of an automatically enabled/disabled analysis function + * Searches selected sequences for xRef products and builds the Show + * Cross-References menu (formerly called Show Products) * + * @return true if Show Cross-references menu should be enabled. */ - protected void setShowProductsEnabled() + public boolean canShowProducts() { 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) - { + AlignmentI dataset = viewport.getAlignment().getDataset(); boolean showp = false; try { showProducts.removeAll(); final boolean dna = viewport.getAlignment().isNucleotide(); - final Alignment ds = dataset; String[] ptypes = (selection == null || selection.length == 0) ? null : 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 && t < ptypes.length; t++) { showp = true; - final boolean isRegSel = isRegionSelection; final AlignFrame af = this; final String source = ptypes[t]; JMenuItem xtype = new JMenuItem(ptypes[t]); @@ -4722,9 +4690,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void actionPerformed(ActionEvent e) { - // TODO: new thread for this call with vis-delay - af.showProductsFor(af.viewport.getSequenceSelection(), - isRegSel, dna, source); + showProductsFor(af.viewport.getSequenceSelection(), dna, source); } }); @@ -4735,15 +4701,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } catch (Exception e) { jalview.bin.Cache.log - .warn("canTranslate threw an exception - please report to help@jalview.org", + .warn("canShowProducts threw an exception - please report to help@jalview.org", e); return false; } return showp; } - protected void showProductsFor(final SequenceI[] sel, - final boolean isRegSel, final boolean dna, final String source) + protected void showProductsFor(final SequenceI[] sel, final boolean dna, + final String source) { Runnable foo = new Runnable() { @@ -4757,44 +4723,42 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, new Object[] { source }), sttime); try { - // update our local dataset reference - Alignment ds = AlignFrame.this.getViewport().getAlignment() - .getDataset(); - Alignment prods = CrossRef - .findXrefSequences(sel, dna, source, ds); - if (prods != null) + /* + * 'peer' sequences are any to add to this alignment, for example + * alternative protein products for my protein's gene + */ + List addedPeers = new ArrayList(); + AlignmentI alignment = AlignFrame.this.getViewport() + .getAlignment(); + Alignment xrefs = CrossRef.findXrefSequences(sel, dna, source, + alignment, addedPeers); + if (xrefs != null) { - SequenceI[] sprods = new SequenceI[prods.getHeight()]; - for (int s = 0; s < sprods.length; s++) + /* + * figure out colour scheme if any to apply to features + */ + ASequenceFetcher sftch = new SequenceFetcher(); + List proxies = sftch.getSourceProxy(source); + FeatureSettingsModelI featureColourScheme = null; + for (DbSourceProxy proxy : proxies) { - sprods[s] = (prods.getSequenceAt(s)).deriveSequence(); - if (ds.getSequences() == null - || !ds.getSequences().contains( - sprods[s].getDatasetSequence())) + FeatureSettingsModelI preferredColours = proxy + .getFeatureColourScheme(); + if (preferredColours != null) { - ds.addSequence(sprods[s].getDatasetSequence()); + featureColourScheme = preferredColours; + break; } - sprods[s].updatePDBIds(); } - Alignment al = new Alignment(sprods); - al.setDataset(ds); + AlignmentI al = makeCrossReferencesAlignment( + alignment.getDataset(), xrefs); - /* - * Copy dna-to-protein mappings to new alignment - */ - // TODO 1: no mappings are set up for EMBL product - // TODO 2: if they were, should add them to protein alignment, not - // dna - List cf = prods.getCodonFrames(); - for (AlignedCodonFrame acf : cf) - { - al.addCodonFrame(acf); - } AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT); - String newtitle = "" + (dna ? "Proteins" : "Nucleotides") - + " for " + (isRegSel ? "selected region of " : "") - + getTitle(); + String newtitle = String.format("%s %s %s", + MessageManager.getString(dna ? "label.proteins" + : "label.nucleotides"), MessageManager + .getString("label.for"), getTitle()); newFrame.setTitle(newtitle); boolean asSplitFrame = Cache.getDefault( @@ -4808,36 +4772,102 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignmentI copyAlignment = null; final SequenceI[] sequenceSelection = AlignFrame.this.viewport .getSequenceSelection(); + List cf = xrefs.getCodonFrames(); if (dna) { copyAlignment = AlignmentUtils.makeCdsAlignment( - sequenceSelection, cf); + sequenceSelection, cf, alignment); + if (copyAlignment.getHeight() == 0) + { + System.err.println("Failed to make CDS alignment"); + } al.getCodonFrames().clear(); al.getCodonFrames().addAll(cf); - final StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.instance); - ssm.registerMappings(cf); } else { copyAlignment = new Alignment(new Alignment( sequenceSelection)); + copyAlignment.getCodonFrames().addAll(cf); + } + copyAlignment.setGapCharacter(AlignFrame.this.viewport + .getGapCharacter()); + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(Desktop.instance); + ssm.registerMappings(cf); + + /* + * add in any extra 'peer' sequences discovered + * (e.g. alternative protein products) + */ + for (SequenceI peer : addedPeers) + { + copyAlignment.addSequence(peer); + } + + if (copyAlignment.getHeight() > 0) + { + /* + * align protein to dna + */ + // FIXME what if the dna is not aligned :-O + if (dna) + { + al.alignAs(copyAlignment); + } + else + { + /* + * align cdna to protein - currently only if + * fetching and aligning Ensembl transcripts! + */ + if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)) + { + copyAlignment.alignAs(al); + } + } + + AlignFrame copyThis = new AlignFrame(copyAlignment, + AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); + copyThis.setTitle(AlignFrame.this.getTitle()); + + boolean showSequenceFeatures = viewport + .isShowSequenceFeatures(); + newFrame.setShowSeqFeatures(showSequenceFeatures); + copyThis.setShowSeqFeatures(showSequenceFeatures); + FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas + .getFeatureRenderer(); + + /* + * copy feature rendering settings to split frame + */ + newFrame.alignPanel.getSeqPanel().seqCanvas + .getFeatureRenderer().transferSettings( + myFeatureStyling); + copyThis.alignPanel.getSeqPanel().seqCanvas + .getFeatureRenderer().transferSettings( + myFeatureStyling); + + /* + * apply 'database source' feature configuration + * if any was found + */ + // TODO is this the feature colouring for the original + // alignment or the fetched xrefs? either could be Ensembl + newFrame.getViewport().applyFeaturesStyle( + featureColourScheme); + copyThis.getViewport().applyFeaturesStyle( + featureColourScheme); + + SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame, + dna ? newFrame : copyThis); + newFrame.setVisible(true); + copyThis.setVisible(true); + String linkedTitle = MessageManager + .getString("label.linked_view_title"); + Desktop.addInternalFrame(sf, linkedTitle, -1, -1); + sf.adjustDivider(); } - AlignFrame copyThis = new AlignFrame(copyAlignment, - AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); - copyThis.setTitle(AlignFrame.this.getTitle()); - // SplitFrame with dna above, protein below - boolean showSequenceFeatures = viewport - .isShowSequenceFeatures(); - newFrame.setShowSeqFeatures(showSequenceFeatures); - copyThis.setShowSeqFeatures(showSequenceFeatures); - SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame, - dna ? newFrame : copyThis); - newFrame.setVisible(true); - copyThis.setVisible(true); - String linkedTitle = MessageManager - .getString("label.linked_view_title"); - Desktop.addInternalFrame(sf, linkedTitle, -1, -1); } else { @@ -4867,6 +4897,49 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, new Object[] { source }), sttime); } + /** + * Makes an alignment containing the given sequences. If this is of the + * same type as the given dataset (nucleotide/protein), then the new + * alignment shares the same dataset, and its dataset sequences are added + * to it. Otherwise a new dataset sequence is created for the + * cross-references. + * + * @param dataset + * @param seqs + * @return + */ + protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset, + AlignmentI seqs) + { + boolean sameType = dataset.isNucleotide() == seqs.isNucleotide(); + + SequenceI[] sprods = new SequenceI[seqs.getHeight()]; + for (int s = 0; s < sprods.length; s++) + { + sprods[s] = (seqs.getSequenceAt(s)).deriveSequence(); + if (sameType) + { + if (dataset.getSequences() == null + || !dataset.getSequences().contains( + sprods[s].getDatasetSequence())) + { + dataset.addSequence(sprods[s].getDatasetSequence()); + } + } + sprods[s].updatePDBIds(); + } + Alignment al = new Alignment(sprods); + if (sameType) + { + al.setDataset((Alignment) dataset); + } + else + { + al.createDatasetAlignment(); + } + return al; + } + }; Thread frunner = new Thread(foo); frunner.start(); @@ -5303,10 +5376,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.paintAlignment(true); } } - else - { - new FileLoader().LoadFile(viewport, file, protocol, format); - } + else + { + new FileLoader().LoadFile(viewport, file, protocol, format); + } } } if (isAnnotation) @@ -5510,18 +5583,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { new Thread(new Runnable() { - @Override public void run() { - boolean isNuclueotide = alignPanel.alignFrame - .getViewport().getAlignment() - .isNucleotide(); - new jalview.ws.DBRefFetcher(alignPanel.av - .getSequenceSelection(), - alignPanel.alignFrame, null, - alignPanel.alignFrame.featureSettings, - isNuclueotide) + boolean isNucleotide = alignPanel.alignFrame.getViewport() + .getAlignment().isNucleotide(); + DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av + .getSequenceSelection(), alignPanel.alignFrame, null, + alignPanel.alignFrame.featureSettings, isNucleotide); + dbRefFetcher.addListener(new FetchFinishedListenerI() + { + @Override + public void finished() + { + AlignFrame.this.setMenusForViewport(); + } + }); + dbRefFetcher .fetchDBRefs(false); } }).start(); @@ -5536,7 +5614,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - final jalview.ws.SequenceFetcher sf = SequenceFetcher + final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher .getSequenceFetcherSingleton(me); javax.swing.SwingUtilities.invokeLater(new Runnable() { @@ -5590,15 +5668,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - boolean isNuclueotide = alignPanel.alignFrame + boolean isNucleotide = alignPanel.alignFrame .getViewport().getAlignment() .isNucleotide(); - new jalview.ws.DBRefFetcher(alignPanel.av - .getSequenceSelection(), + DBRefFetcher dbRefFetcher = new DBRefFetcher( + alignPanel.av.getSequenceSelection(), alignPanel.alignFrame, dassource, alignPanel.alignFrame.featureSettings, - isNuclueotide) - .fetchDBRefs(false); + isNucleotide); + dbRefFetcher + .addListener(new FetchFinishedListenerI() + { + @Override + public void finished() + { + AlignFrame.this.setMenusForViewport(); + } + }); + dbRefFetcher.fetchDBRefs(false); } }).start(); } @@ -5631,15 +5718,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - boolean isNuclueotide = alignPanel.alignFrame + boolean isNucleotide = alignPanel.alignFrame .getViewport().getAlignment() .isNucleotide(); - new jalview.ws.DBRefFetcher(alignPanel.av - .getSequenceSelection(), + DBRefFetcher dbRefFetcher = new DBRefFetcher( + alignPanel.av.getSequenceSelection(), alignPanel.alignFrame, dassource, alignPanel.alignFrame.featureSettings, - isNuclueotide) - .fetchDBRefs(false); + isNucleotide); + dbRefFetcher + .addListener(new FetchFinishedListenerI() + { + @Override + public void finished() + { + AlignFrame.this.setMenusForViewport(); + } + }); + dbRefFetcher.fetchDBRefs(false); } }).start(); } @@ -5687,15 +5783,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - boolean isNuclueotide = alignPanel.alignFrame + boolean isNucleotide = alignPanel.alignFrame .getViewport().getAlignment() .isNucleotide(); - new jalview.ws.DBRefFetcher(alignPanel.av - .getSequenceSelection(), + DBRefFetcher dbRefFetcher = new DBRefFetcher( + alignPanel.av.getSequenceSelection(), alignPanel.alignFrame, dassrc, alignPanel.alignFrame.featureSettings, - isNuclueotide) - .fetchDBRefs(false); + isNucleotide); + dbRefFetcher + .addListener(new FetchFinishedListenerI() + { + @Override + public void finished() + { + AlignFrame.this.setMenusForViewport(); + } + }); + dbRefFetcher.fetchDBRefs(false); } }).start(); }