harrispopgen / mushi

[mu]tation [s]pectrum [h]istory [i]nference
https://harrispopgen.github.io/mushi/
MIT License
24 stars 6 forks source link

`true_divide` error in folded SFS inference with integer SFS data #63

Closed wsdewitt closed 3 years ago

wsdewitt commented 3 years ago

When the SFS array is of integer dtype, this line fails: https://github.com/harrispopgen/mushi/blob/6dee54c00d7d0274771a590e69ce9d734537a26a/mushi/ksfs.py#L237 E.g.

>>> ksfs = kSFS(X=np.array([3, 2, 1]))
>>> ksfs.infer_history(np.array([10, 100, 1000]), 1, folded=True, infer_mu=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/net/gs/vol1/home/wsdewitt/miniconda3/envs/1KG/lib/python3.7/site-packages/mushi/ksfs.py", line 237, in infer_history
    x[self.n // 2 - 1] /= 2

This can be corrected by using integer division, //2 instead of /2:

 x[self.n // 2 - 1] //= 2
wsdewitt commented 3 years ago

Plotting the total SFS is also affected by this issue: https://github.com/harrispopgen/mushi/blob/40552ce712e683a008757bc6d65c76a1e7e79ecc/mushi/ksfs.py#L509