gl.randomize.snps: Randomly swaps the homozygote coding (0 and 2) in half of the...

View source: R/gl.randomize.snps.r

gl.randomize.snpsR Documentation

Randomly swaps the homozygote coding (0 and 2) in half of the loci

Description

This function samples half of the loci at random and, in the sampled loci, swaps the coding of the two homozygotes: 0 becomes 2 and 2 becomes 0. Heterozygotes (1) and missing values are unchanged. The allele labels of the sampled loci are reversed to match, so the object still describes the same genotypes; only which allele is counted changes.

Usage

gl.randomize.snps(
  x,
  plot.display = TRUE,
  plot.theme = theme_dartR(),
  plot.colors = NULL,
  plot.file = NULL,
  plot.dir = NULL,
  verbose = NULL
)

Arguments

x

Name of the genlight object containing the SNP data [required].

plot.display

If TRUE, resultant plots are displayed in the plot window [default TRUE].

plot.theme

Theme for the plot. See Details for options [default theme_dartR()].

plot.colors

Vector of four color names passed to gl.smearplot for homozygote reference, heterozygote, homozygote alternative and missing data [default c("#0000FF","#00FFFF","#FF0000","#e0e0e0")].

plot.file

Name for the RDS binary file to save (base name only, exclude extension) [default NULL]

plot.dir

Directory in which to save the plot file [default as specified by the global working directory or tempdir()]

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default NULL, unless specified using gl.set.verbosity].

Details

DArT calls the most common allele as the reference allele. In a genlight object, homozygous for the reference allele are coded with a '0' and homozygous for the alternative allele are coded with a '2'. This causes some distortions in visuals from time to time. Only SNP data are accepted. FBM-backed objects are recoded in a copy of their backing file, so the input object is not modified. If plot.display = TRUE, two smear plots (pre-randomisation and post-randomisation) are presented using a random subset of individuals (10) and loci (100) to provide an overview of the changes. The combined plot is saved only when plot.file is specified.

Value

Returns a genlight object with half of the loci re-coded and their allele labels (loc.all) reversed; the REF and ALT read counts and the 0/0 and 1/1 likelihoods in other$geno.metrics (see gl.read.vcf) are swapped with them. Locus metric flags are reset, as the allele-frequency metrics no longer match the recoded genotypes.

Author(s)

Author(s): Luis Mijangos. Custodian: Luis Mijangos – Post to https://groups.google.com/d/forum/dartr

Examples

if (isTRUE(getOption("dartR_fbm"))) testset.gl <- gl.gen2fbm(testset.gl)
gl <- gl.filter.monomorphs(testset.gl)
res <- gl.randomize.snps(gl,verbose = 5)

dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.