Skip to content

Commit

Permalink
add number of loci to gl.report.heterozygosity method "ind"
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Mijangos authored and Luis Mijangos committed Feb 5, 2024
1 parent f5637d2 commit 00fa98b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/gl.report.heterozygosity.r
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,8 @@ gl.report.heterozygosity <- function(x,
c.hets <- array(NA, nInd(x))
c.hom0 <- array(NA, nInd(x))
c.hom2 <- array(NA, nInd(x))
c.nloc <- array(NA, nInd(x))

for (i in 1:nInd(x)) {
c.na[i] <- sum(is.na(m[i, ]))
c.hets[i] <-
Expand All @@ -1082,13 +1084,14 @@ gl.report.heterozygosity <- function(x,
sum(m[i, ] == 0, na.rm = TRUE) / (nLoc(x) - c.na[i])
c.hom2[i] <-
sum(m[i, ] == 2, na.rm = TRUE) / (nLoc(x) - c.na[i])
c.nloc[i] <- (nLoc(x) - c.na[i])
}

# Join the sample sizes with the heterozygosities
df <-
cbind.data.frame(x@ind.names, c.hets, c.hom0, c.hom2)
cbind.data.frame(x@ind.names, c.hets, c.hom0, c.hom2,c.nloc)
names(df) <-
c("ind.name", "Ho", "f.hom.ref", "f.hom.alt")
c("ind.name", "Ho", "f.hom.ref", "f.hom.alt","n.Loc")

# Boxplot
if (plot.display) {
Expand Down

0 comments on commit 00fa98b

Please sign in to comment.