Skip to content

Commit

Permalink
Merge pull request #1034 from aabiddanda/main
Browse files Browse the repository at this point in the history
Generated catalog figures for each published demographic model
  • Loading branch information
grahamgower committed Oct 19, 2021
2 parents 91303f3 + ee66346 commit e1c1e72
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
26 changes: 26 additions & 0 deletions docs/_ext/speciescatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sphinx.util import logging

import stdpopsim
import os

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -401,6 +402,30 @@ def model_section(self, species, model):
section += self.model_parameter_table(species, model)
return [target, section]

def model_image(self, species, model):
import demesdraw
import matplotlib.pyplot as plt

mid = self.get_demographic_model_id(species, model)
_, ax = plt.subplots(1, 1, figsize=(4, 4), tight_layout=True)
# Conversion into demes object for easier plotting
graph = model.model.to_demes()
demesdraw.tubes(graph, ax=ax, log_time=True)
ax.set_title(f"{model.id}", fontsize=10)
ax.set_xticklabels(
[p.name for p in model.populations],
rotation=45,
ha="right",
rotation_mode="anchor",
fontsize=10,
)
ax.set_ylabel("Time (generations)", fontsize=10)
os.makedirs(f"parameter_images/{species.id}/", exist_ok=True)
img_name = f"parameter_images/{species.id}/{mid}.png"
plt.savefig(img_name, dpi=150)
section = nodes.image(uri=img_name)
return section

def run(self):
species = stdpopsim.get_species(self.arguments[0])
sid = f"sec_catalog_{species.id}"
Expand All @@ -427,6 +452,7 @@ def run(self):
models_section += self.models_table(species)
for i, model in enumerate(species.demographic_models):
models_section += self.model_section(species, model)
models_section += self.model_image(species, model)
if i < len(species.demographic_models) - 1:
models_section += nodes.transition()
section += models_section
Expand Down
2 changes: 1 addition & 1 deletion docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ message:
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
**DO NOT LISTEN TO GIT IN THIS CASE!** Git is giving you is **terrible advice**
**DO NOT LISTEN TO GIT IN THIS CASE!** Git is giving you **terrible advice**
which will mess up your branch. What we need to do is replace the state of
the branch ``topic_branch_name`` on your fork on GitHub (the ``upstream`` remote)
with the state of your local branch, ``topic_branch_name``. We do this
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
- msprime
- scikit-allel
- matplotlib
- demesdraw
- slim
# load the stdpopsim Github repository as a library using pip
- pip:
Expand Down
2 changes: 2 additions & 0 deletions requirements/CI/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ numpy==1.21.2
scikit-allel==1.3.5
zarr==2.10.0
biopython==1.79
demes==0.1.2
demesdraw==0.1.4
2 changes: 2 additions & 0 deletions requirements/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ numpy
scikit-allel
zarr>=2.4
biopython
demes==0.1.2
demesdraw==0.1.4
2 changes: 1 addition & 1 deletion stdpopsim/catalog/HomSap/demographic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# population definitions that are reused.
_yri_population = stdpopsim.Population(
id="YRI", description="1000 Genomes YRI (Yorubans)"
id="YRI", description="1000 Genomes YRI (Yoruba)"
)
_ceu_population = stdpopsim.Population(
id="CEU",
Expand Down

0 comments on commit e1c1e72

Please sign in to comment.