## ----library_charge-------------------------------------------------------------------------------
library(Pedixplorer)

## ----auto_hint1, echo = FALSE, fig.dim = c(10, 8), fig.alt="Comparison of Pedigrees before and after auto_hint with a simple Pedigree"----
#
# A simple Pedigree to illustrate autohint's code
#
test1 <- data.frame(id = 1:11,
    sex = c("m", "f")[c(1, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1)],
    dadid = c(0, 0, 1, 1, 1, 0, 0, 6, 6, 6, 9),
    momid = c(0, 0, 2, 2, 2, 0, 0, 7, 7, 7, 4)
)
ped1 <- Pedigree(test1, missid = "0")

temp2 <- Pedigree(test1, missid = "0", hints = list(
    horder = setNames(
        c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
        1:11
    )
))

par(mfrow = c(1, 2))
plot(temp2, title = "Before auto_hint")
plot(ped1, title = "After auto_hint")

## ----align2, echo = FALSE, fig.dim = c(10, 8), fig.alt = "Comparison of Pedigrees before and after auto_hint with a more complex Pedigree"----
#
# The second, more complex test Pedigree
#
test2 <- data.frame(id = c(1:13, 21:41),
    dadid = c(0, 0, 1, 1, 1, 0, 0, 6, 6, 6, 0, 11, 11,
        0, 0, 0, 0, 0, 0, 21, 21, 21, 23, 23, 25, 28,
        28, 28, 28, 32, 32, 32, 32, 33
    ),
    momid = c(0, 0, 2, 2, 2, 0, 0, 7, 7, 7, 0, 5, 9,
        0, 0, 0, 0, 0, 0, 22, 22, 22, 24, 24, 26, 31,
        31, 31, 31, 29, 29, 29, 29, 13
    ),
    sex = c(1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 1, 1, 2, 1,
        2, 1, 2, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2,
        1, 2, 1, 1, 2
    )
)
ped2 <- Pedigree(test2, missid = "0")
ped2a <- Pedigree(test2, missid = "0", hints = list(
    horder = setNames(seq_along(test2$id), test2$id)
))
par(mfrow = c(1, 2))
plot(ped2a, title = "Before auto_hint")
plot(ped2, title = "After auto_hint")

## ----align3, echo = FALSE, fig.dim = c(10, 8), fig.alt = "Comparison of Pedigrees before and after changing the horizontal ordering"----
#
# A simple pedigree to illustrate autohint's code
#
test3 <- data.frame(id = 1:14,
    sex = c("m", "f")[c(2, 1, 1, 1, 1, 1, 2,
        2, 1, 2, 1, 2, 2, 1
    )],
    dadid = c(0, 6, 2, 2, 2, 0, 0, 11, 0, 9, 6, 0, 6, 11),
    momid = c(0, 7, 1, 1, 1, 0, 0, 12, 0, 1, 7, 0, 7, 12),
    affected = c(0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0)
)
ped3 <- Pedigree(test3, missid = "0", hints = list(
    horder = setNames(1:14, 1:14)
))

test4 <- data.frame(id = 1:17,
    sex = c("m", "f")[c(2, 1, 1, 2, 2, 1, 2, 1,
        2, 2, 1, 2, 2, 1, 1, 2, 2
    )],
    dadid = c(0, 8, 6, 6, 0, 0, 0, 0, 11,
        0, 0, 6, 0, 0, 0, 11, 14
    ),
    momid = c(0, 9, 5, 5, 0, 0, 0, 0, 10,
        0, 0, 7, 0, 0, 0, 12, 5
    )
)

ped4 <- Pedigree(test4, missid = "0", hints = list(
    horder = setNames(1:17, 1:17)
))

par(mfrow = c(1, 2))
plot(ped4)
plot(ped3)

## -------------------------------------------------------------------------------------------------
sessionInfo()