Preventing node ID's from changing? #3454
-
|
Hi, I am running a simulation, where i take 2 haploid genomes and generate 4 recombinant products through 2 independent shuffling events. So there are mirrored products. In the metadata section of the nodes table, I’m storing the node ID of the corresponding recombinant (mirror) product for a specific node. However, after running Is there a way to either:
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
You can use There's a new tutorial on |
Beta Was this translation helpful? Give feedback.
-
|
You may want to consider that Example to demonstrate: import tskit
tables = tskit.TableCollection(100)
p0 = tables.nodes.add_row(0, 2)
p1 = tables.nodes.add_row(1, 1)
c0 = tables.nodes.add_row(tskit.NODE_IS_SAMPLE, 0)
c1 = tables.nodes.add_row(tskit.NODE_IS_SAMPLE, 0)
tables.edges.add_row(0, 100, p0, p1)
tables.edges.add_row(0, 100, p1, c0)
tables.edges.add_row(0, 100, p1, c1)
tables.sort()
ts = tables.tree_sequence()
print(ts.draw_text())
ts = ts.simplify(filter_nodes=False)
print(ts.draw_text())
print(ts.tables.nodes)One strategy to save memory is to keep your metadata separate from the table collection until you are ready to make a final export to a file, do a final analysis, etc.. You use the "idmap" returned by simplify to modify your metadata as you go. When finished, you can use the "set columns" method on the node table to to write a final version that includes the columns already there + your metadata. |
Beta Was this translation helpful? Give feedback.
-
|
Another option here might be to, instead of saving "who is the partner to this node", save a unique ID in metadata that can be used to match them up later. |
Beta Was this translation helpful? Give feedback.
You can use
filter_nodes=Falseto keep the IDs, or set map_nodes=True to obtain a node mapping.There's a new tutorial on
simplify()that I wrote about 3 days ago: https://tskit.dev/tutorials/simplification.html