R/run_calckinship.R

Defines functions run_calckinship

Documented in run_calckinship

#' Calculate kinship matrix
#'
#' Calculate genetic similarity among individuals (kinship matrix)
#' from conditional genotype probabilities.
#'
#' @param input_file Input RDS file containing genotype or allele probabilities
#' @param output_file Output RDS file for calculated kinship matrix
#' @param type Indicates whether to calculate the overall kinship
#' (`"overall"`, using all chromosomes), the kinship matrix
#' leaving out one chromosome at a time (`"loco"`), or the
#' kinship matrix for each chromosome (`"chr"`).
#' @param omit_x If `TRUE`, only use the autosomes; ignored when
#' `type="chr"`.
#' @param use_allele_probs If `TRUE`, assess similarity with
#' allele probabilities (that is, first run
#' [qtl2::genoprob_to_alleleprob()]); otherwise use the genotype
#' probabilities.
#' @param cores Number of CPU cores to use, for parallel calculations.
#' (If `0`, use [parallel::detectCores()].)
#' Alternatively, this can be links to a set of cluster sockets, as
#' produced by [parallel::makeCluster()].
#' @param compress If TRUE, save a compressed RDS file (smaller but slower).
#'
#' @importFrom qtl2 calc_kinship
#' @export
#'
#' @examples
#' input_file <- paste0("https://github.com/rqtl/qtl2data/",
#'                      "blob/master/B6BTBR/b6btbr.zip")
#' \dontrun{cross2rds(input_file, "b6btbr.rds")}
#' \dontrun{run_calcgenoprob("b6btbr.rds", "b6btbr_probs.rds")}
#' \dontrun{run_calckinship("b6btbr_probs.rds", "b6btbr_kinship.rds")}
run_calckinship <-
    function(input_file, output_file, type=c("overall", "loco", "chr"),
             omit_x=FALSE,
             use_allele_probs=TRUE, cores=1, compress=FALSE)
{
    type <- match.arg(type)

    saveRDS( qtl2::calc_kinship( readRDS(input_file), type=type,
                                omit_x=omit_x, use_allele_probs=use_allele_probs,
                                quiet=TRUE, cores=cores),
            file=output_file, compress=compress )
}
rqtl/qtl2cl documentation built on Oct. 13, 2024, 1:11 a.m.