Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add __str__() and _repr_html_() methods for the Graph, Epoch, et al. #235

Closed
grahamgower opened this issue Mar 2, 2021 · 6 comments · Fixed by #293
Closed

add __str__() and _repr_html_() methods for the Graph, Epoch, et al. #235

grahamgower opened this issue Mar 2, 2021 · 6 comments · Fixed by #293

Comments

@grahamgower
Copy link
Member

So that we do better than, e.g.:

Graph(description='asymmetric migration between two extant demes', time_units='generations', generation_time=None, doi=[], demes=[Deme(id='X', description=None, start_time=inf, ancestors=[], proportions=[], epochs=[Epoch(start_time=inf, end_time=1000, start_size=5000, end_size=5000, size_function='constant', selfing_rate=0, cloning_rate=0)]), Deme(id='A', description=None, start_time=1000, ancestors=['X'], proportions=[1.0], epochs=[Epoch(start_time=1000, end_time=0, start_size=5000, end_size=5000, size_function='constant', selfing_rate=0, cloning_rate=0)]), Deme(id='B', description=None, start_time=1000, ancestors=['X'], proportions=[1.0], epochs=[Epoch(start_time=1000, end_time=0, start_size=5000, end_size=5000, size_function='constant', selfing_rate=0, cloning_rate=0)])], migrations=[AsymmetricMigration(start_time=1000, end_time=0, rate=0.0001, source='A', dest='B')], pulses=[])

Like recently added to msprime's Demography class.

@jeromekelleher
Copy link
Member

I'm really missing a proper str implementation when working with demes - any thoughts on what this should look like? Even a simple tabular output would be very helpful.

@grahamgower
Copy link
Member Author

The attrs default leaves a lot to be desired. There's an example here using the prettyprinter package which looks nice: python-attrs/attrs#508 (comment)

@jeromekelleher
Copy link
Member

I think I'd be better to just hand craft something - it's time well spent, as it makes debugging so much easier.

@grahamgower
Copy link
Member Author

Well, we're making the claim that the yaml files are human readable, so how about using that?

>>> import demes
>>> demes.Graph.__repr__ = demes.dumps
>>> demes.load("examples/gutenkunst_ooa.yml")
description: The Gutenkunst et al. (2009) OOA model.
time_units: years
generation_time: 25
doi:
- https://doi.org/10.1371/journal.pgen.1000695
demes:
- name: ancestral
  description: Equilibrium/root population
  epochs:
  - end_time: 220000.0
    start_size: 7300
- name: AMH
...

@jeromekelleher
Copy link
Member

Excellent point! Yes, that's clearly the right approach.

@grahamgower
Copy link
Member Author

It turns out that it's possible to output a mix of flow style and block style using ruamel.yaml. I haven't quite figured out the incantation to do so, but if we can output deme ancestors/proportions and epochs/migrations/pulses using the flow style, this will certainly make for compact and readable debug output.

grahamgower added a commit to grahamgower/demes-python that referenced this issue May 10, 2021
grahamgower added a commit to grahamgower/demes-python that referenced this issue May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants