diff --git a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantMasks.java b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantMasks.java index abe9e04d..5647b613 100644 --- a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantMasks.java +++ b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantMasks.java @@ -2,11 +2,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import java.io.Serializable; import java.math.BigInteger; +import java.util.Objects; public class VariantMasks implements Serializable { private static final long serialVersionUID = 6225420483804601477L; @@ -174,20 +176,73 @@ public VariantMasks(char[][] maskValues) { public VariantMasks() { } + + public BigInteger homozygousMask; + + public BigInteger heterozygousMask; + + public BigInteger homozygousNoCallMask; + + public BigInteger heterozygousNoCallMask; + + @JsonProperty("ho") @JsonInclude(JsonInclude.Include.NON_NULL) @JsonSerialize(using = ToStringSerializer.class) - public BigInteger homozygousMask; + public BigInteger getHomozygousMask() { + return homozygousMask; + } + + @JsonProperty("ho") + public void setHomozygousMask(String homozygousMask) { + this.homozygousMask = new BigInteger(homozygousMask); + } + @JsonProperty("he") @JsonSerialize(using = ToStringSerializer.class) @JsonInclude(JsonInclude.Include.NON_NULL) - public BigInteger heterozygousMask; + public BigInteger getHeterozygousMask() { + return heterozygousMask; + } + @JsonProperty("he") + public void setHeterozygousMask(String heterozygousMask) { + this.heterozygousMask = new BigInteger(heterozygousMask); + } + @JsonProperty("hon") @JsonSerialize(using = ToStringSerializer.class) @JsonInclude(JsonInclude.Include.NON_NULL) - public BigInteger homozygousNoCallMask; + public BigInteger getHomozygousNoCallMask() { + return homozygousNoCallMask; + } + + @JsonProperty("hon") + public void setHomozygousNoCallMask(String homozygousNoCallMask) { + this.homozygousNoCallMask = new BigInteger(homozygousNoCallMask); + } + @JsonProperty("hen") @JsonSerialize(using = ToStringSerializer.class) @JsonInclude(JsonInclude.Include.NON_NULL) - public BigInteger heterozygousNoCallMask; + public BigInteger getHeterozygousNoCallMask() { + return heterozygousNoCallMask; + } + @JsonProperty("hen") + public void setHeterozygousNoCallMask(String heterozygousNoCallMask) { + this.heterozygousNoCallMask = new BigInteger(heterozygousNoCallMask); + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + VariantMasks that = (VariantMasks) o; + return Objects.equals(homozygousMask, that.homozygousMask) && Objects.equals(heterozygousMask, that.heterozygousMask) && Objects.equals(homozygousNoCallMask, that.homozygousNoCallMask) && Objects.equals(heterozygousNoCallMask, that.heterozygousNoCallMask); + } + + @Override + public int hashCode() { + return Objects.hash(homozygousMask, heterozygousMask, homozygousNoCallMask, heterozygousNoCallMask); + } } diff --git a/data/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantMasksSerializationTest.java b/data/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantMasksSerializationTest.java new file mode 100644 index 00000000..d3b12fc2 --- /dev/null +++ b/data/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantMasksSerializationTest.java @@ -0,0 +1,48 @@ +package edu.harvard.hms.dbmi.avillach.hpds.data.genotype; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.concurrent.ThreadLocalRandom; + +import static org.junit.jupiter.api.Assertions.*; + +public class VariantMasksSerializationTest { + + @Test + public void testFieldMaxLength() throws JsonProcessingException { + VariantMasks variantMasks = new VariantMasks(); + + StringBuilder homozygousStr = new StringBuilder(); + for (int i = 0 ; i < 5000; i++) { + homozygousStr.append(ThreadLocalRandom.current().nextInt(0, 10)); + } + variantMasks.homozygousMask = new BigInteger(homozygousStr.toString()); + + StringBuilder heterozygousStr = new StringBuilder(); + for (int i = 0 ; i < 5000; i++) { + heterozygousStr.append(ThreadLocalRandom.current().nextInt(0, 10)); + } + variantMasks.heterozygousMask = new BigInteger(heterozygousStr.toString()); + + StringBuilder homozygousNoCallStr = new StringBuilder(); + for (int i = 0 ; i < 5000; i++) { + homozygousNoCallStr.append(ThreadLocalRandom.current().nextInt(0, 10)); + } + variantMasks.homozygousNoCallMask = new BigInteger(homozygousNoCallStr.toString()); + + StringBuilder heterozygousNoCallStr = new StringBuilder(); + for (int i = 0 ; i < 5000; i++) { + heterozygousNoCallStr.append(ThreadLocalRandom.current().nextInt(0, 10)); + } + variantMasks.heterozygousNoCallMask = new BigInteger(heterozygousNoCallStr.toString()); + + ObjectMapper objectMapper = new ObjectMapper(); + String serialized = objectMapper.writeValueAsString(variantMasks); + VariantMasks deserialized = objectMapper.readValue(serialized, VariantMasks.class); + + assertEquals(variantMasks, deserialized); + } +}