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;
new Object[] { source }), sttime);
try
{
- /*
- * 'peer' sequences are any to add to this alignment, for example
- * alternative protein products for my protein's gene
- */
- List<SequenceI> addedPeers = new ArrayList<SequenceI>();
AlignmentI alignment = AlignFrame.this.getViewport()
.getAlignment();
- Alignment xrefs = CrossRef.findXrefSequences(sel, dna, source,
- alignment, addedPeers);
+ AlignmentI xrefs = CrossRef.findXrefSequences(sel, dna, source,
+ alignment);
if (xrefs != null)
{
/*
- * figure out colour scheme if any to apply to features
+ * get display scheme (if any) to apply to features
*/
- ASequenceFetcher sftch = new SequenceFetcher();
- List<DbSourceProxy> proxies = sftch.getSourceProxy(source);
- FeatureSettingsModelI featureColourScheme = null;
- for (DbSourceProxy proxy : proxies)
- {
- FeatureSettingsModelI preferredColours = proxy
- .getFeatureColourScheme();
- if (preferredColours != null)
- {
- featureColourScheme = preferredColours;
- break;
- }
- }
+ FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
+ .getFeatureColourScheme(source);
+
AlignmentI al = makeCrossReferencesAlignment(
alignment.getDataset(), xrefs);
.getString("label.for"), getTitle());
newFrame.setTitle(newtitle);
- boolean asSplitFrame = Cache.getDefault(
- Preferences.ENABLE_SPLIT_FRAME, true);
- if (asSplitFrame)
+ if (!Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
{
/*
- * Make a copy of this alignment (sharing the same dataset
- * sequences). If we are DNA, drop introns and update mappings
+ * split frame display is turned off in preferences file
*/
- AlignmentI copyAlignment = null;
- final SequenceI[] sequenceSelection = AlignFrame.this.viewport
- .getSequenceSelection();
- List<AlignedCodonFrame> cf = xrefs.getCodonFrames();
- if (dna)
- {
- copyAlignment = AlignmentUtils.makeCdsAlignment(
- sequenceSelection, cf, alignment);
- if (copyAlignment.getHeight() == 0)
- {
- System.err.println("Failed to make CDS alignment");
- }
- al.getCodonFrames().clear();
- al.getCodonFrames().addAll(cf);
- }
- else
+ Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
+ DEFAULT_HEIGHT);
+ return; // via finally clause
+ }
+
+ /*
+ * Make a copy of this alignment (sharing the same dataset
+ * sequences). If we are DNA, drop introns and update mappings
+ */
+ AlignmentI copyAlignment = null;
+ final SequenceI[] sequenceSelection = AlignFrame.this.viewport
+ .getSequenceSelection();
+ List<AlignedCodonFrame> cf = xrefs.getCodonFrames();
+ boolean copyAlignmentIsAligned = false;
+ if (dna)
+ {
+ copyAlignment = AlignmentUtils.makeCdsAlignment(
+ sequenceSelection, cf, alignment);
+ if (copyAlignment.getHeight() == 0)
{
- copyAlignment = new Alignment(new Alignment(
- sequenceSelection));
- copyAlignment.getCodonFrames().addAll(cf);
+ System.err.println("Failed to make CDS alignment");
}
- copyAlignment.setGapCharacter(AlignFrame.this.viewport
- .getGapCharacter());
- StructureSelectionManager ssm = StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance);
- ssm.registerMappings(cf);
+ al.getCodonFrames().clear();
+ al.getCodonFrames().addAll(copyAlignment.getCodonFrames());
/*
- * add in any extra 'peer' sequences discovered
- * (e.g. alternative protein products)
+ * pending getting Embl transcripts to 'align',
+ * we are only doing this for Ensembl
*/
- for (SequenceI peer : addedPeers)
+ // TODO proper criteria for 'can align as cdna'
+ if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
+ || AlignmentUtils.looksLikeEnsembl(alignment))
{
- copyAlignment.addSequence(peer);
+ copyAlignment.alignAs(alignment);
+ copyAlignmentIsAligned = true;
}
+ }
+ else
+ {
+ copyAlignment = AlignmentUtils.makeCopyAlignment(
+ sequenceSelection, xrefs.getSequencesArray());
+ copyAlignment.getCodonFrames().addAll(cf);
+ }
+ copyAlignment.setGapCharacter(AlignFrame.this.viewport
+ .getGapCharacter());
- 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);
- }
- }
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(Desktop.instance);
+ ssm.registerMappings(cf);
- 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();
- }
+ if (copyAlignment.getHeight() <= 0)
+ {
+ System.err.println("No Sequences generated for xRef type "
+ + source);
+ return;
+ }
+ /*
+ * align protein to dna
+ */
+ if (dna && copyAlignmentIsAligned)
+ {
+ al.alignAs(copyAlignment);
}
else
{
- Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
- DEFAULT_HEIGHT);
+ /*
+ * align cdna to protein - currently only if
+ * fetching and aligning Ensembl transcripts!
+ */
+ if (DBRefSource.ENSEMBL.equalsIgnoreCase(source))
+ {
+ copyAlignment.alignAs(al);
+ }
}
- }
- else
- {
- System.err.println("No Sequences generated for xRef type "
- + source);
+
+ 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();
}
} catch (Exception e)
{
- jalview.bin.Cache.log.error(
+ Cache.log.error(
"Exception when finding crossreferences", e);
} catch (OutOfMemoryError e)
{
new OOMWarning("whilst fetching crossreferences", e);
- } catch (Error e)
+ } catch (Throwable e)
{
- jalview.bin.Cache.log.error("Error when finding crossreferences",
+ Cache.log.error("Error when finding crossreferences",
e);
+ } finally
+ {
+ AlignFrame.this.setProgressBar(MessageManager.formatMessage(
+ "status.finished_searching_for_sequences_from",
+ new Object[] { source }), sttime);
}
- AlignFrame.this.setProgressBar(MessageManager.formatMessage(
- "status.finished_searching_for_sequences_from",
- new Object[] { source }), sttime);
}
/**
frunner.start();
}
- public boolean canShowTranslationProducts(SequenceI[] selection,
- AlignmentI alignment)
- {
- // old way
- try
- {
- return (jalview.analysis.Dna.canTranslate(selection,
- viewport.getViewAsVisibleContigs(true)));
- } catch (Exception e)
- {
- jalview.bin.Cache.log
- .warn("canTranslate threw an exception - please report to help@jalview.org",
- e);
- return false;
- }
- }
-
/**
* Construct and display a new frame containing the translation of this
* frame's DNA sequences to their aligned protein (amino acid) equivalents.
{
new Thread(new Runnable()
{
-
@Override
public void run()
{
- boolean isNuclueotide = alignPanel.alignFrame.getViewport()
+ boolean isNucleotide = alignPanel.alignFrame.getViewport()
.getAlignment().isNucleotide();
- new jalview.ws.DBRefFetcher(alignPanel.av
+ DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
.getSequenceSelection(), alignPanel.alignFrame, null,
- alignPanel.alignFrame.featureSettings, isNuclueotide)
+ alignPanel.alignFrame.featureSettings, isNucleotide);
+ dbRefFetcher.addListener(new FetchFinishedListenerI()
+ {
+ @Override
+ public void finished()
+ {
+ AlignFrame.this.setMenusForViewport();
+ }
+ });
+ dbRefFetcher
.fetchDBRefs(false);
}
}).start();
@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();
}
@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();
}
@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();
}