Skip to content

bug fixes in add_mutation_metadata_tables - #434

Merged
petrelharp merged 1 commit into
tskit-dev:mainfrom
jeffspence:main
Sep 1, 2026
Merged

petrelharp merged 1 commit into
tskit-dev:mainfrom
jeffspence:main

Conversation

@jeffspence

@jeffspence jeffspence commented Aug 19, 2026

Copy link
Copy Markdown

I've been trying to use pyslim in the multi-trait addition to stdpopsim and was getting some errors related to pyslim.add_mutation_metadata_tables . Digging into it, there were two separate things going on:

  1. If the tables object passed to pyslim.add_mutation_metadata_tables has multiple traits, that information is not passed into default_slim_metadata(), which then results in errors resulting from mismatching dimensions. Adding num_traits=len(ts_metadata["SLiM"]["traits"]) as a kwarg to default_slim_metadata() fixes that.
  2. if mut_ids is empty, then np.array(mut_ids, dtype="int") only has one dimension (of length 0), but subsequent code assumes that it is 2 dimensional. Wrapping the code to extend ts_metadata["SLiM_mutation_list"] in an if block deals with this, and shouldn't affect anything because if mut_ids is empty, then there's nothing to add to ts_metadata["SLiM_mutation_list"] anyway.

I didn't write any tests for these because I'm not sure where to start (and a bunch of the tests are currently failing independent of the code changes proposed in this PR) but I'd be happy to do that with a bit of guidance.

Edit: I also found a missing word in the convert_alleles docstring.

@petrelharp

Copy link
Copy Markdown
Contributor

Whoops, sorry - I seem to have missed this? I'll get this in.

@petrelharp

Copy link
Copy Markdown
Contributor

Hey @jeffspence - can you let me know what was the code that was wrong that you needed to fix with this?

@jeffspence

jeffspence commented Aug 31, 2026

Copy link
Copy Markdown
Author

@petrelharp I triggered the errors in the fork of stdpopsim where I'm working on traits stuff (https://github.com/jeffspence/stdpopsim/tree/traits_into_slim_engine). Running the tests in TestTraits in test_slim_engine.py with the non-patched version of pyslim incorporating the above changes results in a bunch of errors.

A MWE that shows both of the issues is in the attached files. mwe.zip contains mwe.slim which initializes two traits and then simulates a tree sequence (present in mwe.trees). The code in mwe.py essentially tries to recapitate it and then add mutations. If the mutation rate is low, no mutations get added and the error in number 2 here gets triggered. If the mutation rate is high enough that some mutations get added, then error number 1 gets triggered.

Let me know if any of that is unclear, or if I'm doing something trivially wrong.

petrelharp added a commit to jeffspence/pyslim that referenced this pull request Sep 1, 2026
@petrelharp

Copy link
Copy Markdown
Contributor

Thanks for this! I've got some tests in that should trigger these issues. I guess we need some more traits-related tests in here!

petrelharp added a commit to petrelharp/pyslim that referenced this pull request Sep 1, 2026
@codecov-commenter

codecov-commenter commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.71%. Comparing base (c6b4b5d) to head (1290fb7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #434      +/-   ##
==========================================
+ Coverage   96.69%   96.71%   +0.01%     
==========================================
  Files           8        8              
  Lines         909      914       +5     
  Branches      179      181       +2     
==========================================
+ Hits          879      884       +5     
  Misses         18       18              
  Partials       12       12              
Flag Coverage Δ
python-tests 96.71% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petrelharp
petrelharp merged commit d24770c into tskit-dev:main Sep 1, 2026
11 checks passed
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 this pull request may close these issues.

3 participants