target = link.substring(0, sep);
sep = link.lastIndexOf("|");
label = link.substring(0, sep);
- url_prefix = link.substring(sep + 1);
+ url_prefix = link.substring(sep + 1).trim();
regexReplace = null; // implies we trim any prefix if necessary //
// regexReplace=".*\\|?(.*)";
url_suffix = null;
*/
protected void parseUrl(String link, String varName, int sqidPos, int sep)
{
- url_prefix = link.substring(sep + 1, sqidPos);
+ url_prefix = link.substring(sep + 1, sqidPos).trim();
// delimiter at start of regex: e.g. $SEQUENCE_ID=/
String startDelimiter = "$" + varName + "=/";
}
/**
+ * Create a set of URL links for a sequence
*
- * @param urlLink
* @param seq
+ * The sequence to create links for
* @param linkset
+ * Map of links: key = id | link, value = [target, label, id, link]
*/
public void createLinksFromSeq(final SequenceI seq,
Map<String, List<String>> linkset)
* Create a static URL link
*
* @param linkset
+ * Map of links: key = id | link, value = [target, label, id, link]
*/
- public void createStaticLink(Map<String, List<String>> linkset)
+ protected void createStaticLink(Map<String, List<String>> linkset)
{
if (!linkset.containsKey(label + "|" + getUrl_prefix()))
{
}
/**
- * Create a dynamic URL link
+ * Create dynamic URL links
*
* @param seq
+ * The sequence to create links for
* @param linkset
+ * Map of links: key = id | link, value = [target, label, id, link]
*/
- public void createDynamicLinks(final SequenceI seq,
+ protected void createDynamicLinks(final SequenceI seq,
Map<String, List<String>> linkset)
{
// collect id string too
for (int r = 0; r < dbr.length; r++)
{
// create Bare ID link for this URL
- createBareURLLink(dbr[r].getAccessionId(), linkset, true);
+ createBareURLLink(dbr[r].getAccessionId(), true, linkset);
}
}
}
else if (!usesSeqId() && id != null) // link is name
{
// create Bare ID link for this URL
- createBareURLLink(id, linkset, false);
+ createBareURLLink(id, false, linkset);
}
// Create urls from description but only for URL links which are regex
if (descr != null && getRegexReplace() != null)
{
// create link for this URL from description where regex matches
- createBareURLLink(descr, linkset, false);
+ createBareURLLink(descr, false, linkset);
}
}
/*
* Create a bare URL Link
+ * Returns map where key = id | link, and value = [target, label, id, link]
*/
- protected void createBareURLLink(String id,
- Map<String, List<String>> linkset, Boolean combineLabel)
+ protected void createBareURLLink(String id, Boolean combineLabel,
+ Map<String, List<String>> linkset)
{
String[] urls = makeUrls(id, true);
if (urls != null)
String thisLabel = label;
if (combineLabel)
{
+ // incorporate label with idstring
thisLabel = label + "|" + urls[u];
}
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.Sequence;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
import org.testng.annotations.Test;
public class UrlLinkTest
}
/**
- * Test construction of link by substituting sequence id or name
+ * Test construction of link by substituting sequence id or name using regular
+ * expression
*/
@Test(groups = { "Functional" })
public void testMakeUrlWithRegex()
assertNull(ul.getInvalidMessage());
}
+ /**
+ * Test creating links with null sequence
+ */
+ @Test(groups = { "Functional" })
+ public void testCreateLinksFromNullSequence()
+ {
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ + DELIM + URL_SUFFIX);
+
+ Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
+ ul.createLinksFromSeq(null, linkset);
+
+ String key = DB + SEP + URL_PREFIX;
+ assertEquals(1, linkset.size());
+ assertTrue(linkset.containsKey(key));
+ assertEquals(linkset.get(key).get(0), DB.toUpperCase());
+ assertEquals(linkset.get(key).get(1), DB);
+ assertEquals(linkset.get(key).get(2), null);
+ assertEquals(linkset.get(key).get(3), URL_PREFIX);
+ }
+
+ /**
+ * Test creating links with non-dynamic urlLink
+ */
+ @Test(groups = { "Functional" })
+ public void testCreateLinksForNonDynamic()
+ {
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + URL_SUFFIX);
+
+ Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
+ ul.createLinksFromSeq(null, linkset);
+
+ String key = DB + SEP + URL_PREFIX + URL_SUFFIX;
+ assertEquals(1, linkset.size());
+ assertTrue(linkset.containsKey(key));
+ assertEquals(linkset.get(key).get(0), DB.toUpperCase());
+ assertEquals(linkset.get(key).get(1), DB);
+ assertEquals(linkset.get(key).get(2), null);
+ assertEquals(linkset.get(key).get(3), URL_PREFIX + URL_SUFFIX);
+ }
+
+ /**
+ * Test creating links
+ */
+ @Test(groups = { "Functional" })
+ public void testCreateLinksFromSequence()
+ {
+
+ // 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 + "$");
+
+ // 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"));
+
+ Sequence seq0 = new Sequence("FER1", "AKPNGVL");
+
+ // add all the dbrefs to the sequence
+ seq0.addDBRef(refs.get(0));
+ seq0.addDBRef(refs.get(1));
+ seq0.addDBRef(refs.get(2));
+ seq0.addDBRef(refs.get(3));
+ seq0.createDatasetSequence();
+
+ // Test where link takes a sequence id as replacement
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ + DELIM + URL_SUFFIX);
+
+ Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
+ ul.createLinksFromSeq(seq0, linkset);
+
+ String key = seq0.getName() + SEP + URL_PREFIX + seq0.getName()
+ + URL_SUFFIX;
+ assertEquals(1, linkset.size());
+ assertTrue(linkset.containsKey(key));
+ assertEquals(linkset.get(key).get(0), DB.toUpperCase());
+ assertEquals(linkset.get(key).get(1), DB);
+ assertEquals(linkset.get(key).get(2), seq0.getName());
+ assertEquals(linkset.get(key).get(3), URL_PREFIX + seq0.getName()
+ + URL_SUFFIX);
+
+ // Test where link takes a db annotation id and only has one dbref
+ ul = new UrlLink(links.get(1));
+ linkset = new LinkedHashMap<String, List<String>>();
+ ul.createLinksFromSeq(seq0, linkset);
+
+ key = "P83527|http://www.uniprot.org/uniprot/P83527";
+ assertEquals(1, linkset.size());
+ assertTrue(linkset.containsKey(key));
+ assertEquals(linkset.get(key).get(0), DBRefSource.UNIPROT);
+ assertEquals(linkset.get(key).get(1), DBRefSource.UNIPROT + SEP
+ + "P83527");
+ assertEquals(linkset.get(key).get(2), "P83527");
+ assertEquals(linkset.get(key).get(3),
+ "http://www.uniprot.org/uniprot/P83527");
+
+ // Test where link takes a db annotation id and has multiple dbrefs
+ ul = new UrlLink(links.get(2));
+ linkset = new LinkedHashMap<String, List<String>>();
+ ul.createLinksFromSeq(seq0, linkset);
+ assertEquals(3, linkset.size());
+
+ // check each link made it in correctly
+ key = "IPR001041|http://www.ebi.ac.uk/interpro/entry/IPR001041";
+ assertTrue(linkset.containsKey(key));
+ assertEquals(linkset.get(key).get(0), "INTERPRO");
+ assertEquals(linkset.get(key).get(1), "INTERPRO" + SEP + "IPR001041");
+ assertEquals(linkset.get(key).get(2), "IPR001041");
+ assertEquals(linkset.get(key).get(3),
+ "http://www.ebi.ac.uk/interpro/entry/IPR001041");
+
+ key = "IPR006058|http://www.ebi.ac.uk/interpro/entry/IPR006058";
+ assertTrue(linkset.containsKey(key));
+ assertEquals(linkset.get(key).get(0), "INTERPRO");
+ assertEquals(linkset.get(key).get(1), "INTERPRO" + SEP + "IPR006058");
+ assertEquals(linkset.get(key).get(2), "IPR006058");
+ assertEquals(linkset.get(key).get(3),
+ "http://www.ebi.ac.uk/interpro/entry/IPR006058");
+
+ key = "IPR012675|http://www.ebi.ac.uk/interpro/entry/IPR012675";
+ assertTrue(linkset.containsKey(key));
+ assertEquals(linkset.get(key).get(0), "INTERPRO");
+ assertEquals(linkset.get(key).get(1), "INTERPRO" + SEP + "IPR012675");
+ assertEquals(linkset.get(key).get(2), "IPR012675");
+ assertEquals(linkset.get(key).get(3),
+ "http://www.ebi.ac.uk/interpro/entry/IPR012675");
+
+ // Test where there are no matching dbrefs for the link
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID + DELIM
+ + URL_SUFFIX);
+ linkset = new LinkedHashMap<String, List<String>>();
+ ul.createLinksFromSeq(seq0, linkset);
+ assertTrue(linkset.isEmpty());
+ }
+
}