Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRM-29836: Create an UniProtKB result column to show publication DOI ids #202

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}