Python & tskit

Converting to tskit

An Arg can be converted to a TreeSequence using the ts method. From there, you have access to the complete TreeSequence API.

Conversion of Python objects towards Julia is mainly done by the pyconvert methods (details here).

Installing Moonshine From Python

Moonshine can be installed from Python using the juliapkg package, which is available from pip. After installation, simply run:

import juliapkg
juliapkg.add("Moonshine")

Calling Moonshine From Python

To actually use Moonshine, you will need the juliacall package. Once installed, you can load Moonshine using the seval method:

import juliacall
juliacall.Main.seval("using Moonshine")

You should now have access to the entirety of Moonshine. For instance, you can construct a random arg tree:

M = juliacall.Main.Moonshine

juliacall.Main.seval("using Random")
rng = juliacall.Main.Xoshiro(42)

arg = M.Arg(rng, 1000, 1e-8, 1e-8, 1e4, 1e6)
M.build_b(rng, arg)

Since Python does not allow the character ! in symbol names, it is replaced with _b as shown in the last line. arg is a Julia object, but we can easily convert it to a Python TreeSequence with the aforementioned ts method:

trees = M.ts(arg)