From: kiramt Date: Sat, 22 Oct 2016 16:55:23 +0000 (+0100) Subject: Working links menu X-Git-Tag: Release_2_10_1^2~34 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b8961bc1a1c973c507489abb91572c73edcda1e2;p=jalview.git Working links menu --- diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 7ab6022..e2d397f 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -636,20 +636,22 @@ public class PopupMenu extends JPopupMenu 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++) @@ -661,53 +663,33 @@ public class PopupMenu extends JPopupMenu 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 @@ -719,6 +701,7 @@ public class PopupMenu extends JPopupMenu addshowLink(linkMenu, label, urlLink.getUrl_prefix()); } } + } if (sequence != null) { @@ -730,6 +713,34 @@ public class PopupMenu extends JPopupMenu } } + /* + * Create a bare URL Link + */ + private void createBareURLLink(UrlLink urlLink, String id, + List 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 diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index b43989a..b36a73d 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -21,6 +21,7 @@ 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; @@ -143,6 +144,12 @@ public class Preferences extends GPreferences { 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); + } } /** diff --git a/src/jalview/util/UrlConstants.java b/src/jalview/util/UrlConstants.java index fc6dfdd..ce6d980 100644 --- a/src/jalview/util/UrlConstants.java +++ b/src/jalview/util/UrlConstants.java @@ -25,25 +25,31 @@ package jalview.util; */ 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 diff --git a/src/jalview/util/UrlLink.java b/src/jalview/util/UrlLink.java index e196c8c..a8c0b32 100644 --- a/src/jalview/util/UrlLink.java +++ b/src/jalview/util/UrlLink.java @@ -21,6 +21,7 @@ package jalview.util; import static jalview.util.UrlConstants.SEQUENCE_ID; +import static jalview.util.UrlConstants.SEQUENCE_NAME; import java.util.Vector; @@ -39,6 +40,8 @@ public class UrlLink private boolean dynamic = false; + private boolean uses_seq_id = false; + private String invalidMessage = null; /** @@ -50,34 +53,18 @@ public class UrlLink */ 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) @@ -116,6 +103,50 @@ public class UrlLink } } } + 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); @@ -309,6 +340,34 @@ public class UrlLink } + 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) { @@ -393,6 +452,11 @@ public class UrlLink return dynamic; } + public boolean usesSeqId() + { + return uses_seq_id; + } + public void setLabel(String newlabel) { this.label = newlabel;