Skip to content

Commit

Permalink
Merge pull request #12 from jeromekelleher/fill-more-fields
Browse files Browse the repository at this point in the history
Minimal functional C version
  • Loading branch information
jeromekelleher authored Jul 4, 2024
2 parents ccaf3ef + f17446d commit 591734f
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 108 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install '.[dev]'
# Build the extension module in-place so pytest can find it
python3 setup.py build_ext --inplace
- name: Run tests
run: |
pytest
Expand All @@ -61,4 +63,6 @@ jobs:
- name: Check vcztools CLI
run: |
vcztools --help
# Make sure we don't have ``vcztools`` in the CWD
cd tests
python -m vcztools --help
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include lib/*.h
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

all: ext

ext: _vcztoolsmodule.c
ext: vcztools/_vcztoolsmodule.c
CFLAGS="-std=c99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-cast-function-type" \
python3 setup.py build_ext --inplace

clean:
rm -f *.so *.o tags
rm -f vcztools/*.so
rm -fR build
24 changes: 15 additions & 9 deletions lib/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,45 +118,51 @@ test_variant_encoder_minimal(void)
const int32_t pos_data[] = { 123, 45678 };
const char id_data[] = "RS1RS2";
const char ref_data[] = "AG";
const char alt_data[] = "TC";
const int32_t qual_data[] = { 1000, 12 };
const char filter_data[] = "PASSPASS";
const char alt_data[] = "T";
const float qual_data[] = { 9, 12.1 };
const char filter_id_data[] = "PASS\0FILT1";
const int8_t filter_data[] = {1, 0, 0, 1};
const int32_t an_data[] = { -1, 9 };
const char* aa_data = "G.";
const int8_t flag_data[] = {0, 1};
const int32_t gt_data[] = { 0, 0, 0, 1, 1, 1, 1, 0 };
const int8_t gt_phased_data[] = { 0, 1, 1, 0 };
const int32_t hq_data[] = { 10, 15, 7, 12, -1, -1, -1, -1};
int ret, j;
vcz_variant_encoder_t writer;
const char *expected[] = {
"X\t123\tRS1\tA\tT\t1000\tPASS\tAA=G\tGT:HQ\t0/0:10,15\t0|1:7,12",
"YY\t45678\tRS2\tG\tC\t12\tPASS\tAN=9\tGT\t1|1\t1/0",
"X\t123\tRS1\tA\tT\t9\tPASS\tAA=G\tGT:HQ\t0/0:10,15\t0|1:7,12",
"YY\t45678\tRS2\tG\t.\t12.1\tFILT1\tAN=9;FLAG\tGT\t1|1\t1/0",
};
char buf[1000];

ret = vcz_variant_encoder_init(&writer, 2, 2, contig_data, 2, pos_data, id_data, 3,
1, ref_data, 1, alt_data, 1, 1, qual_data, filter_data, 4, 1);
1, ref_data, 1, alt_data, 1, 1, qual_data,
filter_id_data, 5, 2, filter_data);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = vcz_variant_encoder_add_gt_field(&writer, gt_data, 4, 2, gt_phased_data);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = vcz_variant_encoder_add_info_field(&writer, "AN", VCZ_TYPE_INT, 4, 1, an_data);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = vcz_variant_encoder_add_info_field(&writer, "AA", VCZ_TYPE_STRING, 1, 1, aa_data);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = vcz_variant_encoder_add_info_field(&writer, "FLAG", VCZ_TYPE_BOOL, 1, 1, flag_data);
CU_ASSERT_EQUAL_FATAL(ret, 0);
ret = vcz_variant_encoder_add_format_field(
&writer, "HQ", VCZ_TYPE_INT, 4, 2, hq_data);
CU_ASSERT_EQUAL_FATAL(ret, 0);

printf("\n");
vcz_variant_encoder_print_state(&writer, _devnull);
printf("\n");
/* vcz_variant_encoder_print_state(&writer, stdout); */

for (j = 0; j < num_rows; j++) {
ret = vcz_variant_encoder_write_row(&writer, j, buf, 1000);
/* printf("ret = %d\n", ret); */
printf("GOT:%s\n", buf);
printf("EXP:%s\n", expected[j]);
printf("GOT:%d\n", (int) strlen(buf));
printf("EXP:%d\n", (int) strlen(expected[j]));
/* printf("GOT:%d\n", (int) strlen(buf)); */
/* printf("EXP:%d\n", (int) strlen(expected[j])); */
CU_ASSERT_EQUAL(ret, strlen(expected[j]));
CU_ASSERT_STRING_EQUAL(buf, expected[j]);
}
Expand Down
Loading

0 comments on commit 591734f

Please sign in to comment.