5.2 Inbreeding and Relationships

inbr = pyp_nrm.inbreeding(example)
print 'inbr: ', 
>>> inbr:  {
    'fx': {1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0, 7: 0.0,
        8: 0.0, 9: 0.0, 10: 0.0, 11: 0.0, 12: 0.0, 13: 0.0, 14: 0.0},
    'metadata': {
        'nonzero': {'f_max': 0.0, 'f_avg': 0.0, 'f_rng': 0.0,
            'f_sum': 0.0, 'f_min': 0.0, 'f_count': 0},
        'all': {'f_max': 0.0, 'f_avg': 0.0, 'f_rng': 0.0, 'f_sum': 0.0,
            'f_min': 0.0, 'f_count': 14}
        }
    }
The dictionary returned by inbreeding() contains two dictionaries: "fx" contains coefficients of inbreeding keyes to animal IDs, and "metadata" contains summary information about the coefficients of inbreeding in the pedigree. "metadata" also contains two dictionaries: "nonzero" contains summary statostics only for animals with non-zero coefficients of inbreeding, and "all" contains statistics for all animals.

Relationship metadata, similar to the inbreeding metadata described above but for coefficients of relationship, are available but not calculated by default.

inbr,reln = pyp_nrm.inbreeding(example,rels=1)
print 'reln: ', reln
>>> reln:  {'r_nonzero_count': 10, 'r_nonzero_avg': 0.40000000000000002,
    'r_min': 0.25, 'r_sum': 4.0, 'r_avg': 0.19047619047619047, 'r_max': 0.5,
    'r_count': 21, 'r_rng': 0.25}
The dictionary of relationship metadata returned by inbreeding() also contains statistics for zero and non-zero coefficients of relationship. On the example presented above the pedigree contains

Relationship metadata are not guaranteed to be correct when "method = 'vanraden'" is used. This is because inbreeding_vanraden() uses a speed-up when there are full-sibs in the pedigree to avoid repeating calculations. The metadata should be reasonably accurate for pedigrees with few or no full-sibs. The summary statistics will not be very accurate in the case of pedigrees that contain lots of full-sibs.

The relationship metadata do not include individual pairwise relationships. In order to associate those with your pedigree you must create a NewAMatrix object, form the numerator relationship matrix (NRM), and attach it to the pedigree:

options = {}
...
example = pyp_newclasses.loadPedigree(options)
example.nrm = pyp_newclasses.NewAMatrix(example.kw)
example.nrm.form_a_matrix(example.pedigree)
If you know when you load the pedigree file that you want to calculate and store the NRM you can save a little typing by setting the "form_nrm" option:
options = {}
options['form_nrm'] = 1
...
example = pyp_newclasses.loadPedigree(options)
If you want to inspect the NRM you can use "example.nrm.printme()" to print the matrix to the screen, which is probably not a particularly good idea for large matrices.
[[ 1.   0.   0.   0.   0.5  0.   0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25]
 [ 0.   1.   0.   0.   0.5  0.   0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25]
 [ 0.   0.   1.   0.   0.   0.5  0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25]
 [ 0.   0.   0.   1.   0.   0.5  0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25]
 [ 0.5  0.5  0.   0.   1.   0.   0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5 ]
 [ 0.   0.   0.5  0.5  0.   1.   0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  1.   0.5  0.5  0.5  0.5  0.5  0.5  0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  0.5  1.   0.5  0.5  0.5  0.5  0.5  0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  0.5  0.5  1.   0.5  0.5  0.5  0.5  0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  0.5  0.5  0.5  1.   0.5  0.5  0.5  0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  0.5  0.5  0.5  0.5  1.   0.5  0.5  0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  0.5  0.5  0.5  0.5  0.5  1.   0.5  0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5  1.   0.5 ]
 [ 0.25 0.25 0.25 0.25 0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5  1.  ]]
If you want to get the pairwise relationship between two animals you need to use their renumbered IDs and subtract 1 (because the array is zero-indexed). For example, if you wanted the coeffient of relationship between animals 2 and 5 (an individual and its sire) you would use the indices "1" and "4":
print example.nrm.nrm[1][4]
>>> 0.5
The NRM is symmetric, which means that "nrm[1][4]" and "nrm[4][1]" are identical.
print example.nrm.nrm[1][4]
>>> 0.5
print example.nrm.nrm[5][1]
>>> 0.5
You can also easily save the NRM to a file for future reference:
example.nrm.save('Amatrix.txt')
If you're from Missouri you can verify that the contents of "Amatrix.txt" are:
1.0  0.0  0.0  0.0  0.5 0.0 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25
0.0  1.0  0.0  0.0  0.5 0.0 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25
0.0  0.0  1.0  0.0  0.0 0.5 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25
0.0  0.0  0.0  1.0  0.0 0.5 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.25
0.5  0.5  0.0  0.0  1.0 0.0 0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5
0.0  0.0  0.5  0.5  0.0 1.0 0.5  0.5  0.5  0.5  0.5  0.5  0.5  0.5
0.25 0.25 0.25 0.25 0.5 0.5 1.0  0.5  0.5  0.5  0.5  0.5  0.5  0.5
0.25 0.25 0.25 0.25 0.5 0.5 0.5  1.0  0.5  0.5  0.5  0.5  0.5  0.5
0.25 0.25 0.25 0.25 0.5 0.5 0.5  0.5  1.0  0.5  0.5  0.5  0.5  0.5
0.25 0.25 0.25 0.25 0.5 0.5 0.5  0.5  0.5  1.0  0.5  0.5  0.5  0.5
0.25 0.25 0.25 0.25 0.5 0.5 0.5  0.5  0.5  0.5  1.0  0.5  0.5  0.5
0.25 0.25 0.25 0.25 0.5 0.5 0.5  0.5  0.5  0.5  0.5  1.0  0.5  0.5
0.25 0.25 0.25 0.25 0.5 0.5 0.5  0.5  0.5  0.5  0.5  0.5  1.0  0.5
0.25 0.25 0.25 0.25 0.5 0.5 0.5  0.5  0.5  0.5  0.5  0.5  0.5  1.0
Information on the endianess and precision of the data in the array are lost, so this is not a good way to archive data or move data between machines with different endianess. The data are always written in C (row major) order. For better performance you can set the "nrm_format" option to "binary", which will use a binary file formt.

Finally, if you're going to work on the exact same pedigree later you can load "Amatrix.txt" and avoid having to recalculate the NRM entirely:

example.nrm2 = pyp_newclasses.NewAMatrix(example.kw)
example.nrm2.load('Amatrix.txt')
example.nrm2.printme()
Since we've loaded "Amatrix.txt" into a second NRM ("nrm2") attached to our pedigree it's straightforward, if tedious, to verify that the two NRM contain the same values.

See About this document... for information on suggesting changes.