Repository navigation
Make tree internal to variant and seek to site - #2160
Conversation
4daccab to
b2d1bde
Compare
b2d1bde to
76cd7b7
Compare
|
There's an issue here with the lifetime of the site object as the variant stores a reference to it. This wasn't a problem before as the site was owned by the tree, using the fact that |
|
I agree we should make the argument to tsk_variant_t var;
tsk_id_t site_id;
for (site_id = 0; site_id < (tsk_id_t) tsk_treeseq_get_num_sites(ts); site_id++) {
ret = tsk_variant_decode(&var, site_id, 0);
if (ret != 0) {
goto out;
}
} vs tsk_variant_t var;
tsk_site_t site;
tsk_id_t site_id;
for (site_id = 0; site_id < (tsk_id_t) tsk_treeseq_get_num_sites(ts); site_id++) {
ret = tsk_treeseq_get_site(ts, site_id, &site);
if (ret != 0) {
goto out;
}
ret = tsk_variant_decode(&var, &site, 0);
if (ret != 0) {
goto out;
}
} It's not like we save anything by having to call The first way is much neater I think. |
|
Why not keep storing the site on the variant object @benjeffery? We're keeping a reference to the underlying tree sequence, so there's basically no overhead in storing a pointer to a site, is there? |
Codecov Report
@@ Coverage Diff @@
## main #2160 +/- ##
=======================================
Coverage 93.27% 93.28%
=======================================
Files 27 27
Lines 25919 25896 -23
Branches 1163 1163
=======================================
- Hits 24177 24156 -21
+ Misses 1712 1710 -2
Partials 30 30
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I started the work to make variant lookup and store the site when I realised we didn't actually need to store it. I'm in two minds about it though as the site lookup is cheaper than I realised, basically copying a few pointers. Thought I would upload this version for feedback. If you feel strongly to store the site then we can switch to that, there was more breakage here than I expected so probably that is the right thing to do. |
|
Since it's cheap I don't think it's worth the breakage. From a client perspective, it's nice to be able to do things like: tsk_variant_t var;
tsk_id_t site_id;
for (site_id = 0; site_id < (tsk_id_t) tsk_treeseq_get_num_sites(ts); site_id++) {
ret = tsk_variant_decode(&var, site_id, 0);
if (ret != 0) {
goto out;
}
printf("Variant at site %d (pos=%f)\n", var.site.id, var.site.position);
} Otherwise, you have to do the site lookup again in the client code. |
0542d8d to
5985dcb
Compare
| tsk_size_t num_samples_alloc; | ||
|
|
||
| tsk_memset(self, 0, sizeof(tsk_variant_t)); | ||
| self->site = malloc(sizeof(*self->site)); |
There was a problem hiding this comment.
I think we could probably avoid this malloc, but let's not change it yet to keep the diff size managable. I've made #2161 to track.
5985dcb to
e1eefdb
Compare
|
@Mergifyio rebase |
✅ Branch has been successfully rebased |
Part of #605