Adding variants iterator and other functions - #132
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
c443f64 to
c309e3a
Compare
|
I have rebased this to the most recent |
|
There is quite a bit to review in this PR, so best to make a list of new things! @LynxJinyangii I would appreciate such communication so it's easier to follow your work and thoughts etc. Best to err on the slight "over communication" that "no communication";) Even just copying From what I gather, this is the list of additions we should review:
|
|
@LynxJinyangii I have pushed changes to this branch/PR (rebased to main, which required sorting some merge conflicts; and come comments on sort), so best if you first pull before you start changes on your end. |
|
I have done some polishing of the code, docs, and terms in my recent commit&push. @LynxJinyangii make sure you |
…e of both 1 and 1L
|
@bryo-han do you have capacity to go over this PR while I focus on teaching/course? |
gregorgorjanc
left a comment
There was a problem hiding this comment.
@LynxJinyangii I have tagged you in a bunch of places where I don't see changes when I last reviewed certain parts. Remember to click on the > or v symbol next to file names to fold and unfold the file so you can see comments as you scroll through the files. Also, when the diff is large GitHub will not render the diff so you have to click on the file display to see diffs and comment sections.
| } | ||
|
|
||
| // PUBLIC, wrapper for tsk_treeseq_get_samples | ||
| // @describeIn rtsk_treeseq_summary Get sample node IDs. |
There was a problem hiding this comment.
I don't see any documentation about rtsk_treeseq_get_samples in rtsk_treeseq_summary, so we should address this. The C method is described at https://tskit.dev/tskit/docs/latest/c-api.html#c.tsk_treeseq_get_samples. Since it only accepts tsk_treeseq_t (tree sequence type in C) it does make sense to describe rtsk_treeseq_get_samples in rtsk_treeseq_summary, but we should follow the convention established there for other methods (provide a link etc.).
There was a problem hiding this comment.
I am looking at this again and on reflection think that this method tsk_treeseq_get_samples likely should not be documented in rtsk_treeseq_summary and in fact is not called by rtsk_treeseq_summary whereas other tsk_treeseq_get_* (and similar) methods are called by rtsk_treeseq_summary. So, we should create a more extensive documentation for tsk_treeseq_get_samples here - can you follow documentation of other PUBLIC methods that have their own documentation?
| .Call(`_RcppTskit_tskit_version`) | ||
| } | ||
|
|
||
| rtsk_const_tsk_no_check_integrity <- function() { |
There was a problem hiding this comment.
Since Python sort method does not have options I assume we do not need rtsk_const_tsk_no_check_integrity at all?
| // @title Add a row to the migration table in a table collection | ||
| // @param tc an external pointer to table collection as a | ||
| // \code{tsk_table_collection_t} object. | ||
| // @param left numeric scalar left coordinate for the new migration. |
There was a problem hiding this comment.
Mention inclusive/exclusive
There was a problem hiding this comment.
Mention inclusive/exclusive
| // (n_before <- RcppTskit:::rtsk_table_collection_get_num_migrations(tc_xptr)) | ||
| // (m_before <- | ||
| // RcppTskit:::rtsk_table_collection_metadata_length(tc_xptr)$migrations) new_id | ||
| // <- RcppTskit:::rtsk_migration_table_add_row( |
There was a problem hiding this comment.
As in R side - let's do a meaningful example
| `pointer` to `xptr`. | ||
| - Ensured `TableCollection$tree_sequence()` matches `tskit Python` API: | ||
| it now builds indexes on the `TableCollection`, if indexes are not present. | ||
| - Improved table row getter APIs and documentation for better `tskit C`/Python |
There was a problem hiding this comment.
@LynxJinyangii I think we can remove 78-80 since getters have been introduced as part of 0.3.0 anyway.
| ) | ||
| }, | ||
|
|
||
| # TODO: how should we handle useR's experience with numeric&integer in getters? |
There was a problem hiding this comment.
@LynxJinyangii remove these TODOs please - we have now decided we support both integers and numerics and that we will work with 0-based indexing (I assume)
| SEXP ts, Rcpp::Nullable<Rcpp::IntegerVector> samples = R_NilValue, | ||
| bool isolated_as_missing = true, | ||
| Rcpp::Nullable<Rcpp::CharacterVector> alleles = R_NilValue, | ||
| double left = 0.0, double right = NA_REAL); |
There was a problem hiding this comment.
@LynxJinyangii Python API has None for all of these args so would be good to be consistent/in-line with that API here to. The Python API then checks the inputs and does what it does. Best to follow that style on our end too. So, put R_NilValue (or should it be NA_REAL?). We can come back to this once I review everything;)
| int options = 0); | ||
| SEXP rtsk_treeseq_copy_tables(SEXP ts, int options = 0); | ||
| SEXP rtsk_treeseq_init(SEXP tc, int options = 0); | ||
| SEXP rtsk_variant_iterator_init( |
There was a problem hiding this comment.
@LynxJinyangii Python API uses variants so best to follow that nomenclature.
There was a problem hiding this comment.
Other functions here are named as rtsk_treeseq_smth so this should then be one of rtsk_treeseq_variants (this matches Python, but we are here at C++ level so we can deviate from Python if this makes sense!),
rtsk_treeseq_variants_init (this is clearer in action/verb), rtsk_treeseq_variants_iterator_init (this one says what we are actually initialising),
rtsk_treeseq_variants_init_iterator or maybe better rtsk_treeseq_init_variants_iterator. I personally like the last one most;0
| bool isolated_as_missing = true, | ||
| Rcpp::Nullable<Rcpp::CharacterVector> alleles = R_NilValue, | ||
| double left = 0.0, double right = NA_REAL); | ||
| SEXP rtsk_variant_iterator_next(SEXP iterator); |
There was a problem hiding this comment.
@LynxJinyangii Python API uses variants (with s) so best to follow that nomenclature.
There was a problem hiding this comment.
We need a better name too. Options?
We have rtsk_treeseq_init_variants_iterator for the initialiser. We could do something like that, as in long, but rtsk_treeseq_next_variant seems simpler and clear, so let's go with that.
| bool rtsk_table_collection_has_index(SEXP tc, int options = 0); | ||
| void rtsk_table_collection_build_index(SEXP tc, int options = 0); | ||
| void rtsk_table_collection_drop_index(SEXP tc, int options = 0); | ||
| void rtsk_table_collection_sort(SEXP tc, int edge_start = 0, int site_start = 0, |
There was a problem hiding this comment.
C API calls this arg as start and passes in a bookmark, which is a structure with edges, nodes, etc. members, but not all are working and Pyhon only implements 3 args listed here. We won't implement the bookmark on our end at this point. So let's call these arg on our end start_edges, start_sites, and start_mutations so we match C and C++ API, but keep these arg names on R side to match Python. I know this is super annoying, but this is the pattern we follow everywhere - C++ matches C and R matches Python. Super annoying!
| void rtsk_table_collection_drop_index(SEXP tc, int options = 0); | ||
| void rtsk_table_collection_sort(SEXP tc, int edge_start = 0, int site_start = 0, | ||
| int mutation_start = 0, int options = 0); | ||
| Rcpp::IntegerVector rtsk_table_collection_simplify( |
There was a problem hiding this comment.
Aha, no need as node_map is return from this function, right?
| `TableCollection$simplify()` to simplify table collections, with C-level | ||
| options at low level and Python-style arguments at the R6 level. | ||
| - Added low-level variant iterators | ||
| (`rtsk_variant_iterator_init()`/`rtsk_variant_iterator_next()`) and a |
There was a problem hiding this comment.
Sync the names of these functions
| @@ -40,7 +40,31 @@ and releases adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html | |||
| - Added `rtsk_mutation_table_add_row()` and | |||
| `TableCollection$mutation_table_add_row()` to append mutation rows from | |||
| \code{R}, mirroring `tsk_mutation_table_add_row()`. | |||
There was a problem hiding this comment.
| \code{R}, mirroring `tsk_mutation_table_add_row()`. | |
| `R`, mirroring `tsk_mutation_table_add_row()`. |
| - TODO | ||
| - Added `rtsk_population_table_add_row()` and | ||
| `TableCollection$population_table_add_row()` to append population rows from | ||
| \code{R}, mirroring `tsk_population_table_add_row()`. |
There was a problem hiding this comment.
| \code{R}, mirroring `tsk_population_table_add_row()`. | |
| `R`, mirroring `tsk_population_table_add_row()`. |
| \code{R}, mirroring `tsk_population_table_add_row()`. | ||
| - Added `rtsk_migration_table_add_row()` and | ||
| `TableCollection$migration_table_add_row()` to append migration rows from | ||
| \code{R}, mirroring `tsk_migration_table_add_row()`. |
There was a problem hiding this comment.
| \code{R}, mirroring `tsk_migration_table_add_row()`. | |
| `R`, mirroring `tsk_migration_table_add_row()`. |
| \code{R}, mirroring `tsk_migration_table_add_row()`. | ||
| - Added `rtsk_provenance_table_add_row()` and | ||
| `TableCollection$provenance_table_add_row()` to append provenance rows from | ||
| \code{R}, mirroring `tsk_provenance_table_add_row()`. |
There was a problem hiding this comment.
| \code{R}, mirroring `tsk_provenance_table_add_row()`. | |
| `R`, mirroring `tsk_provenance_table_add_row()`. |
| - Added `rtsk_table_collection_sort()` and `TableCollection$sort()` to sort | ||
| table collections. | ||
| - Added `rtsk_table_collection_simplify()` and | ||
| `TableCollection$simplify()` to simplify table collections, with C-level |
There was a problem hiding this comment.
| `TableCollection$simplify()` to simplify table collections, with C-level | |
| `TableCollection$simplify()` to simplify table collection. |
| - Added `rtsk_node_table_get_row()` and `TableCollection$node_table_get_row()` | ||
| to retrieve node-table rows by 0-based row index. | ||
| - Added `rtsk_table_collection_sort()` and `TableCollection$sort()` to sort | ||
| table collections. |
There was a problem hiding this comment.
| table collections. | |
| table collection. |
| table collections. | ||
| - Added `rtsk_table_collection_simplify()` and | ||
| `TableCollection$simplify()` to simplify table collections, with C-level | ||
| options at low level and Python-style arguments at the R6 level. |
There was a problem hiding this comment.
| options at low level and Python-style arguments at the R6 level. |
| - Added low-level variant iterators | ||
| (`rtsk_variant_iterator_init()`/`rtsk_variant_iterator_next()`) and a | ||
| user-facing `TreeSequence$variants()` method to iterate over decoded | ||
| site-by-site variants from \code{R}, aligned with `tskit` Python API |
There was a problem hiding this comment.
| site-by-site variants from \code{R}, aligned with `tskit` Python API | |
| site-by-site variants from `R`, aligned with `Python` API |
No description provided.