- * }); webService.add(testAlView);
- */
- // TODO: refactor to RestClient discoverer and merge menu entries for
- // rest-style services with other types of analysis/calculation service
- // SHmmr test client - still being implemented.
- // DEBUG - alignmentView
-
- for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
- .getRestClients())
- {
- client.attachWSMenuEntry(
- JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
- this);
- }
- }
-
- /*
- * 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
- *
- */
- 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 = (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]);
- xtype.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- // TODO: new thread for this call with vis-delay
- af.showProductsFor(af.viewport.getSequenceSelection(),
- isRegSel, dna, source);
- }
-
- });
- showProducts.add(xtype);
- }
- showProducts.setVisible(showp);
- showProducts.setEnabled(showp);
- } catch (Exception e)
- {
- jalview.bin.Cache.log
- .warn("canTranslate 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)
- {
- 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
- {
- // update our local dataset reference
- Alignment ds = AlignFrame.this.getViewport().getAlignment()
- .getDataset();
- Alignment prods = CrossRef
- .findXrefSequences(sel, dna, source, ds);
- if (prods != null)
- {
- SequenceI[] sprods = new SequenceI[prods.getHeight()];
- for (int s = 0; s < sprods.length; s++)
- {
- sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
- if (ds.getSequences() == null
- || !ds.getSequences().contains(
- sprods[s].getDatasetSequence()))
- {
- ds.addSequence(sprods[s].getDatasetSequence());
- }
- sprods[s].updatePDBIds();
- }
- Alignment al = new Alignment(sprods);
- al.setDataset(ds);
-
- /*
- * 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
- Set<AlignedCodonFrame> cf = prods.getCodonFrames();
- for (AlignedCodonFrame acf : cf)
- {
- al.addCodonFrame(acf);
- }
- AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
- DEFAULT_HEIGHT);
- String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
- + " for " + ((isRegSel) ? "selected region of " : "")
- + getTitle();
- naf.setTitle(newtitle);
-
- // temporary flag until SplitFrame is released
- boolean asSplitFrame = Cache.getDefault(
- Preferences.ENABLE_SPLIT_FRAME, false);
- 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();
- if (dna)
- {
- copyAlignment = AlignmentUtils.makeExonAlignment(
- sequenceSelection, cf);
- al.getCodonFrames().clear();
- al.getCodonFrames().addAll(cf);
- final StructureSelectionManager ssm = StructureSelectionManager
- .getStructureSelectionManager(Desktop.instance);
- ssm.addMappings(cf);
- }
- else
- {
- copyAlignment = new Alignment(new Alignment(
- sequenceSelection));
- }
- AlignFrame copyThis = new AlignFrame(copyAlignment,
- AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
- copyThis.setTitle(AlignFrame.this.getTitle());
- // SplitFrame with dna above, protein below
- SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
- dna ? naf : copyThis);
- naf.setVisible(true);
- copyThis.setVisible(true);
- String linkedTitle = MessageManager
- .getString("label.linked_view_title");
- Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
- }
- else
- {
- Desktop.addInternalFrame(naf, 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);
- }