alleles2loci: Build Loci Object From Matrix of Alleles

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/conversion.R

Description

These functions transform a matrix of alleles into an object of class "loci", or the reverse operation.

Usage

1
2
3
alleles2loci(x, ploidy = 2, rownames = NULL, population = NULL,
             phased = FALSE)
loci2alleles(x)

Arguments

x

a matrix or a data frame where each column is an allele, or an object of class "loci".

ploidy

an integer specifying the level of ploidy.

rownames

an integer giving the column number to be used as rownames of the output.

population

an integer giving the column number to be used as population (if any).

phased

a logical specifying whether the genotypes should be output as phased. By default, they are unphased.

Details

Genetic data matrices are often arranged with one allele in each column of the matrix (particularly for micro-satellites), so that the number of columns is equal to the number of loci times the level of ploidy. alleles2loci transforms such matrices into a "loci" object.

If the rownames of the input matrix are already set, they are used in the output. Alternatively, it is possible to specify which column to use as rownames (this column will be deleted before creating the genotypes).

If the input matrix has colnames, then the names of the first column of each genotype is used as names of the output loci (see examples).

loci2alleles checks that all individuals have the ploidy for a given locus (if not an error occurs), but ploidy can vary among loci.

Value

an object of class "loci" or a matrix.

Author(s)

Emmanuel Paradis

See Also

read.loci, as.loci

The vignette “ReadingFiles” explains how to read such a data set from Dryad (https://datadryad.org/stash).

Examples

1
2
3
4
5
x <- matrix(c("A", "A", "A", "a"), 2)
colnames(x) <- c("Loc1", NA)
y <- alleles2loci(x)
print(y, details = TRUE)
loci2alleles(y)

Example output

Loading required package: ape
Loading required package: adegenet
Loading required package: ade4
Registered S3 method overwritten by 'spdep':
  method   from
  plot.mst ape 

   /// adegenet 2.1.3 is loaded ////////////

   > overview: '?adegenet'
   > tutorials/doc/questions: 'adegenetWeb()' 
   > bug reports/feature requests: adegenetIssues()


Registered S3 method overwritten by 'pegas':
  method      from
  print.amova ade4

Attaching package:pegasThe following object is masked frompackage:ade4:

    amova

The following object is masked frompackage:ape:

    mst

  Loc1
1  A/A
2  A/a
  Loc1.1 Loc1.2
1 "A"    "A"   
2 "A"    "a"   

pegas documentation built on May 17, 2021, 9:08 a.m.