Skip to content

Commit

Permalink
Read BED files stored as TileDB files (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
gspowley authored Apr 28, 2024
1 parent 69c30d4 commit 3940593
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 196 deletions.
19 changes: 0 additions & 19 deletions apis/java/src/main/java/io/tiledb/libvcfnative/LibVCFNative.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,6 @@ Java_io_tiledb_libvcfnative_LibVCFNative_tiledb_1vcf_1reader_1set_1bed_1file(
return rc;
}

JNIEXPORT jint JNICALL
Java_io_tiledb_libvcfnative_LibVCFNative_tiledb_1vcf_1reader_1set_1bed_1array(
JNIEnv* env, jclass self, jlong readerPtr, jstring uri) {
(void)self;
tiledb_vcf_reader_t* reader = (tiledb_vcf_reader_t*)readerPtr;
if (reader == 0) {
return TILEDB_VCF_ERR;
}

const char* c_uri = (*env)->GetStringUTFChars(env, uri, 0);
if (c_uri == NULL) {
return TILEDB_VCF_ERR;
}

int rc = tiledb_vcf_reader_set_bed_array(reader, c_uri);
(*env)->ReleaseStringUTFChars(env, uri, c_uri);
return rc;
}

JNIEXPORT jint JNICALL
Java_io_tiledb_libvcfnative_LibVCFNative_tiledb_1vcf_1reader_1set_1samples(
JNIEnv* env, jclass self, jlong readerPtr, jstring samples) {
Expand Down
9 changes: 0 additions & 9 deletions apis/java/src/main/java/io/tiledb/libvcfnative/LibVCFNative.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class LibVCFNative {

public static final native int tiledb_vcf_reader_set_bed_file(long readerPtr, String uri);

public static final native int tiledb_vcf_reader_set_bed_array(long readerPtr, String uri);

public static final native int tiledb_vcf_reader_set_samples(long readerPtr, String samplesCSV);

public static final native int tiledb_vcf_reader_set_regions(long readerPtr, String regionsCSV);
Expand Down
9 changes: 0 additions & 9 deletions apis/java/src/main/java/io/tiledb/libvcfnative/VCFReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,6 @@ public VCFReader setBedFile(String uri) {
return this;
}

public VCFReader setBedArray(String uri) {
int rc = LibVCFNative.tiledb_vcf_reader_set_bed_array(readerPtr, uri);
if (rc != 0) {
String msg = getLastErrorMessage();
throw new RuntimeException("Error setting query bed array '" + uri + "': " + msg);
}
return this;
}

public VCFReader setSortRegions(boolean sortRegions) {
int rc = LibVCFNative.tiledb_vcf_reader_set_sort_regions(readerPtr, sortRegions);
if (rc != 0) {
Expand Down
37 changes: 12 additions & 25 deletions apis/java/src/test/java/io/tiledb/libvcfnative/VCFReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ private String[] getSamples() throws IOException {
* @return The VCFReader instance
* @throws IOException
*/
private VCFReader getVFCReader(
Optional<String[]> inputSamples, Optional<String> bedFile, Optional<String> bedArray)
private VCFReader getVFCReader(Optional<String[]> inputSamples, Optional<String> bedFile)
throws IOException {
String samples[] = inputSamples.orElse(getSamples());

Expand All @@ -83,8 +82,6 @@ private VCFReader getVFCReader(

if (bedFile.isPresent()) reader.setBedFile(bedFile.get());

if (bedArray.isPresent()) reader.setBedArray(bedArray.get());

return reader;
}

Expand All @@ -95,7 +92,7 @@ private VCFReader getVFCReader(
*/
@Test
public void testReadCompletes() throws IOException {
VCFReader reader = getVFCReader(Optional.empty(), Optional.empty(), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.empty());

int results = 0;

Expand All @@ -114,7 +111,7 @@ public void testReadCompletes() throws IOException {
*/
@Test
public void testReaderValues() throws IOException {
VCFReader reader = getVFCReader(Optional.empty(), Optional.empty(), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.empty());

reader.setRanges("1:12100-13360,1:13500-17350".split(","));

Expand Down Expand Up @@ -287,7 +284,7 @@ public void testNumResultsMultipleRangePartitions() throws IOException {
int[] partitionsToCheck = {1, 2, 5, 10, 50, 100};

for (int numPartitions : partitionsToCheck) {
VCFReader reader = getVFCReader(Optional.empty(), Optional.empty(), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.empty());

int results = 0;

Expand All @@ -313,9 +310,7 @@ public void testNumResultsMultipleRangePartitions() throws IOException {
*/
@Test
public void testSingleSample() throws IOException {
VCFReader reader =
getVFCReader(
Optional.of(new String[] {getSamples()[0]}), Optional.empty(), Optional.empty());
VCFReader reader = getVFCReader(Optional.of(new String[] {getSamples()[0]}), Optional.empty());

int results = 0;

Expand All @@ -334,8 +329,7 @@ public void testSingleSample() throws IOException {
*/
@Test
public void testBEDFile() throws IOException {
VCFReader reader =
getVFCReader(Optional.empty(), Optional.of(constructBEDURI()), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.of(constructBEDURI()));

int results = 0;

Expand All @@ -355,8 +349,7 @@ public void testBEDFile() throws IOException {
*/
@Test
public void testBEDArray() throws IOException {
VCFReader reader =
getVFCReader(Optional.empty(), Optional.empty(), Optional.of(constructBEDArrayURI()));
VCFReader reader = getVFCReader(Optional.empty(), Optional.of(constructBEDArrayURI()));

int results = 0;

Expand All @@ -376,8 +369,7 @@ public void testBEDArray() throws IOException {
*/
@Test
public void testSetSingleBuffer() throws IOException {
VCFReader reader =
getVFCReader(Optional.empty(), Optional.of(constructBEDURI()), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.of(constructBEDURI()));
ByteBuffer data = ByteBuffer.allocateDirect(1024);
reader.setBuffer("sample_name", data);

Expand All @@ -394,16 +386,14 @@ public void testSetSingleBuffer() throws IOException {

@Test
public void testSetStatsEnabled() throws IOException {
VCFReader reader =
getVFCReader(Optional.empty(), Optional.of(constructBEDURI()), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.of(constructBEDURI()));

reader.setStatsEnabled(true);
}

@Test
public void testGetStatsEnabled() throws IOException {
VCFReader reader =
getVFCReader(Optional.empty(), Optional.of(constructBEDURI()), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.of(constructBEDURI()));

Assert.assertFalse(reader.getStatsEnabled());
reader.setStatsEnabled(true);
Expand All @@ -414,8 +404,7 @@ public void testGetStatsEnabled() throws IOException {

@Test
public void testStats() throws IOException {
VCFReader reader =
getVFCReader(Optional.empty(), Optional.of(constructBEDURI()), Optional.empty());
VCFReader reader = getVFCReader(Optional.empty(), Optional.of(constructBEDURI()));
reader.setStatsEnabled(true);
Assert.assertNotNull(reader.stats());
}
Expand All @@ -427,9 +416,7 @@ public void testStats() throws IOException {
*/
@Test
public void testAttributes() throws IOException {
VCFReader reader =
getVFCReader(
Optional.of(new String[] {getSamples()[0]}), Optional.empty(), Optional.empty());
VCFReader reader = getVFCReader(Optional.of(new String[] {getSamples()[0]}), Optional.empty());

Assert.assertTrue(reader.attributes.size() > 0);
Assert.assertTrue(reader.fmtAttributes.size() > 0);
Expand Down
1 change: 0 additions & 1 deletion apis/python/src/tiledbvcf/binding/libtiledbvcf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ PYBIND11_MODULE(libtiledbvcf, m) {
.def("set_samples_file", &Reader::set_samples_file)
.def("set_regions", &Reader::set_regions)
.def("set_bed_file", &Reader::set_bed_file)
.def("set_bed_array", &Reader::set_bed_array)
.def("set_sort_regions", &Reader::set_sort_regions)
.def("set_region_partition", &Reader::set_region_partition)
.def("set_sample_partition", &Reader::set_sample_partition)
Expand Down
5 changes: 0 additions & 5 deletions apis/python/src/tiledbvcf/binding/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ void Reader::set_bed_file(const std::string& uri) {
check_error(reader, tiledb_vcf_reader_set_bed_file(reader, uri.c_str()));
}

void Reader::set_bed_array(const std::string& uri) {
auto reader = ptr.get();
check_error(reader, tiledb_vcf_reader_set_bed_array(reader, uri.c_str()));
}

void Reader::set_region_partition(int32_t partition, int32_t num_partitions) {
auto reader = ptr.get();
check_error(
Expand Down
3 changes: 0 additions & 3 deletions apis/python/src/tiledbvcf/binding/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class Reader {
/** Sets a URI of a BED file containing regions to include in the read. */
void set_bed_file(const std::string& uri);

/** Sets a URI of a BED array containing regions to include in the read. */
void set_bed_array(const std::string& uri);

/** Sets the region partition of this reader. */
void set_region_partition(int32_t partition, int32_t num_partitions);

Expand Down
18 changes: 0 additions & 18 deletions apis/python/src/tiledbvcf/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def read_arrow(
regions: (str, List[str]) = None,
samples_file: str = None,
bed_file: str = None,
bed_array: str = None,
skip_check_samples: bool = False,
set_af_filter: str = "",
scan_all_samples: bool = False,
Expand All @@ -236,8 +235,6 @@ def read_arrow(
URI of file containing sample names to be read, one per line.
bed_file
URI of a BED file of genomic regions to be read.
bed_array
URI of a BED array of genomic regions to be read.
skip_check_samples
Skip checking if the samples in `samples_file` exist in the dataset.
set_af_filter
Expand Down Expand Up @@ -276,9 +273,6 @@ def read_arrow(
if bed_file is not None:
self.reader.set_bed_file(bed_file)

if bed_array is not None:
self.reader.set_bed_array(bed_array)

return self.continue_read_arrow()

def read_variant_stats(
Expand Down Expand Up @@ -322,7 +316,6 @@ def read(
regions: (str, List[str]) = None,
samples_file: str = None,
bed_file: str = None,
bed_array: str = None,
skip_check_samples: bool = False,
set_af_filter: str = "",
scan_all_samples: bool = False,
Expand Down Expand Up @@ -350,8 +343,6 @@ def read(
URI of file containing sample names to be read, one per line.
bed_file
URI of a BED file of genomic regions to be read.
bed_array
URI of a BED array of genomic regions to be read.
skip_check_samples
Skip checking if the samples in `samples_file` exist in the dataset.
set_af_filter
Expand Down Expand Up @@ -388,9 +379,6 @@ def read(
if bed_file is not None:
self.reader.set_bed_file(bed_file)

if bed_array is not None:
self.reader.set_bed_array(bed_array)

return self.continue_read()

def export(
Expand All @@ -399,7 +387,6 @@ def export(
regions: (str, List[str]) = None,
samples_file: str = None,
bed_file: str = None,
bed_array: str = None,
skip_check_samples: bool = False,
enable_progress_estimation: bool = False,
merge: bool = False,
Expand All @@ -420,8 +407,6 @@ def export(
URI of file containing sample names to be read, one per line.
bed_file
URI of a BED file of genomic regions to be read.
bed_array
URI of a BED array of genomic regions to be read.
skip_check_samples
Skip checking if the samples in `samples_file` exist in the dataset.
set_af_filter
Expand Down Expand Up @@ -467,9 +452,6 @@ def export(
if bed_file is not None:
self.reader.set_bed_file(bed_file)

if bed_array is not None:
self.reader.set_bed_array(bed_array)

self.reader.read()
if not self.read_completed():
raise Exception("Unexpected read status during export.")
Expand Down
Loading

0 comments on commit 3940593

Please sign in to comment.