- protected void showProductsFor(final SequenceI[] sel, final boolean dna,
- final String source)
- {
- Runnable foo = new Runnable()
- {
-
- @Override
- public void run()
- {
- final long sttime = System.currentTimeMillis();
- AlignFrame.this.setProgressBar(MessageManager.formatMessage(
- "status.searching_for_sequences_from",
- 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);
- if (xrefs != null)
- {
- /*
- * get display scheme (if any) to apply to features
- */
- FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
- .getFeatureColourScheme(source);
-
- AlignmentI al = makeCrossReferencesAlignment(
- alignment.getDataset(), xrefs);
-
- AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH,
- DEFAULT_HEIGHT);
- 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(
- Preferences.ENABLE_SPLIT_FRAME, true);
- if (asSplitFrame)
- {
- /*
- * 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();
- 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
- {
- 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();
- }
- }
- else
- {
- Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
- DEFAULT_HEIGHT);
- }
- }
- else
- {
- System.err.println("No Sequences generated for xRef type "
- + source);
- }
- } catch (Exception e)
- {
- jalview.bin.Cache.log.error(
- "Exception when finding crossreferences", e);
- } catch (OutOfMemoryError e)
- {
- new OOMWarning("whilst fetching crossreferences", e);
- } catch (Error e)
- {
- jalview.bin.Cache.log.error("Error when finding crossreferences",
- e);
- }
- AlignFrame.this.setProgressBar(MessageManager.formatMessage(
- "status.finished_searching_for_sequences_from",
- 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();
- }
-
- public boolean canShowTranslationProducts(SequenceI[] selection,
- AlignmentI alignment)