Skip to content

Support for reference sequences #146

Closed

Description

@jeromekelleher

For some applications it would be useful to know the reference sequence that a tree sequence coordinate space refers to. For example, with real data, we should (at a minimum) record the reference build (e.g., GRCh38) and the contig ID (e.g., chr22) associated with a tree sequence. Ideally, we would also like to be able to do things like:

for site in ts.sites():
     print(site.position, site.ref_allele)

As well as situations in which a well-known canonical reference is available, we may also have a one-off reference sequence that we wish to record, e.g., in simulations.

To support this, I suggest adding a reference section to the file store, with some fields. Roughly, these might looks like:

reference/build         -- e.g. GRCh38
reference/contig       -- e.g. chr22
reference/id              -- md5 hash of the sequence, c.f. refget
reference/sequence -- Actual sequence information

The references section would be itself optional (keeping backward compatability), and some fields would probably be optional within this section (for example, reference/sequence would definitely be optional --- no point in storing GRCh38 chr1 over and over again). We can imagine having some mechanisms for automatically retrieving sequences using refget, but this isn't at all necessary for a basic implementation.

At a high-level, we should try to follow any upstream standards as closely as possible, e.g. GA4GH refget and any others that are relevant.

Any thoughts @tskit-dev/all, @bhaller?

