Skip to content

Commit

Permalink
fix NRC calculation when len(a)!=len(b)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Dec 13, 2024
1 parent 0138f7b commit bc36b63
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions R/common.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,23 @@ 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)
}
}
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)
Expand Down

0 comments on commit bc36b63

Please sign in to comment.