Learn R Programming

adegenet (version 2.0.0)

Accessors: Accessors for adegenet objects

Description

An accessor is a function that allows to interact with slots of an object in a convenient way. Several accessors are available for genind or genpop objects. The operator "$" and "$<-" are used to access the slots, being equivalent to "@" and "@<-". The operator "[" is a flexible way to subset data by individuals, populations, alleles, and loci. When using a matrix-like syntax, subsetting will apply to the dimensios of the @tab slot. In addition, specific arguments loc and pop can be used to indicate subsets of loci and populations. The argument drop is a logical indicating if alleles becoming non-polymorphic in a new dataset should be removed (default: FALSE). Examples:
  • "obj[i,j]" returns "obj" with a subset 'i' of individuals and 'j' of alleles.
  • "obj[1:10,]" returns an object with only the first 10 genotypes (if "obj" is agenind) or the first 10 populations (if "obj" is agenpop)
  • "obj[1:10, 5:10]" returns an object keeping the first 10 entities and the alleles 5 to 10.
  • "obj[loc=c(1,3)]" returns an object keeping only the 1st and 3rd loci, usinglocNames(obj)as reference; logicals, or named loci also work; this overrides other subsetting of alleles.
  • "obj[pop=2:4]" returns an object keeping only individuals from the populations 2, 3 and 4, usingpopNames(obj)as reference; logicals, or named populations also work; this overrides other subsetting of individuals.
The argument treatOther handles the treatment of objects in the @other slot (see details). The argument drop can be set to TRUE to drop alleles that are no longer represented in the subset.

Usage

nInd(x, ...)
nLoc(x, ...)
nPop(x, ...)
pop(x)
indNames(x, ...)
## S3 method for class 'genind':
indNames(x, \dots)
locNames(x, ...)
## S3 method for class 'genind':
locNames(x, withAlleles=FALSE, \dots)
## S3 method for class 'genpop':
locNames(x, withAlleles=FALSE, \dots)
popNames(x, ...)
## S3 method for class 'genind':
popNames(x, \dots)
popNames(x, ...)
## S3 method for class 'genpop':
popNames(x, \dots)
ploidy(x, ...)
## S3 method for class 'genind':
ploidy(x, \dots)
## S3 method for class 'genpop':
ploidy(x, \dots)
## S3 method for class 'genind':
other(x, \dots)
## S3 method for class 'genpop':
other(x, \dots)

Arguments

x
a genind or a genpop object.
withAlleles
a logical indicating whether the result should be of the form [locus name].[allele name], instead of [locus name].
...
further arguments to be passed to other methods (currently not used).

Value

  • A genind or genpop object.

encoding

UTF-8

Details

The "[" operator can treat elements in the @other slot as well. For instance, if obj@other$xy contains spatial coordinates, the obj[1:3, ]@other$xy will contain the spatial coordinates of the genotypes (or population) 1,2 and 3. This is handled through the argument treatOther, a logical defaulting to TRUE. If set to FALSE, the @other returned unmodified. Note that only matrix-like, vector-like and lists can be proceeded in @other. Other kind of objects will issue a warning an be returned as they are, unless the argument quiet is left to TRUE, its default value. The drop argument can be set to TRUE to retain only alleles that are present in the subset. To achieve better control of polymorphism of the data, see isPoly.

Examples

Run this code
data(nancycats)
nancycats
pop(nancycats) # get the populations
indNames(nancycats) # get the labels of individuals
locNames(nancycats) # get the labels of the loci
alleles(nancycats) # get the alleles

head(tab(nancycats)) # get allele counts

# get allele frequencies, replace NAs
head(tab(nancycats, freq = TRUE, NA.method = "mean")) 

# let's isolate populations 4 and 8
popNames(nancycats)
obj <- nancycats[pop=c(4,8)]
obj
popNames(obj)
pop(obj)

# let's isolate two markers, fca23 and fca90
locNames(nancycats)
obj <- nancycats[loc=c("fca23","fca90")]
obj
locNames(obj)

# illustrate pop
obj <- nancycats[sample(1:100, 10)]
pop(obj)
pop(obj) <- rep(c('b', 'a'), each = 5)
pop(obj)

# illustrate locNames
locNames(obj)
locNames(obj, withAlleles = TRUE)
locNames(obj)[1] <- "newLocus"
locNames(obj)
locNames(obj, withAlleles=TRUE)

# illustrate how 'other' slot is handled
data(sim2pop)
nInd(sim2pop)
other(sim2pop[1:6]) # xy is subsetted automatically
other(sim2pop[1:6, treatOther=FALSE]) # xy is left as is

Run the code above in your browser using DataLab