Skip to content

Add metadata to individuals #2021

Discussion options

You must be logged in to vote

Hi @andrei-barysenka 👋

The TreeSequence object is read-only, and any modifications that you make to the Python objects you get back will either fail, or be transitory (as you have here with the Individual objects). If you want the changes to "stick" you need to work with the underlying TableCollection. For your example:

import msprime

ts = msprime.sim_ancestry(3, random_seed=2)

tables = ts.dump_tables()
tables.individuals.clear()
for individual in ts.individuals():
    individual.metadata = b"META"
    tables.individuals.append(individual)

print(tables.individuals)
ts2 = tables.tree_sequence()
for i in ts2.individuals():
    print(i)

However, you probably want to use a schema if you're…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andrei-barysenka
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants