gl.sort: Sorts genlight objects by individual, population, or genomic...

View source: R/gl.sort.r

gl.sortR Documentation

Sorts genlight objects by individual, population, or genomic position

Description

Reorders individuals in a genlight object by individual names, population names, or by chromosome and SNP position. Useful for ensuring meaningful genotype ordering in visualizations such as gl.smearplot.

Usage

gl.sort(
  x,
  sort.by = "pop",
  order.by = NULL,
  order.by.chr.pos = FALSE,
  verbose = NULL
)

Arguments

x

Genlight object containing SNP/Silicodart genotypes [required].

sort.by

Specify to sort the genotypes by either 'ind' or 'pop' [default 'pop'].

order.by

Vector used to order genotypes [default NULL].

order.by.chr.pos

Whether to order loci first by chromosome and then by SNP position [default FALSE].

verbose

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

Details

This is a function to sort genotypes in a genlight object by individual name, by population name or by chromosome and SNP position. This is useful if you want to visualise the structure across populations (bands) in a gl.smearplot; order of genotypes is important.

The order.by parameter needs to be a vector upon which to effect the sort, of length of nPop(gl) if sort.by is 'pop' or nInd(gl) if sort.by is 'ind'. For sort.by='ind' order.by can be a vector such as a variable in gl@other$ind.metrics.

If not specified by nominating a vector with order.by, alphabetical order of populations or individuals is used.

Ordering by chromosome and SNP position requires that chromosome and position slots are set in the genlight object.

Value

Returns a reordered genlight object. Sorts also the ind/loc.metrics and coordinates accordingly

Author(s)

Author(s): Bernd Gruber. Custodian: Bernd Gruber (Post to https://groups.google.com/d/forum/dartr)

See Also

Other data manipulation: gl.add.indmetrics(), gl.define.pop(), gl.drop.ind(), gl.drop.loc(), gl.drop.pop(), gl.edit.recode.pop(), gl.fbm.cleanup(), gl.fbm2gen(), gl.gen2fbm(), gl.impute(), gl.join(), gl.keep.ind(), gl.keep.loc(), gl.keep.pop(), gl.make.recode.ind(), gl.make.recode.pop(), gl.merge.pop(), gl.reassign.ind(), gl.reassign.pop(), gl.recode.ind(), gl.recode.pop(), gl.rename.pop(), gl.sample(), gl.sim.genotypes(), gl.subsample.ind(), gl.subsample.loc(), gl.subsample.loci()

Examples

#sort by populations
if (isTRUE(getOption("dartR_fbm"))) bandicoot.gl <- gl.gen2fbm(bandicoot.gl)
bc <- gl.sort(bandicoot.gl)
#sort from West to East
bc2 <- gl.sort(bandicoot.gl, sort.by="pop" ,
order.by=c("WA", "SA", "VIC", "NSW", "QLD"))
#sort by missing values
miss <- rowSums(is.na(as.matrix(bandicoot.gl)))
bc3 <- gl.sort(bandicoot.gl, sort.by="ind", order.by=miss)
gl.smearplot(bc3)

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