-
Notifications
You must be signed in to change notification settings - Fork 78
Description
In getting pyslim to use the new metadata machinery I'm coming across some things to be documented, so I'm opening this to make a list of those (and to check if I'm doing things right):
-
to check if metadata is being decoded, you can check if
len(metadata_schema.schema) > 0(but there's probably a better way) -
the C functions to set metadata schemas want valid json strings (and note that this looks almost like a python dictionary but not quite: e.g.
truenotTrue) -
the top-level (tree sequence) metadata can be directly assigned to, e.g.
tables.metadata = { 'a': 'valid_dict' }(and, does it get validated?) -
if you change the metadata schema, it does not (?) go through and validate all your metadata (even the top-level metadata)
-
different things can co-exist in the top-level metadata, so client code should usually create their own top-level key and put stuff under that, leaving alone whatever is there already in both the schema and the metadata itself
-
to allow metadata to be "this thing or else nothing", set
"type": ["object", "null"](and, carry on withproperties, they'll only apply if the metadata is not null) -
to add keys to the top-level metadata schema, (a) get the dictionary that is the metadata-schema.schema property, e.g.,
schema = tables.metadata_schema.schema, and then edit it, e.g.schema['objects']['properties']['SLiM'] = { some new dict }, and then reassign it (e.g.tables.metadata_schema = tskit.MetadataSchema(schema)) Beware that doing some of these operations on a tree sequence, or even a table collection, silently does nothing) -
things are a bit confusing because (IIUC) you can modify the top-level metadata in place, as a dict, but you cannot modify the top-level metadata_schema.schema in place, even though it's also a dict
Apologies for the unordered brain dump.