Skip to content

Commit

Permalink
Fix VariantMask serialization bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Jan 4, 2024
1 parent 57499ea commit bf5e6f5
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit bf5e6f5

Please sign in to comment.