*/
package jalview.util;
+import static jalview.util.UrlConstants.DB_ACCESSION;
import static jalview.util.UrlConstants.SEQUENCE_ID;
-import static jalview.util.UrlConstants.SEQUENCE_NAME;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.SequenceI;
private boolean dynamic = false;
- private boolean uses_seq_id = false;
+ private boolean uses_db_accession = false;
private String invalidMessage = null;
public UrlLink(String link)
{
int sep = link.indexOf("|");
- int psqid = link.indexOf("$" + SEQUENCE_ID);
- int nsqid = link.indexOf("$" + SEQUENCE_NAME);
+ int psqid = link.indexOf("$" + DB_ACCESSION);
+ int nsqid = link.indexOf("$" + SEQUENCE_ID);
if (psqid > -1)
{
dynamic = true;
- uses_seq_id = true;
+ uses_db_accession = true;
sep = parseTargetAndLabel(sep, psqid, link);
- parseUrl(link, SEQUENCE_ID, psqid, sep);
+ parseUrl(link, DB_ACCESSION, psqid, sep);
}
else if (nsqid > -1)
{
dynamic = true;
sep = parseTargetAndLabel(sep, nsqid, link);
- parseUrl(link, SEQUENCE_NAME, nsqid, sep);
+ parseUrl(link, SEQUENCE_ID, nsqid, sep);
}
else
{
@Override
public String toString()
{
- String var = (uses_seq_id ? SEQUENCE_ID : SEQUENCE_NAME);
+ String var = (uses_db_accession ? DB_ACCESSION : SEQUENCE_ID);
return label
+ "|"
descr = null;
}
- if (usesSeqId()) // link is ID
+ if (usesDBAccession()) // link is ID
{
// collect matching db-refs
DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(),
}
}
}
- else if (!usesSeqId() && id != null) // link is name
+ else if (!usesDBAccession() && id != null) // link is name
{
// create Bare ID link for this URL
createBareURLLink(id, false, linkset);
* "PF3|http://us.expasy.org/cgi-bin/niceprot.pl?$SEQUENCE_ID=/PFAM:(.+)/=$"
* , "NOTFER|http://notfer.org/$SEQUENCE_ID=/(?<!\\s)(.+)/=$",
*/
- "NESTED|http://nested/$" + SEQUENCE_ID
+ "NESTED|http://nested/$" + DB_ACCESSION
+ "=/^(?:Label:)?(?:(?:gi\\|(\\d+))|([^:]+))/=$/nested" };
String[] idstrings = new String[] {
/*
return dynamic;
}
- public boolean usesSeqId()
+ public boolean usesDBAccession()
{
- return uses_seq_id;
+ return uses_db_accession;
}
public void setLabel(String newlabel)
*/
package jalview.util;
+import static jalview.util.UrlConstants.DB_ACCESSION;
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;
@Test(groups = { "Functional" })
public void testUrlLinkCreationNoRegex()
{
- // SEQUENCE_NAME
- UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ // SEQUENCE_ID
+ UrlLink 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());
- assertFalse(ul.usesSeqId());
+ assertFalse(ul.usesDBAccession());
assertNull(ul.getRegexReplace());
assertTrue(ul.isValid());
assertNull(ul.getInvalidMessage());
- // SEQUENCE_ID
- ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID + DELIM
+ // DB_ACCESSION
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + DB_ACCESSION + 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());
+ assertTrue(ul.usesDBAccession());
assertNull(ul.getRegexReplace());
assertTrue(ul.isValid());
assertNull(ul.getInvalidMessage());
assertEquals(DB, ul.getLabel());
assertEquals(URL_PREFIX + URL_SUFFIX.substring(1), ul.getUrl_prefix());
assertFalse(ul.isDynamic());
- assertFalse(ul.usesSeqId());
+ assertFalse(ul.usesDBAccession());
assertNull(ul.getRegexReplace());
assertTrue(ul.isValid());
assertNull(ul.getInvalidMessage());
@Test(groups = { "Functional" })
public void testUrlLinkCreationWithRegex()
{
- // SEQUENCE_NAME
- UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ // SEQUENCE_ID
+ UrlLink 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());
- assertFalse(ul.usesSeqId());
+ assertFalse(ul.usesDBAccession());
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
+ // DB_ACCESSION
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + DB_ACCESSION
+ 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());
+ assertTrue(ul.usesDBAccession());
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
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + DB_ACCESSION
+ 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());
+ assertTrue(ul.usesDBAccession());
assertEquals(REGEX_RUBBISH.substring(2, REGEX_RUBBISH.length() - 2),
ul.getRegexReplace());
assertFalse(ul.isValid());
public void testMakeUrlNoRegex()
{
// Single non-regex
- UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
+ DELIM + URL_SUFFIX);
String idstring = "FER_CAPAA";
String[] urls = ul.makeUrls(idstring, true);
public void testMakeUrlWithRegex()
{
// Unused regex
- UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + DB_ACCESSION
+ REGEX_NESTED + DELIM + URL_SUFFIX);
String idstring = "FER_CAPAA";
String[] urls = ul.makeUrls(idstring, true);
@Test(groups = { "Functional" })
public void testCreateLinksFromNullSequence()
{
- UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
+ DELIM + URL_SUFFIX);
Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
// 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
+ + SEQUENCE_ID + "$");
+ links.add("UNIPROT | http://www.uniprot.org/uniprot/$" + DB_ACCESSION
+ "$");
links.add("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$"
- + SEQUENCE_ID + "$");
+ + DB_ACCESSION + "$");
// make seq0 dbrefs
refs.add(new DBRefEntry(DBRefSource.UNIPROT, "1", "P83527"));
seq0.createDatasetSequence();
// Test where link takes a sequence id as replacement
- UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_NAME
+ UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
+ DELIM + URL_SUFFIX);
Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
"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
+ ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + DB_ACCESSION + DELIM
+ URL_SUFFIX);
linkset = new LinkedHashMap<String, List<String>>();
ul.createLinksFromSeq(seq0, linkset);