You can use the `
mlg.id()` function to extract this information on the full (not clone-corrected) data set. It will return a list where each element represents a genotype and contains a vector of sample names. You can use this list to subset a data frame of geographic coordinates. See the example below.
library("poppr")
data(monpop)
show(monpop)
#>
#> This is a genclone object
#> -------------------------
#> Genotype information:
#>
#> 264 multilocus genotypes
#> 694 haploid individuals
#> 13 codominant loci
#>
#> Population information:
#>
#> 1 stratum - Pop
#> 12 populations defined -
#> 7_09_BB, 26_09_BB, 26_09_FR, ..., 45_10_FR, 26_11_BB, 26_11_FR
#
# Filter the data to collapse all genotypes that are different by
# at most one mutation
e <- .Machine$double.eps^0.5
mlg.filter(monpop) <- 1 + e
show(monpop)
#>
#> This is a genclone object
#> -------------------------
#> Genotype information:
#>
#> 190 contracted multilocus genotypes
#> (1) [t], (diss.dist) [d], (farthest) [a]
#> 694 haploid individuals
#> 13 codominant loci
#>
#> Population information:
#>
#> 1 stratum - Pop
#> 12 populations defined -
#> 7_09_BB, 26_09_BB, 26_09_FR, ..., 45_10_FR, 26_11_BB, 26_11_FR
#
# The `mll()` function will list the multilocus genotype/lineage
# assignment per sample.
mll(monpop)[10:19] # Samples 10, 11, and 12 are all part of the same clone
#> [1] 79 79 79 81 130 41 41 41 38 119
indNames(monpop)[10:19]
#> [1] "A021" "A022" "A007" "A001" "A018" "A020" "A017" "A019" "A003" "A005"
#
mlg.id(monpop)[["79"]] # MLL 79 contains four clones #> [1] "A021" "A022" "A007" "A033"
#
# Using this with a 2-column data frame of geographic coordinates
meandist <- function(i, df) mean(dist(df[i, , drop = FALSE]))
df <- data.frame(x = rnorm(nInd(monpop)),
y = rnorm(nInd(monpop)),
row.names = indNames(monpop))
# Coordinates can be identified for MLL 79
df[ids[["79"]], , drop = FALSE]
#> x y
#> A021 -0.5901603 -0.5354590
#> A022 -1.2622871 0.9373863
#> A007 0.3141743 -1.3958612
#> A033 -1.5612730 -1.2284351
#
# loop over the list to calculate mean distance
res <- vapply(mlg.id(monpop), FUN = meandist, FUN.VALUE = numeric(1), df) names(res) <- names(mlg.id(monpop)) res[["79"]]
#> [1] 1.82423
-----
Zhian N. Kamvar, Ph. D.
Postdoctoral Researcher (Everhart Lab)
Department of Plant Pathology
University of Nebraska-Lincoln
ORCID: 0000-0003-1458-7108