-
Notifications
You must be signed in to change notification settings - Fork 3
/
makeCEPH.R
85 lines (79 loc) · 3.09 KB
/
makeCEPH.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#' Make a CEPH-style pedigree for each id
#'
## Copyright(c) 2017-2020 R. Mark Sharp
## This file is part of nprcgenekeepr
#' Part of Relations
#'
#' Creates a CEPH-style pedigree for each id, consisting of three generations:
#' the id, the parents, and the grandparents. Inserts NA for unknown pedigree
#' members.
#'
#' Calculates the first-order relationships in a pedigree,
#' and to convert pairwise kinships to the appropriate relationship category.
#' Relationships categories:
#' For each ID in the pair, find a CEPH-style pedigree and compare them
#' \itemize{
#' \item {If one is the parent of the other}
#' {--- Designate the relationship as \code{parent-offspring}}
#' \item {Else if both parents are shared}
#' {--- Designate the relationship as \code{full-siblings}}
#' \item {Else if one parent is shared}
#' {--- Designate the relationship as \code{half-siblings}}
#' \item {Else if one is the grandparent of the other}
#' {--- Designate the relationship as \code{grandparent-grandchild}}
#' \item {Else if both grand parents are shared}
#' {--- Designate the relationship as \code{cousin}}
#' \item {Else if at least one grand parent is shared}
#' {--- Designate the relationship as \code{cousin - other}}
#' \item {Else if the parents of one are the grandparents of the other}
#' {--- Designate the relationship as \code{full-avuncular}}
#' \item {Else if a single parent of one is the grandparent of the other}
#' {--- Designate the relationship as \code{avuncular - other}}
#' \item {Else if the kinship is greater than 0, but the pair don't fall into
#' the above categories}
#' {--- Designate the relationship as \code{other}}
#' \item {Else}
#' {--- Designate the relationships as \code{no relation.}}}
#'
#' @return List of lists: \{fields: id, \{subfields: parents, pgp, mgp\}\}.
#' Pedigree information converted into a CEPH-style list. The top level
#' list elements are the IDs from id. Below each ID is a list of three
#' elements: parents (sire, dam), paternal grandparents (pgp: sire, dam),
#' and maternal grandparents (mgp: sire, dam).
#'
#' @examples
#' \donttest{
#' library(nprcgenekeepr)
#' ped <- nprcgenekeepr::lacy1989Ped
#' pedCEPH <- makeCEPH(ped$id, ped$sire, ped$dam)
#' head(ped)
#' head(pedCEPH$F)
#' }
#' @param id character vector with unique identifier for an individual
#' @param sire character vector with unique identifier for an
#' individual's father (\code{NA} if unknown).
#' @param dam character vector with unique identifier for an
#' individual's mother (\code{NA} if unknown).
#' @export
makeCEPH <- function(id, sire, dam) {
ped <- data.frame(sire = sire, dam = dam, row.names = id,
stringsAsFactors = FALSE)
ceph <- list()
for (i in id) {
sire <- ped[i, "sire"]
dam <- ped[i, "dam"]
parents <- c(sire, dam)
if (is.na(sire)) {
pgp <- c(NA, NA)
} else {
pgp <- c(ped[sire, "sire"], ped[sire, "dam"])
}
if (is.na(dam)) {
mgp <- c(NA, NA)
} else {
mgp <- c(ped[dam, "sire"], ped[dam, "dam"])
}
ceph[[i]] <- list(parents = parents, pgp = pgp, mgp = mgp)
}
return(ceph)
}