Skip to content

Implement __getitem__ in ReferenceSequence #1988

Closed as not planned
Closed as not planned

Description

@jeromekelleher

It would be nice to implement the things like

# What is the reference base at position 12345?
ts.reference_sequence[12345]
# What are the bases between position a and b?
ts.reference_sequence[a:b]

etc. Assuming the slices are reasonably small, this can be done efficiently by implementing the __getitem__ method, and either accessing the data via numpy arrays, or just implementing in the Python C layer.

In the future, we can implement the data fetching methodology from URLs in the background to implement these queries.

Activity

  1. added
    Python API
    on Dec 2, 2021
  2. added this to the Python upcoming milestone on Dec 2, 2021
  3. jeromekelleher commented on Dec 2, 2021

    @jeromekelleher
    MemberAuthor

    In general, I guess what we want to to present a str-like API, so that we generally regard the ts.reference_sequence instance as a unicode string, with some extra methods that let us figure out where it came from, etc.

    One odd thing then though would be that __str__ would not return the string itself, but a useful summary.

  4. hyanwong commented on Mar 22, 2024

    @hyanwong
    Member

    It would actually be very helpful not to return the string. At the moment, when I have a whole chromosome reference sequence, if I print it to screen it can stall my python REPL / notebook cell. It would be preferable to show a truncated string.

  5. removed this from the Python upcoming milestone on Jun 12, 2025
  6. added
    enhancement
    future
    on Jun 12, 2025
  7. self-assigned this
    on Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Python APIenhancementfuture

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions