Skip to content

Commit 97988bc

Browse files
add support for the variant stats API
1 parent bfc93e2 commit 97988bc

File tree

7 files changed

+164
-10
lines changed

7 files changed

+164
-10
lines changed

apis/java/src/main/java/io/tiledb/libvcfnative/LibVCFNative.c

+75
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@
66
#include "LibVCFNative.h"
77
#include "tiledbvcf/tiledbvcf.h"
88

9+
static int set_out_params_size_t(JNIEnv* env, size_t value1, size_t value2, jlongArray valuesOut) {
10+
jlong* c_values = (*env)->GetLongArrayElements(env, valuesOut, NULL);
11+
if (c_values == NULL) {
12+
return -1;
13+
}
14+
15+
// Check that an array of length 2 was passed.
16+
if ((*env)->GetArrayLength(env, valuesOut) != 2) {
17+
(*env)->ReleaseLongArrayElements(env, valuesOut, c_values, 0);
18+
return -1;
19+
}
20+
21+
// Set the values in the result array.
22+
c_values[0] = (jlong)value1;
23+
c_values[1] = (jlong)value2;
24+
25+
// Set the modified array back to the Java array.
26+
(*env)->SetLongArrayRegion(env, valuesOut, 0, 2, c_values);
27+
28+
// Release the array elements.
29+
(*env)->ReleaseLongArrayElements(env, valuesOut, c_values, 0);
30+
31+
return TILEDB_VCF_OK;
32+
}
33+
934
static int set_out_param_int32(JNIEnv* env, int32_t value, jintArray valueOut) {
1035
jint* c_value = (*env)->GetIntArrayElements(env, valueOut, NULL);
1136
if (c_value == NULL) {
@@ -1083,3 +1108,53 @@ Java_io_tiledb_libvcfnative_LibVCFNative_tiledb_1vcf_1bed_1file_1get_1contig_1re
10831108

10841109
return rc;
10851110
}
1111+
1112+
JNIEXPORT jint JNICALL
1113+
Java_io_tiledb_libvcfnative_LibVCFNative_tiledb_1vcf_1reader_1get_1variant_1stats_1buffer_1sizes(
1114+
JNIEnv* env, jclass self, jlong readerPtr, jlongArray resultsOut) {
1115+
(void)self;
1116+
tiledb_vcf_reader_t* reader = (tiledb_vcf_reader_t*)readerPtr;
1117+
if (reader == 0) {
1118+
return TILEDB_VCF_ERR;
1119+
}
1120+
1121+
size_t num_rows;
1122+
size_t allele_size;
1123+
int32_t rc = tiledb_vcf_reader_get_variant_stats_buffer_sizes(reader, &num_rows, &allele_size);
1124+
if (rc == TILEDB_VCF_OK) {
1125+
return set_out_params_size_t(env, (size_t)num_rows, (size_t)allele_size, resultsOut);
1126+
}
1127+
1128+
return rc;
1129+
}
1130+
1131+
JNIEXPORT jint JNICALL
1132+
Java_io_tiledb_libvcfnative_LibVCFNative_tiledb_1vcf_1reader_1prepare_1variant_1stats(
1133+
JNIEnv* env, jclass self, jlong readerPtr){
1134+
(void)self;
1135+
1136+
tiledb_vcf_reader_t* reader = (tiledb_vcf_reader_t*)readerPtr;
1137+
1138+
if (reader == 0) {
1139+
return TILEDB_VCF_ERR;
1140+
}
1141+
1142+
int32_t rc = tiledb_vcf_reader_prepare_variant_stats(reader);
1143+
1144+
return rc;
1145+
}
1146+
1147+
JNIEXPORT jint JNICALL
1148+
Java_io_tiledb_libvcfnative_LibVCFNative_tiledb_1vcf_1reader_1read_1from_1variant_1stats(
1149+
JNIEnv* env,
1150+
jclass self,
1151+
jlong readerPtr,
1152+
jlongArray ,
1153+
jstring,
1154+
jlongArray,
1155+
jintArray,
1156+
jintArray,
1157+
jfloatArray){
1158+
1159+
//todo
1160+
}

apis/java/src/main/java/io/tiledb/libvcfnative/LibVCFNative.h

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/java/src/main/java/io/tiledb/libvcfnative/LibVCFNative.java

+14
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,18 @@ public static final native int tiledb_vcf_bed_file_get_contig_region(
171171
byte[] region_contig,
172172
long[] region_start,
173173
long[] region_end);
174+
175+
public static final native int tiledb_vcf_reader_get_variant_stats_buffer_sizes(
176+
long readerPtr, long[] results);
177+
178+
public static final native int tiledb_vcf_reader_prepare_variant_stats(long readerPtr);
179+
180+
public static final native int tiledb_vcf_reader_read_from_variant_stats(
181+
long readerPtr,
182+
long[] pos,
183+
String allele,
184+
long[] allele_offsets,
185+
int[] ac,
186+
int[] an,
187+
float[] af);
174188
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
The LibVCFNative bindings are produced with `javah`.
1+
# The LibVCFNative bindings are produced with `javah`.
22

3-
To build the binding you must first compile the java file to a class file:
3+
## To build the LibVCFNative header run:
4+
```
5+
javac -cp .:commons-io-2.14.0.jar *.java -h dstara
6+
```
7+
8+
This will generate io_tiledb_libvcfnative_LibVCFNative.h as a separate file.
49

10+
## Format the new header file:
511
```
6-
cd api/spark/src/main/java/io/tiledb/libvcfnative
7-
javac LibVCFNative.java
12+
clang-format -i io_tiledb_libvcfnative_LibVCFNative.h
813
```
914

10-
Next you can use `javah` to rebuild the LibVCFNative header:
15+
## Replace the old header file with the new:
1116
```
12-
# Navigate back to top level spark src directory
13-
cd ../../../
14-
javah -v -cp $PWD -o io/tiledb/libvcfnative/LibVCFNative.h io.tiledb.libvcfnative.LibVCFNative
17+
mv io_tiledb_libvcfnative_LibVCFNative.h LibVCFNative.h
1518
```
1619

17-
It is safe to delete the class file now:
20+
## It is safe to delete the class files now:
1821
```
19-
rm io/tiledb/libvcfnative/LibVCFNative.class
22+
rm io/tiledb/libvcfnative/*.class
2023
```
24+
25+
26+
27+
28+
29+
30+

apis/java/src/main/java/io/tiledb/libvcfnative/VCFReader.java

+10
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,16 @@ public String stats() {
584584
return stats;
585585
}
586586

587+
public VCFReader prepareVariantStats() {
588+
int rc =
589+
LibVCFNative.tiledb_vcf_reader_prepare_variant_stats(this.readerPtr);
590+
if (rc != 0) {
591+
String msg = getLastErrorMessage();
592+
throw new RuntimeException("Error preparing variant stats: " + msg);
593+
}
594+
return this;
595+
}
596+
587597
public String version() {
588598
return LibVCFNative.tiledb_vcf_version();
589599
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
javac -cp .:commons-io-2.14.0.jar *.java -h .;
2+
clang-format -i io_tiledb_libvcfnative_LibVCFNative.h;
3+
mv io_tiledb_libvcfnative_LibVCFNative.h LibVCFNative.h;
4+
rm *.class;

apis/java/src/test/java/io/tiledb/libvcfnative/VCFReaderTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ public void testStats() throws IOException {
378378
Assert.assertNotNull(reader.stats());
379379
}
380380

381+
@Test
382+
public void testVariantStats() throws IOException {
383+
VCFReader reader = getVFCReader(Optional.empty(), Optional.of(constructBEDURI()));
384+
reader.prepareVariantStats();
385+
}
386+
381387
/**
382388
* * Checks that the reader attribute details are initialized in constructor
383389
*

0 commit comments

Comments
 (0)