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.SRS_STRING;
{
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);
+ }
}
/**
*/
public class UrlConstants
{
+
/*
- * Default sequence URL link string for EMBL-EBI search
+ * Sequence ID string
*/
- public static final String EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
+ public static final String SEQUENCE_ID = "SEQUENCE_ID";
/*
- * Default sequence URL link string for SRS
+ * Sequence Name string
*/
- public static final String SRS_STRING = "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry";
+ public static final String SEQUENCE_NAME = "SEQUENCE_NAME";
/*
- * Sequence ID string
+ * Default sequence URL link string for EMBL-EBI search
*/
- public static final String SEQUENCE_ID = "SEQUENCE_ID";
+ public static final String EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_NAME$";
/*
- * Sequence Name string
+ * Default sequence URL link string for EMBL-EBI search
*/
- public static final String SEQUENCE_NAME = "SEQUENCE_NAME";
+ 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
package jalview.util;
import static jalview.util.UrlConstants.SEQUENCE_ID;
+import static jalview.util.UrlConstants.SEQUENCE_NAME;
import java.util.Vector;
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;
- }
+ uses_seq_id = true;
+
+ sep = parseTargetAndLabel(sep, psqid, link);
+
// Parse URL : Whole URL string first
+ int p;
url_prefix = link.substring(sep + 1, psqid);
if (link.indexOf("$" + SEQUENCE_ID + "=/") == psqid
&& (p = link.indexOf("/=$", psqid + 14)) > psqid + 14)
}
}
}
+ else if (nsqid > -1)
+ {
+ dynamic = true;
+ sep = parseTargetAndLabel(sep, nsqid, link);
+
+ int p;
+ url_prefix = link.substring(sep + 1, nsqid);
+ if (link.indexOf("$" + SEQUENCE_NAME + "=/") == nsqid
+ && (p = link.indexOf("/=$", nsqid + 16)) > nsqid + 16)
+ {
+ // Extract Regex and suffix
+ url_suffix = link.substring(p + 3);
+ regexReplace = link.substring(nsqid + 16, 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_NAME + "$") == nsqid)
+ {
+ url_suffix = link.substring(nsqid + 15);
+ regexReplace = null;
+ }
+ else
+ {
+ invalidMessage = "Warning: invalid regex structure for URL link : "
+ + link;
+ }
+ }
+ }
else
{
target = link.substring(0, sep);
}
+ private int parseTargetAndLabel(int sep, int psqid, String link)
+ {
+ 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;
+ }
+ return sep;
+ }
+
private static void testUrls(UrlLink ul, String idstring, String[] urls)
{
return dynamic;
}
+ public boolean usesSeqId()
+ {
+ return uses_seq_id;
+ }
+
public void setLabel(String newlabel)
{
this.label = newlabel;