The following command installs the latest official versions of the ped suite packages:
Alternatively, you can install the development versions from GitHub:
If you only need a few of the packages, you may choose to install them individually instead of the entire collection.
The aim of this vignette is to illustrate a few of the possibilities of the ped suite packages. It should be noted that we are barely scratching the surface here; in particular several packages are not even mentioned. For a more comprehensive overview, I recommend the book.
To get started we load the pedsuite package, which is a convenient shortcut for loading all the core packages, making their methods available in the current R session.
We begin by creating and plotting a pedigree with a child of first cousins:
For symmetry let us change the sex of individual 3. We also highlight the child by hatching his symbol, and we only include his ID label in the plot.
The inbreeding coefficient \(f\) of a pedigree member is defined as the probability of autozygosity at a random autosomal locus. That is, the probability that the two homologous alleles have the same origin within the pedigree.
For a child of first cousins one can work out by pen and paper that
\(f = 1/16\). Alternatively, we can
calculate it with the ribd function
The output agrees with \(f = 1/16\).
For any particular child of first cousins, the actual autozygous fraction of the genome (except X & Y) is called the coefficient of realised inbreeding, denoted \(f_R\). This may deviate substantially from the pedigree-based expectation \(f = 1/16\).
We can simulate the distribution of \(f_R\) with the ibdsim2 package. Since this is not a core package we must load it separately.
First, we use the function
ibdsim() to simulate the
recombination process in the entire pedigree, 200 times:
Now extract the autozygous segments of each simulation.
Here is a summary of the first 6 simulations, including the number of segments and various length statistics:
head(fr$perSimulation) #> nSeg meanLen totLen maxLen minLen fReal #> 1 11 19.05892 209.6481 37.60149 0.8069583 0.06181840 #> 2 12 14.17339 170.0807 48.43095 1.3405519 0.05015126 #> 3 12 12.87321 154.4785 26.10949 0.1452881 0.04555068 #> 4 19 17.44059 331.3712 58.63821 1.2124618 0.09771059 #> 5 16 16.95554 271.2886 44.95560 1.0034634 0.07999419 #> 6 13 17.84055 231.9271 49.91405 0.9327245 0.06838775
And here is a histogram of the realised inbreeding coefficients (given in the right-most column above):
As we see, the distribution centres around the expectation \(f = 1/16 = 0.0625\) (red vertical line) but
has substantial spread. The sample standard deviation can be found in
fr$stDev, which in our case is 0.02.
Note that everything we have done so far has been purely theoretical, with no markers involved. In medical and forensic applications we usually work with genetic data in the form of marker genotypes, so let us simulate such a dataset for our family.
markerSim() function of the forrel
package simulates the genotypes of pedigree members for a specific type
of markers. For instance, here we produce 500 SNPs with alleles
B (equally frequent, by default):
We can see the genotypes of the first few markers by printing
y to the console.
y #> id fid mid sex <1> <2> <3> <4> <5> #> 1 * * 1 A/B B/B A/A B/B A/A #> 2 * * 2 A/B A/B A/B A/A A/B #> 3 1 2 2 A/B A/B A/B A/B A/B #> 4 * * 1 A/B A/B B/B A/B A/B #> 5 1 2 1 B/B A/B A/B A/B A/A #> 6 * * 2 A/B B/B A/A A/B A/A #> 7 4 3 1 B/B A/A B/B A/B A/B #> 8 5 6 2 A/B A/B A/B B/B A/A #> 9 7 8 1 B/B A/A B/B B/B A/A #> Only 5 (out of 500) markers are shown.
If this was a real dataset, a natural quality control step would be
to check correctness of the pedigree. One way to do this is to use the
data to estimate each pairwise relationship, and compare the result with
the pedigree. The function
checkPairwise() does all of
this, and presents the result in a relationship triangle.
The plot shows that all pairwise estimates are near their expected location in the triangle. (The yellow symbols correspond to pairs involving the inbred child, which don’t have a well-defined position in the triangle.)
If you enjoyed this quick tour and would like more details, you should check out the GitHub README files of the packages that interest you.
There is also the pedtools vignette, with a lot more details on how to create and plot pedigrees in R.