- }
- }
-
- /**
- * 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.
- */
- public boolean canShowProducts()
- {
- SequenceI[] selection = viewport.getSequenceSelection();
- AlignmentI dataset = viewport.getAlignment().getDataset();
- boolean showp = false;
- try
- {
- showProducts.removeAll();
- final boolean dna = viewport.getAlignment().isNucleotide();
- String[] ptypes = (selection == null || selection.length == 0) ? null
- : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
-
- for (int t = 0; ptypes != null && t < ptypes.length; t++)
- {
- showp = true;
- final AlignFrame af = this;
- final String source = ptypes[t];
- JMenuItem xtype = new JMenuItem(ptypes[t]);
- xtype.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- showProductsFor(af.viewport.getSequenceSelection(), dna, source);
- }
-
- });
- showProducts.add(xtype);
- }
- showProducts.setVisible(showp);
- showProducts.setEnabled(showp);
- } catch (Exception e)
- {
- jalview.bin.Cache.log
- .warn("canShowProducts threw an exception - please report to help@jalview.org",
- e);
- return false;
- }
- return showp;
- }
-
- 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
- {
- AlignmentI alignment = AlignFrame.this.getViewport()
- .getAlignment();
- AlignmentI xrefs = CrossRef.findXrefSequences(sel, dna, source,
- alignment);
- 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);
-
- if (!Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
- {
- /*
- * split frame display is turned off in preferences file
- */
- 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)
- {
- System.err.println("Failed to make CDS alignment");
- }
- al.getCodonFrames().clear();
- al.getCodonFrames().addAll(copyAlignment.getCodonFrames());
-
- /*
- * pending getting Embl transcripts to 'align',
- * we are only doing this for Ensembl
- */
- // TODO proper criteria for 'can align as cdna'
- if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
- || AlignmentUtils.looksLikeEnsembl(alignment))
- {
- copyAlignment.alignAs(alignment);
- copyAlignmentIsAligned = true;
- }
- }
- else
- {
- copyAlignment = AlignmentUtils.makeCopyAlignment(
- sequenceSelection, xrefs.getSequencesArray());
- copyAlignment.getCodonFrames().addAll(cf);
- }
- copyAlignment.setGapCharacter(AlignFrame.this.viewport
- .getGapCharacter());
-
- StructureSelectionManager ssm = StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance);
- ssm.registerMappings(cf);