a wrapper of the write.relationshipMatrix function from the synbreed package. still asreml requires
attr(G_a,"rowNames")<-as.character(df$Os_id_x);attr(G_a,"colNames")<-as.character(df$Os_id_x);attr(G_a,"INVERSE")<-TRUE
. therefore i add them together.
#' A function used to convert a genomic relationship matrix to matrix format allowed in Asreml-R V4
#'
#' @param x A genomic relationship matrix
#' @param digits
#'
#' @return
#' @export
#'
#' @examples
grm2asreml=function(x, digits = 10){
rMinv <- ginv(x)
rMinv <- round(rMinv, digits)
res <- data.frame(Row = rep(1:nrow(rMinv), nrow(rMinv)),
Column = rep(1:nrow(rMinv), each = nrow(rMinv)), coeff = as.numeric(rMinv),
lower = as.logical(lower.tri(rMinv, diag = TRUE)))
res <- res[res$lower == TRUE, c("Row", "Column", "coeff")]
res <- res[order(res$Row, res$Column), ]
res <- res[res$coeff != 0, ]
attr(res,"colNames")=attr(res, "rowNames") <- rownames(x)
attr(res,"INVERSE")<-TRUE
rm(rMinv, x)
return(res)
}
网友评论