skater: an R package for SNP-based kinship analysis, testing, and evaluation

Motivation: SNP-based kinship analysis with genome-wide relationship estimation and IBD segment analysis methods produces results that often require further downstream process- ing and manipulation. A dedicated software package that consistently and intuitively imple- ments this analysis functionality is needed. Results: Here we present the skater R package for SNP-based kinship analysis, testing, and evaluation with R. The skater package contains a suite of well-documented tools for importing, parsing, and analyzing pedigree data, performing relationship degree inference, benchmarking relationship degree classification, and summarizing IBD segment data. Availability: The skater package is implemented as an R package and is released under the MIT license at https://github.com/signaturescience/skater. Documentation is available at https://signaturescience.github.io/skater.


Introduction
Inferring familial relationships between individuals using genetic data is a common practice in population genetics, medical genetics, and forensics. There are multiple approaches to estimating relatedness between samples, including genome-wide measures, such as those implemented in Plink 1 or KING, 2 and methods that rely on identity by descent (IBD) segment detection, such as GERMLINE, 3 hap-IBD, 4 and IBIS. 5 Recent efforts focusing on benchmarking these methods 6 have been aided by tools for simulating pedigrees and genome-wide SNP data. 7 Analyzing results from genome-wide SNP-based kinship analysis or comparing analyses to simulated data for benchmarking have to this point required writing one-off analysis functions or utility scripts that are seldom distributed with robust documentation, test suites, or narrative examples of usage. There is a need in the field for a well-documented software package with a consistent design and API that contains functions to assist with downstream manipulation, benchmarking, and analysis of SNP-based kinship assessment methods. Here we present the skater package for SNP-based kinship analysis, testing, and evaluation with R.

Implementation
The skater package provides an intuitive collection of analysis and utility functions for SNP-based kinship analysis. Functions in the package include tools for importing, parsing, and analyzing pedigree data, performing relationship degree inference, benchmarking relationship degree classification, and summarizing IBD segment data, described in full in the Use Cases section below. The package adheres to "tidy" data analysis principles, and builds upon the tools released under the tidyverse R ecosystem. 8 The skater package is hosted in the Comprehensive R Archive Network (CRAN) which is the main repository for R packages: http://CRAN.R-project.org/package=skater. Users can install skater in R by executing the following code: install.packages("skater") Alternatively, the development version of skater is available on GitHub at https://github.com/signaturescience/skater. The development version may contain new features which are not yet available in the version hosted on CRAN. This version can be installed using the install_github() function in the devtools package: install.packages("devtools") devtools::install_github("signaturescience/skater", build_vignettes=TRUE) When installing skater, other packages which skater depends on are automatically installed, including magritr, tibble, dplyr, tidyr, readr, purrr, kinship2, corrr, rlang, and others.

Operation
Minimal system requirements for installing and using skater include R (version 3.0.0 or higher) and several tidyverse packages 8 that many R users will already have installed. Use cases are demonstrated in detail below. In summary, the skater package has functions for: • Reading in various output files produced by commonly used tools in SNP-based kinship analysis • Pedigree parsing, manpulation, and analysis • Relationship degree inference • Benchmarking and assessing relationship classification accuracy • IBD segment analysis post-processing A comprehensive reference for all the functions in the skater package is available at https://signaturescience.github.io/ skater/.

Use cases
The skater package provides a collection of analysis and utility functions for SNP-based kinship analysis, testing, and evaluation as an R package. Functions in the package include tools for working with pedigree data, performing relationship degree inference, assessing classification accuracy, and summarizing IBD segment data.