Activity

  1. added
    enhancement
    on Mar 13, 2019
  2. hyanwong commented on Mar 13, 2019

    @hyanwong
    Member

    This seems very sensible, but I wonder if the word "reference" is a bit too context-dependent. Perhaps "genome_reference" or something similar would be clearer?

  3. bhaller commented on Mar 13, 2019

    @bhaller

    In SLiM I'm calling it the "ancestral sequence". I'm fine with "reference" or "genome_reference" or any such variant. The rest of the proposal seems good to me. It should be clarified, when this is documented, exactly what format reference/sequence is expected to be in – FASTA? Is a FASTA header allowed? Are newline characters allowed (\r, \n)? Nucleotides only, presumably, not FASTA amino acid sequences? But FASTA codes for ambiguous nucleotides of various sorts? But I think SLiM will just dump an unbroken stream of ACGT into it, so that is all that I need to be supported.

  4. jeromekelleher commented on Mar 13, 2019

    @jeromekelleher
    MemberAuthor

    Thanks @bhaller. To clarify, it'll be a flat array of chars, such that reference[pos] is the reference allele at position pos.

  5. changed the title [-]Support for references[/-] [+]Support for reference sequences[/+] on Mar 15, 2019
  6. petrelharp commented on Mar 15, 2019

    @petrelharp
    Contributor

    I think this is a great idea, and lean towards calling it just reference (although reference_sequence would also be fine). I don't think it should be called ancestral_sequence, because I'd argue these shouldn't be the same thing, necessarily. Here's some reasons:

    • If we say they're supposed to be the same, then the ancestral_state column of the Site table is supposed to match the positions in the reference sequence, which is annoying and redundant.
    • The reference sequence is usually not the ancestral sequence, in practice. (eg GRCh38), but is still useful.
    • The reference sequence could still be used by e.g. SLiM to store, essentially, the ancestral sequence.
  7. hyanwong commented on Mar 15, 2019

    @hyanwong
    Member

    FWIW I would (marginally) vote for reference_sequence. reference sounds like it might contain metadata about bibliographic references relevant to the provenance of the data. But maybe I'm being too naive.

  8. molpopgen commented on Mar 15, 2019

    @molpopgen
    Member

    @petrelharp is right here. I actually get papers across my desk where someone has calculated Fay and Wu's H w.r.to the reference allelic state :(.

    I do like @hyanwong's idea to call it reference_sequence. At first, I thought this thread was about adding bibtex support to the docs.

  9. petrelharp commented on Mar 19, 2019

    @petrelharp
    Contributor

    @bhaller is going to actually start storing a reference sequence on output from SLiM nucleotide models, so we should at least get it nailed down what we will call it. The proposal is, I think,

    • reference_sequence/build -- e.g. GRCh38
    • reference_sequence/contig -- e.g. chr22
    • reference_sequence/id -- md5 hash of the sequence, c.f. refget
    • reference_sequence/sequence -- Actual sequence information

    All of these would be optional. How about it?

  10. jeromekelleher commented on Mar 19, 2019

    @jeromekelleher
    MemberAuthor

    OK, sounds good. I haven't researched what the right names for build, contig etc should be, so perhaps we could just keep it to reference_sequence/sequence if we're going to ship files that include it?

    Also reference_sequence/sequence seems repetitive and unintuitive. Maybe reference_sequence/data would be better?

  11. petrelharp commented on Mar 19, 2019

    @petrelharp
    Contributor

    Besides deciding what to name these entries in the kastore, we should record this somehow, possibly by providing API functions that will write and read it. We think the main question is: is the reference sequence part of a table collection object? It would seem natural to make it a part of the table collection, because then you would get it when you read the .trees file. But, in the SLiM application, the reference sequence is expected to be large, and making it part of the table collection object means that there will be more than one copy of it sitting around, because:

    • we have to copy the table collection when we write it out; and also
    • SLiM has an internal version of the reference sequence, so when reading in the .trees file with table_collection_load( ), if reference_sequence was part of the resulting object, it would need to be copied over to where SLiM wants it

    Since a table_collection_t has a kastore_t, we could define a function tsk_table_collection_read_reference_sequence( ) that would go into the store and pull out the reference sequence (if indeed such a store is associated). I'm not sure how to deal with writing out, though?

  12. petrelharp commented on Mar 19, 2019

    @petrelharp
    Contributor

    We could at least write a function that would re-open a .trees file and add a reference sequence to it.

  13. jeromekelleher commented on Mar 19, 2019

    @jeromekelleher
    MemberAuthor

    I don't know how we're going to manage it from the C perspective @petrelharp, and I'm afraid I just don't have time to work on it right now. I don't want to rush in changes to the C API without thinking through the consequences very carefully (particularly not with something this fundamental).

    I think the best thing to do from a SLiM perspective is to reopen the kastore in append mode after tskit has written it out, and write the reference sequence/data key in. Should be ~10 lines of code.

  14. molpopgen commented on Mar 19, 2019

    @molpopgen
    Member
  15. jeromekelleher commented on Mar 19, 2019

    @jeromekelleher
    MemberAuthor

    Does it make sense to add just the reference state at each variable site vs the entire reference?

    That was my original proposal, but Ben has reasons for wanting the full reference/ancestral sequence.

  16. 24 remaining items

  17. jeromekelleher commented on Nov 11, 2021

    @jeromekelleher
    MemberAuthor

    OK, so if I understand correctly, @petrelharp, I will back out the changes I made to move the reference sequence into metadata and go back to doing it exactly as it was before; as I understand it, that is the right move to be compatible with the tskit changes proposed here. I guess I'll wait to do that until the dust has settled here, to be sure that nothing changes.

    Don't make any changes yet @bhaller! We haven't decided we're definitely going to do it yet, it's a question now of whether we want to get Python 0.4.0 out sooner without reference sequences or a bit later with them. Any opinions @bhaller @petrelharp ?

  18. petrelharp commented on Nov 11, 2021

    @petrelharp
    Contributor

    Well, it'd be nice to not change where reference sequences go and then change back; if this doesn't go into tskit now we'll need to put them in metadata for the time being. But, @bhaller has done the hard work already...

  19. benjeffery commented on Nov 11, 2021

    @benjeffery
    Member

    My gut says to get it in, but undocumented for 0.4.0. I will have a quick recce to guage required effort. As it's just extra fields should be straight forward.

  20. bhaller commented on Nov 11, 2021

    @bhaller

    I'd very much like to see it happen now, so that SLiM 3.7 can have this stuff in place. Ties up a loose end for us, and as @petrelharp says, avoid having to move the reference sequence into metadata and then back out again, which is rather confusing for those users who use it. Undocumented for 0.4.0 seems fine from our end; let's just get it to its final resting place.

  21. jeromekelleher commented on Nov 12, 2021

    @jeromekelleher
    MemberAuthor

    We'll have a look at the details @bhaller and report back with a proposal by Monday.

  22. bhaller commented on Nov 16, 2021

    @bhaller

    Hi campers. Just a ping, since Monday is now history. :->

  23. benjeffery commented on Nov 17, 2021

    @benjeffery
    Member

    Sorry forgot you don't subscribe to the firehose! #1911

  24. bhaller commented on Nov 17, 2021

    @bhaller

    Sorry forgot you don't subscribe to the firehose! #1911

    OK, great! So the decision has been made, the reference sequence will go in reference_sequence/data in kastore for sure? I should set the wheels in motion on my end?

    [EDIT: Well, it sure looks that way from the diffs at #1911, so I'm going to go ahead and do it. :-> Thanks all – good to have this settled!]

  25. benjeffery commented on Nov 18, 2021

    @benjeffery
    Member

    Sorry forgot you don't subscribe to the firehose! #1911

    OK, great! So the decision has been made, the reference sequence will go in reference_sequence/data in kastore for sure? I should set the wheels in motion on my end?

    [EDIT: Well, it sure looks that way from the diffs at #1911, so I'm going to go ahead and do it. :-> Thanks all – good to have this settled!]

    Yes, but you should use the APIs, not accessing the kastore directly.

  26. bhaller commented on Nov 18, 2021

    @bhaller

    Yes, but you should use the APIs, not accessing the kastore directly.

    Ah, yes, indeed. Thanks for reminding me.

  27. added 4 commits that reference this issue on Dec 2, 2021
    d43961e
    2df7ebf
    11c408e
    43921cc
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions