Skip to content

Commit

Permalink
Merge pull request #240 from ebi-uniprot/2024_05
Browse files Browse the repository at this point in the history
2024 05
  • Loading branch information
supun-ebi authored Sep 11, 2024
2 parents dc53bfa + 71e8458 commit 6d50b9e
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.io.Serializable;
import java.util.List;

import org.uniprot.core.Location;

/**
* @author jluo
* @date: 22 May 2019
Expand All @@ -16,5 +14,5 @@ public interface SequenceFeature extends Serializable {

String getSignatureDbId();

List<Location> getLocations();
List<SequenceFeatureLocation> getLocations();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.uniprot.core.uniparc;

import java.io.Serializable;

public interface SequenceFeatureLocation extends Serializable {
int getStart();

int getEnd();

String getAlignment();
}
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,7 +20,7 @@ public class SequenceFeatureBuilder implements Builder<SequenceFeature> {
private InterProGroup interproGroup;
private SignatureDbType dbType;
private String dbId;
private List<Location> locations = new ArrayList<>();
private List<SequenceFeatureLocation> locations = new ArrayList<>();

@Override
public @Nonnull SequenceFeature build() {
Expand All @@ -42,12 +42,12 @@ public class SequenceFeatureBuilder implements Builder<SequenceFeature> {
return this;
}

public @Nonnull SequenceFeatureBuilder locationsSet(List<Location> locations) {
public @Nonnull SequenceFeatureBuilder locationsSet(List<SequenceFeatureLocation> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Location> locations;
private List<SequenceFeatureLocation> locations;

SequenceFeatureImpl() {
this.locations = Collections.emptyList();
}

SequenceFeatureImpl(
InterProGroup domain, SignatureDbType dbType, String dbId, List<Location> locations) {
InterProGroup domain, SignatureDbType dbType, String dbId, List<SequenceFeatureLocation> locations) {
super();
this.interproGroup = domain;
this.database = dbType;
Expand All @@ -53,7 +53,7 @@ public String getSignatureDbId() {
}

@Override
public List<Location> getLocations() {
public List<SequenceFeatureLocation> getLocations() {
return locations;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<SequenceFeatureLocation> {

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());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -223,7 +224,7 @@ public static List<EvidencedValue> createEvidenceValuesWithEvidences() {
}

public static List<SequenceFeature> sequenceFeatures() {
List<Location> locations = Arrays.asList(new Location(12, 23), new Location(45, 89));
List<SequenceFeatureLocation> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ void testSignatureDbId() {

@Test
void testLocations() {
List<Location> locations = Arrays.asList(new Location(12, 23), new Location(45, 89));
List<SequenceFeatureLocation> 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()
Expand All @@ -69,15 +69,15 @@ void testLocations() {

@Test
void testAddLocation() {
List<Location> locations = Arrays.asList(new Location(12, 23), new Location(45, 89));
List<SequenceFeatureLocation> 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()
.interproGroup(domain)
.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());
Expand All @@ -87,7 +87,7 @@ void testAddLocation() {

@Test
void testFrom() {
List<Location> locations = Arrays.asList(new Location(12, 23), new Location(45, 89));
List<SequenceFeatureLocation> 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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -57,7 +52,7 @@ private UniParcEntry create() {
}

private List<SequenceFeature> getSeqFeatures() {
List<Location> locations = Arrays.asList(new Location(12, 23), new Location(45, 89));
List<SequenceFeatureLocation> 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()
Expand Down
Loading

0 comments on commit 6d50b9e

Please sign in to comment.