Imaginings of a Livestock Geneticist

Sorting and Renumbering A Pedigree

When calculating pedigree-based relationships or inbreeding coefficients it is assumed that the pedigree is ordered so that parents come before progeny. Furthermore, across the majority of the methods indexing animals in the pedigree and where they are at in the associated matrix or vector is much easier when the animals are number starting from 1 to the total number of animals in the pedigree. In all of the methods I discuss I assume that the pedigree is already sorted and renumbered. In a normal pedigree that you would receive a pedigree is not sorted and the ID's are not numbered correctly. The simplest way to order a pedigree is to sort animals based on their birthdate. Although, birthdates can be incorrectly recorded or entered, or may not be available for an individual. As a result an approach that assumes birthdates aren't available is optimal. The algorithm to sort a pedigree is outlined below and adapted from Dr. Larry Schaeffer's notes. In his approach, animals are arranged by assigning generation numbers to animals, then iterate through the pedigrees modifying the generation numbers of the sire and dam to be at least one greater than the generation number of the offspring. This algorithm can be very fast if you use hash-tables as look ups to find the sire and dam and determine their respective generation number and is outlined in the C++ code.

The following pedigree file from Dr. Schaeffer's notes can be utilized with the R code above. The columns are animal, sire and dam and the pedigree. Outlined below is what generation each animal is within each iteration of the for loop. It only takes 4 loops for it to figure out the correct order across all animals.

Pedigree: Loop Iteration 0
Animal Sire Dam Generation
BF DD HE 1
DD GA EC 1
GA 0 0 1
EC GA FB 1
FB 0 0 1
AG BF EC 1
HE DD FB 1
Pedigree: Loop Iteration 1
Animal Sire Dam Generation
BF DD HE 2
DD GA EC 3
GA 0 0 3
EC GA FB 2
FB 0 0 3
AG BF EC 1
HE DD FB 2
Pedigree: Loop Iteration 2
Animal Sire Dam Generation
BF DD HE 2
DD GA EC 4
GA 0 0 4
EC GA FB 3
FB 0 0 4
AG BF EC 1
HE DD FB 3
Pedigree: Loop Iteration 3
Animal Sire Dam Generation
BF DD HE 2
DD GA EC 4
GA 0 0 5
EC GA FB 4
FB 0 0 5
AG BF EC 1
HE DD FB 3
Pedigree: Loop Iteration 4
Animal Sire Dam Generation
BF DD HE 2
DD GA EC 4
GA 0 0 6
EC GA FB 5
FB 0 0 6
AG BF EC 1
HE DD FB 3
Pedigree: Sorted
Animal Sire Dam Generation
GA 0 0 6
FB 0 0 6
EC GA FB 5
DD GA EC 4
HE DD FB 3
BF DD HE 2
AG BF EC 1