Tutorials

Installing this Package

To install, using REPL:

julia> using Pkg; Pkg.add("GenLib")

Or in the Pkg REPL mode (]):

add GenLib

You may then use the library with using GenLib or, to mimic the behavior of R's GENLIB, import GenLib as gen.

Loading a Pedigree

From a DataFrame

Here is a pedigree with full first-degree cousins.

import GenLib as gen
using DataFrames
inds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
fathers = [0, 0, 0, 1, 1, 0, 3, 3, 6, 6]
mothers = [0, 0, 0, 2, 2, 0, 4, 4, 5, 5]
sexes = [1, 2, 1, 2, 2, 1, 2, 1, 1, 2]
df = DataFrame([inds, fathers, mothers, sexes], [:ind, :father, :mother, :sex])
ped = gen.genealogy(df)
A pedigree with:
10 individuals;
12 parent-child relations;
5 men;
5 women;
4 subjects;
3 generations.

From a CSV File

The original GENLIB package for R contains two sample pedigrees. They are also available in GenLib.jl as GenLib.genea140 and GenLib.geneaJi.

julia> import GenLib as gen
julia> genea140 = gen.genea140"/home/runner/work/GenLib.jl/GenLib.jl/data/genea140.csv"
julia> ped = gen.genealogy(genea140)A pedigree with: 41523 individuals; 68248 parent-child relations; 20773 men; 20750 women; 140 subjects; 18 generations.
julia> import GenLib as gen
julia> geneaJi = gen.geneaJi"/home/runner/work/GenLib.jl/GenLib.jl/data/geneaJi.csv"
julia> ped = gen.genealogy(geneaJi)A pedigree with: 29 individuals; 44 parent-child relations; 15 men; 14 women; 3 subjects; 8 generations.

Accessing an Individual

A pedigree is an ordered dictionary where the key is the ID and the value corresponds to the GenLib.Individual.

The individual's parents and children are accessed by reference.

julia> import GenLib as gen
julia> genea140 = gen.genea140;
julia> ped = gen.genealogy(genea140);
julia> ped[33724]ind: 33724 father: 10086 mother: 10087 sex: 1
julia> ped[33724].motherind: 10087 father: 0 mother: 0 sex: 2
julia> ped[33724].fatherind: 10086 father: 0 mother: 0 sex: 1
julia> ped[33724].children2-element Vector{GenLib.Individual}: ind: 10033 father: 33724 mother: 35178 sex: 2 ind: 113470 father: 33724 mother: 35178 sex: 1
julia> ped[33724].children[2].fatherind: 33724 father: 10086 mother: 10087 sex: 1

Getting Founders and Probands

This is done using the GenLib.founder and GenLib.pro functions, respectively.

julia> import GenLib as gen
julia> genea140 = gen.genea140;
julia> ped = gen.genealogy(genea140);
julia> founder = gen.founder(ped)7399-element Vector{Int64}: 10086 10087 10102 10103 10128 10129 10136 10137 10150 10151 ⋮ 870618 870619 871681 872039 872040 872102 872103 872106 872107
julia> pro = gen.pro(ped)140-element Vector{Int64}: 217891 218089 219947 288708 288764 302710 302711 302716 302717 302718 ⋮ 676521 677273 717537 717634 717709 718567 802424 868387 868572

Finding Most Recent Common Ancestors

julia> import GenLib as gen
julia> genea140 = gen.genea140;
julia> ped = gen.genealogy(genea140);
julia> pro = gen.pro(ped);
julia> pro1 = pro[1]217891
julia> pro2 = pro[2]218089
julia> genMatrix = gen.findMRCA(ped, [pro1, pro2]);
julia> genMatrix.individuals2-element Vector{Int64}: 217891 218089
julia> genMatrix.ancestors108-element Vector{Int64}: 11171 11601 11602 13234 13235 16910 16911 17060 17087 18215 ⋮ 65345 68161 68162 70305 70306 77206 203641 253080 253081
julia> genMatrix.meioses2×108 Matrix{Int64}: 11 9 9 9 9 11 11 8 9 9 … 11 11 11 10 10 9 9 10 10 12 11 11 10 10 11 11 8 10 13 10 11 11 10 10 11 9 10 10

Computing Genetic Contributions

This is done with the GenLib.gc function.

julia> import GenLib as gen
julia> genea140 = gen.genea140;
julia> ped = gen.genealogy(genea140);
julia> contributions = gen.gc(ped)140×7399 Matrix{Float32}: 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.015625 0.015625 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ⋮ ⋮ ⋱ ⋮ 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
julia> sum(contributions, dims=2)140×1 Matrix{Float32}: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ⋮ 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0

Computing Kinship Coefficients

This is done using one of the GenLib.phi functions.

Pairwise Coefficient

Let's take the two siblings above for example.

import GenLib as gen
genea140 = gen.genea140;
ped = gen.genealogy(genea140);
pro1 = ped[10033]
pro2 = ped[113470]
gen.phi(pro1, pro2)
0.25

Square Matrix

import GenLib as gen
geneaJi = gen.geneaJi
ped = gen.genealogy(geneaJi)
gen.phi(ped)
3×3 Matrix{Float32}:
 0.591797   0.371094   0.0722656
 0.371094   0.591797   0.0722656
 0.0722656  0.0722656  0.535156