Skip to content

Commit

Permalink
add common taxon id as a return field for uniparc light
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadshadab committed Nov 15, 2024
1 parent f962fab commit bcf8f8b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class UniParcEntryLightValueMapper implements EntityValueMapper<UniParcEn
"accession",
"first_seen",
"last_seen",
"common_taxons");
"common_taxons",
"common_taxon_ids");
private static final String DELIMITER2 = "; ";

@Override
Expand Down Expand Up @@ -102,6 +103,13 @@ private Map<String, String> getSimpleAttributeValues(UniParcEntryLight entry, Li
.map(this::getCommonTaxonString)
.orElse(""));
break;
case "common_taxon_ids":
map.put(
UNIPARC_FIELDS.get(10),
Optional.of(entry.getCommonTaxons())
.map(this::getCommonTaxonIdString)
.orElse(""));
break;
default:
// do nothing
}
Expand All @@ -112,4 +120,8 @@ private Map<String, String> getSimpleAttributeValues(UniParcEntryLight entry, Li
private String getCommonTaxonString(List<CommonOrganism> commonTaxons) {
return commonTaxons.stream().map(CommonOrganism::getCommonTaxon).collect(Collectors.joining("; "));
}

private String getCommonTaxonIdString(List<CommonOrganism> commonTaxons) {
return commonTaxons.stream().map(commonOrganism -> String.valueOf(commonOrganism.getCommonTaxonId())).collect(Collectors.joining("; "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UniParcEntryLightValueMapperTest {
@Test
void testGetDataOrganism() {
UniParcEntryLight entry = create();
List<String> fields = Arrays.asList("upi", "organism", "organism_id", "proteome", "common_taxons");
List<String> fields = Arrays.asList("upi", "organism", "organism_id", "proteome", "common_taxons", "common_taxon_ids");

Map<String, String> result = new UniParcEntryLightValueMapper().mapEntity(entry, fields);

Expand All @@ -28,13 +28,14 @@ void testGetDataOrganism() {
verify("9606; 10090", "organism_id", result);
verify("UP000005640:C1; UP000002494:C2", "proteome", result);
verify("Bacteroides; Enterococcus", "common_taxons", result);
verify("12345; 9876", "common_taxon_ids", result);
}

@Test
void testGetDataOrganism_withEmptyCommonTaxons() {
UniParcEntryLight entry = create();
UniParcEntryLight entryWithEmptyCommonTaxons = UniParcEntryLightBuilder.from(entry).commonTaxonsSet(List.of()).build();
List<String> fields = Arrays.asList("upi", "organism", "organism_id", "proteome", "common_taxons");
List<String> fields = Arrays.asList("upi", "organism", "organism_id", "proteome", "common_taxons", "common_taxon_ids");

Map<String, String> result = new UniParcEntryLightValueMapper().mapEntity(entryWithEmptyCommonTaxons, fields);

Expand All @@ -44,6 +45,8 @@ void testGetDataOrganism_withEmptyCommonTaxons() {
verify("9606; 10090", "organism_id", result);
verify("UP000005640:C1; UP000002494:C2", "proteome", result);
verify("", "common_taxons", result);
verify("", "common_taxons", result);
verify("", "common_taxon_ids", result);
}

@Test
Expand Down Expand Up @@ -94,6 +97,8 @@ void testGetSequenceFeature() {
verify("sigId2", "PROSITE", result);
}



private void verify(String expected, String field, Map<String, String> result) {
assertEquals(expected, result.get(field));
}
Expand All @@ -109,7 +114,7 @@ private UniParcEntryLight create() {

LinkedHashSet<String> proteinNames = new LinkedHashSet<>(List.of("protein1", "protein2"));
LinkedHashSet<String> geneNames = new LinkedHashSet<>(List.of("gene1", "gene2"));
List<CommonOrganism> commonTaxons = List.of(new CommonOrganismBuilder().commonTaxon("Bacteroides").build(),new CommonOrganismBuilder().commonTaxon("Enterococcus").build());
List<CommonOrganism> commonTaxons = List.of(new CommonOrganismBuilder().commonTaxon("Bacteroides").commonTaxonId(12345L).build(),new CommonOrganismBuilder().commonTaxon("Enterococcus").commonTaxonId(9876L).build());
LinkedHashSet<Proteome> proteomes = new LinkedHashSet<>(List.of(new ProteomeBuilder().id("UP000005640").component("C1").build(), new ProteomeBuilder().id("UP000002494").component("C2").build()));

return new UniParcEntryLightBuilder()
Expand Down

0 comments on commit bcf8f8b

Please sign in to comment.