JAL-3863 mark first accession retrieved from Uniprot as the canonical accession
authorJim Procter <j.procter@dundee.ac.uk>
Mon, 30 Aug 2021 09:08:07 +0000 (10:08 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Mon, 30 Aug 2021 11:17:32 +0000 (12:17 +0100)
src/jalview/datamodel/DBRefEntry.java
src/jalview/ws/dbsources/Uniprot.java
test/jalview/ws/dbsources/UniprotTest.java

index f557ff8..ae06650 100755 (executable)
@@ -39,6 +39,8 @@ public class DBRefEntry implements DBRefEntryI
   int sourceKey = Integer.MIN_VALUE;
 
   String canonicalSourceName;
+  
+  boolean isCanonicalAccession;
 
   /*
    * maps from associated sequence to the database sequence's coordinate system
@@ -61,12 +63,25 @@ public class DBRefEntry implements DBRefEntryI
    */
   public DBRefEntry(String source, String version, String accessionId)
   {
-    this(source, version, accessionId, null);
+    this(source, version, accessionId, null,false);
   }
 
   /**
    * 
    * @param source
+   *                      may not be null
+   * @param version
+   *                      may be null
+   * @param accessionId
+   *                      may be null
+   */
+  public DBRefEntry(String source, String version, String accessionId, Mapping map)
+  {
+    this(source, version, accessionId, map,false);
+  }
+  /**
+   * 
+   * @param source
    *          canonical source (turned to uppercase; cannot be null)
    * @param version
    *          (source dependent version string or null)
@@ -77,13 +92,14 @@ public class DBRefEntry implements DBRefEntryI
    *          numbering or null)
    */
   public DBRefEntry(String source, String version, String accessionId,
-          Mapping map)
+          Mapping map,boolean isCanonical)
   {
        
     this.source = source.toUpperCase();
     setVersion(version);
     this.accessionId = accessionId;
     this.map = map;
+    this.isCanonicalAccession=isCanonical;
   }
 
   /**
@@ -383,4 +399,22 @@ public class DBRefEntry implements DBRefEntryI
   public String getCanonicalSourceName() {
        return (canonicalSourceName == null ? (canonicalSourceName = DBRefUtils.getCanonicalName(this.source)) : canonicalSourceName);
   }
+
+  /**
+   * 
+   * @param canonical
+   */
+  public void setCanonical(boolean canonical)
+  {
+    isCanonicalAccession = canonical;
+  }
+  /**
+   * 
+   * @return true if this is the primary canonical accession for the database source
+   */
+  public boolean isCanonical()
+  {
+    // TODO Auto-generated method stub
+    return isCanonicalAccession;
+  }
 }
index 6f5f033..2fc5893 100644 (file)
@@ -195,10 +195,12 @@ public class Uniprot extends DbSourceProxyImpl
      */
     final String dbVersion = getDbVersion();
     List<DBRefEntry> dbRefs = new ArrayList<>();
+    boolean canonical=true;
     for (String accessionId : entry.getAccession())
     {
       DBRefEntry dbRef = new DBRefEntry(DBRefSource.UNIPROT, dbVersion,
-              accessionId);
+              accessionId,null,canonical);
+      canonical=false;
       dbRefs.add(dbRef);
     }
 
index d8ed08e..31cd513 100644 (file)
  */
 package jalview.ws.dbsources;
 
+import static org.testng.Assert.assertFalse;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.JvOptionPane;
+import jalview.util.DBRefUtils;
 import jalview.xml.binding.uniprot.DbReferenceType;
 import jalview.xml.binding.uniprot.Entry;
 import jalview.xml.binding.uniprot.FeatureType;
@@ -218,6 +221,11 @@ public class UniprotTest
     assertEquals(6, seq.getDBRefs().size()); // 2*Uniprot, PDB, PDBsum, 2*EMBL
     assertEquals(seq.getSequenceAsString(),
             seq.createDatasetSequence().getSequenceAsString());
+    assertEquals(2,seq.getPrimaryDBRefs().size());
+    List<DBRefEntry> res = DBRefUtils.searchRefs(seq.getPrimaryDBRefs(), "A9CKP4");
+    assertEquals(1,res.size());
+    assertTrue(res.get(0).isCanonical());
+    assertFalse(res.get(1).isCanonical());
   }
 
   /**