Skip to content

Add "insert sites" method to TableCollection (and possibly TS) #675

Closed as not planned

Description

@hyanwong

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:

def insert_sites(self, positions, ancestral_states, metadata=None):
    if metadata is None:
        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 ones
    new_locations = np.searchsorted(self.sites.position[:], positions)
    assert np.all(self.sites.position[:][new_locations] == positions)
    return new_locations

Activity

  1. jeromekelleher commented on Jun 9, 2020

    @jeromekelleher
    Member

    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.

  2. hyanwong commented on Jun 9, 2020

    @hyanwong
    MemberAuthor

    @petrelharp just mentioned that #623 might be an alternative. I'll wait until that is done before taking this further, if necessary.

  3. petrelharp commented on Jun 9, 2020

    @petrelharp
    Contributor

    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?)

  4. added
    C API
    enhancement
    Python API
    on Sep 29, 2020
  5. added
    future
    on Jun 12, 2025
  6. benjeffery commented on Jun 12, 2025

    @benjeffery
    Member

    Closing for inactivity and labelling "future", please re-open if you plan to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C APIPython APIenhancementfuture

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions