JAL-2758 flag and tests for omitting uniprot accession prefix from sequence names features/JAL-2758_shorteruniprot
authorJim Procter <jprocter@issues.jalview.org>
Fri, 6 Oct 2017 15:01:54 +0000 (16:01 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 6 Oct 2017 15:01:54 +0000 (16:01 +0100)
src/jalview/ws/dbsources/Uniprot.java
test/jalview/ws/dbsources/UniprotTest.java

index c9beb8e..2452aed 100644 (file)
@@ -60,6 +60,11 @@ 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()
@@ -203,7 +208,7 @@ public class Uniprot extends DbSourceProxyImpl
    */
   public SequenceI uniprotEntryToSequenceI(UniprotEntry entry)
   {
-    String id = getUniprotEntryId(entry);
+    String id = getUniprotEntryId(entry, includeAllIds);
     SequenceI sequence = new Sequence(id,
             entry.getUniprotSequence().getContent());
     sequence.setDescription(getUniprotEntryDescription(entry));
@@ -313,20 +318,27 @@ public class Uniprot extends DbSourceProxyImpl
    *          UniportEntry
    * @return The accession id(s) and name(s) delimited by '|'.
    */
-  public static String getUniprotEntryId(UniprotEntry entry)
+  public static String getUniprotEntryId(UniprotEntry entry,
+          boolean includeAllIds)
   {
     StringBuilder name = new StringBuilder(32);
-    // name.append("UniProt/Swiss-Prot");
-    // use 'canonicalised' name for optimal id matching
-    name.append(DBRefSource.UNIPROT);
-    for (String accessionId : entry.getAccession())
+    if (includeAllIds)
     {
-      name.append(BAR_DELIMITER);
-      name.append(accessionId);
+      // // 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())
     {
-      name.append(BAR_DELIMITER);
+      if (name.length() > 0)
+      {
+        name.append(BAR_DELIMITER);
+      }
       name.append(n);
     }
     return name.toString();
index 2d4be71..5421a44 100644 (file)
@@ -167,7 +167,10 @@ public class UniprotTest
      * source database converted to Jalview canonical name
      */
     String expectedName = "UNIPROT|A9CKP4|A9CKP5|A9CKP4_AGRT5|A9CKP4_AGRT6";
-    assertEquals(expectedName, Uniprot.getUniprotEntryId(entry));
+    assertEquals(expectedName, Uniprot.getUniprotEntryId(entry, true));
+    String expectedShortName = "A9CKP4_AGRT5|A9CKP4_AGRT6";
+    assertEquals(expectedShortName,
+            Uniprot.getUniprotEntryId(entry, false));
   }
 
   /**