structure_to_genind: Convert a file in STRUCTURE format into a genind object

View source: R/structure_to_genind.R

structure_to_genindR Documentation

Convert a file in STRUCTURE format into a genind object

Description

The function converts a text file in STRUCTURE format into a genind object to use in R

Usage

structure_to_genind(
  path,
  pop_names = NULL,
  loci_names = NULL,
  ind_names = NULL
)

Arguments

path

A character string indicating the path to the STRUCTURE file in format .txt, or alternatively the name of the file in the working directory. The STRUCTURE file must only have :

  • A first column with the IDs of the individuals (can be a simple number)

  • A second column with the IDs of the populations (can be a simple number)

  • Some loci columns : as many columns as loci in the data

The row for loci names is optional but recommended. Each individual is displayed on 2 rows.

pop_names

(optional) A character vector indicating the population names in the same order as in the STRUCTURE file. It is of the same length as the number of populations. Without this argument, populations are numbered from 1 to the total number of individuals.

loci_names

A character vector with the names of the loci if not specified in the file first row. This argument is mandatory if the STRUCTURE file does not include the names of the loci in the first row. In other cases, the names of the loci is extracted from the file first row

ind_names

(optional) A character vector indicating the individual names in the same order as in the STRUCTURE file. It is of the same length as the number of individuals. Without this argument, individuals are numbered from 1 to the total number of individuals.

Details

The column order of the resulting object can be different from that of objects returned by gstud_to_genind and genepop_to_genind, depending on allele and loci coding This function uses functions from pegas package. For details about STRUCTURE file format : STRUCTURE user manual

Value

An object of type genind.

Author(s)

P. Savary

Examples

data("data_ex_genind")
loci_names <- levels(data_ex_genind@loc.fac)
pop_names <- levels(data_ex_genind@pop)
ind_names <- row.names(data_ex_genind@tab)
path_in <- system.file('extdata', 'data_ex_str.txt',
                       package = 'graph4lg')
file_n <- file.path(tempdir(), "data_ex_str.txt")
file.copy(path_in, file_n, overwrite = TRUE)
str <- structure_to_genind(path = file_n, loci_names = loci_names,
                           pop_names = pop_names, ind_names = ind_names)
file.remove(file_n)

graph4lg documentation built on Feb. 16, 2023, 5:43 p.m.