Quick start example 1: Simulated data

knitr::opts_chunk$set(echo = TRUE, eval=TRUE, #cache=TRUE,
                      fig.height=4, fig.width=6, 
#                      fig.path='/figs',   DO NOT USE
                      fig.pos="ht!")
library(sequoia)

Get started

For a succinct version of this example where you can copy/paste all code in one go, see the main vignette

In this example genotypes are simulated from a fictional pedigree, which together with the associated life history data is provided with the package. This pedigree consists of 5 discrete generations with interconnected half-sib clusters (Pedigree II in the paper[^1]).

[^1]: Huisman, Jisca. "Pedigree reconstruction from SNP data: parentage assignment, sibship clustering and beyond." Molecular ecology resources 17.5 (2017): 1009-1024.

# Install the package. This is only the required the first time, or if you wish to update
# install.packages("sequoia")   

# Load the package. This is required at the start of every new R session.
library(sequoia) 

# Load the example pedigree and life history data
data(Ped_HSg5, LH_HSg5)

# Take a look at the data structure
tail(Ped_HSg5)
head(LH_HSg5)

# or, in Rstudio, view the full dataframe:
View(Ped_HSg5)

Simulate genotypes

Simulate some genotype data to use for this try-out.

Geno <- SimGeno(Ped = Ped_HSg5, nSnp = 200)

Function SimGeno() can simulate data with a specific genotyping error rate, call rate and proportion of non-genotyped parents, see its helpfile (?SimGeno) for details. Here we use the defaults; 40\% of parents are presumed non-genotyped (their genotypes are removed from the dataset before SimGeno() returns its result).

Alternatively, use the simulated genotype data included in the package to get identical results:

Geno <- Geno_HSg5

Parentage assignment

Run sequoia with the genotype data, lifehistory data, and otherwise default values. It is often advisable to first only run parentage assignment, and check if the results are sensible and/or if any parameters need adjusting. Full pedigree reconstruction, including sibship clustering etc., is much more time consuming.

To only run a data check, duplicate check (always performed first) and parentage assignment, specify Module = 'par':

ParOUT <- sequoia(GenoM = Geno,
                  LifeHistData = LH_HSg5,
                  Module = 'par')

You will see several plots appearing:

In addition, you will see several messages, including about the initial and post-parentage total LL (log10-likelihood). This is the probability of observing the genotype data, given the (current) pedigree; initially it is assumed that all individuals are unrelated. This number is negative, and gets closer to zero when the pedigree explains the data better.

The result is a list, with the following elements:

names(ParOUT)

which are explained in detail in the helpfile (?sequoia) and the main vignette.

you find the assigned parents in list element PedigreePar:

tail(ParOUT$PedigreePar)

we can compare these to the true parents, in the original pedigree from which we simulated the genotype data:

chk_par <- PedCompare(Ped1 = Ped_HSg5, Ped2 = ParOUT$PedigreePar)
chk_par$Counts["GG",,]   

Here 'GG' stands for Genotyped offspring, Genotyped parent.

Pedigree reconstruction

Then, we can run full pedigree reconstruction. By default, this re-runs the parentage assignment.

SeqOUT_HSg5 <- sequoia(GenoM = Geno, LifeHistData = LH_HSg5, Module = "ped")

If you don't want to re-run parentage assignment (e.g. because it took quite a bit of time), or if you have specified several non-default parameter values you want to use again, , you can provide the old output as input.

Re-used will be:

The last is generated by MakeAgePrior(), which has detected that all parent-offspring pairs have an age difference of $1$, and all siblings an age difference of $0$, i.e. that generations do not overlap. This information will be used during the full pedigree reconstruction.

ParOUT$AgePriors

So run sequoia() with the old output as input,

SeqOUT_HSg5 <- sequoia(GenoM = Geno,
                  SeqList = ParOUT,
                  Module = "ped")

Full pedigree reconstruction will take at least a few minutes to run on this fairly simple dataset with one thousand individuals. It may take a few hours on larger or more complex datasets, and/or if there is much ambiguity about relationships due to a low number of SNPs, genotyping errors, and missing data.

The output from this example pedigree is included with the package:

data(SeqOUT_HSg5)

You will get several messages:

Again you will see some plots:

For additional plots and a few tables to inspect the pedigree, you can use SummarySeq():

summary_seq1 <- SummarySeq(SeqOUT_HSg5, Panels=c("sibships", "D.parents", "LLR"))
names(summary_seq1)

And again we can also compare the results to the true parents:

chk <- PedCompare(Ped1 = Ped_HSg5, Ped2 = SeqOUT_HSg5$Pedigree)
chk$Counts

See ?PedCompare for a more interesting example with some mismatches.

If you wish to count e.g. the number of full sibling pairs that are assigned as full siblings, paternal half siblings, maternal halfsiblings, or unrelated, or similar comparisons, use ComparePairs().

Save results

Lastly, you often wish to save the results to file. You can do this as an Rdata file, which can contain any number of R objects. You can later retrieve these in R using load, so that you can later resume where you left of. The disadvantage is that you cannot open the Rdata files outside of R (as far as I am aware). Therefore, sequoia also includes a function to write all output to a set of plain text files in a specified folder.

save(SeqOUT_HSg5, Geno, file="Sequoia_output_date.RData")
writeSeq(SeqList = SeqOUT_HSg5, GenoM = Geno, folder = "Sequoia-OUT")


Try the sequoia package in your browser

Any scripts or data that you put into this service are public.

sequoia documentation built on Sept. 8, 2023, 5:29 p.m.