Skip to content

dump reference sequence #84

Closed
Closed

Description

@petrelharp

We currently aren't doing this! But need to.

Activity

  1. petrelharp commented on May 31, 2020

    @petrelharp
    ContributorAuthor

    Say, @jeromekelleher - is this currently do-able? Recall that SLiM includes the reference sequence in the kastore, which we then read in afterwards using kastore. But looking at the kastore documentation, I'm not seeing a non-ugly way to add something to the store? It looks like I could (a) dump the tree seequence (b) load it back with kastore (c) convert the store to a dictionary (d) add the reference sequence, and (e) dump it again with kastore, but this seems not so good.

  2. jeromekelleher commented on Jun 1, 2020

    @jeromekelleher
    Member

    Ah, so the issue is that there's some extra stuff in the kastore output by SLiM that isn't preserved when we load/modify/dump through pyslim? I think it's probably best to resolve that generally by looking at any keys in the loaded store and add them to the output one. The load/convert/add/dump stuff isn't very elegant, but should be pretty efficient as the arrays won't be copied. A kastore file can't be updated in place by design, so that's what you'd end up doing anyway.

  3. petrelharp commented on Jun 1, 2020

    @petrelharp
    ContributorAuthor

    there's some extra stuff in the kastore output by SLiM that isn't preserved when we load/modify/dump through pyslim

    yes - the reference sequence.

    I think it's probably best to resolve that generally by looking at any keys in the loaded store and add them to the output one.

    How do you do this?

  4. jeromekelleher commented on Jun 1, 2020

    @jeromekelleher
    Member
    new_keys = set(new_store.keys()) - set(old_store.keys())
    for key in new_keys:
         new_store[key] = old_store[key]
    kastore.dump(file, new_store)

    the conversion to dict will be very cheap.

  5. petrelharp commented on Jun 1, 2020

    @petrelharp
    ContributorAuthor

    Great, thanks. And, how should new_store be initialized? new_store = {}? (Perhaps I should write up an example for the kastore docs.)

  6. jeromekelleher commented on Jun 1, 2020

    @jeromekelleher
    Member

    Here's what I'm imagining:

    def to_stuff_to_slim_ts_and_save(slim_ts, filename):
        with tempfile.TemporaryDirectory() as tmpdir:
            slim_file = filename in tmpdir
            slim_ts.dump(slim_file)
            old_store = kastore.load(slim_file)
            new_ts = msprime.dosomething(slim_ts)
            new_ts_file = another filename in tmpdir
            new_ts.dump(new_ts_file)
            new_store = dict(kastore.load(new_ts_file))
            new_keys = set(new_store.keys()) - set(old_store.keys())
            for key in new_keys:
                new_store[key] = old_store[key]
            kastore.dump(filename, new_store)

    It's a bit awkward because we have to use the temp files, but it'll work.

  7. jeromekelleher commented on Jun 1, 2020

    @jeromekelleher
    Member

    You could use the same temporary file, if you like, I've just got used to doing things with temporary directories because it makes life easier on windows.

  8. added a commit that references this issue on Jun 1, 2020
    e369b79
  9. petrelharp commented on Jun 1, 2020

    @petrelharp
    ContributorAuthor

    I think this does what I want here - I know exactly what the extra key is, so don't need to be so general about it. Could you let me know if this looks reasonable?

  10. jeromekelleher commented on Jun 1, 2020

    @jeromekelleher
    Member

    Yep, that'll do the trick.

  11. added a commit that references this issue on Aug 9, 2020
    fd2f165
  12. added a commit that references this issue on Aug 27, 2020
    086a0ad
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions