R/GetHpltStats_func_20200915.R

Defines functions GetHpltStats

Documented in GetHpltStats

#' GetHpltStats() function
#'
#' \code{\link{GetHpltStats}} uses the output files produced by the HpltFind()
#' function to calculate the mean of the mean proportion of incongruent
#' sequences across all nests in the data set.
#'
#' If you publish data or results produced with MHCtools, please cite both of
#' the following references:
#' Roved, J. 2022. MHCtools: Analysis of MHC data in non-model species. Cran.
#' Roved, J., Hansson, B., Stervander, M., Hasselquist, D., & Westerdahl, H. 2022.
#' MHCtools - an R package for MHC high-throughput sequencing data: genotyping,
#' haplotype and supertype inference, and downstream genetic analyses in non-model
#' organisms. Molecular Ecology Resources. https://doi.org/10.1111/1755-0998.13645
#'
#' @param filepath is a user defined path to the folder where the output files
#'   from the HpltFind() function have been saved.
#' @return  A mean of the mean proportion of incongruent sequences for each
#'   nest.
#' @seealso \code{\link{HpltFind}}; \code{\link{GetHpltTable}}
#' @examples
#' filepath <- system.file("extdata/HpltFindOut/", package="MHCtools")
#' GetHpltStats(filepath)
#' @export

GetHpltStats <- function(filepath) {

  # Get the file names of the .Rds output generated by the HpltFind function
  file_names <- dir(filepath)

  mean_props <- numeric()

  # Extract the mean proportion of incongruent sequences for each nest
  for(i in 1:length(file_names)) {

    mean_props[i] <- readRDS(file.path(filepath, file_names[i]))$Mean_prop_incongr_seqs

  }

  # Calculate the mean
  MoM_props <- mean(mean_props)

  MoM_props

}

Try the MHCtools package in your browser

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

MHCtools documentation built on July 9, 2023, 5:13 p.m.