Skip to content

Commit

Permalink
Merge pull request #202 from ebi-uniprot/TRM-29836_doi
Browse files Browse the repository at this point in the history
TRM-29836: Create an UniProtKB result column to show publication DOI ids
  • Loading branch information
LeonardoGonzales authored Nov 3, 2023
2 parents 41f7d4e + e6f9c29 commit 1d09373
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.uniprot.core.uniprotkb.UniProtKBReference;

public class EntryReferenceMap implements NamedValueMap {
static final List<String> FIELDS = Arrays.asList("lit_pubmed_id");
static final String LIT_PUBMED_ID = "lit_pubmed_id";
static final String LIT_DOI_ID = "lit_doi_id";
static final List<String> FIELDS = Arrays.asList(LIT_PUBMED_ID, LIT_DOI_ID);
private final List<UniProtKBReference> references;

public EntryReferenceMap(List<UniProtKBReference> references) {
Expand All @@ -26,16 +28,20 @@ public Map<String, String> attributeValues() {
return Collections.emptyMap();
}

String result =
Map<CitationDatabase, String> idMaps =
references.stream()
.map(UniProtKBReference::getCitation)
.filter(val -> val.getCitationCrossReferences() != null)
.flatMap(val -> val.getCitationCrossReferences().stream())
.filter(val -> val.getDatabase().equals(CitationDatabase.PUBMED))
.map(CrossReference::getId)
.collect(Collectors.joining("; "));
.collect(
Collectors.groupingBy(
CrossReference::getDatabase,
Collectors.mapping(
CrossReference::getId, Collectors.joining("; "))));

Map<String, String> map = new HashMap<>();
map.put(FIELDS.get(0), result);
map.put(LIT_PUBMED_ID, idMaps.getOrDefault(CitationDatabase.PUBMED, ""));
map.put(LIT_DOI_ID, idMaps.getOrDefault(CitationDatabase.DOI, ""));
return map;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.uniprot.core.parser.tsv.uniprot;

import static org.junit.jupiter.api.Assertions.*;
import static org.uniprot.core.parser.tsv.uniprot.EntryReferenceMap.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.uniprot.core.citation.Citation;
import org.uniprot.core.citation.CitationDatabase;
import org.uniprot.core.citation.impl.ElectronicArticleBuilder;
import org.uniprot.core.impl.CrossReferenceBuilder;
import org.uniprot.core.uniprotkb.UniProtKBReference;
import org.uniprot.core.uniprotkb.impl.UniProtKBReferenceBuilder;

class EntryReferenceMapTest {

private static final String FIELD_SEPARATOR = "; ";

@Test
void testFields() {
List<String> expected = Arrays.asList(LIT_PUBMED_ID, LIT_DOI_ID);
assertEquals(expected, FIELDS);
}

@Test
void testLitDoiId() {
String doiId = "doiId1";
List<UniProtKBReference> references = getUniProtKBReferences(CitationDatabase.DOI, doiId);
EntryReferenceMap mapper = new EntryReferenceMap(references);
Map<String, String> result = mapper.attributeValues();

verifyFieldValue(result, LIT_DOI_ID, doiId);
}

@Test
void testMultipleLitDoiId() {
String doiId = "doiId1";
String doiId2 = "doiId2";
List<UniProtKBReference> references =
getUniProtKBReferences(CitationDatabase.DOI, doiId, doiId2);
EntryReferenceMap mapper = new EntryReferenceMap(references);
Map<String, String> result = mapper.attributeValues();

verifyFieldValue(result, LIT_DOI_ID, doiId + FIELD_SEPARATOR + doiId2);
}

@Test
void testLitPubmedId() {
String pubmedId = "pubmedId1";
List<UniProtKBReference> references =
getUniProtKBReferences(CitationDatabase.PUBMED, pubmedId);
EntryReferenceMap mapper = new EntryReferenceMap(references);
Map<String, String> result = mapper.attributeValues();

verifyFieldValue(result, LIT_PUBMED_ID, pubmedId);
}

@Test
void testMultipleLitPubmedId() {
String pubmedId = "pubmedId1";
String pubmedId2 = "pubmedId2";
List<UniProtKBReference> references =
getUniProtKBReferences(CitationDatabase.PUBMED, pubmedId, pubmedId2);

EntryReferenceMap mapper = new EntryReferenceMap(references);
Map<String, String> result = mapper.attributeValues();

verifyFieldValue(result, LIT_PUBMED_ID, pubmedId + FIELD_SEPARATOR + pubmedId2);
}

@Test
void testMixedIds() {
String pubmedId = "pubmedId1";
String pubmedId2 = "pubmedId2";
String doiId = "doiId1";
String doiId2 = "doiId2";
List<UniProtKBReference> references =
getUniProtKBReferences(CitationDatabase.PUBMED, pubmedId, pubmedId2);
references.addAll(getUniProtKBReferences(CitationDatabase.DOI, doiId, doiId2));

EntryReferenceMap mapper = new EntryReferenceMap(references);
Map<String, String> result = mapper.attributeValues();

verifyFieldValue(result, LIT_PUBMED_ID, pubmedId + FIELD_SEPARATOR + pubmedId2);
verifyFieldValue(result, LIT_DOI_ID, doiId + FIELD_SEPARATOR + doiId2);
}

private List<UniProtKBReference> getUniProtKBReferences(
CitationDatabase database, String... ids) {
List<UniProtKBReference> result = new ArrayList<>();
for (String id : ids) {
Citation citation =
new ElectronicArticleBuilder()
.citationCrossReferencesAdd(
new CrossReferenceBuilder<CitationDatabase>()
.database(database)
.id(id)
.build())
.build();
UniProtKBReference reference =
new UniProtKBReferenceBuilder().citation(citation).build();
result.add(reference);
}
return result;
}

private void verifyFieldValue(
Map<String, String> result, String fieldName, String expectedValue) {
String resultValue = result.get(fieldName);
assertNotNull(resultValue);
assertEquals(expectedValue, resultValue);
}
}

0 comments on commit 1d09373

Please sign in to comment.