You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add "insert sites" method to TableCollection (and possibly TS) #675
C APIIssue is about the C APIPython APIIssue is about the Python APIenhancementNew feature or requestfutureIssues that are closed as they are not planned in the medium-term, but which are still desirable.
It might be useful to have an insert_sites method which adds new (empty) sites at user-specified positions and updates the mutations table to keep everything sane? I can imagine this being useful as a prerequisite step for e.g. combining 2 tree sequences (or maybe VCF files) that have accumulated mutations at unique sites, or adding in new sites that have just been reported in an updated sequencing effort, etc. Other existing functions such as map_mutations could then be used to add mutations at any specific (currently empty) site.
It would be useful to sort the sites and return the new ids of the inserted sites, in the same order that the positions were passed in. I imagine it something like this:
definsert_sites(self, positions, ancestral_states, metadata=None):
ifmetadataisNone:
self.sites.append_columns(positions, *tskit.pack_bytes(ancestral_states))
else:
self.sites.append_columns(
positions,
*tskit.pack_bytes(ancestral_states),
*tskit.pack_bytes(metadata))
self.sort()
# Positions are required to be unique, so we can use these to identify the new onesnew_locations=np.searchsorted(self.sites.position[:], positions)
assertnp.all(self.sites.position[:][new_locations] ==positions)
returnnew_locations
LGTM. A bit wasteful to do a full sort when it's only the sites that need rejiggering, but we could fix that. Also might be better to use the singular position,and ancestral_state for consistency with the rest of the tables API.
I don't think there's any point in adding the same method to TreeSequence.
Discussing with @mufernando - I think this should be a different method to #623, but might use some of the same C infrastructure (which we plan to write). (Also, shouldn't this be a method to add sites and (optionally) mutations?)
C APIIssue is about the C APIPython APIIssue is about the Python APIenhancementNew feature or requestfutureIssues that are closed as they are not planned in the medium-term, but which are still desirable.
Activity
jeromekelleher commentedon Jun 9, 2020
LGTM. A bit wasteful to do a full sort when it's only the sites that need rejiggering, but we could fix that. Also might be better to use the singular
position,andancestral_statefor consistency with the rest of the tables API.I don't think there's any point in adding the same method to TreeSequence.
hyanwong commentedon Jun 9, 2020
@petrelharp just mentioned that #623 might be an alternative. I'll wait until that is done before taking this further, if necessary.
petrelharp commentedon Jun 9, 2020
Discussing with @mufernando - I think this should be a different method to #623, but might use some of the same C infrastructure (which we plan to write). (Also, shouldn't this be a method to add sites and (optionally) mutations?)
benjeffery commentedon Jun 12, 2025
Closing for inactivity and labelling "future", please re-open if you plan to work on this.