diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/SequenceFeature.java b/core-domain/src/main/java/org/uniprot/core/uniparc/SequenceFeature.java index d4b2add93..065388a9a 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniparc/SequenceFeature.java +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/SequenceFeature.java @@ -3,8 +3,6 @@ import java.io.Serializable; import java.util.List; -import org.uniprot.core.Location; - /** * @author jluo * @date: 22 May 2019 @@ -16,5 +14,5 @@ public interface SequenceFeature extends Serializable { String getSignatureDbId(); - List getLocations(); + List getLocations(); } diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/SequenceFeatureLocation.java b/core-domain/src/main/java/org/uniprot/core/uniparc/SequenceFeatureLocation.java new file mode 100644 index 000000000..dde2de0b0 --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/SequenceFeatureLocation.java @@ -0,0 +1,11 @@ +package org.uniprot.core.uniparc; + +import java.io.Serializable; + +public interface SequenceFeatureLocation extends Serializable { + int getStart(); + + int getEnd(); + + String getAlignment(); +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/SignatureDbType.java b/core-domain/src/main/java/org/uniprot/core/uniparc/SignatureDbType.java index e02c1dc7b..6635303d0 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniparc/SignatureDbType.java +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/SignatureDbType.java @@ -1,9 +1,9 @@ package org.uniprot.core.uniparc; -import javax.annotation.Nonnull; - import org.uniprot.core.util.EnumDisplay; +import javax.annotation.Nonnull; + public enum SignatureDbType implements EnumDisplay { CDD("CDD"), GENE3D("Gene3D"), @@ -16,7 +16,8 @@ public enum SignatureDbType implements EnumDisplay { SFLD("SFLD"), SMART("SMART"), SUPFAM("SUPFAM"), - NCBIFAM("NCBIfam"); + NCBIFAM("NCBIfam"), + FUNFAM("FUNFAM"); private final String name; diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilder.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilder.java index 9d84711af..3fbf633ed 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilder.java +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilder.java @@ -6,9 +6,9 @@ import javax.annotation.Nonnull; import org.uniprot.core.Builder; -import org.uniprot.core.Location; import org.uniprot.core.uniparc.InterProGroup; import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.SequenceFeatureLocation; import org.uniprot.core.uniparc.SignatureDbType; import org.uniprot.core.util.Utils; @@ -20,7 +20,7 @@ public class SequenceFeatureBuilder implements Builder { private InterProGroup interproGroup; private SignatureDbType dbType; private String dbId; - private List locations = new ArrayList<>(); + private List locations = new ArrayList<>(); @Override public @Nonnull SequenceFeature build() { @@ -42,12 +42,12 @@ public class SequenceFeatureBuilder implements Builder { return this; } - public @Nonnull SequenceFeatureBuilder locationsSet(List locations) { + public @Nonnull SequenceFeatureBuilder locationsSet(List locations) { this.locations = Utils.modifiableList(locations); return this; } - public @Nonnull SequenceFeatureBuilder locationsAdd(Location location) { + public @Nonnull SequenceFeatureBuilder locationsAdd(SequenceFeatureLocation location) { Utils.addOrIgnoreNull(location, locations); return this; } diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureImpl.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureImpl.java index 3c1381689..723d2e64d 100644 --- a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureImpl.java +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureImpl.java @@ -4,9 +4,9 @@ import java.util.List; import java.util.Objects; -import org.uniprot.core.Location; import org.uniprot.core.uniparc.InterProGroup; import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.SequenceFeatureLocation; import org.uniprot.core.uniparc.SignatureDbType; import org.uniprot.core.util.Utils; @@ -17,19 +17,19 @@ public class SequenceFeatureImpl implements SequenceFeature { /** */ - private static final long serialVersionUID = -8511912268843073779L; + private static final long serialVersionUID = 5234475851615797849L; private InterProGroup interproGroup; private SignatureDbType database; private String databaseId; - private List locations; + private List locations; SequenceFeatureImpl() { this.locations = Collections.emptyList(); } SequenceFeatureImpl( - InterProGroup domain, SignatureDbType dbType, String dbId, List locations) { + InterProGroup domain, SignatureDbType dbType, String dbId, List locations) { super(); this.interproGroup = domain; this.database = dbType; @@ -53,7 +53,7 @@ public String getSignatureDbId() { } @Override - public List getLocations() { + public List getLocations() { return locations; } diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationBuilder.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationBuilder.java new file mode 100644 index 000000000..99c64fe6d --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationBuilder.java @@ -0,0 +1,47 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.Builder; +import org.uniprot.core.uniparc.SequenceFeatureLocation; + +import javax.annotation.Nonnull; + +public class SequenceFeatureLocationBuilder implements Builder { + + private int start; + private int end; + private String alignment; + + @Nonnull + @Override + public SequenceFeatureLocation build() { + return new SequenceFeatureLocationImpl(start,end,alignment); + } + + public @Nonnull SequenceFeatureLocationBuilder range(int start, int end) { + this.start = start; + this.end = end; + return this; + } + + public @Nonnull SequenceFeatureLocationBuilder start(int start) { + this.start = start; + return this; + } + + public @Nonnull SequenceFeatureLocationBuilder end(int end) { + this.end = end; + return this; + } + + public @Nonnull SequenceFeatureLocationBuilder alignment(String alignment) { + this.alignment = alignment; + return this; + } + + public static @Nonnull SequenceFeatureLocationBuilder from(@Nonnull SequenceFeatureLocation instance) { + return new SequenceFeatureLocationBuilder() + .start(instance.getStart()) + .end(instance.getEnd()) + .alignment(instance.getAlignment()); + } +} diff --git a/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationImpl.java b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationImpl.java new file mode 100644 index 000000000..e65cd3e53 --- /dev/null +++ b/core-domain/src/main/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationImpl.java @@ -0,0 +1,41 @@ +package org.uniprot.core.uniparc.impl; + +import org.uniprot.core.Location; +import org.uniprot.core.uniparc.SequenceFeatureLocation; + +import java.util.Objects; + +public class SequenceFeatureLocationImpl extends Location implements SequenceFeatureLocation{ + + private static final long serialVersionUID = -4804406936471873484L; + private String alignment; + + SequenceFeatureLocationImpl(){ + super(0, 0); + } + + SequenceFeatureLocationImpl(int start, int end, String alignment) { + super(start, end); + this.alignment = alignment; + } + + @Override + public String getAlignment() { + return alignment; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + SequenceFeatureLocationImpl that = (SequenceFeatureLocationImpl) o; + return Objects.equals(alignment, that.alignment); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), alignment); + } +} diff --git a/core-domain/src/test/java/org/uniprot/core/ObjectsForTests.java b/core-domain/src/test/java/org/uniprot/core/ObjectsForTests.java index 7db087922..020cb1edb 100644 --- a/core-domain/src/test/java/org/uniprot/core/ObjectsForTests.java +++ b/core-domain/src/test/java/org/uniprot/core/ObjectsForTests.java @@ -29,6 +29,7 @@ import org.uniprot.core.uniparc.*; 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.UniParcCrossReferenceBuilder; import org.uniprot.core.uniprotkb.comment.*; import org.uniprot.core.uniprotkb.comment.impl.*; @@ -223,7 +224,7 @@ public static List createEvidenceValuesWithEvidences() { } public static List sequenceFeatures() { - List locations = Arrays.asList(new Location(12, 23), new Location(45, 89)); + 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(); SequenceFeature sf = new SequenceFeatureBuilder() diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilderTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilderTest.java index 7ad39d368..3ba44fc9d 100644 --- a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilderTest.java +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureBuilderTest.java @@ -6,9 +6,9 @@ import java.util.List; import org.junit.jupiter.api.Test; -import org.uniprot.core.Location; import org.uniprot.core.uniparc.InterProGroup; import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.SequenceFeatureLocation; import org.uniprot.core.uniparc.SignatureDbType; /** @@ -52,7 +52,7 @@ void testSignatureDbId() { @Test void testLocations() { - List locations = Arrays.asList(new Location(12, 23), new Location(45, 89)); + 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(); SequenceFeature sf = new SequenceFeatureBuilder() @@ -69,7 +69,7 @@ void testLocations() { @Test void testAddLocation() { - List locations = Arrays.asList(new Location(12, 23), new Location(45, 89)); + 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(); SequenceFeature sf = new SequenceFeatureBuilder() @@ -77,7 +77,7 @@ void testAddLocation() { .signatureDbType(SignatureDbType.PFAM) .signatureDbId("sigId2") .locationsSet(locations) - .locationsAdd(new Location(100, 300)) + .locationsAdd(new SequenceFeatureLocationBuilder().range(100, 300).build()) .build(); assertEquals(domain, sf.getInterProDomain()); assertEquals(SignatureDbType.PFAM, sf.getSignatureDbType()); @@ -87,7 +87,7 @@ void testAddLocation() { @Test void testFrom() { - List locations = Arrays.asList(new Location(12, 23), new Location(45, 89)); + 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(); SequenceFeature sf = new SequenceFeatureBuilder() diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationBuilderTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationBuilderTest.java new file mode 100644 index 000000000..d954f31d0 --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationBuilderTest.java @@ -0,0 +1,55 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.Property; +import org.uniprot.core.uniparc.SequenceFeatureLocation; +import org.uniprot.core.uniparc.UniParcCrossReference; +import org.uniprot.core.uniparc.UniParcDatabase; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class SequenceFeatureLocationBuilderTest { + @Test + void testStart() { + int start = 10; + SequenceFeatureLocation location = + new SequenceFeatureLocationBuilder().start(start).build(); + assertEquals(start, location.getStart()); + } + + @Test + void testEnd() { + int end = 20; + SequenceFeatureLocation location = + new SequenceFeatureLocationBuilder().end(end).build(); + assertEquals(end, location.getEnd()); + } + + @Test + void testRange() { + int start = 10; + int end = 20; + SequenceFeatureLocation location = + new SequenceFeatureLocationBuilder().range(start, end).build(); + assertEquals(start, location.getStart()); + assertEquals(end, location.getEnd()); + } + + @Test + void testAlignment() { + String alignment = "M55"; + SequenceFeatureLocation location = + new SequenceFeatureLocationBuilder().alignment(alignment).build(); + assertEquals(alignment, location.getAlignment()); + } + @Test + void testFromSequenceFeatureLocation() { + SequenceFeatureLocation location = new SequenceFeatureLocationImpl(10, 20, "VALUE"); + SequenceFeatureLocation fromLocation = SequenceFeatureLocationBuilder.from(location).build(); + assertEquals(location, fromLocation); + } +} \ No newline at end of file diff --git a/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationImplTest.java b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationImplTest.java new file mode 100644 index 000000000..0c2289a25 --- /dev/null +++ b/core-domain/src/test/java/org/uniprot/core/uniparc/impl/SequenceFeatureLocationImplTest.java @@ -0,0 +1,30 @@ +package org.uniprot.core.uniparc.impl; + +import org.junit.jupiter.api.Test; +import org.uniprot.core.uniparc.SequenceFeatureLocation; +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 static org.junit.jupiter.api.Assertions.*; + +class SequenceFeatureLocationImplTest { + + @Test + void needDefaultConstructorForJsonDeserialization() { + SequenceFeatureLocation obj = new SequenceFeatureLocationImpl(); + assertNotNull(obj); + } + + @Test + void builderFrom_constructorImp_shouldCreate_equalObject() { + SequenceFeatureLocationImpl impl = + new SequenceFeatureLocationImpl(10,20, "component"); + SequenceFeatureLocation obj = SequenceFeatureLocationBuilder.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-parser/src/test/java/org/uniprot/core/parser/fasta/UniParcFastaParserTest.java b/core-parser/src/test/java/org/uniprot/core/parser/fasta/UniParcFastaParserTest.java index cfbdcbcf7..9c7151dc1 100644 --- a/core-parser/src/test/java/org/uniprot/core/parser/fasta/UniParcFastaParserTest.java +++ b/core-parser/src/test/java/org/uniprot/core/parser/fasta/UniParcFastaParserTest.java @@ -8,17 +8,12 @@ import java.util.List; import org.junit.jupiter.api.Test; -import org.uniprot.core.Location; import org.uniprot.core.Property; import org.uniprot.core.Sequence; import org.uniprot.core.impl.SequenceBuilder; import org.uniprot.core.uniparc.*; import org.uniprot.core.uniparc.UniParcCrossReference; -import org.uniprot.core.uniparc.impl.InterProGroupBuilder; -import org.uniprot.core.uniparc.impl.SequenceFeatureBuilder; -import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; -import org.uniprot.core.uniparc.impl.UniParcEntryBuilder; -import org.uniprot.core.uniparc.impl.UniParcIdBuilder; +import org.uniprot.core.uniparc.impl.*; import org.uniprot.core.uniprotkb.taxonomy.Organism; import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; @@ -57,7 +52,7 @@ private UniParcEntry create() { } private List getSeqFeatures() { - List locations = Arrays.asList(new Location(12, 23), new Location(45, 89)); + 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(); SequenceFeature sf = new SequenceFeatureBuilder() 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 39d4eab0b..1bafde168 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 @@ -9,17 +9,12 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import org.uniprot.core.Location; import org.uniprot.core.Property; import org.uniprot.core.Sequence; import org.uniprot.core.impl.SequenceBuilder; import org.uniprot.core.uniparc.*; import org.uniprot.core.uniparc.UniParcDatabase; -import org.uniprot.core.uniparc.impl.InterProGroupBuilder; -import org.uniprot.core.uniparc.impl.SequenceFeatureBuilder; -import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; -import org.uniprot.core.uniparc.impl.UniParcEntryBuilder; -import org.uniprot.core.uniparc.impl.UniParcIdBuilder; +import org.uniprot.core.uniparc.impl.*; import org.uniprot.core.uniprotkb.taxonomy.Organism; import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; @@ -118,7 +113,7 @@ private UniParcEntry create() { } private List getSeqFeatures() { - List locations = Arrays.asList(new Location(12, 23), new Location(45, 89)); + 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(); SequenceFeature sf = new SequenceFeatureBuilder() diff --git a/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcJsonConfig.java b/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcJsonConfig.java index e0437e4b5..cfe169133 100644 --- a/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcJsonConfig.java +++ b/json-parser/src/main/java/org/uniprot/core/json/parser/uniparc/UniParcJsonConfig.java @@ -13,11 +13,7 @@ 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.InterProGroup; -import org.uniprot.core.uniparc.SequenceFeature; -import org.uniprot.core.uniparc.UniParcCrossReference; -import org.uniprot.core.uniparc.UniParcEntry; -import org.uniprot.core.uniparc.UniParcId; +import org.uniprot.core.uniparc.*; import org.uniprot.core.uniparc.impl.*; import org.uniprot.core.uniparc.impl.UniParcCrossReferenceImpl; import org.uniprot.core.uniprotkb.evidence.Evidence; @@ -69,6 +65,7 @@ private ObjectMapper initObjectMapper() { mod.addAbstractTypeMapping(UniParcEntry.class, UniParcEntryImpl.class); mod.addAbstractTypeMapping(InterProGroup.class, InterProGroupImpl.class); mod.addAbstractTypeMapping(SequenceFeature.class, SequenceFeatureImpl.class); + mod.addAbstractTypeMapping(SequenceFeatureLocation.class, SequenceFeatureLocationImpl.class); mod.addAbstractTypeMapping(Organism.class, OrganismImpl.class); mod.addAbstractTypeMapping(Evidence.class, EvidenceImpl.class); mod.addAbstractTypeMapping(UniParcCrossReference.class, UniParcCrossReferenceImpl.class); diff --git a/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/SequenceFeatureTest.java b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/SequenceFeatureTest.java index 9b7bf6372..f4aeb566b 100644 --- a/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/SequenceFeatureTest.java +++ b/json-parser/src/test/java/org/uniprot/core/json/parser/uniparc/SequenceFeatureTest.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; -import org.uniprot.core.Location; import org.uniprot.core.json.parser.ValidateJson; import org.uniprot.core.uniparc.InterProGroup; import org.uniprot.core.uniparc.SequenceFeature; @@ -12,6 +11,7 @@ import org.uniprot.core.uniparc.impl.SequenceFeatureBuilder; import com.fasterxml.jackson.databind.ObjectMapper; +import org.uniprot.core.uniparc.impl.SequenceFeatureLocationBuilder; /** * @author jluo @@ -40,11 +40,11 @@ void testSequenceFeature() { SequenceFeatureBuilder builder = new SequenceFeatureBuilder(); builder.signatureDbType(SignatureDbType.PFAM) .signatureDbId("PF00626") - .locationsAdd(new Location(81, 163)) - .locationsAdd(new Location(202, 267)) - .locationsAdd(new Location(330, 398)) - .locationsAdd(new Location(586, 653)) - .locationsAdd(new Location(692, 766)) + .locationsAdd(new SequenceFeatureLocationBuilder().range(81, 163).alignment("81M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(202, 267).alignment("202M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(330, 398).alignment("81M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(586, 653).alignment("586M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(692, 766).alignment("81M").build()) .interproGroup( new InterProGroupBuilder() .id("IPR007123") 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 5ddca7fb8..610068d03 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 @@ -8,17 +8,13 @@ import java.util.List; import org.junit.jupiter.api.Test; -import org.uniprot.core.Location; 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.impl.InterProGroupBuilder; -import org.uniprot.core.uniparc.impl.SequenceFeatureBuilder; -import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; -import org.uniprot.core.uniparc.impl.UniParcEntryBuilder; +import org.uniprot.core.uniparc.impl.*; import org.uniprot.core.uniprotkb.evidence.Evidence; import org.uniprot.core.uniprotkb.taxonomy.Organism; import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; @@ -125,7 +121,7 @@ private static SequenceFeature getSeqFeature(SignatureDbType signatureType) { return new SequenceFeatureBuilder() .signatureDbType(signatureType) .signatureDbId("id-" + signatureType) - .locationsAdd(new Location(81, 163)) + .locationsAdd(new SequenceFeatureLocationBuilder().range(81, 163).alignment("48M").build()) .interproGroup( new InterProGroupBuilder() .id("IPR007123") diff --git a/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverter.java b/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverter.java index 3658343df..ca139d41e 100644 --- a/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverter.java +++ b/xml-parser/src/main/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverter.java @@ -2,12 +2,13 @@ import java.util.stream.Collectors; -import org.uniprot.core.Location; import org.uniprot.core.uniparc.InterProGroup; import org.uniprot.core.uniparc.SequenceFeature; +import org.uniprot.core.uniparc.SequenceFeatureLocation; import org.uniprot.core.uniparc.SignatureDbType; 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.xml.Converter; import org.uniprot.core.xml.jaxb.uniparc.LocationType; import org.uniprot.core.xml.jaxb.uniparc.ObjectFactory; @@ -36,13 +37,15 @@ public SequenceFeatureConverter(ObjectFactory xmlFactory) { @Override public SequenceFeature fromXml(SeqFeatureType xmlObj) { SequenceFeatureBuilder builder = new SequenceFeatureBuilder(); - builder.interproGroup(interproGroupConverter.fromXml(xmlObj.getIpr())) - .signatureDbType(SignatureDbType.typeOf(xmlObj.getDatabase())) + builder.signatureDbType(SignatureDbType.typeOf(xmlObj.getDatabase())) .signatureDbId(xmlObj.getId()) .locationsSet( xmlObj.getLcn().stream() .map(locationConverter::fromXml) .collect(Collectors.toList())); + if(xmlObj.getIpr() != null){ + builder.interproGroup(interproGroupConverter.fromXml(xmlObj.getIpr())); + } return builder.build(); } @@ -52,7 +55,9 @@ public SeqFeatureType toXml(SequenceFeature uniObj) { SeqFeatureType xmlObj = xmlFactory.createSeqFeatureType(); xmlObj.setDatabase(uniObj.getSignatureDbType().getDisplayName()); xmlObj.setId(uniObj.getSignatureDbId()); - xmlObj.setIpr(interproGroupConverter.toXml(uniObj.getInterProDomain())); + if(uniObj.getInterProDomain() != null) { + xmlObj.setIpr(interproGroupConverter.toXml(uniObj.getInterProDomain())); + } uniObj.getLocations().stream() .map(locationConverter::toXml) @@ -81,7 +86,7 @@ public SeqFeatureGroupType toXml(InterProGroup uniObj) { } } - class LocationConverter implements Converter { + class LocationConverter implements Converter { private final ObjectFactory xmlFactory; LocationConverter(ObjectFactory xmlFactory) { @@ -89,15 +94,23 @@ class LocationConverter implements Converter { } @Override - public Location fromXml(LocationType xmlObj) { - return new Location(xmlObj.getStart(), xmlObj.getEnd()); + public SequenceFeatureLocation fromXml(LocationType xmlObj) { + SequenceFeatureLocationBuilder builder = new SequenceFeatureLocationBuilder(); + builder.range(xmlObj.getStart(), xmlObj.getEnd()); + if (xmlObj.getAlignment() != null) { + builder.alignment(xmlObj.getAlignment()); + } + return builder.build(); } @Override - public LocationType toXml(Location uniObj) { + public LocationType toXml(SequenceFeatureLocation uniObj) { LocationType xmlObj = xmlFactory.createLocationType(); xmlObj.setStart(uniObj.getStart()); xmlObj.setEnd(uniObj.getEnd()); + if (uniObj.getAlignment() != null) { + xmlObj.setAlignment(uniObj.getAlignment()); + } return xmlObj; } } diff --git a/xml-parser/src/main/resources/xsd/uniparc.xsd b/xml-parser/src/main/resources/xsd/uniparc.xsd index e7efa3628..eebd1cbcb 100644 --- a/xml-parser/src/main/resources/xsd/uniparc.xsd +++ b/xml-parser/src/main/resources/xsd/uniparc.xsd @@ -82,6 +82,7 @@ + diff --git a/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverterTest.java b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverterTest.java index 0c8c8d2f9..3c69c6a14 100644 --- a/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverterTest.java +++ b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/SequenceFeatureConverterTest.java @@ -3,11 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; -import org.uniprot.core.Location; import org.uniprot.core.uniparc.SequenceFeature; import org.uniprot.core.uniparc.SignatureDbType; 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.xml.jaxb.uniparc.SeqFeatureType; /** @@ -25,7 +25,22 @@ void testSingleLocation() { SequenceFeatureBuilder builder = new SequenceFeatureBuilder(); builder.signatureDbType(SignatureDbType.PANTHER) .signatureDbId("PTHR11977") - .locationsAdd(new Location(49, 790)) + .locationsAdd(new SequenceFeatureLocationBuilder().range(49, 790).build()) + .interproGroup( + new InterProGroupBuilder().id("IPR007122").name("Villin/Gelsolin").build()); + verify(builder.build()); + } + + @Test + void testSingleLocationWithAlignment() { + // + // + // + // + SequenceFeatureBuilder builder = new SequenceFeatureBuilder(); + builder.signatureDbType(SignatureDbType.PANTHER) + .signatureDbId("PTHR11977") + .locationsAdd(new SequenceFeatureLocationBuilder().range(49, 790).alignment("55M").build()) .interproGroup( new InterProGroupBuilder().id("IPR007122").name("Villin/Gelsolin").build()); verify(builder.build()); @@ -54,11 +69,11 @@ void testMultiLocations() { SequenceFeatureBuilder builder = new SequenceFeatureBuilder(); builder.signatureDbType(SignatureDbType.PFAM) .signatureDbId("PF00626") - .locationsAdd(new Location(81, 163)) - .locationsAdd(new Location(202, 267)) - .locationsAdd(new Location(330, 398)) - .locationsAdd(new Location(586, 653)) - .locationsAdd(new Location(692, 766)) + .locationsAdd(new SequenceFeatureLocationBuilder().range(81, 163).build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(202, 267).alignment("21M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(330, 398).build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(586, 653).alignment("55M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(692, 766).build()) .interproGroup( new InterProGroupBuilder() .id("IPR007123") diff --git a/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcEntryConverterTest.java b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcEntryConverterTest.java index 3a39a9cc7..437126411 100644 --- a/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcEntryConverterTest.java +++ b/xml-parser/src/test/java/org/uniprot/core/xml/uniparc/UniParcEntryConverterTest.java @@ -7,15 +7,11 @@ import java.util.List; 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.*; import org.uniprot.core.uniparc.UniParcDatabase; -import org.uniprot.core.uniparc.impl.InterProGroupBuilder; -import org.uniprot.core.uniparc.impl.SequenceFeatureBuilder; -import org.uniprot.core.uniparc.impl.UniParcCrossReferenceBuilder; -import org.uniprot.core.uniparc.impl.UniParcEntryBuilder; +import org.uniprot.core.uniparc.impl.*; import org.uniprot.core.uniprotkb.taxonomy.Organism; import org.uniprot.core.uniprotkb.taxonomy.impl.OrganismBuilder; import org.uniprot.core.xml.jaxb.uniparc.Entry; @@ -52,7 +48,7 @@ private UniParcEntry createEntry() { sfBuilder .signatureDbType(SignatureDbType.PANTHER) .signatureDbId("PTHR11977") - .locationsAdd(new Location(49, 790)) + .locationsAdd(new SequenceFeatureLocationBuilder().range(49, 790).build()) .interproGroup( new InterProGroupBuilder().id("IPR007122").name("Villin/Gelsolin").build()); @@ -60,16 +56,11 @@ private UniParcEntry createEntry() { sfBuilder2 .signatureDbType(SignatureDbType.PFAM) .signatureDbId("PF00626") - .locationsAdd(new Location(81, 163)) - .locationsAdd(new Location(202, 267)) - .locationsAdd(new Location(330, 398)) - .locationsAdd(new Location(586, 653)) - .locationsAdd(new Location(692, 766)) - .interproGroup( - new InterProGroupBuilder() - .id("IPR007123") - .name("Gelsolin-like domain") - .build()); + .locationsAdd(new SequenceFeatureLocationBuilder().range(81, 163).build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(202, 267).alignment("22M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(330, 398).build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(586, 653).alignment("57M").build()) + .locationsAdd(new SequenceFeatureLocationBuilder().range(692, 766).build()); sfs.add(sfBuilder.build()); sfs.add(sfBuilder2.build()); builder.uniParcId("UPI0000083A08")