diff --git a/controlled-vocabulary/src/test/java/org/uniprot/cv/xdb/UniProtKBCrossReferenceDisplayOrderTest.java b/controlled-vocabulary/src/test/java/org/uniprot/cv/xdb/UniProtKBCrossReferenceDisplayOrderTest.java index 4bfc35670..9e8af788d 100644 --- a/controlled-vocabulary/src/test/java/org/uniprot/cv/xdb/UniProtKBCrossReferenceDisplayOrderTest.java +++ b/controlled-vocabulary/src/test/java/org/uniprot/cv/xdb/UniProtKBCrossReferenceDisplayOrderTest.java @@ -1,13 +1,19 @@ package org.uniprot.cv.xdb; -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.uniprot.core.cv.xdb.UniProtDatabaseDetail; +import org.uniprot.cv.common.CVSystemProperties; import java.util.List; -import org.junit.jupiter.api.Test; -import org.uniprot.core.cv.xdb.UniProtDatabaseDetail; +import static org.junit.jupiter.api.Assertions.*; class UniProtKBCrossReferenceDisplayOrderTest { + @BeforeAll + static void setSystemProperty(){ + System.setProperty(CVSystemProperties.DR_ORD_LOCATION,"src/test/resources/xdb/dr_ord"); + } @Test void testCreateUniProtXDbDisplayOrder() { diff --git a/core-common/src/main/java/org/uniprot/core/util/PairImpl.java b/core-common/src/main/java/org/uniprot/core/util/PairImpl.java index 8cbfb5b4c..2faa4c2d0 100644 --- a/core-common/src/main/java/org/uniprot/core/util/PairImpl.java +++ b/core-common/src/main/java/org/uniprot/core/util/PairImpl.java @@ -5,6 +5,10 @@ public class PairImpl implements Pair { private final K key; private final V value; + PairImpl(){ // do not use, just to make Jackson serializer happy + this(null, null); + } + public PairImpl(K key, V value) { this.key = key; this.value = value; diff --git a/core-common/src/test/java/org/uniprot/core/util/UtilsTest.java b/core-common/src/test/java/org/uniprot/core/util/UtilsTest.java index 0a28a01b5..7b1aa24e6 100644 --- a/core-common/src/test/java/org/uniprot/core/util/UtilsTest.java +++ b/core-common/src/test/java/org/uniprot/core/util/UtilsTest.java @@ -191,26 +191,26 @@ void nonEmpty_shouldAlwaysReturnFalse() { class unmodifiableList { @Test void passingNullReturnEmptyList() { - List l = Utils.unmodifiableList(null); - assertTrue(l.isEmpty()); + List unmodifiableList = Utils.unmodifiableList(null); + assertTrue(unmodifiableList.isEmpty()); } @Test void passing_emptyList_returnEmptyList() { - List l = Utils.unmodifiableList(new ArrayList<>()); - assertTrue(l.isEmpty()); + List unmodifiableList = Utils.unmodifiableList(new ArrayList<>()); + assertTrue(unmodifiableList.isEmpty()); } @Test void passingNullReturnEmptyList_unmodifiable() { - List l = Utils.unmodifiableList(null); - assertThrows(UnsupportedOperationException.class, () -> l.add("abc")); + List unmodifiableList = Utils.unmodifiableList(null); + assertThrows(UnsupportedOperationException.class, () -> unmodifiableList.add("abc")); } @Test void passing_emptyList_returnEmptyList_unmodifiable() { - List l = Utils.unmodifiableList(new ArrayList<>()); - assertThrows(UnsupportedOperationException.class, () -> l.add("abc")); + List unmodifiableList = Utils.unmodifiableList(new ArrayList<>()); + assertThrows(UnsupportedOperationException.class, () -> unmodifiableList.add("abc")); } @Test @@ -218,7 +218,55 @@ void passingList_returnUnmodifiable() { List list = new ArrayList<>(); list.add("a"); list.add("b"); - List l = Utils.unmodifiableList(list); + List unmodifiableList = Utils.unmodifiableList(list); + assertThrows(UnsupportedOperationException.class, () -> unmodifiableList.add("c")); + } + } + + @Nested + class unmodifiableSet { + @Test + void passingNullReturnEmptySet() { + Set unmodifiableSet = Utils.unmodifiableSet(null); + assertTrue(unmodifiableSet.isEmpty()); + } + + @Test + void passing_emptySet_returnEmptySet() { + Set unmodifiableSet = Utils.unmodifiableSet(new HashSet<>()); + assertTrue(unmodifiableSet.isEmpty()); + } + + @Test + void passingNullReturnEmptySet_unmodifiable() { + Set unmodifiableSet = Utils.unmodifiableSet(null); + assertThrows(UnsupportedOperationException.class, () -> unmodifiableSet.add("abc")); + } + + @Test + void passing_emptySet_returnEmptySet_unmodifiable() { + Set unmodifiableSet = Utils.unmodifiableSet(new HashSet<>()); + assertThrows(UnsupportedOperationException.class, () -> unmodifiableSet.add("abc")); + } + + @Test + void passingSet_returnUnmodifiable() { + Set set = new HashSet<>(); + set.add("a"); + set.add("b"); + Set unmodifiableSet = Utils.unmodifiableSet(set); + assertThrows(UnsupportedOperationException.class, () -> unmodifiableSet.add("c")); + } + + @Test + void passingLinkedHashSet_returnUnmodifiable() { + Set list = new LinkedHashSet<>(); + list.add("a"); + list.add("b"); + list.add("d"); + list.add("c"); + Set l = Utils.unmodifiableSet(list); + assertEquals(list,l); assertThrows(UnsupportedOperationException.class, () -> l.add("c")); } } diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/CommonOrganism.java b/core-domain/src/main/java/org/uniprot/core/uniparc/CommonOrganism.java new file mode 100644 index 000000000..562fcea4e --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/CommonOrganism.java @@ -0,0 +1,8 @@ +package org.uniprot.core.uniparc; + +import java.io.Serializable; + +public interface CommonOrganism extends Serializable { + String getTopLevel(); + String getCommonTaxon(); +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/Proteome.java b/core-domain/src/main/java/org/uniprot/core/uniparc/Proteome.java new file mode 100644 index 000000000..c24714f99 --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/Proteome.java @@ -0,0 +1,10 @@ +package org.uniprot.core.uniparc; + +import java.io.Serializable; + +public interface Proteome extends Serializable { + + String getId(); + + String getComponent(); +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/UniParcEntryLight.java b/core-domain/src/main/java/org/uniprot/core/uniparc/UniParcEntryLight.java new file mode 100644 index 000000000..82131e1ef --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/UniParcEntryLight.java @@ -0,0 +1,39 @@ +package org.uniprot.core.uniparc; + +import org.uniprot.core.Sequence; +import org.uniprot.core.uniprotkb.taxonomy.Organism; + +import java.io.Serializable; +import java.time.LocalDate; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public interface UniParcEntryLight extends Serializable { + String getUniParcId(); + + int getCrossReferenceCount(); + + List getCommonTaxons(); + + Set getUniProtKBAccessions(); + + Sequence getSequence(); + + List getSequenceFeatures(); + + LocalDate getOldestCrossRefCreated(); + + LocalDate getMostRecentCrossRefUpdated(); + + Map getExtraAttributes(); + + // lazily loaded fields + Set getOrganisms();// organism id and name pair + + Set getProteinNames(); + + Set getGeneNames(); + + Set getProteomes(); +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/CommonOrganismBuilder.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/CommonOrganismBuilder.java new file mode 100644 index 000000000..31584a9ac --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/CommonOrganismBuilder.java @@ -0,0 +1,36 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.Builder; +import org.uniprot.core.uniparc.CommonOrganism; + +import javax.annotation.Nonnull; + +public class CommonOrganismBuilder implements Builder { + + private String topLevel; + private String commonTaxon; + + @Nonnull + @Override + public CommonOrganism build() { + return new CommonOrganismImpl(topLevel, commonTaxon); + } + + public CommonOrganismBuilder topLevel(String topLevel) { + this.topLevel = topLevel; + return this; + } + + + public CommonOrganismBuilder commonTaxon(String commonTaxon) { + this.commonTaxon = commonTaxon; + return this; + } + + public static @Nonnull CommonOrganismBuilder from(@Nonnull CommonOrganism instance) { + CommonOrganismBuilder builder = new CommonOrganismBuilder() + .topLevel(instance.getTopLevel()) + .commonTaxon(instance.getCommonTaxon()); + return builder; + } +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/CommonOrganismImpl.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/CommonOrganismImpl.java new file mode 100644 index 000000000..47ba1b2ef --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/CommonOrganismImpl.java @@ -0,0 +1,44 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.uniparc.CommonOrganism; + +import java.util.Objects; + +public class CommonOrganismImpl implements CommonOrganism { + + private static final long serialVersionUID = 4897886166938610296L; + + private String topLevel; + private String commonTaxon; + + CommonOrganismImpl(){ + } + + CommonOrganismImpl(String topLevel, String commonTaxon) { + this.topLevel = topLevel; + this.commonTaxon = commonTaxon; + } + + @Override + public String getTopLevel() { + return topLevel; + } + + @Override + public String getCommonTaxon() { + return commonTaxon; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CommonOrganismImpl that = (CommonOrganismImpl) o; + return Objects.equals(topLevel, that.topLevel) && Objects.equals(commonTaxon, that.commonTaxon); + } + + @Override + public int hashCode() { + return Objects.hash(topLevel, commonTaxon); + } +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/ProteomeBuilder.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/ProteomeBuilder.java new file mode 100644 index 000000000..8d8a6fc4f --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/ProteomeBuilder.java @@ -0,0 +1,36 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.Builder; +import org.uniprot.core.uniparc.Proteome; + +import javax.annotation.Nonnull; + +public class ProteomeBuilder implements Builder { + + private String id; + private String component; + + @Nonnull + @Override + public Proteome build() { + return new ProteomeImpl(id, component); + } + + public ProteomeBuilder id(String id) { + this.id = id; + return this; + } + + + public ProteomeBuilder component(String component) { + this.component = component; + return this; + } + + public static @Nonnull ProteomeBuilder from(@Nonnull Proteome instance) { + ProteomeBuilder builder = new ProteomeBuilder() + .id(instance.getId()) + .component(instance.getComponent()); + return builder; + } +} \ No newline at end of file diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/ProteomeImpl.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/ProteomeImpl.java new file mode 100644 index 000000000..40409704f --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/ProteomeImpl.java @@ -0,0 +1,44 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.uniparc.Proteome; + +import java.util.Objects; + +public class ProteomeImpl implements Proteome { + + private static final long serialVersionUID = -7947022870498125809L; + + private String id; + private String component; + + ProteomeImpl() { + } + + ProteomeImpl(String id, String component) { + this.id = id; + this.component = component; + } + + @Override + public String getId() { + return id; + } + + @Override + public String getComponent() { + return component; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ProteomeImpl proteome = (ProteomeImpl) o; + return Objects.equals(id, proteome.id) && Objects.equals(component, proteome.component); + } + + @Override + public int hashCode() { + return Objects.hash(id, component); + } +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcCrossReferencePair.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcCrossReferencePair.java new file mode 100644 index 000000000..d4e62ae7e --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcCrossReferencePair.java @@ -0,0 +1,44 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.uniparc.UniParcCrossReference; +import org.uniprot.core.util.Pair; + +import java.io.Serial; +import java.util.List; +import java.util.Objects; + +public class UniParcCrossReferencePair implements Pair>{ + @Serial + private static final long serialVersionUID = 7906365717659009263L; + private String key; + private List value; + + UniParcCrossReferencePair(){} + public UniParcCrossReferencePair(String key, List value) { + this.key = key; + this.value = value; + } + + @Override + public String getKey() { + return key; + } + + @Override + public List getValue() { + return value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UniParcCrossReferencePair that = (UniParcCrossReferencePair) o; + return Objects.equals(getKey(), that.getKey()) && Objects.equals(getValue(), that.getValue()); + } + + @Override + public int hashCode() { + return Objects.hash(getKey(), getValue()); + } +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilder.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilder.java new file mode 100644 index 000000000..cf6c11ffc --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilder.java @@ -0,0 +1,179 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.Builder; +import org.uniprot.core.Sequence; +import org.uniprot.core.uniparc.CommonOrganism; +import org.uniprot.core.uniparc.Proteome; +import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.UniParcEntryLight; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.util.Utils; + +import javax.annotation.Nonnull; +import java.time.LocalDate; +import java.util.*; + +import static org.uniprot.core.util.Utils.putOrIgnoreNull; + +public class UniParcEntryLightBuilder implements Builder { + public static final String HAS_ACTIVE_CROSS_REF = "hasActiveCrossRef"; + private String uniParcId; + private int crossReferenceCount; + private List commonTaxons = new ArrayList<>(); + private Set uniProtKBAccessions = new LinkedHashSet<>(); + + private Sequence sequence; + + private List sequenceFeatures = new ArrayList<>(); + + private LocalDate oldestCrossRefCreated; + + private LocalDate mostRecentCrossRefUpdated; + + private Set organisms = new LinkedHashSet<>(); + + private Set proteinNames = new LinkedHashSet<>(); + + private Set geneNames = new LinkedHashSet<>(); + + private Set proteomes = new LinkedHashSet<>(); + + private Map extraAttributes = new LinkedHashMap<>(); + + @Nonnull + @Override + public UniParcEntryLight build() { + return new UniParcEntryLightImpl(uniParcId, crossReferenceCount, commonTaxons, uniProtKBAccessions, + sequence, sequenceFeatures, oldestCrossRefCreated, + mostRecentCrossRefUpdated, organisms, proteinNames, + geneNames, proteomes, extraAttributes); + } + + public @Nonnull UniParcEntryLightBuilder uniParcId(String uniParcId) { + this.uniParcId = uniParcId; + return this; + } + + public @Nonnull UniParcEntryLightBuilder crossReferenceCount(int crossReferenceCount){ + this.crossReferenceCount = crossReferenceCount; + return this; + } + + public @Nonnull UniParcEntryLightBuilder commonTaxonsSet(List commonTaxons){ + this.commonTaxons = Utils.modifiableList(commonTaxons); + return this; + } + + public @Nonnull UniParcEntryLightBuilder commonTaxonsAdd(CommonOrganism commonTaxon){ + Utils.addOrIgnoreNull(commonTaxon, this.commonTaxons); + return this; + } + + public @Nonnull UniParcEntryLightBuilder uniProtKBAccessionsSet(LinkedHashSet uniProtKBAccessions){ + this.uniProtKBAccessions = Utils.modifiableLinkedHashSet(uniProtKBAccessions); + return this; + } + + public @Nonnull UniParcEntryLightBuilder uniProtKBAccessionsAdd(String uniProtKBAccession){ + Utils.addOrIgnoreNull(uniProtKBAccession, this.uniProtKBAccessions); + return this; + } + + public @Nonnull UniParcEntryLightBuilder sequence(Sequence sequence) { + this.sequence = sequence; + return this; + } + + public @Nonnull UniParcEntryLightBuilder sequenceFeaturesSet(List sequenceFeatures) { + this.sequenceFeatures = Utils.modifiableList(sequenceFeatures); + return this; + } + + public @Nonnull UniParcEntryLightBuilder sequenceFeaturesAdd(SequenceFeature sequenceFeature) { + Utils.addOrIgnoreNull(sequenceFeature, this.sequenceFeatures); + return this; + } + + public @Nonnull UniParcEntryLightBuilder oldestCrossRefCreated(LocalDate oldestCrossRefCreated) { + this.oldestCrossRefCreated = oldestCrossRefCreated; + return this; + } + + public @Nonnull UniParcEntryLightBuilder mostRecentCrossRefUpdated(LocalDate mostRecentCrossRefUpdated) { + this.mostRecentCrossRefUpdated = mostRecentCrossRefUpdated; + return this; + } + + public @Nonnull UniParcEntryLightBuilder organismsSet(LinkedHashSet organisms) { + this.organisms = Utils.modifiableLinkedHashSet(organisms); + return this; + } + + public @Nonnull UniParcEntryLightBuilder organismsAdd(Organism organism) { + Utils.addOrIgnoreNull(organism, this.organisms); + return this; + } + + public @Nonnull UniParcEntryLightBuilder proteinNamesSet(LinkedHashSet proteinNames) { + this.proteinNames = Utils.modifiableLinkedHashSet(proteinNames); + return this; + } + + public @Nonnull UniParcEntryLightBuilder proteinNamesAdd(String proteinName) { + Utils.addOrIgnoreNull(proteinName, this.proteinNames); + return this; + } + + public @Nonnull UniParcEntryLightBuilder geneNamesSet(LinkedHashSet geneNames) { + this.geneNames = Utils.modifiableLinkedHashSet(geneNames); + return this; + } + + public @Nonnull UniParcEntryLightBuilder geneNamesAdd(String geneName) { + Utils.addOrIgnoreNull(geneName, this.geneNames); + return this; + } + + public @Nonnull UniParcEntryLightBuilder proteomesSet(LinkedHashSet proteomes) { + this.proteomes = Utils.modifiableLinkedHashSet(proteomes); + return this; + } + + public @Nonnull UniParcEntryLightBuilder proteomesAdd(Proteome proteome) { + Utils.addOrIgnoreNull(proteome, this.proteomes); + return this; + } + + public @Nonnull UniParcEntryLightBuilder extraAttributesAdd(String name, Object value) { + putOrIgnoreNull(name, value, this.extraAttributes); + return this; + } + + public @Nonnull UniParcEntryLightBuilder extraAttributesSet(Map extraAttributes) { + this.extraAttributes = new LinkedHashMap<>(extraAttributes); + return this; + } + + public static @Nonnull UniParcEntryLightBuilder from(UniParcEntryLight uniParcEntryLight){ + LinkedHashSet uniProtKBAccessions = new LinkedHashSet<>(uniParcEntryLight.getUniProtKBAccessions()); + LinkedHashSet organisms = new LinkedHashSet<>(uniParcEntryLight.getOrganisms()); + LinkedHashSet proteinNames = new LinkedHashSet<>(uniParcEntryLight.getProteinNames()); + LinkedHashSet geneNames = new LinkedHashSet<>(uniParcEntryLight.getGeneNames()); + LinkedHashSet proteomes = new LinkedHashSet<>(uniParcEntryLight.getProteomes()); + UniParcEntryLightBuilder builder = new UniParcEntryLightBuilder(); + builder.uniParcId(uniParcEntryLight.getUniParcId()) + .crossReferenceCount(uniParcEntryLight.getCrossReferenceCount()) + .commonTaxonsSet(uniParcEntryLight.getCommonTaxons()) + .uniProtKBAccessionsSet(uniProtKBAccessions) + .sequence(uniParcEntryLight.getSequence()) + .sequenceFeaturesSet(uniParcEntryLight.getSequenceFeatures()) + .oldestCrossRefCreated(uniParcEntryLight.getOldestCrossRefCreated()) + .mostRecentCrossRefUpdated(uniParcEntryLight.getMostRecentCrossRefUpdated()) + .organismsSet(organisms) + .proteinNamesSet(proteinNames) + .geneNamesSet(geneNames) + .proteomesSet(proteomes) + .extraAttributesSet(uniParcEntryLight.getExtraAttributes()); + return builder; + } +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImpl.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImpl.java new file mode 100644 index 000000000..9e5a845f6 --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImpl.java @@ -0,0 +1,157 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.Sequence; +import org.uniprot.core.uniparc.CommonOrganism; +import org.uniprot.core.uniparc.Proteome; +import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.UniParcEntryLight; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.util.Utils; + +import java.time.LocalDate; +import java.util.*; + +public class UniParcEntryLightImpl implements UniParcEntryLight { + + private static final long serialVersionUID = 6932484977764108673L; + private final String uniParcId; + private final int crossReferenceCount; + private final List commonTaxons; + private final Set uniProtKBAccessions; + private final Sequence sequence; + private final List sequenceFeatures; + private final LocalDate oldestCrossRefCreated; + private final LocalDate mostRecentCrossRefUpdated; + + private final Set organisms; + private final Set proteinNames; + private final Set geneNames; + private final Set proteomes; + + private final Map extraAttributes; + + UniParcEntryLightImpl() { + this(null, 0, null, null, null, null, null, null); + } + + UniParcEntryLightImpl(String uniParcId, int crossReferenceCount, + List commonTaxons, LinkedHashSet uniProtKBAccessions, + Sequence sequence, List sequenceFeatures, + LocalDate oldestCrossRefCreated, LocalDate mostRecentCrossRefUpdated) { + this(uniParcId, crossReferenceCount, commonTaxons, uniProtKBAccessions, + sequence, sequenceFeatures, oldestCrossRefCreated, mostRecentCrossRefUpdated, + null, null, null, null, null); + } + UniParcEntryLightImpl(String uniParcId, int crossReferenceCount, + List commonTaxons, Set uniProtKBAccessions, + Sequence sequence, List sequenceFeatures, + LocalDate oldestCrossRefCreated, LocalDate mostRecentCrossRefUpdated, + Set organisms, Set proteinNames, Set geneNames, + Set proteomes, Map extraAttributes) { + this.uniParcId = uniParcId; + this.crossReferenceCount = crossReferenceCount; + this.commonTaxons = Utils.unmodifiableList(commonTaxons); + this.uniProtKBAccessions = Utils.unmodifiableSet(uniProtKBAccessions); + this.sequence = sequence; + this.sequenceFeatures = Utils.unmodifiableList(sequenceFeatures); + this.oldestCrossRefCreated = oldestCrossRefCreated; + this.mostRecentCrossRefUpdated = mostRecentCrossRefUpdated; + this.organisms = Utils.unmodifiableSet(organisms); + this.proteinNames = Utils.unmodifiableSet(proteinNames); + this.geneNames = Utils.unmodifiableSet(geneNames); + this.proteomes = Utils.unmodifiableSet(proteomes); + this.extraAttributes = Objects.isNull(extraAttributes) ? Map.of() : extraAttributes; + } + + @Override + public String getUniParcId() { + return uniParcId; + } + + @Override + public int getCrossReferenceCount() { + return crossReferenceCount; + } + + @Override + public List getCommonTaxons() { + return commonTaxons; + } + + @Override + public Set getUniProtKBAccessions() { + return uniProtKBAccessions; + } + + @Override + public Sequence getSequence() { + return sequence; + } + + @Override + public List getSequenceFeatures() { + return sequenceFeatures; + } + + @Override + public LocalDate getOldestCrossRefCreated() { + return oldestCrossRefCreated; + } + + @Override + public LocalDate getMostRecentCrossRefUpdated() { + return mostRecentCrossRefUpdated; + } + + @Override + public Set getOrganisms() { + return organisms; + } + + @Override + public Set getProteinNames() { + return proteinNames; + } + + @Override + public Set getGeneNames() { + return geneNames; + } + + @Override + public Set getProteomes() { + return proteomes; + } + + @Override + public Map getExtraAttributes() { + return this.extraAttributes; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UniParcEntryLightImpl that = (UniParcEntryLightImpl) o; + return Objects.equals(getUniParcId(), that.getUniParcId()) && Objects.equals(getCrossReferenceCount(), + that.getCrossReferenceCount()) && Objects.equals(getCommonTaxons(), that.getCommonTaxons()) && + Objects.equals(getUniProtKBAccessions(), that.getUniProtKBAccessions()) && + Objects.equals(getSequence(), that.getSequence()) && + Objects.equals(getSequenceFeatures(), that.getSequenceFeatures()) && + Objects.equals(getOldestCrossRefCreated(), that.getOldestCrossRefCreated()) && + Objects.equals(getMostRecentCrossRefUpdated(), that.getMostRecentCrossRefUpdated()) && + Objects.equals(getOrganisms(), that.getOrganisms()) && + Objects.equals(getProteinNames(), that.getProteinNames()) && + Objects.equals(getGeneNames(), that.getGeneNames()) && + Objects.equals(getProteomes(), that.getProteomes()) && + Objects.equals(getExtraAttributes(), that.getExtraAttributes()); + } + + @Override + public int hashCode() { + return Objects.hash(getUniParcId(), getCrossReferenceCount(), getCommonTaxons(), getUniProtKBAccessions(), + getSequence(), getSequenceFeatures(), getOldestCrossRefCreated(), + getMostRecentCrossRefUpdated(), getOrganisms(), getProteinNames(), getGeneNames(), getProteomes(), + getExtraAttributes()); + } +} diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/CommonOrganismBuilderTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/CommonOrganismBuilderTest.java new file mode 100644 index 000000000..7fbdcb71a --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/CommonOrganismBuilderTest.java @@ -0,0 +1,30 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.uniparc.CommonOrganism; + +import static org.junit.jupiter.api.Assertions.*; + +class CommonOrganismBuilderTest { + @Test + void testTopLevel() { + CommonOrganism common = new CommonOrganismBuilder().topLevel("toLevel1").build(); + assertEquals("toLevel1", common.getTopLevel()); + } + + @Test + void testCommonTaxon() { + CommonOrganism common = new CommonOrganismBuilder().commonTaxon("commonTaxon1").build(); + assertEquals("commonTaxon1", common.getCommonTaxon()); + } + + @Test + void testFrom() { + CommonOrganism common = new CommonOrganismBuilder().topLevel("toLevel1").commonTaxon("common1").build(); + CommonOrganism common1 = CommonOrganismBuilder.from(common).build(); + assertEquals(common, common1); + CommonOrganism common3 = CommonOrganismBuilder.from(common).commonTaxon("common3").build(); + assertEquals("toLevel1", common3.getTopLevel()); + assertEquals("common3", common3.getCommonTaxon()); + } +} \ No newline at end of file diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/CommonOrganismImplTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/CommonOrganismImplTest.java new file mode 100644 index 000000000..f9f002a0d --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/CommonOrganismImplTest.java @@ -0,0 +1,24 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.uniparc.CommonOrganism; +import org.uniprot.core.uniparc.InterProGroup; + +import static org.junit.jupiter.api.Assertions.*; + +class CommonOrganismImplTest { + + @Test + void needDefaultConstructorForJsonDeserialization() { + CommonOrganism obj = new CommonOrganismImpl(); + assertNotNull(obj); + } + + @Test + void builderFrom_constructorImp_shouldCreate_equalObject() { + CommonOrganism impl = new CommonOrganismImpl("id", "name"); + CommonOrganism obj = CommonOrganismBuilder.from(impl).build(); + assertTrue(impl.equals(obj) && obj.equals(impl)); + assertEquals(impl.hashCode(), obj.hashCode()); + } +} \ No newline at end of file diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/ProteomeBuilderTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/ProteomeBuilderTest.java new file mode 100644 index 000000000..8571ed91d --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/ProteomeBuilderTest.java @@ -0,0 +1,30 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.uniparc.Proteome; + +import static org.junit.jupiter.api.Assertions.*; + +class ProteomeBuilderTest { + @Test + void testId() { + Proteome domain = new ProteomeBuilder().id("someId").build(); + assertEquals("someId", domain.getId()); + } + + @Test + void testComponent() { + Proteome domain = new ProteomeBuilder().component("some name").build(); + assertEquals("some name", domain.getComponent()); + } + + @Test + void testFrom() { + Proteome proteome1 = new ProteomeBuilder().id("some id").component("some name").build(); + Proteome proteome2 = ProteomeBuilder.from(proteome1).build(); + assertEquals(proteome1, proteome2); + Proteome proteome3 = ProteomeBuilder.from(proteome1).component("component2").build(); + assertEquals("some id", proteome3.getId()); + assertEquals("component2", proteome3.getComponent()); + } +} \ No newline at end of file diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/ProteomeImplTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/ProteomeImplTest.java new file mode 100644 index 000000000..35f48c684 --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/ProteomeImplTest.java @@ -0,0 +1,23 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.uniparc.Proteome; + +import static org.junit.jupiter.api.Assertions.*; + +class ProteomeImplTest { + + @Test + void needDefaultConstructorForJsonDeserialization() { + Proteome obj = new ProteomeImpl(); + assertNotNull(obj); + } + + @Test + void builderFrom_constructorImp_shouldCreate_equalObject() { + Proteome impl = new ProteomeImpl("id", "component"); + Proteome obj = ProteomeBuilder.from(impl).build(); + assertTrue(impl.equals(obj) && obj.equals(impl)); + assertEquals(impl.hashCode(), obj.hashCode()); + } +} \ No newline at end of file diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcCrossReferencePairTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcCrossReferencePairTest.java new file mode 100644 index 000000000..4441dc4b9 --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcCrossReferencePairTest.java @@ -0,0 +1,54 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.uniprot.core.uniparc.UniParcCrossReference; +import org.uniprot.core.uniparc.UniParcDatabase; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; + +import java.time.LocalDate; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UniParcCrossReferencePairTest { + + @Test + void testCreatePair(){ + String key = "sample"; + List values = List.of(new UniParcCrossReferenceBuilder().build()); + UniParcCrossReferencePair pair = new UniParcCrossReferencePair(key, values); + Assertions.assertNotNull(pair); + Assertions.assertEquals("sample", pair.getKey()); + Assertions.assertEquals(values, pair.getValue()); + } + + @Test + void testEqualsAndHashCode(){ + UniParcCrossReference xref1 = + new UniParcCrossReferenceImpl( + UniParcDatabase.SWISSPROT, + "id", + Collections.emptyList(), + 2, + -3, + true, + LocalDate.now(), + LocalDate.now(), + "geneName", + "proteinName", + new OrganismBuilder().taxonId(10L).scientificName("sName").build(), + "chain", + "ncbiGi", + "proteomeId", + "component"); + String key = "Sample"; + UniParcCrossReferencePair pair1 = new UniParcCrossReferencePair(key, List.of(xref1)); + UniParcCrossReferencePair pair2 = new UniParcCrossReferencePair(key, List.of(xref1)); + assertTrue(pair1.equals(pair2) && pair2.equals(pair1)); + assertEquals(pair1.hashCode(), pair2.hashCode()); + } + +} diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilderTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilderTest.java new file mode 100644 index 000000000..d24c04bd2 --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightBuilderTest.java @@ -0,0 +1,383 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.uniprot.core.Sequence; +import org.uniprot.core.impl.SequenceBuilder; +import org.uniprot.core.uniparc.CommonOrganism; +import org.uniprot.core.uniparc.Proteome; +import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.UniParcEntryLight; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; + +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; + + +class UniParcEntryLightBuilderTest { + + @Test + void testUniParcIdString() { + UniParcEntryLight entry = + new UniParcEntryLightBuilder() + .uniParcId("UPI0000083A08") + .build(); + assertEquals("UPI0000083A08", entry.getUniParcId()); + assertNull(entry.getOldestCrossRefCreated()); + assertNull(entry.getMostRecentCrossRefUpdated()); + } + + @Test + void testCrossReferenceCount() { + int crossReferenceCount = 20; + UniParcEntryLight entry = new UniParcEntryLightBuilder().crossReferenceCount(crossReferenceCount).build(); + assertEquals(crossReferenceCount, entry.getCrossReferenceCount()); + } + + @Test + void testCommonTaxonsSet() { + List commonTaxons = List.of( + new CommonOrganismBuilder().topLevel("Viruses").commonTaxon("HIV").build(), + new CommonOrganismBuilder().topLevel("unclassified").commonTaxon("Mus musculus").build() + ); + UniParcEntryLight entry = new UniParcEntryLightBuilder().commonTaxonsSet(commonTaxons).build(); + assertEquals(commonTaxons, entry.getCommonTaxons()); + } + + @Test + void testCommonTaxonsAdd() { + CommonOrganism commonTaxon = new CommonOrganismBuilder().topLevel("Viruses").commonTaxon("Homo sapiens").build(); + UniParcEntryLight entry = new UniParcEntryLightBuilder().commonTaxonsAdd(commonTaxon).build(); + assertTrue(entry.getCommonTaxons().contains(commonTaxon)); + } + + @Test + void testCommonTaxonsAddNull() { + UniParcEntryLight entry = new UniParcEntryLightBuilder().commonTaxonsAdd(null).build(); + assertTrue(entry.getCommonTaxons().isEmpty()); + } + + @Test + void testCommonTaxonsSetThenAdd() { + List commonTaxons = List.of( + new CommonOrganismBuilder().topLevel("Viruses").commonTaxon("HIV").build()); + CommonOrganism additionalCommonTaxon = new CommonOrganismBuilder() + .topLevel("Other type") + .commonTaxon("Mus musculus") + .build(); + UniParcEntryLight entry = new UniParcEntryLightBuilder() + .commonTaxonsSet(commonTaxons) + .commonTaxonsAdd(additionalCommonTaxon) + .build(); + assertEquals(2, entry.getCommonTaxons().size()); + assertTrue(entry.getCommonTaxons().containsAll(List.of( + new CommonOrganismBuilder().topLevel("Viruses").commonTaxon("HIV").build(), + new CommonOrganismBuilder().topLevel("Other type").commonTaxon("Mus musculus").build() + ))); + } + + @Test + void testUniProtKBAccessionsSet() { + LinkedHashSet accessions = new LinkedHashSet<>(List.of("P12345", "Q67890")); + UniParcEntryLight entry = new UniParcEntryLightBuilder().uniProtKBAccessionsSet(accessions).build(); + assertEquals(accessions, entry.getUniProtKBAccessions()); + } + + @Test + void testUniProtKBAccessionsAdd() { + String accession = "P12345"; + UniParcEntryLight entry = new UniParcEntryLightBuilder().uniProtKBAccessionsAdd(accession).build(); + assertTrue(entry.getUniProtKBAccessions().contains(accession)); + } + + @Test + void testUniProtKBAccessionsAddNull() { + UniParcEntryLight entry = new UniParcEntryLightBuilder().uniProtKBAccessionsAdd(null).build(); + assertTrue(entry.getUniProtKBAccessions().isEmpty()); + } + + @Test + void testUniProtKBAccessionsSetThenAdd() { + LinkedHashSet accessions = new LinkedHashSet<>(List.of("P12345")); + String additionalAccession = "Q67890"; + UniParcEntryLight entry = new UniParcEntryLightBuilder() + .uniProtKBAccessionsSet(accessions) + .uniProtKBAccessionsAdd(additionalAccession) + .build(); + assertEquals(2, entry.getUniProtKBAccessions().size()); + assertTrue(entry.getUniProtKBAccessions().containsAll(List.of("P12345", "Q67890"))); + } + + @Test + void testSequence() { + String seq = "MVSWGRFICLVVVTMATLSLARPSFSLVED"; + Sequence sequence = new SequenceBuilder(seq).build(); + UniParcEntryLight entry = new UniParcEntryLightBuilder().sequence(sequence).build(); + assertEquals(sequence, entry.getSequence()); + } + + @Test + void testSequenceFeaturesSet() { + List sequenceFeatures = sequenceFeatures(); + UniParcEntryLight entry = new UniParcEntryLightBuilder().sequenceFeaturesSet(sequenceFeatures).build(); + assertEquals(sequenceFeatures, entry.getSequenceFeatures()); + } + + @Test + void testSequenceFeaturesAdd() { + SequenceFeature sequenceFeature = sequenceFeatures().get(0); + UniParcEntryLight entry = new UniParcEntryLightBuilder().sequenceFeaturesAdd(sequenceFeature).build(); + assertTrue(entry.getSequenceFeatures().contains(sequenceFeature)); + } + + @Test + void testSequenceFeaturesAddNull() { + UniParcEntryLight entry = new UniParcEntryLightBuilder().sequenceFeaturesAdd(null).build(); + assertTrue(entry.getSequenceFeatures().isEmpty()); + } + + @Test + void testSequenceFeaturesSetThenAdd() { + List sequenceFeatures = sequenceFeatures(); + SequenceFeature feature2 = sequenceFeatures().get(0); + UniParcEntryLight entry = new UniParcEntryLightBuilder() + .sequenceFeaturesSet(sequenceFeatures) + .sequenceFeaturesAdd(feature2) + .build(); + assertEquals(sequenceFeatures.size() + 1, entry.getSequenceFeatures().size()); + } + + @Test + void testOldestCrossRefCreated() { + LocalDate date = LocalDate.of(2022, 1, 1); + UniParcEntryLight entry = new UniParcEntryLightBuilder().oldestCrossRefCreated(date).build(); + assertEquals(date, entry.getOldestCrossRefCreated()); + } + + @Test + void testMostRecentCrossRefUpdated() { + LocalDate date = LocalDate.of(2023, 1, 1); + UniParcEntryLight entry = new UniParcEntryLightBuilder().mostRecentCrossRefUpdated(date).build(); + assertEquals(date, entry.getMostRecentCrossRefUpdated()); + } + + @Test + void testOrganismsSet() { + Organism organism1 = new OrganismBuilder().taxonId(9606).scientificName("Homo sapiens").build(); + Organism organism2 = new OrganismBuilder().taxonId(10090).scientificName("Mus musculus").build(); + LinkedHashSet organisms = new LinkedHashSet<>(List.of(organism1, organism2)); + UniParcEntryLight entry = new UniParcEntryLightBuilder().organismsSet(organisms).build(); + assertEquals(organisms, entry.getOrganisms()); + } + + @Test + void testOrganismsAdd() { + Organism organism = new OrganismBuilder().taxonId(9606).scientificName("Homo sapiens").build(); + UniParcEntryLight entry = new UniParcEntryLightBuilder().organismsAdd(organism).build(); + assertTrue(entry.getOrganisms().contains(organism)); + } + + @Test + void testProteinNamesSet() { + LinkedHashSet proteinNames = new LinkedHashSet<>(List.of("Protein1", "Protein2")); + UniParcEntryLight entry = new UniParcEntryLightBuilder().proteinNamesSet(proteinNames).build(); + assertEquals(proteinNames, entry.getProteinNames()); + } + + @Test + void testProteinNamesAdd() { + String proteinName = "Protein1"; + UniParcEntryLight entry = new UniParcEntryLightBuilder().proteinNamesAdd(proteinName).build(); + assertTrue(entry.getProteinNames().contains(proteinName)); + } + + @Test + void testGeneNamesSet() { + LinkedHashSet geneNames = new LinkedHashSet<>(List.of("Gene1", "Gene2")); + UniParcEntryLight entry = new UniParcEntryLightBuilder().geneNamesSet(geneNames).build(); + assertEquals(geneNames, entry.getGeneNames()); + } + + @Test + void testGeneNamesAdd() { + String geneName = "Gene1"; + UniParcEntryLight entry = new UniParcEntryLightBuilder().geneNamesAdd(geneName).build(); + assertTrue(entry.getGeneNames().contains(geneName)); + } + + @Test + void testProteomesSet() { + LinkedHashSet proteomes = new LinkedHashSet<>(List.of(new ProteomeBuilder().id("UP000005640").component("C1").build(), new ProteomeBuilder().id("UP000002494").component("C2").build())); + UniParcEntryLight entry = new UniParcEntryLightBuilder().proteomesSet(proteomes).build(); + assertEquals(proteomes, entry.getProteomes()); + } + + @Test + void testProteomeAdd() { + Proteome proteome = new ProteomeBuilder().id("UP000005640").component("C1").build(); + UniParcEntryLight entry = new UniParcEntryLightBuilder().proteomesAdd(proteome).build(); + assertTrue(entry.getProteomes().contains(proteome)); + } + + @Test + void testProteomesSetThenAdd() { + Proteome proteome1 = new ProteomeBuilder().id("UP000005640").component("chromosome").build(); + LinkedHashSet 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(); + Organism organism2 = new OrganismBuilder().taxonId(10090).scientificName("Mus musculus").build(); + LinkedHashSet organisms = new LinkedHashSet<>(List.of(organism1)); + UniParcEntryLight entry = new UniParcEntryLightBuilder() + .organismsSet(organisms) + .organismsAdd(organism2) + .build(); + assertEquals(2, entry.getOrganisms().size()); + assertTrue(entry.getOrganisms().containsAll(List.of(organism1, organism2))); + } + + @Test + void testProteinNamesSetThenAdd() { + LinkedHashSet proteinNames = new LinkedHashSet<>(List.of("Protein1")); + String proteinName = "Protein2"; + UniParcEntryLight entry = new UniParcEntryLightBuilder() + .proteinNamesSet(proteinNames) + .proteinNamesAdd(proteinName) + .build(); + assertEquals(2, entry.getProteinNames().size()); + assertTrue(entry.getProteinNames().containsAll(List.of("Protein1", "Protein2"))); + } + + @Test + void testGeneNamesSetThenAdd() { + LinkedHashSet geneNames = new LinkedHashSet<>(List.of("Gene1")); + String geneName = "Gene2"; + UniParcEntryLight entry = new UniParcEntryLightBuilder() + .geneNamesSet(geneNames) + .geneNamesAdd(geneName) + .build(); + assertEquals(2, entry.getGeneNames().size()); + assertTrue(entry.getGeneNames().containsAll(List.of("Gene1", "Gene2"))); + } + + + @Test + void testFrom() { + String uniParcId = "UPI0000000001"; + int crossReferenceCount = 18; + List commonTaxons = List.of( + new CommonOrganismBuilder().topLevel("Viruses").commonTaxon("HIV").build(), + new CommonOrganismBuilder().topLevel("unclassified").commonTaxon("Mus musculus").build()); + String seq = "MVSWGRFICLVVVTMATLSLARPSFSLVED"; + Sequence sequence = new SequenceBuilder(seq).build(); + List sequenceFeatures = sequenceFeatures(); + LocalDate oldestCrossRefCreated = LocalDate.of(2022, 1, 1); + LocalDate mostRecentCrossRefUpdated = LocalDate.of(2023, 1, 1); + + Organism organism1 = new OrganismBuilder().taxonId(9606).scientificName("Homo sapiens").build(); + Organism organism2 = new OrganismBuilder().taxonId(10090).scientificName("Mus musculus").build(); + LinkedHashSet organisms = new LinkedHashSet<>(List.of(organism1, organism2)); + + LinkedHashSet proteinNames = new LinkedHashSet(List.of("Protein1", "Protein2")); + LinkedHashSet geneNames = new LinkedHashSet(List.of("Gene1", "Gene2")); + LinkedHashSet proteomes = new LinkedHashSet<>(List.of(new ProteomeBuilder().id("UP000005640").component("C1").build(), new ProteomeBuilder().id("UP000002494").component("C2").build())); + + UniParcEntryLight originalEntry = new UniParcEntryLightBuilder() + .uniParcId(uniParcId) + .crossReferenceCount(crossReferenceCount) + .commonTaxonsSet(commonTaxons) + .sequence(sequence) + .sequenceFeaturesSet(sequenceFeatures) + .oldestCrossRefCreated(oldestCrossRefCreated) + .mostRecentCrossRefUpdated(mostRecentCrossRefUpdated) + .organismsSet(organisms) + .proteinNamesSet(proteinNames) + .geneNamesSet(geneNames) + .proteomesSet(proteomes) + .build(); + + UniParcEntryLight newEntry = UniParcEntryLightBuilder.from(originalEntry).build(); + + verifyOriginalAndNewEntry(originalEntry, newEntry); + } + + @Test + void testFromWithEmptyAccessions(){ + UniParcEntryLight entry = + new UniParcEntryLightBuilder() + .uniParcId("UPI0000083A08") + .uniProtKBAccessionsSet(null) + .build(); + Assertions.assertDoesNotThrow(() -> UniParcEntryLightBuilder.from(entry)); + UniParcEntryLightBuilder builder = UniParcEntryLightBuilder.from(entry); + builder.uniProtKBAccessionsAdd(null); + Assertions.assertDoesNotThrow(() -> UniParcEntryLightBuilder.from(builder.build())); + } + + @Test + void testExtraAttributes(){ + UniParcEntryLight entry = new UniParcEntryLightBuilder().uniParcId("UPI0000083A08") + .extraAttributesAdd("hasActiveCrossRef", true).build(); + assertEquals("UPI0000083A08", entry.getUniParcId()); + assertEquals(1, entry.getExtraAttributes().size()); + assertEquals(true, entry.getExtraAttributes().get("hasActiveCrossRef")); + } + @Test + void testAddExtraAttributes(){ + UniParcEntryLight entry = new UniParcEntryLightBuilder().uniParcId("UPI0000083A08").build(); + assertEquals("UPI0000083A08", entry.getUniParcId()); + assertTrue(entry.getExtraAttributes().isEmpty()); + // add extra attribute + UniParcEntryLight updatedEntry = UniParcEntryLightBuilder.from(entry) + .extraAttributesAdd("hasActiveCrossRef", false).build(); + assertEquals("UPI0000083A08", updatedEntry.getUniParcId()); + assertEquals(1, updatedEntry.getExtraAttributes().size()); + 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); + } + +} diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImplTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImplTest.java new file mode 100644 index 000000000..e6107d3e0 --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/UniParcEntryLightImplTest.java @@ -0,0 +1,67 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.uniprot.core.Sequence; +import org.uniprot.core.impl.SequenceBuilder; +import org.uniprot.core.uniparc.CommonOrganism; +import org.uniprot.core.uniparc.Proteome; +import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.UniParcEntryLight; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; + +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; + +class UniParcEntryLightImplTest { + @Test + void needDefaultConstructorForJsonDeserialization() { + UniParcEntryLight lightObject = new UniParcEntryLightImpl(); + assertNotNull(lightObject); + } + + @Test + void builderFrom_constructorImp_shouldCreate_equalObject() { + String uniParcId = "UPI0000000001"; + int crossReferenceCount = 30; + List commonTaxons = List.of( + new CommonOrganismBuilder().topLevel("Viruses").commonTaxon("HIV").build(), + new CommonOrganismBuilder().topLevel("unclassified").commonTaxon("Mus musculus").build()); + String seq = "MVSWGRFICLVVVTMATLSLARPSFSLVED"; + Sequence sequence = new SequenceBuilder(seq).build(); + List sequenceFeatures = sequenceFeatures(); + LocalDate oldestCrossRefCreated = LocalDate.of(2022, 1, 1); + LocalDate mostRecentCrossRefUpdated = LocalDate.of(2023, 1, 1); + + Organism organism1 = new OrganismBuilder().taxonId(9606).scientificName("Homo sapiens").build(); + Organism organism2 = new OrganismBuilder().taxonId(10090).scientificName("Mus musculus").build(); + LinkedHashSet organisms = new LinkedHashSet<>(List.of(organism1, organism2)); + + LinkedHashSet proteinNames = new LinkedHashSet<>(List.of("Protein1", "Protein2")); + LinkedHashSet geneNames = new LinkedHashSet<>(List.of("Gene1", "Gene2")); + LinkedHashSet proteomes = new LinkedHashSet<>(List.of(new ProteomeBuilder().id("UP000005640").component("C1").build(), new ProteomeBuilder().id("UP000002494").component("C2").build())); + LinkedHashSet uniProtKBAccessions = new LinkedHashSet<>(List.of("P21802", "P12345")); + Map extraAttributes = Map.of("hasActiveCrossRef", true); + + UniParcEntryLight impl = new UniParcEntryLightImpl(uniParcId, crossReferenceCount, commonTaxons, uniProtKBAccessions, + sequence, sequenceFeatures, oldestCrossRefCreated, mostRecentCrossRefUpdated, organisms, + proteinNames, geneNames, proteomes, extraAttributes); + + UniParcEntryLight obj = UniParcEntryLightBuilder.from(impl).build(); + assertTrue(impl.equals(obj) && obj.equals(impl)); + assertEquals(impl.hashCode(), obj.hashCode()); + } + + @Test + void defaultConstructorAndBuilderFrom() { + UniParcEntryLight lightObject = new UniParcEntryLightImpl(); + assertNotNull(lightObject); + Assertions.assertDoesNotThrow(() -> UniParcEntryLightBuilder.from(lightObject)); + } +} diff --git a/core-parser/src/main/java/org/uniprot/core/parser/fasta/UniParcFastaParser.java b/core-parser/src/main/java/org/uniprot/core/parser/fasta/UniParcFastaParser.java index 5e7a860b5..898752dda 100644 --- a/core-parser/src/main/java/org/uniprot/core/parser/fasta/UniParcFastaParser.java +++ b/core-parser/src/main/java/org/uniprot/core/parser/fasta/UniParcFastaParser.java @@ -1,26 +1,46 @@ package org.uniprot.core.parser.fasta; +import org.uniprot.core.Sequence; +import org.uniprot.core.uniparc.UniParcCrossReference; import org.uniprot.core.uniparc.UniParcEntry; +import org.uniprot.core.uniparc.UniParcEntryLight; + +import static org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder.HAS_ACTIVE_CROSS_REF; /** * @author jluo * @date: 24 Jun 2019 */ public class UniParcFastaParser { + private UniParcFastaParser(){} + public static String toFasta(UniParcEntry entry) { - StringBuilder sb = new StringBuilder(); String status = "active"; - boolean isActive = - entry.getUniParcCrossReferences().stream().anyMatch(val -> val.isActive()); + boolean isActive = entry.getUniParcCrossReferences() + .stream() + .anyMatch(UniParcCrossReference::isActive); if (!isActive) { status = "inactive"; } - sb.append(">").append(entry.getUniParcId().getValue()).append(" "); + return getFastaString(entry.getUniParcId().getValue(), status, entry.getSequence()); + } + + public static String toFasta(UniParcEntryLight entry) { + String status = "active"; + if(entry.getExtraAttributes().containsKey(HAS_ACTIVE_CROSS_REF) && + entry.getExtraAttributes().get(HAS_ACTIVE_CROSS_REF).equals(false)){ + status = "inactive"; + } + return getFastaString(entry.getUniParcId(), status, entry.getSequence()); + } + + private static String getFastaString(String entry, String status, Sequence sequence) { + StringBuilder sb = new StringBuilder(); + sb.append(">").append(entry).append(" "); sb.append("status=").append(status); sb.append("\n"); int columnCounter = 0; - String sequence = entry.getSequence().getValue(); - for (char c : sequence.toCharArray()) { + for (char c : sequence.getValue().toCharArray()) { if (columnCounter % 60 == 0 && columnCounter > 0) { sb.append("\n"); } diff --git a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java index e4bd60e86..dfb0f271f 100644 --- a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java +++ b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMap.java @@ -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 @@ -36,8 +28,6 @@ public class UniParcCrossReferenceMap implements NamedValueMap { "protein", "proteome", "accession", - "first_seen", - "last_seen", "database", "active", "ncbiGi", @@ -57,22 +47,17 @@ public UniParcCrossReferenceMap(List uniParcCrossReferenc @Override public Map attributeValues() { Map map = new HashMap<>(); - Optional firstSeen = getFirstSeenDate(); - Optional 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; } 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 new file mode 100644 index 000000000..c149912a9 --- /dev/null +++ b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapper.java @@ -0,0 +1,115 @@ +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; + +import java.time.LocalDate; +import java.util.*; +import java.util.stream.Collectors; + +public class UniParcEntryLightValueMapper implements EntityValueMapper { + + private static final List UNIPARC_FIELDS = + List.of("upi", + "organism", + "organism_id", + "gene", + "protein", + "proteome", + "accession", + "first_seen", + "last_seen", + "common_taxons"); + private static final String DELIMITER2 = "; "; + + @Override + public Map mapEntity(UniParcEntryLight entry, List fields) { + Map map = new HashMap<>(); + if(contains(fields)){ + map.putAll(getSimpleAttributeValues(entry, fields)); + } + if (UniParcSequenceFeatureMap.contains(fields)) { + UniParcSequenceFeatureMap featureMapper = new UniParcSequenceFeatureMap(entry.getSequenceFeatures()); + map.putAll(featureMapper.attributeValues()); + } + if (UniParcSequenceMap.contains(fields)) { + UniParcSequenceMap sequenceMapper = new UniParcSequenceMap(entry.getSequence()); + map.putAll(sequenceMapper.attributeValues()); + } + return map; + } + + + + private static boolean contains(List fields) { + return fields.stream().anyMatch(UNIPARC_FIELDS::contains); + } + + private Map getSimpleAttributeValues(UniParcEntryLight entry, List fields) { + Map map = new HashMap<>(); + for (String field : fields) { + switch (field) { + case "upi": + map.put(UNIPARC_FIELDS.get(0), entry.getUniParcId()); + break; + case "organism": + map.put( + UNIPARC_FIELDS.get(1), + entry.getOrganisms().stream() + .map(Organism::getScientificName) + .collect(Collectors.joining(DELIMITER2))); + break; + case "organism_id": + map.put( + UNIPARC_FIELDS.get(2), + entry.getOrganisms().stream() + .map(Organism::getTaxonId) + .map(String::valueOf) + .collect(Collectors.joining(DELIMITER2))); + break; + case "gene": + map.put(UNIPARC_FIELDS.get(3),String.join(DELIMITER2, entry.getGeneNames())); + break; + case "protein": + map.put(UNIPARC_FIELDS.get(4),String.join(DELIMITER2, entry.getProteinNames())); + break; + case "proteome": + map.put(UNIPARC_FIELDS.get(5),entry.getProteomes().stream().map(e -> e.getId()+":"+e.getComponent()).collect(Collectors.joining(DELIMITER2))); + break; + case "accession": + map.put(UNIPARC_FIELDS.get(6),String.join(DELIMITER2, entry.getUniProtKBAccessions())); + break; + case "first_seen": + map.put( + UNIPARC_FIELDS.get(7), + Optional.of(entry.getOldestCrossRefCreated()) + .map(LocalDate::toString) + .orElse("")); + break; + case "last_seen": + map.put( + UNIPARC_FIELDS.get(8), + Optional.of(entry.getMostRecentCrossRefUpdated()) + .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/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java index e5313709e..ef86b4755 100644 --- a/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java +++ b/core-parser/src/main/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapper.java @@ -17,7 +17,7 @@ public class UniParcEntryValueMapper implements EntityValueMapper { private static final List UNIPARC_FIELDS = - List.of("upi", "oldestCrossRefCreated", "mostRecentCrossRefUpdated"); + List.of("upi", "first_seen", "last_seen"); @Override public Map mapEntity(UniParcEntry entry, List fields) { @@ -60,14 +60,14 @@ private Map getSimpleAttributeValues(UniParcEntry entry, ListUPI0000083A08 status=active + MSMAMARALATLGRLRYRVSGQLPLLDETAIEVMAGGQFLDGRKAREELGFFSTTALDDT + LLRAIDWFRDNGYFNA"""; + public static final String EXPECTED_FASTA_RESULT_INACTIVE = """ + >UPI0000083A08 status=inactive + MSMAMARALATLGRLRYRVSGQLPLLDETAIEVMAGGQFLDGRKAREELGFFSTTALDDT + LLRAIDWFRDNGYFNA"""; @Test - void testToFasta() { + void testUniParcEntryToFasta() { UniParcEntry entry = create(); String fasta = UniParcFastaParser.toFasta(entry); - System.out.println(fasta); - String expected = - ">UPI0000083A08 status=active\n" - + "MSMAMARALATLGRLRYRVSGQLPLLDETAIEVMAGGQFLDGRKAREELGFFSTTALDDT\n" - + "LLRAIDWFRDNGYFNA"; - assertEquals(expected, fasta); + assertEquals(EXPECTED_FASTA_RESULT, fasta); + } + + @Test + void testUniParcEntryLightToFasta() { + UniParcEntryLight entry = createEntryLight(); + String fasta = UniParcFastaParser.toFasta(entry); + assertEquals(EXPECTED_FASTA_RESULT, fasta); + } + + @Test + void testUniParcEntryLightToFastaInactive() { + UniParcEntryLight entry = createEntryLight(); + entry = UniParcEntryLightBuilder.from(entry).extraAttributesAdd(HAS_ACTIVE_CROSS_REF, false).build(); + String fasta = UniParcFastaParser.toFasta(entry); + assertEquals(EXPECTED_FASTA_RESULT_INACTIVE, fasta); } private UniParcEntry create() { - String seq = - "MSMAMARALATLGRLRYRVSGQLPLLDETAIEVMAGGQFLDGRKAREELGFFSTTALDDT" + "LLRAIDWFRDNGYFNA"; - Sequence sequence = new SequenceBuilder(seq).build(); + Sequence sequence = getSequence(); List xrefs = getXrefs(); List seqFeatures = getSeqFeatures(); UniParcEntry entry = @@ -51,6 +67,20 @@ private UniParcEntry create() { return entry; } + private UniParcEntryLight createEntryLight() { + return new UniParcEntryLightBuilder() + .uniParcId("UPI0000083A08") + .sequence(getSequence()) + .build(); + } + + private static Sequence getSequence() { + String seq = + "MSMAMARALATLGRLRYRVSGQLPLLDETAIEVMAGGQFLDGRKAREELGFFSTTALDDT" + "LLRAIDWFRDNGYFNA"; + Sequence sequence = new SequenceBuilder(seq).build(); + return sequence; + } + private List getSeqFeatures() { List locations = Arrays.asList(new SequenceFeatureLocationBuilder().range(12, 23).alignment("55M").build(), new SequenceFeatureLocationBuilder().range(45, 89).build()); InterProGroup domain = new InterProGroupBuilder().name("name1").id("id1").build(); diff --git a/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMapTest.java b/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMapTest.java index 46b1d271d..69650d1fb 100644 --- a/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMapTest.java +++ b/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcCrossReferenceMapTest.java @@ -1,16 +1,17 @@ package org.uniprot.core.parser.tsv.uniparc; -import static org.junit.jupiter.api.Assertions.*; - -import java.time.LocalDate; -import java.util.*; - import org.junit.jupiter.api.Test; import org.uniprot.core.Property; import org.uniprot.core.uniparc.UniParcCrossReference; import org.uniprot.core.uniparc.UniParcDatabase; import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; +import java.time.LocalDate; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author jluo * @date: 24 Jun 2019 @@ -31,9 +32,7 @@ void testSimpleAttributeValues() { UniParcCrossReferenceMap xrefMap = new UniParcCrossReferenceMap(Collections.singletonList(xref)); Map result = xrefMap.attributeValues(); - assertEquals(13, result.size()); - assertEquals("2017-05-17", result.get("first_seen")); - assertEquals("2018-02-07", result.get("last_seen")); + assertEquals(11, result.size()); assertEquals("IDVALUE", result.get("EnsemblBacteria")); assertEquals("", result.get("gene")); assertEquals("", result.get("protein")); @@ -52,13 +51,11 @@ void testAttributeValues() { List xrefs = create(); UniParcCrossReferenceMap xrefMap = new UniParcCrossReferenceMap(xrefs); Map result = xrefMap.attributeValues(); - assertEquals(14, result.size()); + assertEquals(12, result.size()); assertEquals("geneValue", result.get("gene")); assertEquals("some pname;some pname2", result.get("protein")); assertEquals("P12345; P12347.2 (obsolete)", result.get("accession")); assertEquals("UP00000564:chromosome 1", result.get("proteome")); - assertEquals("2015-01-11", result.get("first_seen")); - assertEquals("2018-02-07", result.get("last_seen")); assertEquals("P12345", result.get("UniProtKB/Swiss-Prot")); assertEquals("P12347", result.get("UniProtKB/TrEMBL")); } @@ -72,8 +69,6 @@ void testFields() { "protein", "proteome", "accession", - "first_seen", - "last_seen", "database", "active", "ncbiGi", @@ -95,9 +90,7 @@ void testAttributeValuesWithoutDates() { List xrefs = createWithoutDates(); UniParcCrossReferenceMap xrefMap = new UniParcCrossReferenceMap(xrefs); Map result = xrefMap.attributeValues(); - assertEquals(14, result.size()); - assertTrue(result.get("first_seen").isEmpty()); - assertTrue(result.get("last_seen").isEmpty()); + assertEquals(12, result.size()); assertTrue(result.get("timeline").isEmpty()); } 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 new file mode 100644 index 000000000..e613c83b0 --- /dev/null +++ b/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryLightValueMapperTest.java @@ -0,0 +1,147 @@ +package org.uniprot.core.parser.tsv.uniparc; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.Sequence; +import org.uniprot.core.impl.SequenceBuilder; +import org.uniprot.core.uniparc.*; +import org.uniprot.core.uniparc.impl.*; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; + +import java.time.LocalDate; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class UniParcEntryLightValueMapperTest { + + @Test + void testGetDataOrganism() { + UniParcEntryLight entry = create(); + List fields = Arrays.asList("upi", "organism", "organism_id", "proteome", "common_taxons"); + + Map result = new UniParcEntryLightValueMapper().mapEntity(entry, 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("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 + void testGetDataProteinGene() { + UniParcEntryLight entry = create(); + List fields = Arrays.asList("upi", "protein", "gene", "accession"); + Map result = new UniParcEntryLightValueMapper().mapEntity(entry, fields); + assertEquals(4, result.size()); + verify("UPI0000083A08", "upi", result); + verify("protein1; protein2", "protein", result); + verify("gene1; gene2", "gene", result); + verify("P52346; P12345", "accession", result); + } + + @Test + void testGetDate() { + UniParcEntryLight entry = create(); + List fields = Arrays.asList("upi", "first_seen", "last_seen"); + Map result = new UniParcEntryLightValueMapper().mapEntity(entry, fields); + assertEquals(3, result.size()); + verify("UPI0000083A08", "upi", result); + verify("2017-02-12", "first_seen", result); + verify("2020-10-25", "last_seen", result); + } + + @Test + void testGetSequence() { + UniParcEntryLight entry = create(); + List fields = Arrays.asList("upi", "checksum", "length", "sequence"); + Map result = new UniParcEntryLightValueMapper().mapEntity(entry, fields); + assertEquals(fields.size(), result.size()); + verify("UPI0000083A08", "upi", result); + verify("AA7812161AF4EB5E", "checksum", result); + verify("30", "length", result); + verify("MVSWGRFICLVVVTMATLSLARPSFSLVED", "sequence", result); + } + + @Test + void testGetSequenceFeature() { + UniParcEntryLight entry = create(); + List fields = Arrays.asList("upi", "HAMAP", "InterPro", "Pfam", "PROSITE"); + Map result = new UniParcEntryLightValueMapper().mapEntity(entry, fields); + assertEquals(14, result.size()); + verify("UPI0000083A08", "upi", result); + verify("", "HAMAP", result); + verify("id1", "InterPro", result); + verify("sigId2", "Pfam", result); + verify("sigId2", "PROSITE", result); + } + + private void verify(String expected, String field, Map result) { + assertEquals(expected, result.get(field)); + } + + private UniParcEntryLight create() { + String seq = "MVSWGRFICLVVVTMATLSLARPSFSLVED"; + Sequence sequence = new SequenceBuilder(seq).build(); + List seqFeatures = getSeqFeatures(); + + Organism organism1 = new OrganismBuilder().taxonId(9606).scientificName("Homo sapiens").build(); + Organism organism2 = new OrganismBuilder().taxonId(10090).scientificName("MOUSE").build(); + LinkedHashSet organisms = new LinkedHashSet<>(List.of(organism1, organism2)); + + 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() + .uniParcId("UPI0000083A08") + .uniProtKBAccessionsSet(new LinkedHashSet<>(List.of("P52346", "P12345"))) + .organismsSet(organisms) + .proteomesSet(proteomes) + .geneNamesSet(geneNames) + .commonTaxonsSet(commonTaxons) + .proteinNamesSet(proteinNames) + .mostRecentCrossRefUpdated(LocalDate.of(2020, 10, 25)) + .oldestCrossRefCreated(LocalDate.of(2017, 2, 12)) + .sequence(sequence) + .sequenceFeaturesSet(seqFeatures) + .build(); + } + + private List getSeqFeatures() { + SequenceFeatureLocationBuilder sflBuilder = new SequenceFeatureLocationBuilder(); + SequenceFeatureLocation sfl1 = sflBuilder.range(12, 13).alignment("M55").build(); + SequenceFeatureLocation sfl2 = sflBuilder.range(45, 89).alignment("Alignment").build(); + List sfls = List.of(sfl1, sfl2); + InterProGroup domain = new InterProGroupBuilder().name("name1").id("id1").build(); + SequenceFeature sf = + new SequenceFeatureBuilder() + .interproGroup(domain) + .signatureDbType(SignatureDbType.PFAM) + .signatureDbId("sigId2") + .locationsSet(sfls) + .build(); + SequenceFeature sf3 = + SequenceFeatureBuilder.from(sf).signatureDbType(SignatureDbType.PROSITE).build(); + return Arrays.asList(sf, sf3); + } +} \ No newline at end of file diff --git a/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapperTest.java b/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapperTest.java index 1bafde168..54a07bcda 100644 --- a/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapperTest.java +++ b/core-parser/src/test/java/org/uniprot/core/parser/tsv/uniparc/UniParcEntryValueMapperTest.java @@ -42,7 +42,7 @@ void testGetDataProteinGene() { UniParcEntry entry = create(); List fields = Arrays.asList("upi", "protein", "gene", "accession"); Map result = new UniParcEntryValueMapper().mapEntity(entry, fields); - assertEquals(15, result.size()); + assertEquals(13, result.size()); verify("UPI0000083A08", "upi", result); verify("some pname;some pname", "protein", result); verify("some gname", "gene", result); @@ -54,7 +54,7 @@ void testGetDate() { UniParcEntry entry = create(); List fields = Arrays.asList("upi", "first_seen", "last_seen"); Map result = new UniParcEntryValueMapper().mapEntity(entry, fields); - assertEquals(15, result.size()); + assertEquals(3, result.size()); verify("UPI0000083A08", "upi", result); verify("2017-02-12", "first_seen", result); verify("2017-04-23", "last_seen", result); @@ -88,11 +88,11 @@ void testGetSequenceFeature() { @Test void testGetDates() { UniParcEntry entry = create(); - List fields = Arrays.asList("oldestCrossRefCreated", "mostRecentCrossRefUpdated"); + List fields = Arrays.asList("first_seen", "last_seen"); Map result = new UniParcEntryValueMapper().mapEntity(entry, fields); assertEquals(2, result.size()); - verify("2017-02-12", "oldestCrossRefCreated", result); - verify("2017-04-23", "mostRecentCrossRefUpdated", result); + verify("2017-02-12", "first_seen", result); + verify("2017-04-23", "last_seen", result); } private void verify(String expected, String field, Map result) { diff --git a/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfig.java b/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfig.java index 0dc8cd841..508ec9649 100644 --- a/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfig.java +++ b/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfig.java @@ -12,6 +12,7 @@ import org.uniprot.core.json.parser.serializer.LocalDateSerializer; import org.uniprot.core.uniparc.UniParcCrossReference; import org.uniprot.core.uniparc.impl.UniParcCrossReferenceImpl; +import org.uniprot.core.uniparc.impl.UniParcCrossReferencePair; import org.uniprot.core.uniprotkb.evidence.Evidence; import org.uniprot.core.uniprotkb.evidence.impl.EvidenceImpl; import org.uniprot.core.uniprotkb.taxonomy.Organism; @@ -19,6 +20,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; +import org.uniprot.core.util.Pair; +import org.uniprot.core.util.PairImpl; /** * @author jluo @@ -63,6 +66,7 @@ private ObjectMapper initObjectMapper() { mod.addAbstractTypeMapping(Evidence.class, EvidenceImpl.class); mod.addAbstractTypeMapping(CrossReference.class, CrossReferenceImpl.class); mod.addAbstractTypeMapping(Database.class, DefaultDatabase.class); + mod.addAbstractTypeMapping(Pair.class, UniParcCrossReferencePair.class); objMapper.registerModule(mod); return objMapper; } diff --git a/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcEntryLightJsonConfig.java b/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcEntryLightJsonConfig.java new file mode 100644 index 000000000..193348556 --- /dev/null +++ b/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcEntryLightJsonConfig.java @@ -0,0 +1,77 @@ +package org.uniprot.core.json.parser.uniparc; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import org.uniprot.core.CrossReference; +import org.uniprot.core.Sequence; +import org.uniprot.core.impl.CrossReferenceImpl; +import org.uniprot.core.impl.SequenceImpl; +import org.uniprot.core.json.parser.JsonConfig; +import org.uniprot.core.json.parser.deserializer.LocalDateDeserializer; +import org.uniprot.core.json.parser.serializer.LocalDateSerializer; +import org.uniprot.core.uniparc.*; +import org.uniprot.core.uniparc.impl.*; +import org.uniprot.core.uniprotkb.evidence.Evidence; +import org.uniprot.core.uniprotkb.evidence.impl.EvidenceImpl; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismImpl; + +import java.time.LocalDate; + +public class UniParcEntryLightJsonConfig extends JsonConfig { + private static UniParcEntryLightJsonConfig instance; + + private final ObjectMapper objectMapper; + private final ObjectMapper prettyMapper; + + private UniParcEntryLightJsonConfig() { + this.objectMapper = initObjectMapper(); + this.prettyMapper = initPrettyObjectMapper(); + } + + public static synchronized UniParcEntryLightJsonConfig getInstance() { + if (instance == null) { + instance = new UniParcEntryLightJsonConfig(); + } + return instance; + } + + @Override + public ObjectMapper getSimpleObjectMapper() { + return this.prettyMapper; + } + + @Override + public ObjectMapper getFullObjectMapper() { + return this.objectMapper; + } + + private ObjectMapper initObjectMapper() { + ObjectMapper objMapper = getDefaultFullObjectMapper(); + + SimpleModule mod = new SimpleModule(); + mod.addSerializer(LocalDate.class, new LocalDateSerializer()); + mod.addDeserializer(LocalDate.class, new LocalDateDeserializer()); + mod.addAbstractTypeMapping(UniParcEntryLight.class, UniParcEntryLightImpl.class); + mod.addAbstractTypeMapping(InterProGroup.class, InterProGroupImpl.class); + mod.addAbstractTypeMapping(SequenceFeature.class, SequenceFeatureImpl.class); + mod.addAbstractTypeMapping(SequenceFeatureLocation.class, SequenceFeatureLocationImpl.class); + mod.addAbstractTypeMapping(CrossReference.class, CrossReferenceImpl.class); + mod.addAbstractTypeMapping(Sequence.class, SequenceImpl.class); + mod.addAbstractTypeMapping(CommonOrganism.class, CommonOrganismImpl.class); + mod.addAbstractTypeMapping(Organism.class, OrganismImpl.class); + mod.addAbstractTypeMapping(Evidence.class, EvidenceImpl.class); + mod.addAbstractTypeMapping(Proteome.class, ProteomeImpl.class); + objMapper.registerModule(mod); + + return objMapper; + } + + private ObjectMapper initPrettyObjectMapper() { + ObjectMapper prettyObjMapper = getDefaultSimpleObjectMapper(); + SimpleModule simpleMod = new SimpleModule(); + simpleMod.addSerializer(LocalDate.class, new LocalDateSerializer()); + prettyObjMapper.registerModule(simpleMod); + return prettyObjMapper; + } +} diff --git a/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfigTest.java b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfigTest.java index 241ed6ed3..9449beb40 100644 --- a/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfigTest.java +++ b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcCrossRefJsonConfigTest.java @@ -1,25 +1,30 @@ 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 org.uniprot.core.uniparc.UniParcEntry; +import org.uniprot.core.uniparc.impl.UniParcCrossReferencePair; +import org.uniprot.core.util.Pair; -import com.fasterxml.jackson.databind.ObjectMapper; +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() { - UniParcCrossReference entry = getCompleteUniParcEntry().getUniParcCrossReferences().get(0); + UniParcEntry completeUniParcEntry = getCompleteUniParcEntry(); + Pair> entry = new UniParcCrossReferencePair(completeUniParcEntry.getUniParcId().getValue(), completeUniParcEntry.getUniParcCrossReferences()); ValidateJson.verifyJsonRoundTripParser( UniParcCrossRefJsonConfig.getInstance().getFullObjectMapper(), entry); ValidateJson.verifyEmptyFields(entry); try { ObjectMapper mapper = UniParcCrossRefJsonConfig.getInstance().getSimpleObjectMapper(); String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(entry); + System.out.println(json); } catch (Exception e) { fail(e.getMessage()); } diff --git a/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcEntryLightJsonConfigTest.java b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcEntryLightJsonConfigTest.java new file mode 100644 index 000000000..a6585222f --- /dev/null +++ b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcEntryLightJsonConfigTest.java @@ -0,0 +1,97 @@ +package org.uniprot.core.json.parser.uniparc; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.uniprot.core.Sequence; +import org.uniprot.core.impl.SequenceBuilder; +import org.uniprot.core.json.parser.ValidateJson; +import org.uniprot.core.json.parser.uniprot.CreateUtils; +import org.uniprot.core.uniparc.*; +import org.uniprot.core.uniparc.impl.CommonOrganismBuilder; +import org.uniprot.core.uniparc.impl.ProteomeBuilder; +import org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder; +import org.uniprot.core.uniprotkb.evidence.Evidence; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; + +import java.time.LocalDate; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.fail; +import static org.uniprot.core.json.parser.uniparc.UniParcEntryTest.getSeqFeature; +import static org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder.HAS_ACTIVE_CROSS_REF; + + +class UniParcEntryLightJsonConfigTest { + + @Test + void testFullUniParcEntryLightJsonRoundTrip() { + UniParcEntryLight entry = getCompleteUniParcEntryLight(); + + ValidateJson.verifyJsonRoundTripParser( + UniParcEntryLightJsonConfig.getInstance().getFullObjectMapper(), entry); + ValidateJson.verifyEmptyFields(entry); + try { + ObjectMapper mapper = UniParcEntryLightJsonConfig.getInstance().getSimpleObjectMapper(); + String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(entry); + System.out.println(json); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + private UniParcEntryLight getCompleteUniParcEntryLight() { + // Create sample data for all the fields + String uniParcId = "UPI0000000001"; + + int crossReferenceCount = 19; + + List commonTaxons = List.of( + new CommonOrganismBuilder().topLevel("cellular organisms").commonTaxon("Homo sapiens").build(), + new CommonOrganismBuilder().topLevel("Viruses").commonTaxon("Mus musculus").build() + ); + + LinkedHashSet uniProtKBAccessions = new LinkedHashSet<>(List.of("P12345", "Q67890")); + + String sequenceStr = "MVSWGRFICLVVVTMATLSLARPSFSLVED"; + Sequence sequence = new SequenceBuilder(sequenceStr).build(); + + List sequenceFeatures = new ArrayList<>(); + Arrays.stream(SignatureDbType.values()).forEach(signatureType -> sequenceFeatures.add(getSeqFeature(signatureType))); + + LocalDate oldestCrossRefCreated = LocalDate.of(2020, 1, 1); + LocalDate mostRecentCrossRefUpdated = LocalDate.of(2023, 6, 19); + + List evidences = CreateUtils.createEvidenceList("ECO:0000269|PubMed:11389730"); + Organism organism = new OrganismBuilder() + .taxonId(123L) + .scientificName("ScientificName") + .lineagesAdd("Lineage 1") + .commonName("common Name") + .synonymsAdd("syn name") + .evidencesSet(evidences) + .build(); + + LinkedHashSet organisms = new LinkedHashSet<>(List.of(organism)); + LinkedHashSet proteinNames = new LinkedHashSet<>(List.of("Protein Alpha", "Protein Beta")); + LinkedHashSet geneNames = new LinkedHashSet<>(List.of("Gene1", "Gene2")); + LinkedHashSet proteomes = new LinkedHashSet<>(List.of(new ProteomeBuilder().id("UP000005640").component("Chromosome 1").build(), new ProteomeBuilder().id("UP000000589").component("Chromosome 2").build())); + + // Use the builder to create a complete UniParcEntryLight + return new UniParcEntryLightBuilder() + .uniParcId(uniParcId) + .crossReferenceCount(crossReferenceCount) + .commonTaxonsSet(commonTaxons) + .uniProtKBAccessionsSet(uniProtKBAccessions) + .sequence(sequence) + .sequenceFeaturesSet(sequenceFeatures) + .oldestCrossRefCreated(oldestCrossRefCreated) + .mostRecentCrossRefUpdated(mostRecentCrossRefUpdated) + .organismsSet(organisms) + .proteinNamesSet(proteinNames) + .geneNamesSet(geneNames) + .proteomesSet(proteomes) + .extraAttributesAdd(HAS_ACTIVE_CROSS_REF, true) + .build(); + } +} diff --git a/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcEntryTest.java b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcEntryTest.java index 610068d03..3d588a7ef 100644 --- a/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcEntryTest.java +++ b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/UniParcEntryTest.java @@ -1,25 +1,27 @@ package org.uniprot.core.json.parser.uniparc; -import static org.junit.jupiter.api.Assertions.fail; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.uniprot.core.Property; import org.uniprot.core.Sequence; import org.uniprot.core.impl.SequenceBuilder; import org.uniprot.core.json.parser.ValidateJson; import org.uniprot.core.json.parser.uniprot.CreateUtils; -import org.uniprot.core.uniparc.*; +import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.SignatureDbType; import org.uniprot.core.uniparc.impl.*; +import org.uniprot.core.uniparc.UniParcDatabase; +import org.uniprot.core.uniparc.UniParcEntry; import org.uniprot.core.uniprotkb.evidence.Evidence; import org.uniprot.core.uniprotkb.taxonomy.Organism; import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.fail; /** * @author jluo @@ -27,7 +29,7 @@ */ public class UniParcEntryTest { @Test - void test() { + void testUniParcEntryJsonParser() { UniParcEntry entry = getCompleteUniParcEntry(); ValidateJson.verifyJsonRoundTripParser( @@ -117,7 +119,7 @@ public static UniParcEntry getCompleteUniParcEntry() { return builder.build(); } - private static SequenceFeature getSeqFeature(SignatureDbType signatureType) { + static SequenceFeature getSeqFeature(SignatureDbType signatureType) { return new SequenceFeatureBuilder() .signatureDbType(signatureType) .signatureDbId("id-" + signatureType) diff --git a/xml-parser/pom.xml b/xml-parser/pom.xml index 7d8ced32f..f9827b86d 100644 --- a/xml-parser/pom.xml +++ b/xml-parser/pom.xml @@ -24,6 +24,7 @@ org.uniprot.core.xml.jaxb.coordinate org.uniprot.core.xml.jaxb.uniref org.uniprot.core.xml.jaxb.uniparc + org.uniprot.core.xml.jaxb.dbreference org.uniprot.core.xml.jaxb.unirule org.uniprot.core.xml.jaxb.feature @@ -215,6 +216,16 @@ -XhashCode + + true + ${xsd-location}/uniparc-dbreference.xsd + ${dbreference-xsd-pojo-package} + + -verbose + -Xequals + -XhashCode + + diff --git a/xml-parser/src/main/java/org/uniprot/core/xml/CrossReferenceConverterUtils.java b/xml-parser/src/main/java/org/uniprot/core/xml/CrossReferenceConverterUtils.java new file mode 100644 index 000000000..c9ca29d03 --- /dev/null +++ b/xml-parser/src/main/java/org/uniprot/core/xml/CrossReferenceConverterUtils.java @@ -0,0 +1,81 @@ +package org.uniprot.core.xml; + +import com.google.common.base.Strings; +import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; +import org.uniprot.cv.taxonomy.TaxonomicNode; +import org.uniprot.cv.taxonomy.TaxonomyRepo; + +import java.util.Optional; + +public class CrossReferenceConverterUtils { + public static final String PROPERTY_GENE_NAME = "gene_name"; + public static final String PROPERTY_PROTEIN_NAME = "protein_name"; + public static final String PROPERTY_CHAIN = "chain"; + public static final String PROPERTY_NCBI_GI = "NCBI_GI"; + public static final String PROPERTY_PROTEOME_ID = "proteome_id"; + public static final String PROPERTY_COMPONENT = "component"; + public static final String PROPERTY_NCBI_TAXONOMY_ID = "NCBI_taxonomy_id"; + public static final String PROPERTY_UNIPROTKB_ACCESSION = "UniProtKB_accession"; + + private CrossReferenceConverterUtils(){} + + public static void populateUniParcCrossReferenceBuilder(String propertyType, String propertyValue, UniParcCrossReferenceBuilder builder, TaxonomyRepo taxonomyRepo) { + switch (propertyType) { + case PROPERTY_GENE_NAME: + builder.geneName(propertyValue); + break; + case PROPERTY_PROTEIN_NAME: + builder.proteinName(propertyValue); + break; + case PROPERTY_CHAIN: + builder.chain(propertyValue); + break; + case PROPERTY_NCBI_GI: + builder.ncbiGi(propertyValue); + break; + case PROPERTY_PROTEOME_ID: + builder.proteomeId(propertyValue); + break; + case PROPERTY_COMPONENT: + builder.component(propertyValue); + break; + case PROPERTY_NCBI_TAXONOMY_ID: + builder.organism(CrossReferenceConverterUtils.convertTaxonomy(propertyValue, taxonomyRepo)); + break; + case PROPERTY_UNIPROTKB_ACCESSION: + builder.propertiesAdd(PROPERTY_UNIPROTKB_ACCESSION, propertyValue); + break; + default: + throw new XmlReaderException( + "Unable to read xml property: " + + propertyType + + "value: " + + propertyValue); + } + } + + private static Organism convertTaxonomy(String taxId, TaxonomyRepo taxonomyRepo) { + OrganismBuilder builder = new OrganismBuilder().taxonId(Long.parseLong(taxId)); + Optional opNode = getTaxonomyNode(taxId, taxonomyRepo); + if (opNode.isPresent()) { + TaxonomicNode node = opNode.get(); + builder.scientificName(node.scientificName()); + if (!Strings.isNullOrEmpty(node.commonName())) { + builder.commonName(node.commonName()); + } + if (!Strings.isNullOrEmpty(node.synonymName())) { + builder.synonymsAdd(node.synonymName()); + } + } + + return builder.build(); + } + + private static Optional getTaxonomyNode(String taxId, TaxonomyRepo taxonomyRepo) { + if (taxonomyRepo == null) { + return Optional.empty(); + } else return taxonomyRepo.retrieveNodeUsingTaxID(Integer.parseInt(taxId)); + } +} diff --git a/xml-parser/src/main/java/org/uniprot/core/xml/dbreference/UniParcCrossReferenceConverter.java b/xml-parser/src/main/java/org/uniprot/core/xml/dbreference/UniParcCrossReferenceConverter.java new file mode 100644 index 000000000..3e019b590 --- /dev/null +++ b/xml-parser/src/main/java/org/uniprot/core/xml/dbreference/UniParcCrossReferenceConverter.java @@ -0,0 +1,101 @@ +package org.uniprot.core.xml.dbreference; + +import org.uniprot.core.uniparc.UniParcCrossReference; +import org.uniprot.core.uniparc.UniParcDatabase; +import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; +import org.uniprot.core.util.Utils; +import org.uniprot.core.xml.Converter; +import org.uniprot.core.xml.CrossReferenceConverterUtils; +import org.uniprot.core.xml.jaxb.dbreference.DbReference; +import org.uniprot.core.xml.jaxb.dbreference.ObjectFactory; +import org.uniprot.core.xml.jaxb.dbreference.PropertyType; +import org.uniprot.core.xml.uniprot.XmlConverterHelper; +import org.uniprot.cv.taxonomy.TaxonomyRepo; + +import java.util.ArrayList; +import java.util.List; + +import static org.uniprot.core.xml.CrossReferenceConverterUtils.*; + +public class UniParcCrossReferenceConverter + implements Converter { + private final ObjectFactory xmlFactory; + private final TaxonomyRepo taxonomyRepo; + + public UniParcCrossReferenceConverter() { + this(new ObjectFactory(), null); + } + + public UniParcCrossReferenceConverter(ObjectFactory xmlFactory, TaxonomyRepo taxonomyRepo) { + this.xmlFactory = xmlFactory; + this.taxonomyRepo = taxonomyRepo; + } + + @Override + public UniParcCrossReference fromXml(DbReference xmlObj) { + UniParcCrossReferenceBuilder builder = new UniParcCrossReferenceBuilder(); + builder.database(UniParcDatabase.typeOf(xmlObj.getType())) + .id(xmlObj.getId()) + .active(xmlObj.getActive().equals("Y")) + .versionI(xmlObj.getVersionI()) + .created(XmlConverterHelper.dateFromXml(xmlObj.getCreated())) + .lastUpdated(XmlConverterHelper.dateFromXml(xmlObj.getLast())); + + for (PropertyType property : xmlObj.getProperty()) { + CrossReferenceConverterUtils.populateUniParcCrossReferenceBuilder(property.getType(), property.getValue(), builder, taxonomyRepo); + } + if (xmlObj.getVersion() != null) builder.version(xmlObj.getVersion()); + return builder.build(); + } + + @Override + public DbReference toXml(UniParcCrossReference uniObj) { + DbReference xmlObj = xmlFactory.createDbReference(); + xmlObj.setActive(uniObj.isActive() ? "Y" : "N"); + xmlObj.setId(uniObj.getId()); + xmlObj.setType(uniObj.getDatabase().getDisplayName()); + xmlObj.setVersionI(uniObj.getVersionI()); + if (uniObj.getVersion() != null) xmlObj.setVersion(uniObj.getVersion()); + xmlObj.setCreated(XmlConverterHelper.dateToXml(uniObj.getCreated())); + xmlObj.setLast(XmlConverterHelper.dateToXml(uniObj.getLastUpdated())); + + List properties = new ArrayList<>(); + if (Utils.notNullNotEmpty(uniObj.getGeneName())) { + properties.add(createProperty(PROPERTY_GENE_NAME, uniObj.getGeneName())); + } + if (Utils.notNullNotEmpty(uniObj.getProteinName())) { + properties.add(createProperty(PROPERTY_PROTEIN_NAME, uniObj.getProteinName())); + } + if (Utils.notNullNotEmpty(uniObj.getChain())) { + properties.add(createProperty(PROPERTY_CHAIN, uniObj.getChain())); + } + if (Utils.notNullNotEmpty(uniObj.getNcbiGi())) { + properties.add(createProperty(PROPERTY_NCBI_GI, uniObj.getNcbiGi())); + } + if (Utils.notNullNotEmpty(uniObj.getProteomeId())) { + properties.add(createProperty(PROPERTY_PROTEOME_ID, uniObj.getProteomeId())); + } + if (Utils.notNullNotEmpty(uniObj.getComponent())) { + properties.add(createProperty(PROPERTY_COMPONENT, uniObj.getComponent())); + } + if (Utils.notNull(uniObj.getOrganism())) { + String taxonId = String.valueOf(uniObj.getOrganism().getTaxonId()); + properties.add(createProperty(PROPERTY_NCBI_TAXONOMY_ID, taxonId)); + } + xmlObj.getProperty().addAll(properties); + if (Utils.notNullNotEmpty(uniObj.getProperties())) { + uniObj.getProperties().stream() + .map(prop -> createProperty(prop.getKey(), prop.getValue())) + .forEach(val -> xmlObj.getProperty().add(val)); + } + + return xmlObj; + } + + private PropertyType createProperty(String key, String value) { + PropertyType xmlObj = xmlFactory.createPropertyType(); + xmlObj.setType(key); + xmlObj.setValue(value); + return xmlObj; + } +} diff --git a/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverter.java b/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverter.java index 9a71713be..bf47e761f 100644 --- a/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverter.java +++ b/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverter.java @@ -1,25 +1,21 @@ package org.uniprot.core.xml.uniparc; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import org.uniprot.core.uniparc.UniParcCrossReference; import org.uniprot.core.uniparc.UniParcDatabase; import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; -import org.uniprot.core.uniprotkb.taxonomy.Organism; -import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; import org.uniprot.core.util.Utils; import org.uniprot.core.xml.Converter; -import org.uniprot.core.xml.XmlReaderException; +import org.uniprot.core.xml.CrossReferenceConverterUtils; import org.uniprot.core.xml.jaxb.uniparc.DbReferenceType; import org.uniprot.core.xml.jaxb.uniparc.ObjectFactory; import org.uniprot.core.xml.jaxb.uniparc.PropertyType; import org.uniprot.core.xml.uniprot.XmlConverterHelper; -import org.uniprot.cv.taxonomy.TaxonomicNode; import org.uniprot.cv.taxonomy.TaxonomyRepo; -import com.google.common.base.Strings; +import java.util.ArrayList; +import java.util.List; + +import static org.uniprot.core.xml.CrossReferenceConverterUtils.*; /** * @author jluo @@ -28,14 +24,6 @@ public class UniParcDBCrossReferenceConverter implements Converter { - public static final String PROPERTY_GENE_NAME = "gene_name"; - public static final String PROPERTY_PROTEIN_NAME = "protein_name"; - public static final String PROPERTY_CHAIN = "chain"; - public static final String PROPERTY_NCBI_GI = "NCBI_GI"; - public static final String PROPERTY_PROTEOME_ID = "proteome_id"; - public static final String PROPERTY_COMPONENT = "component"; - public static final String PROPERTY_NCBI_TAXONOMY_ID = "NCBI_taxonomy_id"; - public static final String PROPERTY_UNIPROTKB_ACCESSION = "UniProtKB_accession"; private final ObjectFactory xmlFactory; private final TaxonomyRepo taxonomyRepo; @@ -60,38 +48,7 @@ public UniParcCrossReference fromXml(DbReferenceType xmlObj) { .lastUpdated(XmlConverterHelper.dateFromXml(xmlObj.getLast())); for (PropertyType property : xmlObj.getProperty()) { - switch (property.getType()) { - case PROPERTY_GENE_NAME: - builder.geneName(property.getValue()); - break; - case PROPERTY_PROTEIN_NAME: - builder.proteinName(property.getValue()); - break; - case PROPERTY_CHAIN: - builder.chain(property.getValue()); - break; - case PROPERTY_NCBI_GI: - builder.ncbiGi(property.getValue()); - break; - case PROPERTY_PROTEOME_ID: - builder.proteomeId(property.getValue()); - break; - case PROPERTY_COMPONENT: - builder.component(property.getValue()); - break; - case PROPERTY_NCBI_TAXONOMY_ID: - builder.organism(convertTaxonomy(property.getValue())); - break; - case PROPERTY_UNIPROTKB_ACCESSION: - builder.propertiesAdd(PROPERTY_UNIPROTKB_ACCESSION, property.getValue()); - break; - default: - throw new XmlReaderException( - "Unable to read xml property: " - + xmlObj.getType() - + "value: " - + property.getValue()); - } + CrossReferenceConverterUtils.populateUniParcCrossReferenceBuilder(property.getType(), property.getValue(), builder, taxonomyRepo); } if (xmlObj.getVersion() != null) builder.version(xmlObj.getVersion()); return builder.build(); @@ -141,29 +98,6 @@ public DbReferenceType toXml(UniParcCrossReference uniObj) { return xmlObj; } - private Organism convertTaxonomy(String taxId) { - OrganismBuilder builder = new OrganismBuilder().taxonId(Long.parseLong(taxId)); - Optional opNode = getTaxonomyNode(taxId); - if (opNode.isPresent()) { - TaxonomicNode node = opNode.get(); - builder.scientificName(node.scientificName()); - if (!Strings.isNullOrEmpty(node.commonName())) { - builder.commonName(node.commonName()); - } - if (!Strings.isNullOrEmpty(node.synonymName())) { - builder.synonymsAdd(node.synonymName()); - } - } - - return builder.build(); - } - - private Optional getTaxonomyNode(String taxId) { - if (taxonomyRepo == null) { - return Optional.empty(); - } else return taxonomyRepo.retrieveNodeUsingTaxID(Integer.parseInt(taxId)); - } - private PropertyType createProperty(String key, String value) { PropertyType xmlObj = xmlFactory.createPropertyType(); xmlObj.setType(key); diff --git a/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/UniParcEntryLightConverter.java b/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/UniParcEntryLightConverter.java new file mode 100644 index 000000000..fcb0bc7c0 --- /dev/null +++ b/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/UniParcEntryLightConverter.java @@ -0,0 +1,48 @@ +package org.uniprot.core.xml.uniparc; + +import org.uniprot.core.uniparc.UniParcEntryLight; +import org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder; +import org.uniprot.core.xml.Converter; +import org.uniprot.core.xml.jaxb.uniparc.Entry; +import org.uniprot.core.xml.jaxb.uniparc.ObjectFactory; + +public class UniParcEntryLightConverter implements Converter { + private static final String UNIPARC = "uniparc"; + private final ObjectFactory xmlFactory; + private final SequenceFeatureConverter seqFeatureConverter; + private final SequenceConverter sequenceConverter; + + public UniParcEntryLightConverter(){ + this(new ObjectFactory()); + } + + public UniParcEntryLightConverter(ObjectFactory xmlFactory) { + this.xmlFactory = xmlFactory; + this.seqFeatureConverter = new SequenceFeatureConverter(xmlFactory); + this.sequenceConverter = new SequenceConverter(xmlFactory); + } + + @Override + public UniParcEntryLight fromXml(Entry xmlObj) { + UniParcEntryLightBuilder builder = new UniParcEntryLightBuilder(); + builder.uniParcId(xmlObj.getAccession()) + .sequence(sequenceConverter.fromXml(xmlObj.getSequence())) + .sequenceFeaturesSet( + xmlObj.getSignatureSequenceMatch().stream() + .map(seqFeatureConverter::fromXml) + .toList()); + return builder.build(); + } + + @Override + public Entry toXml(UniParcEntryLight uniObj) { + Entry entry = xmlFactory.createEntry(); + entry.setDataset(UNIPARC); + entry.setAccession(uniObj.getUniParcId()); + entry.setSequence(sequenceConverter.toXml(uniObj.getSequence())); + uniObj.getSequenceFeatures().stream() + .map(seqFeatureConverter::toXml) + .forEach(val -> entry.getSignatureSequenceMatch().add(val)); + return entry; + } +} diff --git a/xml-parser/src/main/resources/xsd/uniparc-dbreference.xsd b/xml-parser/src/main/resources/xsd/uniparc-dbreference.xsd new file mode 100644 index 000000000..b9883367f --- /dev/null +++ b/xml-parser/src/main/resources/xsd/uniparc-dbreference.xsd @@ -0,0 +1,39 @@ + + + + + + Describes a collection of dbReference entries. + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xml-parser/src/main/resources/xsd/uniparc.xsd b/xml-parser/src/main/resources/xsd/uniparc.xsd index eebd1cbcb..b3bde2442 100644 --- a/xml-parser/src/main/resources/xsd/uniparc.xsd +++ b/xml-parser/src/main/resources/xsd/uniparc.xsd @@ -25,7 +25,7 @@ + minOccurs="0" maxOccurs="unbounded" /> diff --git a/xml-parser/src/test/java/org/uniprot/core/xml/dbreference/UniParcCrossReferenceConverterTest.java b/xml-parser/src/test/java/org/uniprot/core/xml/dbreference/UniParcCrossReferenceConverterTest.java new file mode 100644 index 000000000..626aa64b6 --- /dev/null +++ b/xml-parser/src/test/java/org/uniprot/core/xml/dbreference/UniParcCrossReferenceConverterTest.java @@ -0,0 +1,45 @@ +package org.uniprot.core.xml.dbreference; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.uniparc.UniParcCrossReference; +import org.uniprot.core.uniparc.UniParcDatabase; +import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; +import org.uniprot.core.uniprotkb.taxonomy.Organism; +import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; +import org.uniprot.core.xml.jaxb.dbreference.DbReference; + +import java.time.LocalDate; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.uniprot.core.xml.CrossReferenceConverterUtils.PROPERTY_UNIPROTKB_ACCESSION; + + +class UniParcCrossReferenceConverterTest { + @Test + void testComplete() { + Organism taxonomy = new OrganismBuilder().taxonId(7227).build(); + UniParcCrossReferenceBuilder builder = new UniParcCrossReferenceBuilder(); + builder.database(UniParcDatabase.TREMBL) + .id("A0A0C4DHG2-PB") + .versionI(1) + .version(1) + .active(true) + .organism(taxonomy) + .proteinName("Gelsolin, isoform J") + .proteomeId("proteomeValue") + .geneName("Gel") + .component("ComponentValue") + .ncbiGi("ncbiGiValue") + .chain("chainValue") + .propertiesAdd(PROPERTY_UNIPROTKB_ACCESSION, "P21802") + .created(LocalDate.of(2015, 4, 1)) + .lastUpdated(LocalDate.of(2019, 5, 8)); + + UniParcCrossReference xref = builder.build(); + UniParcCrossReferenceConverter converter = new UniParcCrossReferenceConverter(); + DbReference xmlObj = converter.toXml(xref); + UniParcCrossReference converted = converter.fromXml(xmlObj); + assertEquals(xref, converted); + + } +} diff --git a/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverterTest.java b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverterTest.java index 4ed30c247..70bed5bd4 100644 --- a/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverterTest.java +++ b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcDBCrossReferenceConverterTest.java @@ -2,7 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.uniprot.core.xml.uniparc.UniParcDBCrossReferenceConverter.PROPERTY_UNIPROTKB_ACCESSION; +import static org.uniprot.core.xml.CrossReferenceConverterUtils.PROPERTY_UNIPROTKB_ACCESSION; import java.time.LocalDate; diff --git a/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcEntryLightConverterTest.java b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcEntryLightConverterTest.java new file mode 100644 index 000000000..5fe64e805 --- /dev/null +++ b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcEntryLightConverterTest.java @@ -0,0 +1,81 @@ +package org.uniprot.core.xml.uniparc; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.Location; +import org.uniprot.core.Sequence; +import org.uniprot.core.impl.SequenceBuilder; +import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.SequenceFeatureLocation; +import org.uniprot.core.uniparc.SignatureDbType; +import org.uniprot.core.uniparc.UniParcEntryLight; +import org.uniprot.core.uniparc.impl.InterProGroupBuilder; +import org.uniprot.core.uniparc.impl.SequenceFeatureBuilder; +import org.uniprot.core.uniparc.impl.SequenceFeatureLocationBuilder; +import org.uniprot.core.uniparc.impl.UniParcEntryLightBuilder; +import org.uniprot.core.xml.jaxb.uniparc.Entry; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class UniParcEntryLightConverterTest { + + @Test + void objectToXMLAndXMLToObjectTest() { + UniParcEntryLight uniParcEntryLight = createUniParcEntryLight(); + UniParcEntryLightConverter converter = new UniParcEntryLightConverter(); + Entry xmlObj = converter.toXml(uniParcEntryLight); + UniParcEntryLight converted = converter.fromXml(xmlObj); + assertEquals(uniParcEntryLight, converted); + } + + private UniParcEntryLight createUniParcEntryLight() { + UniParcEntryLightBuilder builder = new UniParcEntryLightBuilder(); + String sequenceStr = + "MALYSISKPVGSKINKHSYQDENTLVGKQALSKGTEKTKLSTNFEINLPRRTVLSDVSNV" + + "GKNNADEKDTKKAKRSFDESNLSTNEEADKPVESKFVKKLKVYSKNADPSVETLQKDRVS" + + "NVDDHLSSNPLMAEEYAPEIFEYIRKLDLKCLPNPKYMDQQKELTWKMREILNEWLVEIH" + + "SNFCLMPETLYLAVNIIDRFLSRRSCSLSKFQLTGITALLIASKYEEVMCPSIQNFVYMT" + + "DGAFTVEDVCVAERYMLNVLNFDLSYPSPLNFLRKISQAEGYDAQTRTLGKYLTEIYLFD" + + "HDLLRYPMSKIAAAAMYLSRRLLRRGPWTPKLVESSGGYEEHELKEIAYIMLHYHNKPLE" + + "HKAFFQKYSSKRFLKASIFVHQLVRQRYSVNRTDDDDLQSEPSSSLTNDGH"; + Sequence sequence = new SequenceBuilder(sequenceStr).build(); + List sfs = new ArrayList<>(); + SequenceFeatureBuilder sfBuilder = new SequenceFeatureBuilder(); + sfBuilder + .signatureDbType(SignatureDbType.PANTHER) + .signatureDbId("PTHR11977") + .locationsAdd(createSequenceFeatureLocationObject(49, 790, "component")) + .interproGroup( + new InterProGroupBuilder().id("IPR007122").name("Villin/Gelsolin").build()); + + SequenceFeatureBuilder sfBuilder2 = new SequenceFeatureBuilder(); + sfBuilder2 + .signatureDbType(SignatureDbType.PFAM) + .signatureDbId("PF00626") + .locationsAdd(createSequenceFeatureLocationObject(81, 163, "component")) + .locationsAdd(createSequenceFeatureLocationObject(202, 267, "component")) + .locationsAdd(createSequenceFeatureLocationObject(330, 398, "component")) + .locationsAdd(createSequenceFeatureLocationObject(586, 653, "component")) + .locationsAdd(createSequenceFeatureLocationObject(692, 766, "component")) + .interproGroup( + new InterProGroupBuilder() + .id("IPR007123") + .name("Gelsolin-like domain") + .build()); + sfs.add(sfBuilder.build()); + sfs.add(sfBuilder2.build()); + builder.uniParcId("UPI0000083A08") + .sequence(sequence) + .sequenceFeaturesSet(sfs); + return builder.build(); + } + + private SequenceFeatureLocation createSequenceFeatureLocationObject(int start, int end, String alignment){ + SequenceFeatureLocationBuilder builder = new SequenceFeatureLocationBuilder(); + builder.range(start, end); + builder.alignment(alignment); + return builder.build(); + } +}