From d0d660cab06c31659e7bb0a1780317b3d2231eb6 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 30 Aug 2021 10:08:07 +0100 Subject: [PATCH] JAL-3863 mark first accession retrieved from Uniprot as the canonical accession --- src/jalview/datamodel/DBRefEntry.java | 38 ++++++++++++++++++++++++++-- src/jalview/ws/dbsources/Uniprot.java | 4 ++- test/jalview/ws/dbsources/UniprotTest.java | 8 ++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/jalview/datamodel/DBRefEntry.java b/src/jalview/datamodel/DBRefEntry.java index f557ff8..ae06650 100755 --- a/src/jalview/datamodel/DBRefEntry.java +++ b/src/jalview/datamodel/DBRefEntry.java @@ -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; + } } diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index 6f5f033..2fc5893 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -195,10 +195,12 @@ public class Uniprot extends DbSourceProxyImpl */ final String dbVersion = getDbVersion(); List 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); } diff --git a/test/jalview/ws/dbsources/UniprotTest.java b/test/jalview/ws/dbsources/UniprotTest.java index d8ed08e..31cd513 100644 --- a/test/jalview/ws/dbsources/UniprotTest.java +++ b/test/jalview/ws/dbsources/UniprotTest.java @@ -20,13 +20,16 @@ */ 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 res = DBRefUtils.searchRefs(seq.getPrimaryDBRefs(), "A9CKP4"); + assertEquals(1,res.size()); + assertTrue(res.get(0).isCanonical()); + assertFalse(res.get(1).isCanonical()); } /** -- 1.7.10.2