magnusdv / pedtools

Tools for working with pedigrees in R
GNU General Public License v3.0
23 stars 3 forks source link

Definition of generations #44

Closed zachariae closed 1 year ago

zachariae commented 1 year ago

Dear Magnus,

I am using your pedtools-function generations() to determine the generations in a pedigree, and to calculate the generations in relation to a certain target. It seems, that all 'founders' are listed as generation 1 in the pedigree, even if there are married to a generation 2 (or even higher?) person. So a couple with children can consist of a parent from generation 1 and another parent from generation 2, the child is listed as generation 3. When I calculate the difference between the child and their parents, the one parent is one (correctly) or the other one two generations (this seems incorrect to me) ahead.

I hope, I could make my point clear. I would find a generations-function very useful.

Best wishes, Silke

magnusdv commented 1 year ago

Thanks for bringing this up, I agree that the current version of generations() compute something slightly different that what the name suggests.

I've pushed a new version of generations() now, whose output is controlled by a parameter what. By default, the total generation count is produced, but what = "indiv" gives what you want, I think:

library(pedtools)

x = linearPed(2)
g = generations(x, what = "indiv")
g
#> 1 2 3 4 5 
#> 1 1 2 2 3
plot(x, labs = setNames(x$ID, paste("g =",g)))

Also compare with the relabel function, which already had a similar feature:

y = relabel(x, new = "generations")
plot(y)

Created on 2023-04-21 with reprex v2.0.2

zachariae commented 1 year ago

Thank you very much. This is exactly how I expected the function to work.