Skip to content

Commit

Permalink
TRM-27505: Add reason for entry deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoGonzales committed Apr 23, 2024
1 parent a8324b8 commit c4e9010
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.uniprot.core.uniprotkb;

import org.uniprot.core.util.EnumDisplay;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;

public enum DeletedReason implements EnumDisplay {

UNKNOWN( "Unknown reason", 0, 4, 5, 7, 9, 12),
SOURCE_DELETION( "Sequence source deletion", 1, 6, 8, 11),
SWISSPROT_DELETION( "SwissProt deletion", 2),
REDUNDANCY( "Sequence redundancy", 3),
ENTRY_TYPE_CHANGE( "Entry type change", 10),
PROTEOME_REDUNDANCY( "Proteome Redundancy", 13),
PROTEOME_EXCLUSION( "Proteome Exclusion", 14),
OVERREPRESENTED( "Overrepresented sequence", 15);

private final List<Integer> ids;
private final String description;

DeletedReason(String description,Integer ... id) {
this.ids = Arrays.asList(id);
this.description = description;
}

@Nonnull
@Override
public String getName() {
return description;
}

public List<Integer> getIds() {
return ids;
}

public static DeletedReason fromId(String id) {
try {
return Arrays.stream(DeletedReason.values())
.filter(reason -> reason.getIds().contains(Integer.parseInt(id)))
.findFirst()
.orElseThrow();
} catch (Exception e) {
throw new IllegalArgumentException("The DeletedReason id '" + id + "' doesn't exist.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface EntryInactiveReason extends Serializable {
InactiveReasonType getInactiveReasonType();

List<String> getMergeDemergeTos();

DeletedReason getDeletedReason();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.annotation.Nonnull;

import org.uniprot.core.Builder;
import org.uniprot.core.uniprotkb.DeletedReason;
import org.uniprot.core.uniprotkb.EntryInactiveReason;
import org.uniprot.core.uniprotkb.InactiveReasonType;
import org.uniprot.core.util.Utils;
Expand All @@ -17,11 +18,18 @@ public class EntryInactiveReasonBuilder implements Builder<EntryInactiveReason>
private InactiveReasonType inactiveReasonType;
private List<String> mergeDemergeTos = new ArrayList<>();

private DeletedReason deletedReason;

public @Nonnull EntryInactiveReasonBuilder type(InactiveReasonType inactiveReasonType) {
this.inactiveReasonType = inactiveReasonType;
return this;
}

public @Nonnull EntryInactiveReasonBuilder deletedReason(DeletedReason deletedReason) {
this.deletedReason = deletedReason;
return this;
}

public @Nonnull EntryInactiveReasonBuilder mergeDemergeTosSet(List<String> mergeDemergeTo) {
this.mergeDemergeTos = modifiableList(mergeDemergeTo);
return this;
Expand All @@ -34,12 +42,13 @@ public class EntryInactiveReasonBuilder implements Builder<EntryInactiveReason>

@Override
public @Nonnull EntryInactiveReason build() {
return new EntryInactiveReasonImpl(inactiveReasonType, mergeDemergeTos);
return new EntryInactiveReasonImpl(inactiveReasonType, mergeDemergeTos, deletedReason);
}

public static @Nonnull EntryInactiveReasonBuilder from(@Nonnull EntryInactiveReason instance) {
return new EntryInactiveReasonBuilder()
.type(instance.getInactiveReasonType())
.mergeDemergeTosSet(instance.getMergeDemergeTos());
.mergeDemergeTosSet(instance.getMergeDemergeTos())
.deletedReason(instance.getDeletedReason());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.List;

import org.uniprot.core.uniprotkb.DeletedReason;
import org.uniprot.core.uniprotkb.EntryInactiveReason;
import org.uniprot.core.uniprotkb.InactiveReasonType;
import org.uniprot.core.util.Utils;
Expand All @@ -11,14 +12,16 @@ public class EntryInactiveReasonImpl implements EntryInactiveReason {
private static final long serialVersionUID = 1358481260367130982L;
private InactiveReasonType inactiveReasonType;
private List<String> mergeDemergeTo;
private DeletedReason deletedReason;

EntryInactiveReasonImpl() {
this.mergeDemergeTo = Collections.emptyList();
}

EntryInactiveReasonImpl(InactiveReasonType inactiveReasonType, List<String> mergeDemergeTo) {
EntryInactiveReasonImpl(InactiveReasonType inactiveReasonType, List<String> mergeDemergeTo, DeletedReason deletedReason) {
this.inactiveReasonType = inactiveReasonType;
this.mergeDemergeTo = Utils.unmodifiableList(mergeDemergeTo);
this.deletedReason = deletedReason;
}

@Override
Expand All @@ -31,13 +34,19 @@ public List<String> getMergeDemergeTos() {
return mergeDemergeTo;
}

@Override
public DeletedReason getDeletedReason() {
return deletedReason;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result =
prime * result + ((inactiveReasonType == null) ? 0 : inactiveReasonType.hashCode());
result = prime * result + ((mergeDemergeTo == null) ? 0 : mergeDemergeTo.hashCode());
result = prime * result + ((deletedReason == null) ? 0 : deletedReason.hashCode());
return result;
}

Expand All @@ -48,6 +57,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) return false;
EntryInactiveReasonImpl other = (EntryInactiveReasonImpl) obj;
if (inactiveReasonType != other.inactiveReasonType) return false;
if (deletedReason != other.deletedReason) return false;
return mergeDemergeTo.equals(other.mergeDemergeTo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.uniprot.core.uniprotkb;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class DeletedReasonTest {

@Test
void canGetIds() {
assertEquals(List.of(2), DeletedReason.SWISSPROT_DELETION.getIds());
}

@Test
void canGetName() {
assertEquals("Overrepresented sequence", DeletedReason.OVERREPRESENTED.getName());
}

@Test
void canGetFromIdWithValidSingleId() {
assertEquals(DeletedReason.PROTEOME_REDUNDANCY, DeletedReason.fromId("13"));
}

@Test
void canGetFromIdWithValidMultipleId() {
assertEquals(DeletedReason.SOURCE_DELETION, DeletedReason.fromId("8"));
}

@Test
void canGetFromIdWithInValidIdThrowsException() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> DeletedReason.fromId("99"));
assertEquals("The DeletedReason id '99' doesn't exist.", exception.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.uniprot.core.uniprotkb.DeletedReason;
import org.uniprot.core.uniprotkb.EntryInactiveReason;

class EntryInactiveReasonBuilderTest {
Expand All @@ -16,6 +17,16 @@ void canBuildWithMergeDemergeTo() {
assertEquals("merge", reason.getMergeDemergeTos().get(0));
}

@Test
void canBuildWithDeletedReason() {
DeletedReason deletedReason = DeletedReason.SWISSPROT_DELETION;
EntryInactiveReason reason = new EntryInactiveReasonBuilder()
.deletedReason(deletedReason)
.build();
assertNotNull(reason.getDeletedReason());
assertEquals(deletedReason, reason.getDeletedReason());
}

@Test
void canCreateBuilderFromInstance() {
EntryInactiveReason reason = new EntryInactiveReasonBuilder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Collections;

import org.junit.jupiter.api.Test;
import org.uniprot.core.uniprotkb.DeletedReason;
import org.uniprot.core.uniprotkb.EntryInactiveReason;
import org.uniprot.core.uniprotkb.InactiveReasonType;

Expand Down Expand Up @@ -35,12 +36,15 @@ void testEntryInactiveReasonImplMerge() {

@Test
void testEntryInactiveReasonImplDelete() {
DeletedReason deletedReason = DeletedReason.PROTEOME_REDUNDANCY;
EntryInactiveReason reason =
new EntryInactiveReasonBuilder()
.type(InactiveReasonType.DELETED)
.deletedReason(deletedReason)
.mergeDemergeTosSet(null)
.build();
assertEquals(InactiveReasonType.DELETED, reason.getInactiveReasonType());
assertEquals(deletedReason, reason.getDeletedReason());
assertTrue(reason.getMergeDemergeTos().isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
/** @author lgonzales */
public class UniProtKBEntryIT {

private static Logger logger = LoggerFactory.getLogger(UniProtKBEntryIT.class);
private static final Logger logger = LoggerFactory.getLogger(UniProtKBEntryIT.class);

@Test
void testInactiveUniProtEntryComplete() {
EntryInactiveReason inactiveReason =
new EntryInactiveReasonBuilder()
.type(InactiveReasonType.MERGED)
.deletedReason(DeletedReason.SWISSPROT_DELETION)
.mergeDemergeTosAdd("merge id")
.build();

Expand Down

0 comments on commit c4e9010

Please sign in to comment.