From f47e7c2da5a0542cd0020c727abb3dc05f8442e5 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 6 Oct 2017 16:01:54 +0100 Subject: [PATCH] JAL-2758 flag and tests for omitting uniprot accession prefix from sequence names --- src/jalview/ws/dbsources/Uniprot.java | 30 +++++++++++++++++++--------- test/jalview/ws/dbsources/UniprotTest.java | 5 ++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index c9beb8e..2452aed 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -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(); diff --git a/test/jalview/ws/dbsources/UniprotTest.java b/test/jalview/ws/dbsources/UniprotTest.java index 2d4be71..5421a44 100644 --- a/test/jalview/ws/dbsources/UniprotTest.java +++ b/test/jalview/ws/dbsources/UniprotTest.java @@ -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)); } /** -- 1.7.10.2