sort_alleles: Sort Alleles in genlight or genind Objects as Major/Minor

View source: R/sort_alleles.R

sort_allelesR Documentation

Sort Alleles in genlight or genind Objects as Major/Minor

Description

This function sorts alleles in 'genlight' or 'genind' objects based on their major/minor status. Optionally, it allows specifying reference populations to analyze relative to a focal population.

Usage

sort_alleles(geno, pops = NULL)

Arguments

geno

A 'genlight' or 'genind' object containing the genotype data.

pops

A character vector specifying the populations to use as a reference for sorting alleles. If not supplied, alleles are sorted across all populations in the data. (optional)

Details

The function first checks if the input is a 'genlight' object and converts it to a 'genind' object if necessary. The alleles are then sorted based on their major/minor status (most common/least common). If the 'pops' parameter is specified, the alleles are sorted relative to the specified focal populations. This can be useful for analyzing the genetic structure or allele frequency differences between specific populations. If no focal populations are provided, the alleles are sorted across all populations in the dataset.

Value

A 'genind' or 'genlight' object with alleles sorted as major/minor.

Examples

## Not run: 

# Example using a genlight object
data(nancycats)
genlight_obj <- glSim(nInd = 50, nLoc = 100)
sorted_genlight <- sort_alleles(genlight_obj)

# Example using a genind object
genind_obj <- nancycats
sorted_genind <- sort_alleles(genind_obj)

# Example specifying a focal population
sorted_genind_focal <- sort_alleles(genind_obj, pops = "P01")

#' # Example specifying a group of focal populations
sorted_genind_focals <- sort_alleles(genind_obj, pops = c("P01", "P02"))

## End(Not run)

pygmyperch/melfuR documentation built on Aug. 26, 2024, 12:48 a.m.