Learn R Programming

strataG (version 2.0.2)

gtypes.accessors: gtypes Accessors

Description

Accessors for slots in '>gtypes objects.

Usage

# S4 method for gtypes
nInd(x, ...)

# S4 method for gtypes nLoc(x, ...)

nStrata(x, ...)

# S4 method for gtypes nStrata(x, ...)

# S4 method for gtypes indNames(x, ...)

# S4 method for gtypes locNames(x, ...)

strataNames(x, ...)

# S4 method for gtypes strataNames(x, ...)

# S4 method for gtypes ploidy(x, ...)

# S4 method for gtypes other(x, ...)

# S4 method for gtypes strata(x)

strata(x) <- value

# S4 method for gtypes strata(x) <- value

schemes(x, ...)

# S4 method for gtypes schemes(x, ...)

schemes(x) <- value

# S4 method for gtypes schemes(x) <- value

alleleNames(x, ...)

# S4 method for gtypes alleleNames(x)

sequences(x, ...)

# S4 method for gtypes sequences(x, seqName = NULL, as.haplotypes = TRUE, ...)

description(x, ...)

# S4 method for gtypes description(x, ...)

description(x) <- value

# S4 method for gtypes description(x) <- value

# S4 method for gtypes,ANY,ANY,ANY [(x, i, j, k, ..., quiet = TRUE, drop = FALSE)

Arguments

x

a '>gtypes object.

...

other arguments passed from generics (ignored).

value

value being assigned by accessor.

seqName

the name (or number) of a set of sequences from the @sequences slot to return.

as.haplotypes

return sequences as haplotypes? If TRUE, contents of @sequences slot are returned. If FALSE, one sequence per individual is returned.

i, j, k

subsetting slots for individuals (i), loci (j), or strata (k). See Details for more information.

quiet

suppress warnings about unmatched requested individuals, loci, or strata?

drop

if TRUE the return object will have unused sequences removed.

Value

nInd

number of individuals

nLoc

number of loci

nStrata

number of strata

indNames

vector of individual/sample names

locNames

vector of locus names

strataNames

vector of strata names for current scheme

ploidy

number of alleles at each locus

other

contents of @other slot

strata

return or modify the current stratification

schemes

return or modify the current stratification schemes

alleleNames

return a list of alleles at each locus

sequences

return the '>multidna object in the @sequences slot. See getSequences to extract individual genes or sequences from this object

description

return the object's description

Details

Indexing a gtypes object with integers, characters, or logicals with the [ operator follows the same rules as normal indexing in R. The order that individuals, loci, and strata are chosen in the order returned by indNames, locNames, and strataNames respectively. If unstratified samples are present, they can be selected as a group either by including NA in the character or numeric vector of the k slot, or by providing a logical vector based on is.na(strata(g)) to the i slot.

Examples

Run this code
# NOT RUN {
#--- create a diploid (microsatellite) gtypes object
data(msats.g)
msats.g <- stratify(msats.g, "fine")

nStrata(msats.g)
strataNames(msats.g)
nLoc(msats.g)
locNames(msats.g)

# reassign all samples to two randomly chosen strata
strata(msats.g) <- sample(c("A", "B"), nInd(msats.g), rep = TRUE)
msats.g


#--- a sequence example
library(ape)
data(woodmouse)
genes <- list(gene1=woodmouse[,1:500], gene2=woodmouse[,501:965])
x <- new("multidna", genes)
wood.g <- sequence2gtypes(x)
strata(wood.g) <- sample(c("A", "B"), nInd(wood.g), rep = TRUE)
wood.g

# get the multidna sequence object
multi.seqs <- sequences(wood.g)
class(multi.seqs) # "multidna"

# get a list of DNAbin objects
library(apex)
dnabin.list <- getSequences(multi.seqs)
class(dnabin.list) # "list"

# get a DNAbin object of the first locus
dnabin.1 <- getSequences(multi.seqs, locNames(wood.g)[1])
class(dnabin.1) # "DNAbin"

# NOTE: The default to the 'simplify' argument in 'getSequences' is TRUE, 
#   so if there is only one locus, 'getSequences' will return a DNAbin object
#   rather than a single element list unless 'simplify = FALSE':
gene1 <- wood.g[, "gene1", ]
gene1.dnabin <- getSequences(sequences(gene1))
class(gene1.dnabin) # "DNAbin"

# }

Run the code above in your browser using DataLab