library(skater)
Pedigree parsing, manipulation, and analysis Pedigrees define familial relationships in a hierarchical structure. One of the common formats used by PLINK 1 and other genetic analysis tools is the.fam file. A.fam file is a tabular format with one row per individual and columns for unique IDs of the mother, father, and the family unit. The package includes read_fam() to read files in this format: famfile <-system.file("extdata", "3gens.fam", package="skater", mustWork=TRUE) fam <-read_fam(famfile) fam testped2 testped2_g1-b1-s1 0 0 2 1 ## 10 testped2 testped2_g1-b1-i1 0 0 1 1 ## #… with 54 more rows Family structures imported from.fam formated files can then be translated to the pedigree structure used by the kinship2 package. 9 The "fam" format may include multiple families, and the fam2ped() function will collapse them all into a tibble with one row per family:  The plot_pedigree() function from skater will iterate over a list of pedigree objects, writing a multi-page PDF, with each page containing a pedigree from family: plot_pedigree(peds$ped, file="3gens.ped.pdf") The ped2kinpair() function takes a pedigree object and produces a pairwise list of relationships between all individuals in the data with the expected kinship coefficients for each pair. The function can be run on a single family: This function can also be mapped over all families in the pedigree: kinpairs <peds %>% dplyr::mutate(pairs=purrr::map(ped, ped2kinpair)) %>% dplyr::select(fid, pairs) %>% tidyr::unnest(cols=pairs) kinpairs Note that this maps ped2kinpair() over all ped objects in the input tibble, and that relationships are not shown for between-family relationships.

Relationship degree inference and benchmarking
The skater package includes functions to translate kinship coefficients to relationship degrees. The kinship coefficients could come from ped2kinpair() or other kinship estimation software.
The dibble() function creates a degree inference tibble, with degrees up to the specified max_degree (default=3), expected kinship coefficient, and lower (l) and upper (u) inference ranges as defined in Manichaikul et al. 2 Degree 0 corresponds to self/identity/monozygotic twins, with an expected kinship coefficient of 0.5, with inference range >=0.354. Anything beyond the maximum degree resolution is considered unrelated (degree NA). Note also that while the theoretical upper boundary for the kinship coefficient is 0.5, the inference range for 0-degree (same person or identical twins) extends to 1 to allow for floating point arithmetic and stochastic effects resulting in kinship coefficients above 0.5. Note that the distance between relationship degrees becomes smaller as the relationship degree becomes more distant. The dibble() function will emit a warning with max_degree >=10, and will stop with an error at >=12.
The kin2degree() function infers the relationship degree given a kinship coefficient and a max_degree up to which anything more distant is treated as unrelated. Example first degree relative: Example 4th degree relative, but using the default max_degree resolution of 3: kin2degree(.0312, max_degree=3)
The skater package adapts a confusion_matrix() function from Clark 10 to provide standard contingency

4.
A vector with the reciprocal RMSE (R-RMSE). The R-RMSE represents an alternative to classification accuracy when benchmarking relationship degree estimation and is calculated using the formula in (1). Taking the reciprocal of the target and predicted degree results in larger penalties for more egregious misclassifications (e.g., classifying a first-degree relative pair as second degree) than misclassifications at more distant relationships (e.g., misclassifying a fourth-degree relative pair as fifth-degree). The +0.5 adjustment prevents divisionby-zero when a 0th-degree (identical) relative pair is introduced.

IBD segment analysis
Tools such as hap-IBD, 4 and IBIS 5 detect shared IBD segments between individuals. The skater package includes functionality to take those IBD segments, compute shared genomic centimorgan (cM) length, and converts that shared cM to a kinship coefficient. In addition to inferred segments, these functions can estimate "truth" kinship from simulated IBD segments. 7 The read_ibd() function reads pairwise IBD segments from IBD inference tools and from simulated IBD segments. The read_map() function reads in genetic map in a standard format which is required to translate the total centimorgans shared IBD to a kinship coefficient using the ibd2kin() function. See ?read_ibd and ? read_map for additional details on expected format.

Summary
The skater R package provides a robust software package for data import, manipulation, and analysis tasks typically encountered when working with SNP-based kinship analysis tools. All package functions are internally documented with examples, and the package contains a vignette demonstrating usage, inputs, outputs, and interpretation of all key functions. The package contains internal tests that are automatically run with continuous integration via GitHub Actions whenever the package code is updated. The skater package is permissively licensed (MIT) and is easily extensible to accommodate outputs from new genome-wide relatedness and IBD segment methods as they become available.

