R/order_SNV_utility_functions.R

Defines functions orderColsAncestry

Documented in orderColsAncestry

#' Utility function needed by \code{\link{orderSNVs}}
#'
#' This function orders the compatible SNVs in the window around the focal point by their ancestry.
#'
#' This function sorts columns of M as binary numbers in descending order.
#' The first row of M is the first digit of the binary numbers, the second row of M is the second digit, etc.
#' This guarantees that more ancestral SNVs appear before more recent SNVs.
#'
#' @param M hapMat object with compatible SNVs.
#'
#' @return A hapMat object with SNVs ordered according to their ancestry.
#' @seealso \code{\link{orderSNVs}}
#' @keywords internal
#'
#' @examples 
#' 
#' \dontshow{
#' 
#' data(ex_hapMatSmall_data)
#' 
#' # Order SNV by their ancestry.
#' 
#' ex_hapMatSmall_data$hapmat[, orderColsAncestry(ex_hapMatSmall_data$hapmat)]
#' }
#'
orderColsAncestry = function(M) {
  tem = as.data.frame(t(M))
  ord = do.call(order,tem)
  ord = rev(ord) # we want descending order
  return(ord)
}

Try the perfectphyloR package in your browser

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

perfectphyloR documentation built on March 8, 2021, 9:06 a.m.