tskit icon indicating copy to clipboard operation
tskit copied to clipboard

TableCollection method to adjust times

Open hyanwong opened this issue 2 years ago • 4 comments

In e.g. forward simulations, it is common to way to adjust the times in a TableCollection so as to put the current generation at time 0. It is easy to forget that not just node times but also migration times and (if defined) mutation times need to be adjusted too.

I think it would be helpful to have a function roughly along the lines of:

TableCollection.modify_times(add=None, multiply=None)

which changes the times in all the relevant tables. Setting multiply = -1 would reverse the timescale (which is sometimes needed). Other API alternatives happily accepted.

It would be possible to expose this as a TreeSequence method if we wanted to (although negative multiply values would error out, as it would make all parents younger than their children).

hyanwong avatar Jul 28 '23 10:07 hyanwong

If we do add a method, we should also have it fix a vexing annoyance: the "subtract and multiply" method leaves the most recent time as -0.0 and not 0.0. That distinction rarely matters for most use cases, but they are in fact different values at the bit level..

molpopgen avatar Jul 28 '23 15:07 molpopgen

Note that the way we do this in SLiM is to record times in "time before the start of the simulation" (which is -1 * current time) and then add the total time when we output.

petrelharp avatar Jul 31 '23 20:07 petrelharp

and then add the total time when we output.

Right. And you have to add the time to both the node and the mutation table. I assume that you don't add it to the migrations table because that's not used in SLiM. If we had a method to add to time in tskit, then developers wouldn't need to worry about which tables contain times and therefore need adjusting.

hyanwong avatar Jul 31 '23 21:07 hyanwong

Closing for inactivity and labelling "future", please re-open if you plan to work on this.

benjeffery avatar Jun 12 '25 22:06 benjeffery