option.trim_retrieved_seqs = Trim retrieved sequences
label.trim_retrieved_sequences = When the reference sequence is longer than the sequence that you are working with, only keep the relevant subsequences.
label.use_sequence_id_1 = Use $SEQUENCE_ID$ or $SEQUENCE_ID=/<regex>/=$
-label.use_sequence_id_2 = \nto embed sequence id in URL
+label.use_sequence_id_2 = to embed sequence id in URL
+label.use_sequence_id_3 = Use $SEQUENCE_NAME$ similarly to embed sequence name
+label.use_sequence_id_4 =
label.ws_parameters_for = Parameters for {0}
label.switch_server = Switch server
label.choose_jabaws_server = Choose a server for running this service
option.trim_retrieved_seqs = Ajustar las secuencias recuperadas
label.trim_retrieved_sequences = Cuando la secuencia de referencia es más larga que la secuencia con la que está trabajando, sólo se mantienen las subsecuencias relevantes.
label.use_sequence_id_1 = Utilice $SEQUENCE_ID$ o $SEQUENCE_ID=/<regex>/=$
-label.use_sequence_id_2 = \nto para embeber el id de la secuencia en una URL
+label.use_sequence_id_2 = para embeber el id de la secuencia en una URL
+label.use_sequence_id_3 = Utilice $SEQUENCE_NAME$ de manera similar para embeber
+label.use_sequence_id_4 = el nombre de la secuencia
label.ws_parameters_for = Parámetros para {0}
label.switch_server = Cambiar servidor
label.open_jabaws_web_page = Abra el página principal del servidor JABAWS en un navegador web
*/
package jalview.appletgui;
+import static jalview.util.UrlConstants.EMBLEBI_STRING;
+import static jalview.util.UrlConstants.SRS_STRING;
+
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
}
{
// upgrade old SRS link
- int srsPos = links
- .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
+ int srsPos = links.indexOf(SRS_STRING);
if (srsPos > -1)
{
- links.setElementAt(
- "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
- srsPos);
+ links.setElementAt(EMBLEBI_STRING, srsPos);
}
}
if (links.size() < 1)
{
links = new java.util.Vector();
- links.addElement("EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
+ links.addElement(EMBLEBI_STRING);
}
}
continue;
}
final String label = urlLink.getLabel();
- if (seq != null && urlLink.isDynamic())
+
+ // collect id string too
+ String id = seq.getName();
+ String descr = seq.getDescription();
+ if (descr != null && descr.length() < 1)
{
+ descr = null;
+ }
+ if (seq != null && urlLink.usesSeqId()) // link is ID
+ {
// collect matching db-refs
DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
new String[] { urlLink.getTarget() });
- // collect id string too
- String id = seq.getName();
- String descr = seq.getDescription();
- if (descr != null && descr.length() < 1)
- {
- descr = null;
- }
+ // if there are any dbrefs which match up with the link
if (dbr != null)
{
for (int r = 0; r < dbr.length; r++)
id = null;
}
// create Bare ID link for this URL
- String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
- {
- linkset.add(urls[u] + "|" + urls[u + 1]);
- addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
- }
- }
- }
+ createBareURLLink(urlLink, dbr[r].getAccessionId(), linkset,
+ linkMenu, label, true);
}
}
+
+ // Create urls from description but only for URL links which are regex
+ // links
+ if (descr != null && urlLink.getRegexReplace() != null)
+ {
+ // create link for this URL from description where regex matches
+ createBareURLLink(urlLink, descr, linkset, linkMenu, label, false);
+ }
+
+ }
+ else if (seq != null && !urlLink.usesSeqId()) // link is name
+ {
if (id != null)
{
// create Bare ID link for this URL
- String[] urls = urlLink.makeUrls(id, true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
- {
- linkset.add(urls[u] + "|" + urls[u + 1]);
- addshowLink(linkMenu, label, urls[u + 1]);
- }
- }
- }
+ createBareURLLink(urlLink, id, linkset, linkMenu, label, false);
}
// Create urls from description but only for URL links which are regex
// links
if (descr != null && urlLink.getRegexReplace() != null)
{
// create link for this URL from description where regex matches
- String[] urls = urlLink.makeUrls(descr, true);
- if (urls != null)
- {
- for (int u = 0; u < urls.length; u += 2)
- {
- if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
- {
- linkset.add(urls[u] + "|" + urls[u + 1]);
- addshowLink(linkMenu, label, urls[u + 1]);
- }
- }
- }
+ createBareURLLink(urlLink, descr, linkset, linkMenu, label, false);
}
}
else
addshowLink(linkMenu, label, urlLink.getUrl_prefix());
}
}
+
}
if (sequence != null)
{
}
}
+ /*
+ * Create a bare URL Link
+ */
+ private void createBareURLLink(UrlLink urlLink, String id,
+ List<String> linkset, JMenu linkMenu, String label,
+ Boolean addSepToLabel)
+ {
+ String[] urls = urlLink.makeUrls(id, true);
+ if (urls != null)
+ {
+ for (int u = 0; u < urls.length; u += 2)
+ {
+ if (!linkset.contains(urls[u] + "|" + urls[u + 1]))
+ {
+ linkset.add(urls[u] + "|" + urls[u + 1]);
+ if (addSepToLabel)
+ {
+ addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
+ }
+ else
+ {
+ addshowLink(linkMenu, label, urls[u + 1]);
+ }
+ }
+ }
+ }
+ }
+
/**
* Add annotation types to 'Show annotations' and/or 'Hide annotations' menus.
* "All" is added first, followed by a separator. Then add any annotation
*/
package jalview.gui;
+import static jalview.util.UrlConstants.EMBLEBI_STRING;
+import static jalview.util.UrlConstants.OLD_EMBLEBI_STRING;
+import static jalview.util.UrlConstants.SEQUENCE_ID;
+import static jalview.util.UrlConstants.SEQUENCE_NAME;
+import static jalview.util.UrlConstants.SRS_STRING;
+
import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.bin.Cache;
import jalview.gui.Help.HelpId;
public static List<String> groupURLLinks;
static
{
- String string = Cache
- .getDefault(
- "SEQUENCE_LINKS",
- "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
+ String string = Cache.getDefault("SEQUENCE_LINKS", EMBLEBI_STRING);
sequenceURLLinks = new Vector<String>();
try
String name = st.nextToken();
String url = st.nextToken();
// check for '|' within a regex
- int rxstart = url.indexOf("$SEQUENCE_ID$");
+ int rxstart = url.indexOf("$" + SEQUENCE_ID + "$");
+ if (rxstart == -1)
+ {
+ rxstart = url.indexOf("$" + SEQUENCE_NAME + "$");
+ }
while (rxstart == -1 && url.indexOf("/=$") == -1)
{
url = url + "|" + st.nextToken();
}
{
// upgrade old SRS link
- int srsPos = sequenceURLLinks
- .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
+ int srsPos = sequenceURLLinks.indexOf(SRS_STRING);
if (srsPos > -1)
{
- sequenceURLLinks
- .setElementAt(
- "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
- srsPos);
+ sequenceURLLinks.setElementAt(EMBLEBI_STRING, srsPos);
+ }
+ // upgrade old EMBL-EBI link
+ int emblPos = sequenceURLLinks.indexOf(OLD_EMBLEBI_STRING);
+ if (emblPos > -1)
+ {
+ sequenceURLLinks.setElementAt(EMBLEBI_STRING, emblPos);
}
}
nameTB.setBounds(new Rectangle(77, 10, 310, 23));
nameTB.addKeyListener(new KeyAdapter()
{
+ @Override
public void keyTyped(KeyEvent e)
{
nameTB_keyTyped(e);
urlTB.setBounds(new Rectangle(78, 40, 309, 23));
urlTB.addKeyListener(new KeyAdapter()
{
+ @Override
public void keyTyped(KeyEvent e)
{
urlTB_keyTyped(e);
jLabel3.setBounds(new Rectangle(21, 72, 351, 15));
jLabel4.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
jLabel4.setText(MessageManager.getString("label.use_sequence_id_2"));
- jLabel4.setBounds(new Rectangle(21, 93, 351, 15));
+ jLabel4.setBounds(new Rectangle(21, 88, 351, 15));
+ jLabel5.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
+ jLabel5.setText(MessageManager.getString("label.use_sequence_id_3"));
+ jLabel5.setBounds(new Rectangle(21, 106, 351, 15));
+
+ String lastLabel = MessageManager.getString("label.use_sequence_id_4");
+ if (lastLabel.length() > 0)
+ {
+ // e.g. Spanish version has longer text
+ jLabel6.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11));
+ jLabel6.setText(lastLabel);
+ jLabel6.setBounds(new Rectangle(21, 122, 351, 15));
+ }
+
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setLayout(null);
jPanel1.add(jLabel1);
jPanel1.add(jLabel2);
jPanel1.add(jLabel3);
jPanel1.add(jLabel4);
+ jPanel1.add(jLabel5);
+
+ int height = 130;
+ if (lastLabel.length() > 0)
+ {
+ jPanel1.add(jLabel6);
+ height = 146;
+ }
+
this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
- 5, 4, 6, 5), 390, 130));
+ 5, 4, 6, 5), 390, height));
}
+ @Override
public void setName(String name)
{
nameTB.setText(name);
urlTB.setText(url);
}
+ @Override
public String getName()
{
return nameTB.getText();
JLabel jLabel4 = new JLabel();
+ JLabel jLabel5 = new JLabel();
+
+ JLabel jLabel6 = new JLabel();
+
JPanel jPanel1 = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+/**
+ * A class to hold constants relating to Url links used in Jalview
+ */
+public class UrlConstants
+{
+
+ /*
+ * Sequence ID string
+ */
+ public static final String SEQUENCE_ID = "SEQUENCE_ID";
+
+ /*
+ * Sequence Name string
+ */
+ public static final String SEQUENCE_NAME = "SEQUENCE_NAME";
+
+ /*
+ * Default sequence URL link string for EMBL-EBI search
+ */
+ public static final String EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_NAME$";
+
+ /*
+ * Default sequence URL link string for EMBL-EBI search
+ */
+ public static final String OLD_EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
+
+ /*
+ * Default sequence URL link string for SRS
+ */
+ public static final String SRS_STRING = "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry";
+
+ /*
+ * not instantiable
+ */
+ private UrlConstants()
+ {
+ }
+}
*/
package jalview.util;
+import static jalview.util.UrlConstants.SEQUENCE_ID;
+import static jalview.util.UrlConstants.SEQUENCE_NAME;
+
import java.util.Vector;
public class UrlLink
private boolean dynamic = false;
+ private boolean uses_seq_id = false;
+
private String invalidMessage = null;
/**
*/
public UrlLink(String link)
{
- int sep = link.indexOf("|"), psqid = link.indexOf("$SEQUENCE_ID");
+ int sep = link.indexOf("|");
+ int psqid = link.indexOf("$" + SEQUENCE_ID);
+ int nsqid = link.indexOf("$" + SEQUENCE_NAME);
if (psqid > -1)
{
dynamic = true;
- int p = sep;
- do
- {
- sep = p;
- p = link.indexOf("|", sep + 1);
- } while (p > sep && p < psqid);
- // Assuming that the URL itself does not contain any '|' symbols
- // sep now contains last pipe symbol position prior to any regex symbols
- label = link.substring(0, sep);
- if (label.indexOf("|") > -1)
- {
- // | terminated database name / www target at start of Label
- target = label.substring(0, label.indexOf("|"));
- }
- else if (label.indexOf(" ") > 2)
- {
- // space separated Label - matches database name
- target = label.substring(0, label.indexOf(" "));
- }
- else
- {
- target = label;
- }
- // Parse URL : Whole URL string first
- url_prefix = link.substring(sep + 1, psqid);
- if (link.indexOf("$SEQUENCE_ID=/") == psqid
- && (p = link.indexOf("/=$", psqid + 14)) > psqid + 14)
- {
- // Extract Regex and suffix
- url_suffix = link.substring(p + 3);
- regexReplace = link.substring(psqid + 14, p);
- try
- {
- com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex.perlCode("/"
- + regexReplace + "/");
- if (rg == null)
- {
- invalidMessage = "Invalid Regular Expression : '"
- + regexReplace + "'\n";
- }
- } catch (Exception e)
- {
- invalidMessage = "Invalid Regular Expression : '" + regexReplace
- + "'\n";
- }
- }
- else
- {
- regexReplace = null;
- // verify format is really correct.
- if (link.indexOf("$SEQUENCE_ID$") == psqid)
- {
- url_suffix = link.substring(psqid + 13);
- regexReplace = null;
- }
- else
- {
- invalidMessage = "Warning: invalid regex structure for URL link : "
- + link;
- }
- }
+ uses_seq_id = true;
+
+ sep = parseTargetAndLabel(sep, psqid, link);
+
+ parseUrl(link, SEQUENCE_ID, psqid, sep);
+ }
+ else if (nsqid > -1)
+ {
+ dynamic = true;
+ sep = parseTargetAndLabel(sep, nsqid, link);
+
+ parseUrl(link, SEQUENCE_NAME, nsqid, sep);
}
else
{
target = link.substring(0, sep);
- label = link.substring(0, sep = link.lastIndexOf("|"));
+ sep = link.lastIndexOf("|");
+ label = link.substring(0, sep);
url_prefix = link.substring(sep + 1);
regexReplace = null; // implies we trim any prefix if necessary //
// regexReplace=".*\\|?(.*)";
url_suffix = null;
}
+
+ label = label.trim();
+ target = target.trim();
+ target = target.toUpperCase(); // DBRefEntry uppercases DB names
+ // NB getCanonicalName might be better but does not currently change case
}
/**
}
}
+ @Override
public String toString()
{
+ String var = (uses_seq_id ? SEQUENCE_ID : SEQUENCE_NAME);
+
return label
+ "|"
+ url_prefix
- + (dynamic ? ("$SEQUENCE_ID" + ((regexReplace != null) ? "="
+ + (dynamic ? ("$" + var + ((regexReplace != null) ? "="
+ regexReplace + "=$" : "$")) : "")
+ ((url_suffix == null) ? "" : url_suffix);
+ }
+
+ /**
+ *
+ * @param firstSep
+ * Location of first occurrence of separator in link string
+ * @param psqid
+ * Position of sequence id or name in link string
+ * @param link
+ * Link string containing database name and url
+ * @return Position of last separator symbol prior to any regex symbols
+ */
+ protected int parseTargetAndLabel(int firstSep, int psqid, String link)
+ {
+ int p = firstSep;
+ int sep = firstSep;
+ do
+ {
+ sep = p;
+ p = link.indexOf("|", sep + 1);
+ } while (p > sep && p < psqid);
+ // Assuming that the URL itself does not contain any '|' symbols
+ // sep now contains last pipe symbol position prior to any regex symbols
+ label = link.substring(0, sep);
+ if (label.indexOf("|") > -1)
+ {
+ // | terminated database name / www target at start of Label
+ target = label.substring(0, label.indexOf("|"));
+ }
+ else if (label.indexOf(" ") > 2)
+ {
+ // space separated Label - matches database name
+ target = label.substring(0, label.indexOf(" "));
+ }
+ else
+ {
+ target = label;
+ }
+ return sep;
+ }
+
+ /**
+ * Parse the URL part of the link string
+ *
+ * @param link
+ * Link string containing database name and url
+ * @param varName
+ * Name of variable in url string (e.g. SEQUENCE_ID, SEQUENCE_NAME)
+ * @param sqidPos
+ * Position of id or name in link string
+ * @param sep
+ * Position of separator in link string
+ */
+ protected void parseUrl(String link, String varName, int sqidPos, int sep)
+ {
+ url_prefix = link.substring(sep + 1, sqidPos);
+
+ // delimiter at start of regex: e.g. $SEQUENCE_ID=/
+ String startDelimiter = "$" + varName + "=/";
+ // delimiter at end of regex: /=$
+ String endDelimiter = "/=$";
+
+ int startLength = startDelimiter.length();
+
+ // Parse URL : Whole URL string first
+ int p = link.indexOf(endDelimiter, sqidPos + startLength);
+
+ if (link.indexOf(startDelimiter) == sqidPos
+ && (p > sqidPos + startLength))
+ {
+ // Extract Regex and suffix
+ url_suffix = link.substring(p + endDelimiter.length());
+ regexReplace = link.substring(sqidPos + startLength, p);
+ try
+ {
+ com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex.perlCode("/"
+ + regexReplace + "/");
+ if (rg == null)
+ {
+ invalidMessage = "Invalid Regular Expression : '" + regexReplace
+ + "'\n";
+ }
+ } catch (Exception e)
+ {
+ invalidMessage = "Invalid Regular Expression : '" + regexReplace
+ + "'\n";
+ }
+ }
+ else
+ {
+ // no regex
+ regexReplace = null;
+ // verify format is really correct.
+ if (link.indexOf("$" + varName + "$") == sqidPos)
+ {
+ url_suffix = link.substring(sqidPos + startLength - 1);
+ regexReplace = null;
+ }
+ else
+ {
+ invalidMessage = "Warning: invalid regex structure for URL link : "
+ + link;
+ }
+ }
}
private static void testUrls(UrlLink ul, String idstring, String[] urls)
* "PF3|http://us.expasy.org/cgi-bin/niceprot.pl?$SEQUENCE_ID=/PFAM:(.+)/=$"
* , "NOTFER|http://notfer.org/$SEQUENCE_ID=/(?<!\\s)(.+)/=$",
*/
- "NESTED|http://nested/$SEQUENCE_ID=/^(?:Label:)?(?:(?:gi\\|(\\d+))|([^:]+))/=$/nested" };
+ "NESTED|http://nested/$" + SEQUENCE_ID
+ + "=/^(?:Label:)?(?:(?:gi\\|(\\d+))|([^:]+))/=$/nested" };
String[] idstrings = new String[] {
/*
* //"LGUL_human", //"QWIQW_123123", "uniprot|why_do+_12313_foo",
return dynamic;
}
+ public boolean usesSeqId()
+ {
+ return uses_seq_id;
+ }
+
public void setLabel(String newlabel)
{
this.label = newlabel;
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.SequenceI;
import jalview.io.AppletFormatAdapter;
import jalview.io.FormatAdapter;
assertEquals(JSeparator.HORIZONTAL,
((JSeparator) hideOptions[1]).getOrientation());
}
+
+ /**
+ * Test for adding feature links
+ */
+ @Test(groups = { "Functional" })
+ public void testAddFeatureLinks()
+ {
+ // sequences from the alignment
+ List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
+
+ // create list of links and list of DBRefs
+ List<String> links = new ArrayList<String>();
+ List<DBRefEntry> refs = new ArrayList<DBRefEntry>();
+
+ // links as might be added into Preferences | Connections dialog
+ links.add("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_NAME$");
+ links.add("UNIPROT | http://www.uniprot.org/uniprot/$SEQUENCE_ID$");
+ links.add("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$SEQUENCE_ID$");
+ // Gene3D entry tests for case (in)sensitivity
+ links.add("Gene3D | http://gene3d.biochem.ucl.ac.uk/Gene3D/search?sterm=$SEQUENCE_ID$&mode=protein");
+
+ // make seq0 dbrefs
+ refs.add(new DBRefEntry(DBRefSource.UNIPROT, "1", "P83527"));
+ refs.add(new DBRefEntry("INTERPRO", "1", "IPR001041"));
+ refs.add(new DBRefEntry("INTERPRO", "1", "IPR006058"));
+ refs.add(new DBRefEntry("INTERPRO", "1", "IPR012675"));
+
+ // make seq1 dbrefs
+ refs.add(new DBRefEntry(DBRefSource.UNIPROT, "1", "Q9ZTS2"));
+ refs.add(new DBRefEntry("GENE3D", "1", "3.10.20.30"));
+
+ // 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));
+
+ seqs.get(0).addDBRef(refs.get(1));
+ seqs.get(0).addDBRef(refs.get(2));
+ seqs.get(0).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);
+ Component[] seqItems = testee.sequenceMenu.getMenuComponents();
+ JMenu linkMenu = (JMenu) seqItems[6];
+ Component[] linkItems = linkMenu.getMenuComponents();
+
+ // check the number of links are the expected number
+ assertEquals(5, linkItems.length);
+
+ // first entry is EMBL-EBI which just uses sequence id not accession id?
+ assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
+
+ // 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])
+ .getText().split("\\|")[0]);
+ assertEquals(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);
+ seqItems = testee.sequenceMenu.getMenuComponents();
+ linkMenu = (JMenu) seqItems[6];
+ linkItems = linkMenu.getMenuComponents();
+
+ // check the number of links are the expected number
+ assertEquals(3, linkItems.length);
+
+ // first entry is EMBL-EBI which just uses sequence id not accession id?
+ assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
+
+ // 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])
+ .getText().split("\\|")[0].toUpperCase());
+ assertEquals(refs.get(i + 3).getAccessionId(),
+ ((JMenuItem) linkItems[i]).getText().split("\\|")[1]);
+ }
+
+
+ }
}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.util;
+
+import static jalview.util.UrlConstants.SEQUENCE_ID;
+import static jalview.util.UrlConstants.SEQUENCE_NAME;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+import org.testng.annotations.Test;
+
+public class UrlLinkTest
+{
+
+ final static String DB = "Test";
+
+ final static String URL_PREFIX = "http://www.jalview.org/";
+
+ final static String URL_SUFFIX = "/blah";
+
+ final static String SEP = "|";
+
+ final static String DELIM = "$";
+
+ final static String REGEX_NESTED = "=/^(?:Label:)?(?:(?:gi\\|(\\d+))|([^:]+))/=";
+
+ final static String REGEX_RUBBISH = "=/[0-9]++/=";
+
+ /**
+ * Test URL link creation when the input string has no regex
+ */
+ @Test(groups = { "Functional" })
+ public void testUrlLinkCreationNoRegex()
+ {
+ // SEQUENCE_NAME
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ + DELIM + URL_SUFFIX);
+ assertEquals(DB.toUpperCase(), ul.getTarget());
+ assertEquals(DB, ul.getLabel());
+ assertEquals(URL_PREFIX, ul.getUrl_prefix());
+ assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertTrue(ul.isDynamic());
+ assertFalse(ul.usesSeqId());
+ assertNull(ul.getRegexReplace());
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ // SEQUENCE_ID
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID + DELIM
+ + URL_SUFFIX);
+ assertEquals(DB.toUpperCase(), ul.getTarget());
+ assertEquals(DB, ul.getLabel());
+ assertEquals(URL_PREFIX, ul.getUrl_prefix());
+ assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertTrue(ul.isDynamic());
+ assertTrue(ul.usesSeqId());
+ assertNull(ul.getRegexReplace());
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ // Not dynamic
+ ul = new UrlLink(DB + SEP + URL_PREFIX + URL_SUFFIX.substring(1));
+ assertEquals(DB.toUpperCase(), ul.getTarget());
+ assertEquals(DB, ul.getLabel());
+ assertEquals(URL_PREFIX + URL_SUFFIX.substring(1), ul.getUrl_prefix());
+ assertFalse(ul.isDynamic());
+ assertFalse(ul.usesSeqId());
+ assertNull(ul.getRegexReplace());
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+ }
+
+ /**
+ * Test URL link creation when the input string has regex
+ */
+ @Test(groups = { "Functional" })
+ public void testUrlLinkCreationWithRegex()
+ {
+ // SEQUENCE_NAME
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ + REGEX_NESTED + DELIM + URL_SUFFIX);
+ assertEquals(DB.toUpperCase(), ul.getTarget());
+ assertEquals(DB, ul.getLabel());
+ assertEquals(URL_PREFIX, ul.getUrl_prefix());
+ assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertTrue(ul.isDynamic());
+ assertFalse(ul.usesSeqId());
+ assertEquals(REGEX_NESTED.substring(2, REGEX_NESTED.length() - 2),
+ ul.getRegexReplace());
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ // SEQUENCE_ID
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
+ + REGEX_NESTED + DELIM + URL_SUFFIX);
+ assertEquals(DB.toUpperCase(), ul.getTarget());
+ assertEquals(DB, ul.getLabel());
+ assertEquals(URL_PREFIX, ul.getUrl_prefix());
+ assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertTrue(ul.isDynamic());
+ assertTrue(ul.usesSeqId());
+ assertEquals(REGEX_NESTED.substring(2, REGEX_NESTED.length() - 2),
+ ul.getRegexReplace());
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ // invalid regex
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
+ + REGEX_RUBBISH + DELIM + URL_SUFFIX);
+ assertEquals(DB.toUpperCase(), ul.getTarget());
+ assertEquals(DB, ul.getLabel());
+ assertEquals(URL_PREFIX, ul.getUrl_prefix());
+ assertEquals(URL_SUFFIX, ul.getUrl_suffix());
+ assertTrue(ul.isDynamic());
+ assertTrue(ul.usesSeqId());
+ assertEquals(REGEX_RUBBISH.substring(2, REGEX_RUBBISH.length() - 2),
+ ul.getRegexReplace());
+ assertFalse(ul.isValid());
+ assertEquals(
+ "Invalid Regular Expression : '"
+ + REGEX_RUBBISH.substring(2, REGEX_RUBBISH.length() - 2)
+ + "'\n",
+ ul.getInvalidMessage());
+ }
+
+ /**
+ * Test construction of link by substituting sequence id or name
+ */
+ @Test(groups = { "Functional" })
+ public void testMakeUrlNoRegex()
+ {
+ // Single non-regex
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ + DELIM + URL_SUFFIX);
+ String idstring = "FER_CAPAA";
+ String[] urls = ul.makeUrls(idstring, true);
+
+ assertEquals(2, urls.length);
+ assertEquals(idstring, urls[0]);
+ assertEquals(URL_PREFIX + idstring + URL_SUFFIX, urls[1]);
+
+ urls = ul.makeUrls(idstring, false);
+
+ assertEquals(2, urls.length);
+ assertEquals(idstring, urls[0]);
+ assertEquals(URL_PREFIX + idstring + URL_SUFFIX, urls[1]);
+ }
+
+ /**
+ * Test construction of link by substituting sequence id or name
+ */
+ @Test(groups = { "Functional" })
+ public void testMakeUrlWithRegex()
+ {
+ // Unused regex
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
+ + REGEX_NESTED + DELIM + URL_SUFFIX);
+ String idstring = "FER_CAPAA";
+ String[] urls = ul.makeUrls(idstring, true);
+
+ assertEquals(2, urls.length);
+ assertEquals(idstring, urls[0]);
+ assertEquals(URL_PREFIX + idstring + URL_SUFFIX, urls[1]);
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ urls = ul.makeUrls(idstring, false);
+
+ assertEquals(2, urls.length);
+ assertEquals(idstring, urls[0]);
+ assertEquals(URL_PREFIX + idstring + URL_SUFFIX, urls[1]);
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ // nested regex
+ idstring = "Label:gi|9234|pdb|102L|A";
+ urls = ul.makeUrls(idstring, true);
+
+ assertEquals(2, urls.length);
+ assertEquals("9234", urls[0]);
+ assertEquals(URL_PREFIX + "9234" + URL_SUFFIX, urls[1]);
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ urls = ul.makeUrls(idstring, false);
+
+ assertEquals(2, urls.length);
+ assertEquals("9234", urls[0]);
+ assertEquals(URL_PREFIX + "9234" + URL_SUFFIX, urls[1]);
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ // unmatched regex
+ idstring = "this does not match";
+ urls = ul.makeUrls(idstring, true);
+
+ assertEquals(2, urls.length);
+ assertEquals(idstring, urls[0]);
+ assertEquals(URL_PREFIX + idstring + URL_SUFFIX, urls[1]);
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ urls = ul.makeUrls(idstring, false);
+
+ assertEquals(2, urls.length);
+ assertEquals(idstring, urls[0]);
+ assertEquals(URL_PREFIX + idstring + URL_SUFFIX, urls[1]);
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+
+ // empty idstring
+ idstring = "";
+ urls = ul.makeUrls(idstring, true);
+
+ assertNull(urls);
+
+ urls = ul.makeUrls(idstring, false);
+
+ assertEquals(2, urls.length);
+ assertEquals("", urls[0]);
+ assertEquals(URL_PREFIX + URL_SUFFIX, urls[1]);
+ assertTrue(ul.isValid());
+ assertNull(ul.getInvalidMessage());
+ }
+
+}