Magnus Dehli Vigeland
Department of Medical Genetics, University of Oslo, Oslo, Norway For many researchers, myself included, R is the language-of-choice when it comes to downstream analysis and tidying-up the output of other programs. This inevitably leads to a disorganized body of ad hoc scripts for parsing, cleaning, and manipulating various result files. Arguably, the best solution to this problem is to collect related scripts into an R package, which can be properly documented, version-controlled, and potentially shared with others. The skater package presented in this paper is precisely such a package, aimed at the users of several popular software for relatedness estimation, including KING, PLINK, hap-IBD, and others. A specific goal of the package is to provide tools that work consistently across these programs.
The paper is written in clear language, well structured, and easy to follow. Parts of the paper resemble a user manual, including detailed code examples. I enjoyed playing around with the package, which is well organized and documented. In particular, I appreciate the thorough input checks and helpful error messages when things go wrong. The package may not offer a ton of novel methods yet, but I can certainly see myself using it the next time I run some of these relatedness programs.
Below are a few issues I have with the manuscript. It would be helpful to clarify what sort of applications skater is intended for. The introduction mentions "relationship inference in population genetics, medical genetics, and forensics", but that seems overly broad. The focus is on simple measures like the kinship coefficient and relatedness degree (rather than detailed coefficients and actual genealogical relationships) suggesting large-scale applications rather than small-scale pedigree analysis as e.g. in forensic case work. Indeed, all the programs referenced in the paper are intended for large-scale population studies. Furthermore, it seems to be an underlying assumption that all individuals are noninbred (suggested e.g. by the statement "the theoretical upper boundary for the kinship coefficient is 0.5"), and also that they are human (by the hardcoded 3560 cM genome length).
To be clear, I think these limitations and assumptions are perfectly fine, but it would be better to state (or discuss) them more clearly.

1.
A connection to "SNP-based methods" is mentioned repeatedly, but never really explained. Is there one? I note at least one of the cited programs (hap-IBD) is designed to work with sequencing data. Does it matter for skater how the kinship estimates were obtained? 2.
The function `confusion_matrix()` produces an impressive array of summary stats when comparing inferred kinship degrees to true ones. This is great, but I wonder about the origin of this function. In my understanding, it is a modified version of a function from another package, confusionMatrix, written by Michael Clark (not an author of the paper). Several related functions appear to be copied verbatim into skater. All of this is clearly marked in the code, with Clark rightfully listed as author, and Clark's package does come with a permissive license (MIT), but I still find it a bit odd. Why not simply import it? That way, bug fixes and improvements in the original version would automatically propagate to skater, avoiding the confusion of multiple versions. If the problem is that confusionMatrix is not on CRAN, perhaps one could reach out to make this happen? 3.
In the example illustrating `confusion_matrix()`, the authors construct a dataset by modifying a previous one, by "randomly flipping ~20% of the true degrees". The term "flip" sounds misplaced to me here, since the variable isn't dichotomous. Also, the procedure doesn't change 20%, only 0.2 * 4/5 = 16% on average, since the new values are generated from the complete set and stay unchanged with probability 1/5. Regardless of these minor issues, I must admit I found the example rather artificial. It would be much more interesting to see confusion_matrix() applied to a real dataset! That could also motivate some comments on how its output should be interpreted.

4.
Finally, I cannot resist offering a couple of suggestions for the skater package itself: The `read_fam()` for reading .fam files is very strict, insisting on space-separated columns and disallowing any format deviations. I note that e.g. PLINK, and several other R packages that read pedigree files, allow variations like tab-separated columns and missing phenotype column; perhaps this could be useful in the skater package too.

1.
Separating parent-offspring pairs from full sibs is a crucial step in many relatedness studies, and often possible by a simple analysis of the output of e.g. KING. Does skater offer such differentiation? If not, it might make a nice addition to the package in the future.

2.
Is the rationale for developing the new software tool clearly explained? Yes

Is the description of the software tool technically sound? Yes
Are sufficient details of the code, methods and analysis (if applicable) provided to allow replication of the software development and its use by others? Yes Is sufficient information provided to allow interpretation of the expected output datasets and any results generated using the tool? Yes