Is there a way to save tag and/or custom metadata to the .trees output by SLiM? #198
-
Hi again, I am using tags heavily in my models. Is there a way to save tags to the metadata so I can use them to calculate stats, along with more easily initiating a new SLiM simulation from the saved .trees file? Additionally it would also be useful to be able to save custom metadata to the .trees file, for instance, the "settings" from the SLiM simulation, so that I can reference them when dealing with the tree sequence in Python. Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
In it's simplest form you can: tables = ts.dump_tables() #Tree sequences are only modifiable via the table API.
tables.metadata_schema = tskit.MetadataSchema({'codec': 'json'}) #The simplest, permissive schema
tables.metadata = {'some':'info', 'anumber': 5} #Assign any python dict with simple types in. Not that this will overwrite any existing metadata on the tree sequence, you can check for any by checking |
Beta Was this translation helpful? Give feedback.
-
Whoops - what @benjeffery says is right, but I think the question is about adding the information to individuals or nodes' metadata within SLiM. This is not possible, unfortunately - it'd be nice to do in the future, but doing it in a way that doesn't affect performance significantly is hard. However, it is possible to add arbitrary information to the top-level metadata, which gets at parts of your question - now |
Beta Was this translation helpful? Give feedback.
Whoops - what @benjeffery says is right, but I think the question is about adding the information to individuals or nodes' metadata within SLiM. This is not possible, unfortunately - it'd be nice to do in the future, but doing it in a way that doesn't affect performance significantly is hard. However, it is possible to add arbitrary information to the top-level metadata, which gets at parts of your question - now
treeSeqOutput
takes ametadata
argument that can be anything you want, and will be available asts.metadata['SLiM']['user_metadata']
. This can for instance contain the SLiM IDs and tags of all individuals alive at the end of the simulation, which you could use for reloading.