JAL-2920 use HGVS notation for protein variant feature
[jalview.git] / src / jalview / ws / dbsources / Uniprot.java
index 2452aed..11fff9d 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ws.dbsources;
 
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
@@ -31,6 +32,8 @@ import jalview.datamodel.SequenceI;
 import jalview.datamodel.xdb.uniprot.UniprotEntry;
 import jalview.datamodel.xdb.uniprot.UniprotFeature;
 import jalview.datamodel.xdb.uniprot.UniprotFile;
+import jalview.schemes.ResidueProperties;
+import jalview.util.StringUtils;
 import jalview.ws.seqfetcher.DbSourceProxyImpl;
 
 import java.io.InputStream;
@@ -52,6 +55,8 @@ import com.stevesoft.pat.Regex;
  */
 public class Uniprot extends DbSourceProxyImpl
 {
+  private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org";
+
   private static final String BAR_DELIMITER = "|";
 
   /*
@@ -60,11 +65,6 @@ public class Uniprot extends DbSourceProxyImpl
   private static Mapping map;
 
   /**
-   * configurable parameter controlling prefixing of entry names with accessions
-   */
-  private boolean includeAllIds = false;
-
-  /**
    * Constructor
    */
   public Uniprot()
@@ -72,6 +72,11 @@ public class Uniprot extends DbSourceProxyImpl
     super();
   }
 
+  private String getDomain()
+  {
+    return Cache.getDefault("UNIPROT_DOMAIN", DEFAULT_UNIPROT_DOMAIN);
+  }
+
   /*
    * (non-Javadoc)
    * 
@@ -168,7 +173,7 @@ public class Uniprot extends DbSourceProxyImpl
               "(UNIPROT\\|?|UNIPROT_|UNIREF\\d+_|UNIREF\\d+\\|?)", "");
       AlignmentI al = null;
 
-      String downloadstring = "http://www.uniprot.org/uniprot/" + queries
+      String downloadstring = getDomain() + "/uniprot/" + queries
               + ".xml";
       URL url = null;
       URLConnection urlconn = null;
@@ -208,7 +213,7 @@ public class Uniprot extends DbSourceProxyImpl
    */
   public SequenceI uniprotEntryToSequenceI(UniprotEntry entry)
   {
-    String id = getUniprotEntryId(entry, includeAllIds);
+    String id = getUniprotEntryId(entry);
     SequenceI sequence = new Sequence(id,
             entry.getUniprotSequence().getContent());
     sequence.setDescription(getUniprotEntryDescription(entry));
@@ -275,7 +280,7 @@ public class Uniprot extends DbSourceProxyImpl
       for (UniprotFeature uf : entry.getFeature())
       {
         SequenceFeature copy = new SequenceFeature(uf.getType(),
-                uf.getDescription(), uf.getBegin(), uf.getEnd(), "Uniprot");
+                getDescription(uf), uf.getBegin(), uf.getEnd(), "Uniprot");
         copy.setStatus(uf.getStatus());
         sequence.addSequenceFeature(copy);
       }
@@ -288,6 +293,43 @@ public class Uniprot extends DbSourceProxyImpl
   }
 
   /**
+   * Constructs a feature description from the description and (optionally)
+   * original and variant fields of the Uniprot XML feature
+   * 
+   * @param uf
+   * @return
+   */
+  protected static String getDescription(UniprotFeature uf)
+  {
+    String orig = uf.getOriginal();
+    String var = uf.getVariation();
+    StringBuilder sb = new StringBuilder();
+
+    /*
+     * append variant in standard format if present
+     * e.g. p.Arg59Lys
+     */
+    if (orig != null && !orig.isEmpty() && var != null && !var.isEmpty())
+    {
+      sb.append("p.");
+      String orig3 = ResidueProperties.aa2Triplet.get(orig);
+      sb.append(orig3 == null ? orig : StringUtils.toSentenceCase(orig3));
+      sb.append(Integer.toString(uf.getPosition()));
+      String var3 = ResidueProperties.aa2Triplet.get(var);
+      sb.append(var3 == null ? var : StringUtils.toSentenceCase(var3));
+      sb.append(" ");
+    }
+
+    String description = uf.getDescription();
+    if (description != null)
+    {
+      sb.append(description);
+    }
+
+    return sb.toString();
+  }
+
+  /**
    * 
    * @param entry
    *          UniportEntry
@@ -315,24 +357,12 @@ public class Uniprot extends DbSourceProxyImpl
   /**
    *
    * @param entry
-   *          UniportEntry
+   *          UniprotEntry
    * @return The accession id(s) and name(s) delimited by '|'.
    */
-  public static String getUniprotEntryId(UniprotEntry entry,
-          boolean includeAllIds)
+  public static String getUniprotEntryId(UniprotEntry entry)
   {
     StringBuilder name = new StringBuilder(32);
-    if (includeAllIds)
-    {
-      // // use 'canonicalised' name for optimal id matching
-      name.append(DBRefSource.UNIPROT);
-      for (String accessionId : entry.getAccession())
-      {
-        name.append(BAR_DELIMITER);
-        name.append(accessionId);
-      }
-
-    }
     for (String n : entry.getName())
     {
       if (name.length() > 0)