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

Output YAML for the Graph __str__. #293

Merged
merged 1 commit into from
May 11, 2021

Conversation

grahamgower
Copy link
Member

Closes #235.
Closes #291.

Sample output:

$ python
Python 3.9.3 (default, Apr  8 2021, 23:35:02)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import demes
>>> 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
  description: Anatomically modern humans
  ancestors: [ancestral]
  epochs:
  - {end_time: 140000.0, start_size: 12300}
- name: OOA
  description: Bottleneck out-of-Africa population
  ancestors: [AMH]
  epochs:
  - {end_time: 21200.0, start_size: 2100}
- name: YRI
  description: Yoruba in Ibadan, Nigeria
  ancestors: [AMH]
  epochs:
  - {end_time: 0, start_size: 12300}
- name: CEU
  description: Utah Residents (CEPH) with Northern and Western European Ancestry
  ancestors: [OOA]
  epochs:
  - {end_time: 0, start_size: 1000, end_size: 29725}
- name: CHB
  description: Han Chinese in Beijing, China
  ancestors: [OOA]
  epochs:
  - {end_time: 0, start_size: 510, end_size: 54090}
migrations:
- demes: [YRI, CEU]
  rate: 3e-05
- demes: [YRI, CHB]
  rate: 1.9e-05
- demes: [CEU, CHB]
  rate: 9.6e-05
- {source: YRI, dest: OOA, rate: 0.00025}
- {source: OOA, dest: YRI, end_time: 21200.0, rate: 0.00025}

@codecov
Copy link

codecov bot commented May 10, 2021

Codecov Report

Merging #293 (3b12f32) into main (5620c5c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #293   +/-   ##
=======================================
  Coverage   98.14%   98.14%           
=======================================
  Files           7        7           
  Lines        1401     1403    +2     
=======================================
+ Hits         1375     1377    +2     
  Misses         26       26           
Impacted Files Coverage Δ
demes/demes.py 100.00% <100.00%> (ø)
demes/load_dump.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5620c5c...3b12f32. Read the comment docs.

@jeromekelleher
Copy link
Member

Looks great, but this should be the __str__ not the __repr__. str is for humans and repr is the concise machine readable version.

@grahamgower
Copy link
Member Author

Thanks @jeromekelleher. You're right, of course. I'll take this as a reminder to always look up the docs for __repr__ and __str__ whenever I use them. :)

The output is now:

$ python
Python 3.9.3 (default, Apr  8 2021, 23:35:02)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import demes
>>> g = demes.load("examples/gutenkunst_ooa.yml")
>>> g
Graph(description='The Gutenkunst et al. (2009) OOA model.', time_units='years', generation_time=25, doi=['https://doi.org/10.1371/journal.pgen.1000695'], demes=[Deme(name='ancestral', description='Equilibrium/root population', start_time=inf, ancestors=[], proportions=[], epochs=[Epoch(start_time=inf, end_time=220000.0, start_size=7300, end_size=7300, size_function='constant', selfing_rate=0, cloning_rate=0)]), Deme(name='AMH', description='Anatomically modern humans', start_time=220000.0, ancestors=['ancestral'], proportions=[1.0], epochs=[Epoch(start_time=220000.0, end_time=140000.0, start_size=12300, end_size=12300, size_function='constant', selfing_rate=0, cloning_rate=0)]), Deme(name='OOA', description='Bottleneck out-of-Africa population', start_time=140000.0, ancestors=['AMH'], proportions=[1.0], epochs=[Epoch(start_time=140000.0, end_time=21200.0, start_size=2100, end_size=2100, size_function='constant', selfing_rate=0, cloning_rate=0)]), Deme(name='YRI', description='Yoruba in Ibadan, Nigeria', start_time=140000.0, ancestors=['AMH'], proportions=[1.0], epochs=[Epoch(start_time=140000.0, end_time=0, start_size=12300, end_size=12300, size_function='constant', selfing_rate=0, cloning_rate=0)]), Deme(name='CEU', description='Utah Residents (CEPH) with Northern and Western European Ancestry', start_time=21200.0, ancestors=['OOA'], proportions=[1.0], epochs=[Epoch(start_time=21200.0, end_time=0, start_size=1000, end_size=29725, size_function='exponential', selfing_rate=0, cloning_rate=0)]), Deme(name='CHB', description='Han Chinese in Beijing, China', start_time=21200.0, ancestors=['OOA'], proportions=[1.0], epochs=[Epoch(start_time=21200.0, end_time=0, start_size=510, end_size=54090, size_function='exponential', selfing_rate=0, cloning_rate=0)])], migrations=[AsymmetricMigration(source='YRI', dest='OOA', start_time=140000.0, end_time=21200.0, rate=0.00025), AsymmetricMigration(source='OOA', dest='YRI', start_time=140000.0, end_time=21200.0, rate=0.00025), AsymmetricMigration(source='YRI', dest='CEU', start_time=21200.0, end_time=0, rate=3e-05), AsymmetricMigration(source='CEU', dest='YRI', start_time=21200.0, end_time=0, rate=3e-05), AsymmetricMigration(source='YRI', dest='CHB', start_time=21200.0, end_time=0, rate=1.9e-05), AsymmetricMigration(source='CHB', dest='YRI', start_time=21200.0, end_time=0, rate=1.9e-05), AsymmetricMigration(source='CEU', dest='CHB', start_time=21200.0, end_time=0, rate=9.6e-05), AsymmetricMigration(source='CHB', dest='CEU', start_time=21200.0, end_time=0, rate=9.6e-05)], pulses=[])

>>> print(g)
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
  description: Anatomically modern humans
  ancestors: [ancestral]
  epochs:
  - {end_time: 140000.0, start_size: 12300}
- name: OOA
  description: Bottleneck out-of-Africa population
  ancestors: [AMH]
  epochs:
  - {end_time: 21200.0, start_size: 2100}
- name: YRI
  description: Yoruba in Ibadan, Nigeria
  ancestors: [AMH]
  epochs:
  - {end_time: 0, start_size: 12300}
- name: CEU
  description: Utah Residents (CEPH) with Northern and Western European Ancestry
  ancestors: [OOA]
  epochs:
  - {end_time: 0, start_size: 1000, end_size: 29725}
- name: CHB
  description: Han Chinese in Beijing, China
  ancestors: [OOA]
  epochs:
  - {end_time: 0, start_size: 510, end_size: 54090}
migrations:
- demes: [YRI, CEU]
  rate: 3e-05
- demes: [YRI, CHB]
  rate: 1.9e-05
- demes: [CEU, CHB]
  rate: 9.6e-05
- {source: YRI, dest: OOA, rate: 0.00025}
- {source: OOA, dest: YRI, end_time: 21200.0, rate: 0.00025}

@grahamgower grahamgower changed the title Output YAML for the Graph __repr__. Output YAML for the Graph __str__. May 11, 2021
Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful!

@grahamgower grahamgower merged commit d200bb4 into popsim-consortium:main May 11, 2021
@grahamgower grahamgower deleted the repr branch May 11, 2021 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants