createSgsObj: Create basic data structure for sgs analysis

Description Usage Arguments Value Details See Also Examples

View source: R/dataio.R

Description

This function creates the basic data structure that will hold all the information necessary for sgs analyses - an object of the class sgsObj. It includes genotype data, spatial data, information about ploidy, groups, names of loci, etc. sgsObjs can be created from scratch through the function below, or by reading in text input files created by SPAGeDi using the readSpagedi function. Note that loci with only one allele will be removed from the sgsObj, as this would cause issues with sgs analyses.

Usage

1
2
createSgsObj(sample_ids, genotype_data, x_coords, y_coords,
  missing_val = -999, groups = NULL, ploidy = 2, loci_names = NULL)

Arguments

sample_ids

A vector of numbers or names giving individual IDs of samples.

genotype_data

A matrix or dataframe with genetic data. See details for more information.

x_coords

A numeric vector with X coordinates of samples.

y_coords

A numeric vector with Y coordinates of samples.

missing_val

Numeric or character value indicating value used for missing data. Default is -999.

groups

An optional vector of of grouping classfication. Note: Analyses on groups have not been implemented yet.

ploidy

Ploidy level. Note: Analyses have only been tested with ploidy = 2.

loci_names

Optional vector of loci names. If no value is supplied, loci names will be assigned from the column names of the genotype data.

Value

Returns an object of the class sgsObj.

Details

Loci with only one allele are removed from the sgsObj data structure to prevent problems with sgs analyses.

Genotype data structure

Genotype data should be formatted as a dataframe or matrix with individual samples as rows and loci as columns. Each locus should have two columns (in the case of diploid organisms), and these pairs of columns should be adjacent to each other. Values should be numeric.

Loc1_A Loc1_B Loc2_A Loc2_B Loc3_A Loc3_B
1 0 7 0 1 0
2 3 4 5 4 1
3 2 2 3 2 4
2 1 1 2 2 2

See Also

summary.sgsObj, plot.sgsObj

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Simulate genetic data
Nind = 100 # Number of individuals
Nloci = 5 # Number of loci
Nallele = 10 # Number of alleles per loci

## Set up data frame and generate random spatial locations
dat <- data.frame(id = 0:(Nind - 1))
dat$x = runif(Nind, 0, 100)
dat$y = runif(Nind, 0, 100)

## Simulate Random genetic data and assign loci names
for (loci in 1:Nloci) {
 loci_name_a = paste("Loc", loci, "_A", sep = "")
 loci_name_b = paste("Loc", loci, "_B", sep = "")
 dat[loci_name_a] <- sample.int(Nallele, Nind, replace = TRUE)
 dat[loci_name_b] <- sample.int(Nallele, Nind, replace = TRUE)
}

## Convert to sgsObj
sgsObj = createSgsObj(sample_ids = dat$id,
                     genotype_data = dat[, 4:(Nloci*2 + 3)],
                     ploidy = 2,
                     x_coords = dat$x,
                     y_coords = dat$y,
                     missing_val = -999)

summary(sgsObj)

plot(sgsObj)

lukembrowne/sgsR documentation built on May 21, 2019, 8:58 a.m.