Skip to content

Commit 1ae7df8

Browse files
committed
Changes to enable update of H2 to version 2.2.x
Update H2 version 1.4.200 -> 2.2.224 Update Flyway version 8.2.1 -> 10.6.0 to support H2 update Add new ProtobufDataType Update ClinVarDataType, AlleleKeyDataType and AllelePropertiesDataType to extend ProtobufDataType Delete static data from exomiser-spring-boot-autoconfigure/test/resources Add new TestDataDirectories class to dynamically create test data for the exomiser-spring-boot-autoconfigure module to allow for simpler updating of H2
1 parent 65a8556 commit 1ae7df8

File tree

39 files changed

+410
-225
lines changed

39 files changed

+410
-225
lines changed

exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/genome/dao/serialisers/AlleleKeyDataType.java

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,23 @@
2020

2121
package org.monarchinitiative.exomiser.core.genome.dao.serialisers;
2222

23-
import com.google.protobuf.InvalidProtocolBufferException;
24-
import org.h2.mvstore.DataUtils;
25-
import org.h2.mvstore.WriteBuffer;
23+
import com.google.protobuf.Parser;
2624
import org.h2.mvstore.type.DataType;
27-
import org.h2.util.Utils;
2825
import org.monarchinitiative.exomiser.core.proto.AlleleProto.AlleleKey;
2926

