Skip to content

Commit

Permalink
address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadshadab committed Sep 24, 2024
1 parent 5e991c9 commit f9426f3
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class UniParcCrossReferenceImpl extends CrossReferenceImpl<UniParcDatabas
private final String proteomeId;
private final String component;

protected UniParcCrossReferenceImpl() {
UniParcCrossReferenceImpl() {
this(
null, null, null, 0, null, false, null, null, null, null, null, null, null, null,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ public class UniParcCrossReferencePair implements Pair<String, List<UniParcCross
private static final long serialVersionUID = 7906365717659009263L;
private String key;
private List<UniParcCrossReference> value;
public UniParcCrossReferencePair(){
this(null, null);
}


public UniParcCrossReferencePair(String key, List<UniParcCrossReference> value) {
this.key = key;
this.value = value;
}


@Override
public String getKey() {
return key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class UniParcEntryLightBuilder implements Builder<UniParcEntryLight> {
private String uniParcId;
private int crossReferenceCount;
private List<CommonOrganism> commonTaxons = new ArrayList<>();
private LinkedHashSet<String> uniProtKBAccessions = new LinkedHashSet<>();
private Set<String> uniProtKBAccessions = new LinkedHashSet<>();

private Sequence sequence;

Expand All @@ -45,8 +45,8 @@ public class UniParcEntryLightBuilder implements Builder<UniParcEntryLight> {
public UniParcEntryLight build() {
return new UniParcEntryLightImpl(uniParcId, crossReferenceCount, commonTaxons, uniProtKBAccessions,
sequence, sequenceFeatures, oldestCrossRefCreated,
mostRecentCrossRefUpdated, (LinkedHashSet<Organism>) organisms, (LinkedHashSet<String>) proteinNames,
(LinkedHashSet<String>) geneNames, (LinkedHashSet<Proteome>) proteomes, extraAttributes);
mostRecentCrossRefUpdated, organisms, proteinNames,
geneNames, proteomes, extraAttributes);
}

public @Nonnull UniParcEntryLightBuilder uniParcId(String uniParcId) {
Expand Down Expand Up @@ -149,6 +149,11 @@ public UniParcEntryLight build() {
return this;
}

public @Nonnull UniParcEntryLightBuilder extraAttributesSet(Map<String, Object> extraAttributes) {
this.extraAttributes = new LinkedHashMap<>(extraAttributes);
return this;
}

public static @Nonnull UniParcEntryLightBuilder from(UniParcEntryLight uniParcEntryLight){
LinkedHashSet<String> uniProtKBAccessions = new LinkedHashSet<>(uniParcEntryLight.getUniProtKBAccessions());
LinkedHashSet<Organism> organisms = new LinkedHashSet<>(uniParcEntryLight.getOrganisms());
Expand All @@ -167,8 +172,8 @@ public UniParcEntryLight build() {
.organismsSet(organisms)
.proteinNamesSet(proteinNames)
.geneNamesSet(geneNames)
.proteomesSet(proteomes);
builder.extraAttributes = new LinkedHashMap<>(uniParcEntryLight.getExtraAttributes());
.proteomesSet(proteomes)
.extraAttributesSet(uniParcEntryLight.getExtraAttributes());
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public class UniParcEntryLightImpl implements UniParcEntryLight {
null, null, null, null, null);
}
UniParcEntryLightImpl(String uniParcId, int crossReferenceCount,
List<CommonOrganism> commonTaxons, LinkedHashSet<String> uniProtKBAccessions,
List<CommonOrganism> commonTaxons, Set<String> uniProtKBAccessions,
Sequence sequence, List<SequenceFeature> sequenceFeatures,
LocalDate oldestCrossRefCreated, LocalDate mostRecentCrossRefUpdated,
LinkedHashSet<Organism> organisms, LinkedHashSet<String> proteinNames, LinkedHashSet<String> geneNames,
LinkedHashSet<Proteome> proteomes, Map<String, Object> extraAttributes) {
Set<Organism> organisms, Set<String> proteinNames, Set<String> geneNames,
Set<Proteome> proteomes, Map<String, Object> extraAttributes) {
this.uniParcId = uniParcId;
this.crossReferenceCount = crossReferenceCount;
this.commonTaxons = Utils.unmodifiableList(commonTaxons);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
import static org.uniprot.core.ObjectsForTests.sequenceFeatures;
Expand Down Expand Up @@ -224,6 +225,20 @@ void testProteomeIdsAdd() {
assertTrue(entry.getProteomes().contains(proteomeId));
}

@Test
void testProteomesSetThenAdd() {
Proteome proteome1 = new ProteomeBuilder().id("UP000005640").component("chromosome").build();
LinkedHashSet<Proteome> proteomes = new LinkedHashSet<>(List.of(proteome1));
Proteome proteome2 = new ProteomeBuilder().id("UP000002494").component("chromosome").build();

UniParcEntryLight entry = new UniParcEntryLightBuilder()
.proteomesSet(proteomes)
.proteomesAdd(proteome2)
.build();
assertEquals(2, entry.getProteomes().size());
assertTrue(entry.getProteomes().containsAll(List.of(proteome1, proteome2)));
}

@Test
void testOrganismsSetThenAdd() {
Organism organism1 = new OrganismBuilder().taxonId(9606).scientificName("Homo sapiens").build();
Expand Down Expand Up @@ -261,20 +276,6 @@ void testGeneNamesSetThenAdd() {
assertTrue(entry.getGeneNames().containsAll(List.of("Gene1", "Gene2")));
}

@Test
void testProteomeIdsSetThenAdd() {
Proteome proteome1 = new ProteomeBuilder().id("UP000005640").component("chromosome").build();
LinkedHashSet<Proteome> proteomes = new LinkedHashSet<>(List.of(proteome1));
Proteome proteome2 = new ProteomeBuilder().id("UP000002494").component("chromosome").build();

UniParcEntryLight entry = new UniParcEntryLightBuilder()
.proteomesSet(proteomes)
.proteomesAdd(proteome2)
.build();
assertEquals(2, entry.getProteomes().size());
assertTrue(entry.getProteomes().containsAll(List.of(proteome1, proteome2)));
}


@Test
void testFrom() {
Expand Down Expand Up @@ -313,18 +314,7 @@ void testFrom() {

UniParcEntryLight newEntry = UniParcEntryLightBuilder.from(originalEntry).build();

assertEquals(originalEntry.getUniParcId(), newEntry.getUniParcId());
assertEquals(originalEntry.getCrossReferenceCount(), newEntry.getCrossReferenceCount());
assertEquals(originalEntry.getCommonTaxons(), newEntry.getCommonTaxons());
assertEquals(originalEntry.getSequence(), newEntry.getSequence());
assertEquals(originalEntry.getSequenceFeatures(), newEntry.getSequenceFeatures());
assertEquals(originalEntry.getOldestCrossRefCreated(), newEntry.getOldestCrossRefCreated());
assertEquals(originalEntry.getMostRecentCrossRefUpdated(), newEntry.getMostRecentCrossRefUpdated());
assertEquals(originalEntry.getOrganisms(), newEntry.getOrganisms());
assertEquals(originalEntry.getProteinNames(), newEntry.getProteinNames());
assertEquals(originalEntry.getGeneNames(), newEntry.getGeneNames());
assertEquals(originalEntry.getProteomes(), newEntry.getProteomes());
assertEquals(originalEntry, newEntry);
verifyOriginalAndNewEntry(originalEntry, newEntry);
}

@Test
Expand Down Expand Up @@ -361,4 +351,33 @@ void testAddExtraAttributes(){
assertEquals(false, updatedEntry.getExtraAttributes().get("hasActiveCrossRef"));
}

@Test
void testSetExtraAttributes(){
UniParcEntryLight entry = new UniParcEntryLightBuilder().uniParcId("UPI0000083A08").build();
assertEquals("UPI0000083A08", entry.getUniParcId());
assertTrue(entry.getExtraAttributes().isEmpty());
// set extra attribute
UniParcEntryLight updatedEntry = UniParcEntryLightBuilder.from(entry)
.extraAttributesSet(Map.of("hasActiveCrossRef", false, "another", "random")).build();
assertEquals("UPI0000083A08", updatedEntry.getUniParcId());
assertEquals(2, updatedEntry.getExtraAttributes().size());
assertEquals(false, updatedEntry.getExtraAttributes().get("hasActiveCrossRef"));
assertEquals("random", updatedEntry.getExtraAttributes().get("another"));
}

private void verifyOriginalAndNewEntry(UniParcEntryLight originalEntry, UniParcEntryLight newEntry) {
assertEquals(originalEntry.getUniParcId(), newEntry.getUniParcId());
assertEquals(originalEntry.getCrossReferenceCount(), newEntry.getCrossReferenceCount());
assertEquals(originalEntry.getCommonTaxons(), newEntry.getCommonTaxons());
assertEquals(originalEntry.getSequence(), newEntry.getSequence());
assertEquals(originalEntry.getSequenceFeatures(), newEntry.getSequenceFeatures());
assertEquals(originalEntry.getOldestCrossRefCreated(), newEntry.getOldestCrossRefCreated());
assertEquals(originalEntry.getMostRecentCrossRefUpdated(), newEntry.getMostRecentCrossRefUpdated());
assertEquals(originalEntry.getOrganisms(), newEntry.getOrganisms());
assertEquals(originalEntry.getProteinNames(), newEntry.getProteinNames());
assertEquals(originalEntry.getGeneNames(), newEntry.getGeneNames());
assertEquals(originalEntry.getProteomes(), newEntry.getProteomes());
assertEquals(originalEntry, newEntry);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class UniParcEntryLightImplTest {
void needDefaultConstructorForJsonDeserialization() {
UniParcEntryLight lightObject = new UniParcEntryLightImpl();
assertNotNull(lightObject);
UniParcEntryLightBuilder.from(lightObject);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
package org.uniprot.core.parser.tsv.uniparc;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import org.uniprot.core.parser.tsv.NamedValueMap;
import org.uniprot.core.uniparc.UniParcCrossReference;
import org.uniprot.core.uniparc.UniParcDatabase;
import org.uniprot.core.util.Utils;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

/**
* @author jluo
* @date: 24 Jun 2019
Expand All @@ -36,8 +28,6 @@ public class UniParcCrossReferenceMap implements NamedValueMap {
"protein",
"proteome",
"accession",
"first_seen",
"last_seen",
"database",
"active",
"ncbiGi",
Expand All @@ -57,22 +47,17 @@ public UniParcCrossReferenceMap(List<UniParcCrossReference> uniParcCrossReferenc
@Override
public Map<String, String> attributeValues() {
Map<String, String> map = new HashMap<>();
Optional<LocalDate> firstSeen = getFirstSeenDate();
Optional<LocalDate> lastSeen = getLastSeenDate();
map.put(FIELDS.get(0), getGeneNames());
map.put(FIELDS.get(1), getProteinNames());
map.put(FIELDS.get(2), getProteomes());
map.put(FIELDS.get(3), getUniProtKBAccessions());
map.put(FIELDS.get(4), firstSeen.map(LocalDate::toString).orElse(""));
map.put(FIELDS.get(5), lastSeen.map(LocalDate::toString).orElse(""));
map.put(FIELDS.get(6), getDatabases());
map.put(FIELDS.get(7), getActives());
map.put(FIELDS.get(8), getNcbiGis());
map.put(FIELDS.get(9), getTimelines());
map.put(FIELDS.get(10), getVersions());
map.put(FIELDS.get(11), getVersionIs());
map.put(FIELDS.get(4), getDatabases());
map.put(FIELDS.get(5), getActives());
map.put(FIELDS.get(6), getNcbiGis());
map.put(FIELDS.get(7), getTimelines());
map.put(FIELDS.get(8), getVersions());
map.put(FIELDS.get(9), getVersionIs());
map.putAll(getDatabasesMap());

return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class UniParcEntryValueMapper implements EntityValueMapper<UniParcEntry> {

private static final List<String> UNIPARC_FIELDS =
List.of("upi", "oldestCrossRefCreated", "mostRecentCrossRefUpdated");
List.of("upi", "first_seen", "last_seen");

@Override
public Map<String, String> mapEntity(UniParcEntry entry, List<String> fields) {
Expand Down Expand Up @@ -60,14 +60,14 @@ private Map<String, String> getSimpleAttributeValues(UniParcEntry entry, List<St
case "upi":
map.put(UNIPARC_FIELDS.get(0), entry.getUniParcId().getValue());
break;
case "oldestCrossRefCreated":
case "first_seen":
map.put(
UNIPARC_FIELDS.get(1),
Optional.of(entry.getOldestCrossRefCreated())
.map(LocalDate::toString)
.orElse(""));
break;
case "mostRecentCrossRefUpdated":
case "last_seen":
map.put(
UNIPARC_FIELDS.get(2),
Optional.of(entry.getMostRecentCrossRefUpdated())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
package org.uniprot.core.json.parser.uniparc;

import static org.junit.jupiter.api.Assertions.fail;
import static org.uniprot.core.json.parser.uniparc.UniParcEntryTest.getCompleteUniParcEntry;

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.uniprot.core.json.parser.ValidateJson;
import org.uniprot.core.uniparc.UniParcCrossReference;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.uniprot.core.uniparc.UniParcEntry;
import org.uniprot.core.uniparc.impl.UniParcCrossReferencePair;
import org.uniprot.core.util.Pair;
import org.uniprot.core.util.PairImpl;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.fail;
import static org.uniprot.core.json.parser.uniparc.UniParcEntryTest.getCompleteUniParcEntry;

class UniParcCrossRefJsonConfigTest {
@Test
void test() {
UniParcEntry completeUniParcEntry = getCompleteUniParcEntry();
Pair<String, List<UniParcCrossReference>> entry = new UniParcCrossReferencePair(completeUniParcEntry.getUniParcId().getValue(), completeUniParcEntry.getUniParcCrossReferences());
/*
ValidateJson.verifyJsonRoundTripParser(
UniParcCrossRefJsonConfig.getInstance().getFullObjectMapper(), completeUniParcEntry.getUniParcCrossReferences().get(0));
ValidateJson.verifyJsonRoundTripParser(
UniParcCrossRefJsonConfig.getInstance().getFullObjectMapper(), new ArrayList<>(completeUniParcEntry.getUniParcCrossReferences()));
*/

ValidateJson.verifyJsonRoundTripParser(
UniParcCrossRefJsonConfig.getInstance().getFullObjectMapper(), entry);
ValidateJson.verifyEmptyFields(entry);
Expand Down

0 comments on commit f9426f3

Please sign in to comment.