Learn R Programming

strataG (version 2.4.905)

gtypes.accessors: gtypes Accessors

Description

Accessors for slots in '>gtypes objects.

Usage

# S4 method for gtypes
getNumInd(x, by.strata = FALSE, ...)

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

getNumStrata(x, ...)

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

getIndNames(x, ...)

# S4 method for gtypes getIndNames(x, by.strata = FALSE, ...)

getLociNames(x, ...)

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

getAlleleNames(x, ...)

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

getStrataNames(x, ...)

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

getPloidy(x, ...)

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

getStrata(x, ...)

# S4 method for gtypes getStrata(x)

setStrata(x) <- value

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

getSchemes(x, ...)

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

setSchemes(x) <- value

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

getSequences(x, ...)

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

getDescription(x, ...)

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

setDescription(x) <- value

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

getOther(x, ...)

# S4 method for gtypes getOther(x, value = NULL, ...)

setOther(x, name) <- value

# S4 method for gtypes setOther(x, name) <- value

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

Arguments

x

a '>gtypes object.

by.strata

logical - return results by strata?

...

other arguments passed from generics (ignored).

value

value being assigned by accessor.

as.haplotypes

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

seqName

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

as.multidna

return sequences as a '>multidna object? If FALSE, sequences are returned as a list.

name

name of the value going into the other list.

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 is the order returned by getIndNames, getLocNames, and getStrataNames 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")

getNumStrata(msats.g)
getStrataNames(msats.g)
getNumLoci(msats.g)
getLociNames(msats.g)

# reassign all samples to two randomly chosen strata
new.strata <- sample(c("A", "B"), getNumInd(msats.g), rep = TRUE)
names(new.strata) <- getIndNames(msats.g)
setStrata(msats.g) <- new.strata
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)
new.strata <- sample(c("A", "B"), getNumInd(wood.g), rep = TRUE)
names(new.strata) <- getIndNames(wood.g)
setStrata(wood.g) <- new.strata
wood.g

# get the multidna sequence object
multi.seqs <- getSequences(wood.g, as.multidna = TRUE)
class(multi.seqs) # "multidna"

# get a list of DNAbin objects
dnabin.list <- getSequences(wood.g)
class(dnabin.list) # "list"

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

# getting and setting values in the `other` slot:
getOther(dloop.g)

setOther(dloop.g, "timestamp") <- timestamp()
setOther(dloop.g, "Author") <- "Hoban Washburne"

getOther(dloop.g)
getOther(dloop.g, "timestamp")

setOther(dloop.g, "Author") <- NULL
getOther(dloop.g)


# }

Run the code above in your browser using DataLab