import jalview.datamodel.DBRefEntry;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.PDBEntry;
-import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
* Creates a new PopupMenu object.
*
* @param ap
- * DOCUMENT ME!
* @param seq
- * DOCUMENT ME!
+ * @param features
+ * non-positional features (for seq not null), or positional features
+ * at residue (for seq equal to null)
*/
- public PopupMenu(final AlignmentPanel ap, Sequence seq,
- List<String> links)
+ public PopupMenu(final AlignmentPanel ap, SequenceI seq,
+ List<SequenceFeature> features)
{
- this(ap, seq, links, null);
+ this(ap, seq, features, null);
}
/**
+ * Constructor
*
- * @param ap
+ * @param alignPanel
* @param seq
- * @param links
+ * the sequence under the cursor if in the Id panel, null if in the
+ * sequence panel
+ * @param features
+ * non-positional features if in the Id panel, features at the
+ * clicked residue if in the sequence panel
* @param groupLinks
*/
- public PopupMenu(final AlignmentPanel ap, final SequenceI seq,
- List<String> links, List<String> groupLinks)
+ public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq,
+ List<SequenceFeature> features, List<String> groupLinks)
{
// /////////////////////////////////////////////////////////
// If this is activated from the sequence panel, the user may want to
//
// If from the IDPanel, we must display the sequence menu
// ////////////////////////////////////////////////////////
- this.ap = ap;
+ this.ap = alignPanel;
sequence = seq;
for (String ff : FileFormats.getInstance().getWritableFormats(true))
/*
* And repeat for the current selection group (if there is one):
*/
- final List<SequenceI> selectedGroup = (ap.av.getSelectionGroup() == null
+ final List<SequenceI> selectedGroup = (alignPanel.av.getSelectionGroup() == null
? Collections.<SequenceI> emptyList()
- : ap.av.getSelectionGroup().getSequences());
+ : alignPanel.av.getSelectionGroup().getSequences());
buildAnnotationTypesMenus(groupShowAnnotationsMenu,
groupHideAnnotationsMenu, selectedGroup);
configureReferenceAnnotationsMenu(groupAddReferenceAnnotations,
if (seq != null)
{
sequenceMenu.setText(sequence.getName());
- if (seq == ap.av.getAlignment().getSeqrep())
+ if (seq == alignPanel.av.getAlignment().getSeqrep())
{
makeReferenceSeq.setText(
MessageManager.getString("action.unmark_as_reference"));
MessageManager.getString("action.set_as_reference"));
}
- if (!ap.av.getAlignment().isNucleotide())
+ if (!alignPanel.av.getAlignment().isNucleotide())
{
remove(rnaStructureMenu);
}
* add menu items to 2D-render any alignment or sequence secondary
* structure annotation
*/
- AlignmentAnnotation[] aas = ap.av.getAlignment()
+ AlignmentAnnotation[] aas = alignPanel.av.getAlignment()
.getAlignmentAnnotation();
if (aas != null)
{
@Override
public void actionPerformed(ActionEvent e)
{
- new AppVarna(seq, aa, ap);
+ new AppVarna(seq, aa, alignPanel);
}
});
rnaStructureMenu.add(menuItem);
public void actionPerformed(ActionEvent e)
{
// TODO: VARNA does'nt print gaps in the sequence
- new AppVarna(seq, aa, ap);
+ new AppVarna(seq, aa, alignPanel);
}
});
rnaStructureMenu.add(menuItem);
});
add(menuItem);
- if (ap.av.getSelectionGroup() != null
- && ap.av.getSelectionGroup().getSize() > 1)
+ if (alignPanel.av.getSelectionGroup() != null
+ && alignPanel.av.getSelectionGroup().getSize() > 1)
{
menuItem = new JMenuItem(MessageManager
.formatMessage("label.represent_group_with", new Object[]
sequenceMenu.add(menuItem);
}
- if (ap.av.hasHiddenRows())
+ if (alignPanel.av.hasHiddenRows())
{
- final int index = ap.av.getAlignment().findIndex(seq);
+ final int index = alignPanel.av.getAlignment().findIndex(seq);
- if (ap.av.adjustForHiddenSeqs(index)
- - ap.av.adjustForHiddenSeqs(index - 1) > 1)
+ if (alignPanel.av.adjustForHiddenSeqs(index)
+ - alignPanel.av.adjustForHiddenSeqs(index - 1) > 1)
{
menuItem = new JMenuItem(
MessageManager.getString("action.reveal_sequences"));
@Override
public void actionPerformed(ActionEvent e)
{
- ap.av.showSequence(index);
- if (ap.overviewPanel != null)
+ alignPanel.av.showSequence(index);
+ if (alignPanel.overviewPanel != null)
{
- ap.overviewPanel.updateOverviewImage();
+ alignPanel.overviewPanel.updateOverviewImage();
}
}
});
}
}
// for the case when no sequences are even visible
- if (ap.av.hasHiddenRows())
+ if (alignPanel.av.hasHiddenRows())
{
{
menuItem = new JMenuItem(
@Override
public void actionPerformed(ActionEvent e)
{
- ap.av.showAllHiddenSeqs();
- if (ap.overviewPanel != null)
+ alignPanel.av.showAllHiddenSeqs();
+ if (alignPanel.overviewPanel != null)
{
- ap.overviewPanel.updateOverviewImage();
+ alignPanel.overviewPanel.updateOverviewImage();
}
}
});
}
}
- SequenceGroup sg = ap.av.getSelectionGroup();
+ SequenceGroup sg = alignPanel.av.getSelectionGroup();
boolean isDefinedGroup = (sg != null)
- ? ap.av.getAlignment().getGroups().contains(sg)
+ ? alignPanel.av.getAlignment().getGroups().contains(sg)
: false;
if (sg != null && sg.getSize() > 0)
Hashtable<String, PDBEntry> pdbe = new Hashtable<>(), reppdb = new Hashtable<>();
SequenceI sqass = null;
- for (SequenceI sq : ap.av.getSequenceSelection())
+ for (SequenceI sq : alignPanel.av.getSequenceSelection())
{
Vector<PDBEntry> pes = sq.getDatasetSequence().getAllPDBEntries();
if (pes != null && pes.size() > 0)
rnaStructureMenu.setVisible(false);
}
- if (links != null && links.size() > 0)
- {
- addFeatureLinks(seq, links);
- }
+ addLinks(seq, features);
}
/**
* Adds a 'Link' menu item with a sub-menu item for each hyperlink provided.
+ * When seq is not null, these are links for the sequence id, which may be to
+ * external web sites for the sequence accession, and/or links embedded in
+ * non-positional features. When seq is null, only links embedded in the
+ * provided features are added.
*
* @param seq
- * @param links
+ * @param features
*/
- void addFeatureLinks(final SequenceI seq, List<String> links)
+ void addLinks(final SequenceI seq, List<SequenceFeature> features)
{
JMenu linkMenu = new JMenu(MessageManager.getString("action.link"));
+
+ List<String> nlinks = null;
+ if (seq != null)
+ {
+ nlinks = Preferences.sequenceUrlLinks.getLinksForMenu();
+ }
+ else
+ {
+ nlinks = new ArrayList<>();
+ }
+
+ if (features != null)
+ {
+ for (SequenceFeature sf : features)
+ {
+ if (sf.links != null)
+ {
+ for (String link : sf.links)
+ {
+ nlinks.add(link);
+ }
+ }
+ }
+ }
+
Map<String, List<String>> linkset = new LinkedHashMap<>();
- for (String link : links)
+ for (String link : nlinks)
{
UrlLink urlLink = null;
try
addshowLinks(linkMenu, linkset.values());
- // disable link menu if there are no valid entries
+ // only add link menu if it has entries
if (linkMenu.getItemCount() > 0)
{
- linkMenu.setEnabled(true);
- }
- else
- {
- linkMenu.setEnabled(false);
- }
-
- if (sequence != null)
- {
- sequenceMenu.add(linkMenu);
- }
- else
- {
- add(linkMenu);
+ if (sequence != null)
+ {
+ sequenceMenu.add(linkMenu);
+ }
+ else
+ {
+ add(linkMenu);
+ }
}
-
}
/**
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
-import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
import jalview.io.FileFormat;
import jalview.io.FormatAdapter;
+import jalview.urls.api.UrlProviderFactoryI;
+import jalview.urls.desktop.DesktopUrlProviderFactory;
import jalview.util.MessageManager;
+import jalview.util.UrlConstants;
import java.awt.Component;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.swing.JMenu;
@BeforeMethod(alwaysRun = true)
public void setUp() throws IOException
{
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ String inMenuString = ("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$"
+ + SEQUENCE_ID
+ + "$"
+ + "|"
+ + "UNIPROT | http://www.uniprot.org/uniprot/$" + DB_ACCESSION + "$")
+ + "|"
+ + ("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$"
+ + DB_ACCESSION + "$")
+ + "|"
+ +
+ // Gene3D entry tests for case (in)sensitivity
+ ("Gene3D | http://gene3d.biochem.ucl.ac.uk/Gene3D/search?sterm=$"
+ + DB_ACCESSION + "$&mode=protein");
+
+ UrlProviderFactoryI factory = new DesktopUrlProviderFactory(
+ UrlConstants.DEFAULT_LABEL, inMenuString, "");
+ Preferences.sequenceUrlLinks = factory.createUrlProvider();
+
alignment = new FormatAdapter().readFile(TEST_DATA,
DataSourceType.PASTE, FileFormat.Fasta);
AlignFrame af = new AlignFrame(alignment, 700, 500);
// add all the dbrefs to the sequences: Uniprot 1 each, Interpro all 3 to
// seq0, Gene3D to seq1
- seqs.get(0).addDBRef(refs.get(0));
+ SequenceI seq = seqs.get(0);
+ seq.addDBRef(refs.get(0));
- seqs.get(0).addDBRef(refs.get(1));
- seqs.get(0).addDBRef(refs.get(2));
- seqs.get(0).addDBRef(refs.get(3));
+ seq.addDBRef(refs.get(1));
+ seq.addDBRef(refs.get(2));
+ seq.addDBRef(refs.get(3));
seqs.get(1).addDBRef(refs.get(4));
seqs.get(1).addDBRef(refs.get(5));
// get the Popup Menu for first sequence
- testee = new PopupMenu(parentPanel, (Sequence) seqs.get(0), links);
+ List<SequenceFeature> noFeatures = Collections.<SequenceFeature> emptyList();
+ testee = new PopupMenu(parentPanel, seq, noFeatures);
Component[] seqItems = testee.sequenceMenu.getMenuComponents();
JMenu linkMenu = (JMenu) seqItems[6];
Component[] linkItems = linkMenu.getMenuComponents();
// sequence id for each link should match corresponding DB accession id
for (int i = 1; i < 4; i++)
{
- assertEquals(refs.get(i - 1).getSource(), ((JMenuItem) linkItems[i])
+ String msg = seq.getName() + " link[" + i + "]";
+ assertEquals(msg, refs.get(i - 1).getSource(),
+ ((JMenuItem) linkItems[i])
.getText().split("\\|")[0]);
- assertEquals(refs.get(i - 1).getAccessionId(),
+ assertEquals(msg, refs.get(i - 1).getAccessionId(),
((JMenuItem) linkItems[i])
.getText().split("\\|")[1]);
}
// get the Popup Menu for second sequence
- testee = new PopupMenu(parentPanel, (Sequence) seqs.get(1), links);
+ seq = seqs.get(1);
+ testee = new PopupMenu(parentPanel, seq, noFeatures);
seqItems = testee.sequenceMenu.getMenuComponents();
linkMenu = (JMenu) seqItems[6];
linkItems = linkMenu.getMenuComponents();
// sequence id for each link should match corresponding DB accession id
for (int i = 1; i < 3; i++)
{
- assertEquals(refs.get(i + 3).getSource(), ((JMenuItem) linkItems[i])
+ String msg = seq.getName() + " link[" + i + "]";
+ assertEquals(msg, refs.get(i + 3).getSource(),
+ ((JMenuItem) linkItems[i])
.getText().split("\\|")[0].toUpperCase());
- assertEquals(refs.get(i + 3).getAccessionId(),
+ assertEquals(msg, refs.get(i + 3).getAccessionId(),
((JMenuItem) linkItems[i]).getText().split("\\|")[1]);
}
nomatchlinks.add("NOMATCH | http://www.uniprot.org/uniprot/$"
+ DB_ACCESSION + "$");
- testee = new PopupMenu(parentPanel, (Sequence) seqs.get(0),
- nomatchlinks);
+ testee = new PopupMenu(parentPanel, seq, noFeatures);
seqItems = testee.sequenceMenu.getMenuComponents();
linkMenu = (JMenu) seqItems[6];
assertFalse(linkMenu.isEnabled());