Learn R Programming

strataG (version 1.0.5)

gtypes.accessors: gtypes Accessors

Description

Accessors for slots in gtypes objects.

Usage

nInd(x, ...)
"nInd"(x, ...)
nLoc(x, ...)
"nLoc"(x, ...)
nStrata(x, ...)
"nStrata"(x, ...)
"indNames"(x, ...)
"locNames"(x, ...)
strataNames(x, ...)
"strataNames"(x, ...)
"ploidy"(x, ...)
"other"(x, ...)
"strata"(x)
strata(x) <- value
"strata"(x) <- value
schemes(x, ...)
"schemes"(x, ...)
schemes(x) <- value
"schemes"(x) <- value
loci(x, ...)
"loci"(x, ids = NULL, loci = NULL)
alleleNames(x, ...)
"alleleNames"(x)
sequences(x, ...)
"sequences"(x, seqName = NULL, as.haplotypes = TRUE, ...)
description(x, ...)
"description"(x, ...)
"["(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.
ids
vector of individual ids.
loci
vector of loci.
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

Details

Indexing a gtypes object with integers, characters, or logicals with the [ operator follows the same rules as normal R indexing. The order that individuals, loci, and strata are chosen in follow 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
#--- 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
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
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