pmckenz1 / ipcoal

Simulation package for getting gene tree distributions and loci / SNPs from input tree topologies and migration / Ne scenarios. Wraps around msprime.
MIT License
12 stars 7 forks source link

unhashable type: 'MassMigration' in Model.py #30

Open David-Peede opened 2 years ago

David-Peede commented 2 years ago

Hi Patrick and Dr. Eaton,

I was running through the documentation and I came across an error with Model.py which I naively think is due to pre msprime v 1.+ syntax not properly working. Here is how to recreate my error:

# Print versions of our libraries.
print('toytree', toytree.__version__)
print('ipcoal', ipcoal.__version__)

toytree 2.0.5 ipcoal 0.1.5

# Generate a random tree with 8 tips and height of 1M generations.
tree1 = toytree.rtree.unittree(8, treeheight=1e6, seed=123)
# Initialize a model object given a species tree and Ne setting.
model = ipcoal.Model(tree=tree1, Ne=1e5)

TypeError Traceback (most recent call last) /tmp/ipykernel_3888/2875736.py in 1 # Initialize a model object given a species tree and Ne setting. ----> 2 model = ipcoal.Model(tree=tree1, Ne=1e5)

~/Applications/JupyterLab.app/Contents/Resources/jlab_server/lib/python3.8/site-packages/ipcoal/Model.py in init(self, tree, > Ne, admixture_edges, admixture_type, nsamples, mut, recomb, recomb_map, seed, seed_mutations, substitution_model, debug, **kwargs) 240 241 # get .ms_demography dict for msprime input --> 242 self._get_demography() 243 244 # get .ms_popconfig as msprime input

~/Applications/JupyterLab.app/Contents/Resources/jlab_server/lib/python3.8/site-packages/ipcoal/Model.py in _get_demography(self) 577 source = max([i._schild for i in node.children]) 578 time = node.height # int(node.height) --> 579 demog.add(ms.MassMigration(time, source, dest)) 580 581 # for all nodes set Ne changes

TypeError: unhashable type: 'MassMigration'

Additionally, when I run this on the binder from the documentation I get the same exact error. What is weird is that looking through the code for Model.py I can't seem to find where this issue is, which is why I am reaching out because I naively think the code base is totally up to date with the latest msprime code. Any help would be greatly appreciated!

-Dave

David-Peede commented 2 years ago

UPDATE: I did some digging around the eaton-lab/sptree-chapter page to try to nail down what was the latest version of ipcoal that worked which seems to be version 0.1.0, unfortunately only versions 0.1.4 and 0.1.5 are available on GitHub and reverting back to version 0.1.4 gave me the same error as above... As a last attempt, I tried to use the code that is currently in this repo via:

%pip install git+git://github.com/pmckenz1/ipcoal.git

but unfortunately when I now run:

# Generate a random tree with 8 tips and height of 1M generations.
tree1 = toytree.rtree.unittree(8, treeheight=1e6, seed=123)
# Initialize a model object given a species tree and Ne setting.
model = ipcoal.Model(tree=tree1, Ne=1e5, debug)

I get this new error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_20742/2875736.py in <module>
      1 # Initialize a model object given a species tree and Ne setting.
----> 2 model = ipcoal.Model(tree=tree1, Ne=1e5)

~/Applications/JupyterLab.app/Contents/Resources/jlab_server/lib/python3.8/site-packages/ipcoal/Model.py in __init__(self, tree, Ne, admixture_edges, admixture_type, nsamples, mut, recomb, recomb_map, seed, seed_mutations, substitution_model, debug, **kwargs)
    240         The demography model renames populations according to their
    241         toytree idx label with an 'n' prefix. This is required since
--> 242         msp has very strict pop naming conventions. Thus, here I
    243         rename the pops (tree tips) to match those names. The final
    244         outputs will be converted back to the tip names on the tree.

~/Applications/JupyterLab.app/Contents/Resources/jlab_server/lib/python3.8/site-packages/ipcoal/Model.py in _get_demography(self)
    560             single 'locus'.
    561         start: (int)
--> 562             Slice start position of sequence array to draw. Default=0.
    563         end: (int)
    564             Slice end position of sequence array to draw. Default=end.

TypeError: unhashable type: 'MassMigration'

which makes even less sense to me since in Model.py all of that text is just the description of the Model class.

mydjc commented 2 years ago

Hi, I hit the same error like you, and I adjusted the ipcoal/model.py according to the comment https://github.com/pmckenz1/ipcoal/commit/ba8d9c00e8760e3c86c18385fe7912663374c8bf?diff=split, and fixed it successfully. Maybe you can have a try.

hemille-huggler commented 11 months ago

any updates?