From bc36b63da4da38ce8b12ee800c836cecf528a99e Mon Sep 17 00:00:00 2001 From: Zilong-Li Date: Fri, 13 Dec 2024 10:39:57 +0100 Subject: [PATCH] fix NRC calculation when len(a)!=len(b) --- R/common.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/common.R b/R/common.R index 9fd3c8b..021a097 100644 --- a/R/common.R +++ b/R/common.R @@ -129,10 +129,16 @@ NRC <- function(a, b) { o <- table(as.vector(a), as.vector(b), useNA = "always") ## make table square if(nrow(o)!=ncol(o)){ + if(min(dim(o)!=3)) { + warning("NRC should be used only for a sample with genotypes of all types, hom ref(0), het(1) and hom alt(2)") + return(NA) + } if(nrow(o) == ncol(o)+1){ o <- o[-nrow(o),] + o <- o[,c(3,1,2)] # move NA col to leftmost } else if (nrow(o)+1==ncol(o)){ o <- o[,-ncol(o)] + o <- o[c(3,1,2),] # move NA row to topmost } else{ warning("ONLY homozygous (0) found in either truth or test data") return(NA) @@ -140,10 +146,6 @@ NRC <- function(a, b) { } if(all(dim(o)==c(4,4))) o <- o[1:3,1:3] - if(all(dim(o)!=c(3,3))) { - warning("NRC should be used only for a sample with genotypes of all types, hom ref(0), het(1) and hom alt(2)") - return(NA) - } mismatches <- sum(c(o[1,2:3], o[2,1], o[2,3], o[3,1:2])) matches <- sum(c(o[2,2], o[3,3])) res <- mismatches / (mismatches+matches)