diff --git a/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyData.java b/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyData.java index 6c11dd277..8b3cb47da 100644 --- a/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyData.java +++ b/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyData.java @@ -324,7 +324,7 @@ public float maxFreq() { @JsonIgnore @Nullable public Frequency maxFrequency() { - return this.size == 0 ? null : frequency(maxSource); + return maxSource == -1 ? null : frequency(maxSource); } /** @@ -454,10 +454,11 @@ public Builder addFrequency(FrequencySource frequencySource, int ac, int an, int */ private Builder addFrequency(FrequencySource frequencySource, float frequency, int ac, int an, int homCount) { frequencySources[frequencySource.ordinal()] = frequencySource; - frequencyData[frequencySource.ordinal() * WORD_SIZE + FREQ_OFFSET] = frequency; - frequencyData[frequencySource.ordinal() * WORD_SIZE + AC_OFFSET] = ac; - frequencyData[frequencySource.ordinal() * WORD_SIZE + AN_OFFSET] = an; - frequencyData[frequencySource.ordinal() * WORD_SIZE + HOM_OFFSET] = homCount; + int freqIndex = frequencySource.ordinal() * WORD_SIZE; + frequencyData[freqIndex + FREQ_OFFSET] = frequency; + frequencyData[freqIndex + AC_OFFSET] = ac; + frequencyData[freqIndex + AN_OFFSET] = an; + frequencyData[freqIndex + HOM_OFFSET] = homCount; return this; } @@ -517,10 +518,12 @@ public FrequencyData build() { FrequencySource source = values[i]; if (frequencySources[source.ordinal()] != null) { sources[dataPos] = source; - data[dataPos * WORD_SIZE + FREQ_OFFSET] = frequencyData[source.ordinal() * WORD_SIZE + FREQ_OFFSET]; - data[dataPos * WORD_SIZE + AC_OFFSET] = frequencyData[source.ordinal() * WORD_SIZE + AC_OFFSET]; - data[dataPos * WORD_SIZE + AN_OFFSET] = frequencyData[source.ordinal() * WORD_SIZE + AN_OFFSET]; - data[dataPos * WORD_SIZE + HOM_OFFSET] = frequencyData[source.ordinal() * WORD_SIZE + HOM_OFFSET]; + int dataIndex = dataPos * WORD_SIZE; + int freqIndex = source.ordinal() * WORD_SIZE; + data[dataIndex + FREQ_OFFSET] = frequencyData[freqIndex + FREQ_OFFSET]; + data[dataIndex + AC_OFFSET] = frequencyData[freqIndex + AC_OFFSET]; + data[dataIndex + AN_OFFSET] = frequencyData[freqIndex + AN_OFFSET]; + data[dataIndex + HOM_OFFSET] = frequencyData[freqIndex + HOM_OFFSET]; dataPos++; } } diff --git a/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyDataTest.java b/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyDataTest.java index 1f09347aa..8db886462 100644 --- a/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyDataTest.java +++ b/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/frequency/FrequencyDataTest.java @@ -26,12 +26,15 @@ package org.monarchinitiative.exomiser.core.model.frequency; +import org.h2.mvstore.MVStore; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.monarchinitiative.exomiser.core.genome.dao.serialisers.MvStoreUtil; +import org.monarchinitiative.exomiser.core.model.AlleleProtoAdaptor; +import org.monarchinitiative.exomiser.core.proto.AlleleProto; +import org.monarchinitiative.exomiser.core.proto.AlleleProtoFormatter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import java.util.*; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -287,6 +290,17 @@ public void testGetMaxFrequencyWithData() { assertThat(instance.maxFrequency(), equalTo(maxFrequency)); } + @Test + public void testGetMaxFrequencyWhenZeroData() { + Frequency maxFrequency = Frequency.of(GNOMAD_E_AFR, 0, 1000, 0); + Frequency minFrequency = Frequency.of(TOPMED, 0f); + FrequencyData instance = FrequencyData.of("rs545662810", minFrequency, maxFrequency); + + assertThat(instance.maxFrequency(), equalTo(null)); + assertThat(instance.maxFreq(), equalTo(0f)); + assertThat(instance.frequencies(), equalTo(List.of(minFrequency, maxFrequency))); + } + @Test public void testHasFrequencyOverPercentageValue() { float maxFreq = 0.05f; @@ -482,12 +496,12 @@ void floatArray() { var an = 10000; var hom = 10; var af = Frequency.percentageFrequency(ac, an); - System.out.println("AF=" + af); + data[0] = (float) ac; data[1] = (float) an; data[2] = (float) hom; data[3] = (float) af; - System.out.println("dataAF=" + data[3]); + assertThat(Frequency.percentageFrequency((int) data[0], (int) data[1]), equalTo((float) data[3])); }