data(partial_clone)
pc <- as.genclone(partial_clone, threads = 1L) # convert to genclone object
# Basic Use ---------------------------------------------------------------
# Show MLGs at threshold 0.05
mlg.filter(pc, threshold = 0.05, distance = "nei.dist", threads = 1L)
pc # 26 mlgs
# Set MLGs at threshold 0.05
mlg.filter(pc, distance = "nei.dist", threads = 1L) <- 0.05
pc # 25 mlgs
## Not run:
#
# # The distance definition is persistant
# mlg.filter(pc) <- 0.1
# pc # 24 mlgs
#
# # But you can still change the definition
# mlg.filter(pc, distance = "diss.dist", percent = TRUE) <- 0.1
# pc
#
# # Choosing a threshold ----------------------------------------------------
#
#
# # Thresholds for collapsing multilocus genotypes should not be arbitrary. It
# # is important to consider what threshold is suitable. One method of choosing
# # a threshold is to find a gap in the distance distribution that represents
# # clonal groups. You can look at this by analyzing the distribution of all
# # possible thresholds with the function "cutoff_predictor".
#
# # For this example, we'll use Bruvo's distance to predict the cutoff for
# # P. infestans.
#
# data(Pinf)
# Pinf
# # Repeat lengths are necessary for Bruvo's distance
# (pinfreps <- fix_replen(Pinf, c(2, 2, 6, 2, 2, 2, 2, 2, 3, 3, 2)))
#
# # Now we can collect information of the thresholds. We can set threshold = 1
# # because we know that this will capture the maximum possible distance:
# (thresholds <- mlg.filter(Pinf, distance = bruvo.dist, stats = "THRESHOLDS",
# replen = pinfreps, threshold = 1))
# # We can use these thresholds to find an appropriate cutoff
# (pcut <- cutoff_predictor(thresholds))
# mlg.filter(Pinf, distance = bruvo.dist, replen = pinfreps) <- pcut
# Pinf
#
# # This can also be visualized with the "filter_stats" function.
#
# # Special case: threshold = 0 ---------------------------------------------
#
#
# # It's important to remember that a threshold of 0 is equal to the original
# # MLG definition. This example will show a data set that contains genotypes
# # with missing data that share all alleles with other genotypes except for
# # the missing one.
#
# data(monpop)
# monpop # 264 mlg
# mlg.filter(monpop) <- 0
# nmll(monpop) # 264 mlg
#
# # In order to merge these genotypes with missing data, we should set the
# # threshold to be slightly higher than 0. We will use the smallest fraction
# # the computer can store.
#
# mlg.filter(monpop) <- .Machine$double.eps ^ 0.5
# nmll(monpop) # 236 mlg
#
# # Custom distance ---------------------------------------------------------
#
# # Custom genetic distances can be used either in functions from other
# # packages or user-defined functions
#
# data(Pinf)
# Pinf
# mlg.filter(Pinf, distance = function(x) dist(tab(x))) <- 3
# Pinf
# mlg.filter(Pinf) <- 4
# Pinf
#
# # genlight / snpclone objects ---------------------------------------------
#
#
# set.seed(999)
# gc <- as.snpclone(glSim(100, 0, n.snp.struc = 1e3, ploidy = 2))
# gc # 100 mlgs
# mlg.filter(gc) <- 0.25
# gc # 82 mlgs
#
# ## End(Not run)
Run the code above in your browser using DataLab