30-
import java.nio.ByteBuffer;
31-
3227
/**
3328
* Specialised {@link DataType} for (de)serialising {@link AlleleKey} objects into and out of
3429
* the {@link org.h2.mvstore.MVStore}.
3530
*
3631
* @author Jules Jacobsen <[email protected]>
3732
*/
38-
public class AlleleKeyDataType implements DataType {
33+
public class AlleleKeyDataType extends ProtobufDataType<AlleleKey> {
3934

4035
public static final AlleleKeyDataType INSTANCE = new AlleleKeyDataType();
4136

37+
private AlleleKeyDataType() {
38+
}
39+
4240
/**
4341
* Sorts variants according to their natural ordering of genome position. Variants are sorted according to
4442
* chromosome number, chromosome position, reference sequence then alternative sequence.
@@ -47,59 +45,26 @@ public class AlleleKeyDataType implements DataType {
4745
* @return comparator score consistent with equals.
4846
*/
4947
@Override
50-
public int compare(Object a, Object b) {
51-
AlleleKey keyA = (AlleleKey) a;
52-
AlleleKey keyB = (AlleleKey) b;
53-
54-
if (keyA.getChr() != keyB.getChr()) {
55-
return Integer.compare(keyA.getChr(), keyB.getChr());
48+
public int compare(AlleleKey a, AlleleKey b) {
49+
if (a.getChr() != b.getChr()) {
50+
return Integer.compare(a.getChr(), b.getChr());
5651
}
57-
if (keyA.getPosition() != keyB.getPosition()) {
58-
return Integer.compare(keyA.getPosition(), keyB.getPosition());
52+
if (a.getPosition() != b.getPosition()) {
53+
return Integer.compare(a.getPosition(), b.getPosition());
5954
}
60-
if (!keyA.getRef().equals(keyB.getRef())) {
61-
return keyA.getRef().compareTo(keyB.getRef());
55+
if (!a.getRef().equals(b.getRef())) {
56+
return a.getRef().compareTo(b.getRef());
6257
}
63-
return keyA.getAlt().compareTo(keyB.getAlt());
58+
return a.getAlt().compareTo(b.getAlt());
6459
}
6560

6661
@Override
67-
public int getMemory(Object obj) {
68-
AlleleKey key = (AlleleKey) obj;
69-
return key.getSerializedSize();
62+
public Parser<AlleleKey> messageParser() {
63+
return AlleleKey.parser();
7064
}
7165

7266
@Override
73-
public void read(ByteBuffer buff, Object[] obj, int len, boolean key) {
74-
for (int i = 0; i < len; i++) {
75-
obj[i] = read(buff);
76-
}
77-
}
78-
79-
@Override
80-
public void write(WriteBuffer buff, Object[] obj, int len, boolean key) {
81-
for (int i = 0; i < len; i++) {
82-
write(buff, obj[i]);
83-
}
67+
public AlleleKey[] createStorage(int size) {
68+
return new AlleleKey[size];
8469
}
85-
86-
@Override
87-
public AlleleKey read(ByteBuffer buff) {
88-
int len = DataUtils.readVarInt(buff);
89-
byte[] data = Utils.newBytes(len);
90-
buff.get(data);
91-
try {
92-
return AlleleKey.parseFrom(data);
93-
} catch (InvalidProtocolBufferException e) {
94-
throw new InvalidAlleleProtoException(e);
95-
}
96-
}
97-
98-
@Override
99-
public void write(WriteBuffer buff, Object obj) {
100-
AlleleKey key = (AlleleKey) obj;
101-
byte[] data = key.toByteArray();
102-
buff.putVarInt(data.length).put(data);
103-
}
104-
10570
}

exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/genome/dao/serialisers/AllelePropertiesDataType.java

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,38 @@
2020

2121
package org.monarchinitiative.exomiser.core.genome.dao.serialisers;
2222

23-
import com.google.protobuf.InvalidProtocolBufferException;
24-
import org.h2.mvstore.DataUtils;
25-
import org.h2.mvstore.WriteBuffer;
23+
import com.google.protobuf.Parser;
2624
import org.h2.mvstore.type.DataType;
27-
import org.h2.util.Utils;
2825
import org.monarchinitiative.exomiser.core.proto.AlleleProto.AlleleProperties;
2926

30-
import java.nio.ByteBuffer;
31-
3227
/**
3328
* Specialised {@link DataType} for (de)serialising {@link AlleleProperties} objects into and out of
3429
* the {@link org.h2.mvstore.MVStore}.
3530
*
3631
* @author Jules Jacobsen <[email protected]>
3732
*/
38-
public class AllelePropertiesDataType implements DataType {
33+
public class AllelePropertiesDataType extends ProtobufDataType<AlleleProperties> {
3934

4035
public static final AllelePropertiesDataType INSTANCE = new AllelePropertiesDataType();
4136

42-
@Override
43-
public int compare(Object a, Object b) {
44-
return -1;
45-
}
46-
47-
@Override
48-
public int getMemory(Object obj) {
49-
AlleleProperties props = (AlleleProperties) obj;
50-
return props.getSerializedSize();
51-
}
52-
53-
@Override
54-
public void read(ByteBuffer buff, Object[] obj, int len, boolean key) {
55-
for (int i = 0; i < len; i++) {
56-
obj[i] = read(buff);
57-
}
37+
private AllelePropertiesDataType() {
5838
}
5939

6040
@Override
61-
public AlleleProperties read(ByteBuffer buff) {
62-
int len = DataUtils.readVarInt(buff);
63-
byte[] data = Utils.newBytes(len);
64-
buff.get(data);
65-
try {
66-
return AlleleProperties.parseFrom(data);
67-
} catch (InvalidProtocolBufferException e) {
68-
throw new InvalidAlleleProtoException(e);
41+
public int compare(AlleleProperties a, AlleleProperties b) {
42+
if (a.equals(b)) {
43+
return 0;
6944
}
45+
throw new UnsupportedOperationException("Unable to compare " + a + " with " + b);
7046
}
7147

7248
@Override
73-
public void write(WriteBuffer buff, Object[] obj, int len, boolean key) {
74-
for (int i = 0; i < len; i++) {
75-
write(buff, obj[i]);
76-
}
49+
public AlleleProperties[] createStorage(int size) {
50+
return new AlleleProperties[size];
7751
}
7852

7953
@Override
80-
public void write(WriteBuffer buff, Object obj) {
81-
AlleleProperties props = (AlleleProperties) obj;
82-
byte[] data = props.toByteArray();
83-
buff.putVarInt(data.length).put(data);
54+
public Parser<AlleleProperties> messageParser() {
55+
return AlleleProperties.parser();
8456
}
8557
}
Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,28 @@
11
package org.monarchinitiative.exomiser.core.genome.dao.serialisers;
22

3-
import com.google.protobuf.InvalidProtocolBufferException;
4-
import org.h2.mvstore.DataUtils;
5-
import org.h2.mvstore.WriteBuffer;
6-
import org.h2.mvstore.type.DataType;
7-
import org.h2.util.Utils;
8-
import org.monarchinitiative.exomiser.core.proto.AlleleProto;
3+
import com.google.protobuf.Parser;
4+
import org.monarchinitiative.exomiser.core.proto.AlleleProto.ClinVar;
95

10-
import java.nio.ByteBuffer;
116

7+
public class ClinVarDataType extends ProtobufDataType<ClinVar> {
128

13-
public enum ClinVarDataType implements DataType {
14-
15-
INSTANCE;
16-
17-
@Override
18-
public int compare(Object a, Object b) {
19-
return -1;
20-
}
21-
22-
@Override
23-
public int getMemory(Object obj) {
24-
AlleleProto.ClinVar clinVar = (AlleleProto.ClinVar) obj;
25-
return clinVar.getSerializedSize();
26-
}
27-
28-
@Override
29-
public void read(ByteBuffer buff, Object[] obj, int len, boolean key) {
30-
for (int i = 0; i < len; i++) {
31-
obj[i] = read(buff);
32-
}
33-
}
9+
public static final ClinVarDataType INSTANCE = new ClinVarDataType();
3410

3511
@Override
36-
public AlleleProto.ClinVar read(ByteBuffer buff) {
37-
int len = DataUtils.readVarInt(buff);
38-
byte[] data = Utils.newBytes(len);
39-
buff.get(data);
40-
try {
41-
return AlleleProto.ClinVar.parseFrom(data);
42-
} catch (InvalidProtocolBufferException e) {
43-
throw new InvalidAlleleProtoException(e);
12+
public int compare(ClinVar a, ClinVar b) {
13+
if (a.equals(b)) {
14+
return 0;
4415
}
16+
throw new UnsupportedOperationException("Unable to compare " + a + " with " + b);
4517
}
4618

4719
@Override
48-
public void write(WriteBuffer buff, Object[] obj, int len, boolean key) {
49-
for (int i = 0; i < len; i++) {
50-
write(buff, obj[i]);
51-
}
20+
public ClinVar[] createStorage(int size) {
21+
return new ClinVar[size];
5222
}
5323

5424
@Override
55-
public void write(WriteBuffer buff, Object obj) {
56-
AlleleProto.ClinVar clinVar = (AlleleProto.ClinVar) obj;
57-
byte[] data = clinVar.toByteArray();
58-
buff.putVarInt(data.length).put(data);
25+
public Parser<ClinVar> messageParser() {
26+
return ClinVar.parser();
5927
}
6028
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.monarchinitiative.exomiser.core.genome.dao.serialisers;
2+
3+
import com.google.protobuf.InvalidProtocolBufferException;
4+
import com.google.protobuf.Message;
5+
import com.google.protobuf.Parser;
6+
import org.h2.mvstore.DataUtils;
7+
import org.h2.mvstore.WriteBuffer;
8+
import org.h2.mvstore.type.BasicDataType;
9+
import org.h2.util.Utils;
10+
11+
import java.nio.ByteBuffer;
12+
13+
public abstract class ProtobufDataType<T extends Message> extends BasicDataType<T> {
14+
15+
@Override
16+
public int getMemory(T obj) {
17+
return obj.getSerializedSize();
18+
}
19+
20+
@Override
21+
public void write(WriteBuffer buff, T obj) {
22+
byte[] data = obj.toByteArray();
23+
buff.putVarInt(data.length).put(data);
24+
}
25+
26+
@Override
27+
public T read(ByteBuffer buff) {
28+
int len = DataUtils.readVarInt(buff);
29+
byte[] data = Utils.newBytes(len);
30+
buff.get(data);
31+
try {
32+
return messageParser().parseFrom(data);
33+
} catch (InvalidProtocolBufferException e) {
34+
throw new InvalidAlleleProtoException(e);
35+
}
36+
}
37+
38+
public abstract Parser<T> messageParser();
39+
40+
}

exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/genome/dao/ClinVarDaoMvStoreTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,18 @@ void manualDataExplorer() {
240240
// https://mart.ensembl.org/info/genome/genebuild/canonical.html (see also vitt). Ideally the Jannovar Annotations
241241
// should be sorted before being converted to TranscriptAnnotations. This isn't an issue if MANE only
242242
// transcripts are being used as these are the only ones available to report on.
243-
GenomicVariant genomicVariant = parseVariant("10-123256215-T-G"); // 10-123256215-T-G
243+
GenomicVariant genomicVariant = parseVariant("10-123256215-T-ACG"); // 10-123256215-T-G hg38:10-121496701-T-G
244244

245245
System.out.println("Searching for: " + toBroad(genomicVariant));
246-
// encode as VariantKey (https://doi.org/10.1101/473744) == 8 bytes fixed size (long);
247246
AlleleProto.AlleleKey alleleKey = AlleleProtoAdaptor.toAlleleKey(genomicVariant);
247+
// encode as VariantKey (https://doi.org/10.1101/473744) == 8 bytes fixed size (long);
248248
System.out.println("AlleleKey size (bytes): " + alleleKey.getSerializedSize()); // SNP = 13 bytes, 11 bases = 23
249249
System.out.println();
250250
AlleleProto.AlleleProperties alleleProperties = allelePropertiesDao.getAlleleProperties(alleleKey, GenomeAssembly.HG19);
251251

252252
System.out.println(clinVarDao.getClinVarData(genomicVariant));
253253
Map<GenomicVariant, ClinVarData> clinVarRecordsOverlappingInterval = clinVarDao.findClinVarRecordsOverlappingInterval(genomicVariant.withPadding(2, 2));
254-
clinVarRecordsOverlappingInterval.forEach((variant, clinVarData) -> {System.out.println(toBroad(variant) + " : " + clinVarData);});
254+
clinVarRecordsOverlappingInterval.forEach((variant, clinVarData) -> System.out.println(toBroad(variant) + " : " + clinVarData));
255255
System.out.println(AlleleProtoAdaptor.toFrequencyData(alleleProperties));
256256
PathogenicityData pathogenicityData = AlleleProtoAdaptor.toPathogenicityData(alleleProperties);
257257
System.out.println(pathogenicityData.getPredictedPathogenicityScores());

exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/genome/dao/SvFrequencyDaoTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
package org.monarchinitiative.exomiser.core.genome.dao;
2222

2323
import org.h2.mvstore.MVStore;
24+
import org.h2.mvstore.db.SpatialKey;
2425
import org.h2.mvstore.rtree.MVRTreeMap;
25-
import org.h2.mvstore.rtree.SpatialKey;
26+
import org.h2.mvstore.rtree.Spatial;
2627
import org.junit.jupiter.api.Disabled;
2728
import org.junit.jupiter.api.Test;
2829
import org.junit.jupiter.api.extension.ExtendWith;
@@ -40,7 +41,6 @@
4041
import org.springframework.test.context.ContextConfiguration;
4142
import org.springframework.test.context.junit.jupiter.SpringExtension;
4243

43-
import java.util.Iterator;
4444
import java.util.List;
4545

4646
import static org.hamcrest.MatcherAssert.assertThat;
@@ -219,12 +219,11 @@ void mvStoreRtree() {
219219
System.out.println("margin: " + margin);
220220
System.out.println("Searching chr" + region.contigId() + " from " + (region.start() - margin) + " to " + (region
221221
.end() + margin));
222-
// iterate over the intersecting keys
223-
Iterator<SpatialKey> it =
222+
MVRTreeMap.RTreeCursor<SvFrequencyDao.SvResult> it =
224223
// r.findContainedKeys(new SpatialKey(0, 0f, 9f, 3f, 6f));
225224
r.findIntersectingKeys(new SpatialKey(0, boundaryCalculator.startMin(), boundaryCalculator.endMax(), region.contigId(), region.contigId()));
226225
while (it.hasNext()) {
227-
SpatialKey k = it.next();
226+
Spatial k = it.next();
228227
SvFrequencyDao.SvResult svResult = r.get(k);
229228
System.out.println(k + ": " + svResult + ", simJ=" + SvDaoUtil.jaccard(region, svResult));
230229
}

0 commit comments

Comments
 (0)