diff --git a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapper.java b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapper.java index 2a9252744..c149912a9 100644 --- a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapper.java +++ b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapper.java @@ -1,6 +1,7 @@ package org.uniprot.core.parser.tsv.uniparc; import org.uniprot.core.parser.tsv.EntityValueMapper; +import org.uniprot.core.uniparc.CommonOrganism; import org.uniprot.core.uniparc.UniParcEntryLight; import org.uniprot.core.uniprotkb.taxonomy.Organism; @@ -19,7 +20,8 @@ public class UniParcEntryLightValueMapper implements EntityValueMapper getSimpleAttributeValues(UniParcEntryLight entry, Li .map(LocalDate::toString) .orElse("")); break; + case "common_taxons": + map.put( + UNIPARC_FIELDS.get(9), + Optional.of(entry.getCommonTaxons()) + .map(this::getCommonTaxonString) + .orElse("")); + break; default: // do nothing } } return map; } + + private String getCommonTaxonString(List commonTaxons) { + return commonTaxons.stream().map(CommonOrganism::getCommonTaxon).collect(Collectors.joining("; ")); + } } diff --git a/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapperTest.java b/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapperTest.java index e7d8b1445..e613c83b0 100644 --- a/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapperTest.java +++ b/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapperTest.java @@ -9,10 +9,7 @@ import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; import java.time.LocalDate; -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -21,7 +18,7 @@ class UniParcEntryLightValueMapperTest { @Test void testGetDataOrganism() { UniParcEntryLight entry = create(); - List fields = Arrays.asList("upi", "organism", "organism_id", "proteome"); + List fields = Arrays.asList("upi", "organism", "organism_id", "proteome", "common_taxons"); Map result = new UniParcEntryLightValueMapper().mapEntity(entry, fields); @@ -30,6 +27,23 @@ void testGetDataOrganism() { verify("Homo sapiens; MOUSE", "organism", result); verify("9606; 10090", "organism_id", result); verify("UP000005640:C1; UP000002494:C2", "proteome", result); + verify("Bacteroides; Enterococcus", "common_taxons", result); + } + + @Test + void testGetDataOrganism_withEmptyCommonTaxons() { + UniParcEntryLight entry = create(); + UniParcEntryLight entryWithEmptyCommonTaxons = UniParcEntryLightBuilder.from(entry).commonTaxonsSet(List.of()).build(); + List fields = Arrays.asList("upi", "organism", "organism_id", "proteome", "common_taxons"); + + Map result = new UniParcEntryLightValueMapper().mapEntity(entryWithEmptyCommonTaxons, fields); + + assertEquals(fields.size(), result.size()); + verify("UPI0000083A08", "upi", result); + verify("Homo sapiens; MOUSE", "organism", result); + verify("9606; 10090", "organism_id", result); + verify("UP000005640:C1; UP000002494:C2", "proteome", result); + verify("", "common_taxons", result); } @Test @@ -95,6 +109,7 @@ private UniParcEntryLight create() { LinkedHashSet proteinNames = new LinkedHashSet<>(List.of("protein1", "protein2")); LinkedHashSet geneNames = new LinkedHashSet<>(List.of("gene1", "gene2")); + List commonTaxons = List.of(new CommonOrganismBuilder().commonTaxon("Bacteroides").build(),new CommonOrganismBuilder().commonTaxon("Enterococcus").build()); LinkedHashSet proteomes = new LinkedHashSet<>(List.of(new ProteomeBuilder().id("UP000005640").component("C1").build(), new ProteomeBuilder().id("UP000002494").component("C2").build())); return new UniParcEntryLightBuilder() @@ -103,6 +118,7 @@ private UniParcEntryLight create() { .organismsSet(organisms) .proteomesSet(proteomes) .geneNamesSet(geneNames) + .commonTaxonsSet(commonTaxons) .proteinNamesSet(proteinNames) .mostRecentCrossRefUpdated(LocalDate.of(2020, 10, 25)) .oldestCrossRefCreated(LocalDate.of(2017, 2, 12))