Skip to contents

individual object store specific information about one individual

Public fields

name

[string] Name of the individual

specie

[specie class] Specie of the SNPs (see:specie)

parent1

[string] Name of the individual's parent

parent2

[string] Name of the individual's parent

haplo

[haplotype class] Haplotype of the individual (see: haplotype)

Methods


Method new()

Create a new individual object.

Usage

individual$new(
  name = "Unnamed",
  specie = specie$new(),
  parent1 = NA,
  parent2 = NA,
  haplo = NA,
  verbose = TRUE
)

Arguments

name

[string] name of the individual

specie

[specie class] Specie of the SNPs (see:specie)

parent1

[string] Name of the individual's parent

parent2

[string] Name of the individual's parent

haplo

[haplotype class] Haplotype of the individual (see: haplotype)

verbose

[boolean] display information

Returns

A new `individual` object.

Examples

# create specie
mySpec <- specie$new(nChr = 3,
                     lchr = c(100, 150, 200),
                     lchrCm = 100,
                     verbose = FALSE)

# simulate SNP
SNPcoord <- data.frame(chr = c(rep("Chr1", 3),
                               rep("Chr2", 4),
                               rep("Chr3", 5)),
                       physPos = c(sample(100, 3),
                               sample(150, 4),
                               sample(200, 5)),
                       linkMapPos = NA,
                       SNPid = sprintf(fmt = paste0("SNP%0", 2,"i"),
                                       1:(3 + 4 + 5)))

# create SNPinfo object
SNPs <- SNPinfo$new(SNPcoord = SNPcoord, specie = mySpec)
# simulate haplotype
rawHaplo <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                   nrow = 2)
colnames(rawHaplo) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo <- haplotype$new(SNPinfo = SNPs,
                       haplo = rawHaplo)
myInd <-  individual$new(name = "Ind 1",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo,
                         verbose = FALSE)


Method generateGametes()

Generate Gametes

Usage

individual$generateGametes(n = 1)

Arguments

n

[float] number of gametes to create (default: 1)

Returns

list of gametes. A gamete is a named vectors with value 0 or 1.

Examples

myInd$generateGametes()
myInd$generateGametes(2)


Method clone()

The objects of this class are cloneable with this method.

Usage

individual$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `individual$new`
## ------------------------------------------------

# create specie
mySpec <- specie$new(nChr = 3,
                     lchr = c(100, 150, 200),
                     lchrCm = 100,
                     verbose = FALSE)

# simulate SNP
SNPcoord <- data.frame(chr = c(rep("Chr1", 3),
                               rep("Chr2", 4),
                               rep("Chr3", 5)),
                       physPos = c(sample(100, 3),
                               sample(150, 4),
                               sample(200, 5)),
                       linkMapPos = NA,
                       SNPid = sprintf(fmt = paste0("SNP%0", 2,"i"),
                                       1:(3 + 4 + 5)))

# create SNPinfo object
SNPs <- SNPinfo$new(SNPcoord = SNPcoord, specie = mySpec)
# simulate haplotype
rawHaplo <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                   nrow = 2)
colnames(rawHaplo) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo <- haplotype$new(SNPinfo = SNPs,
                       haplo = rawHaplo)
myInd <-  individual$new(name = "Ind 1",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo,
                         verbose = FALSE)

## ------------------------------------------------
## Method `individual$generateGametes`
## ------------------------------------------------

myInd$generateGametes()
#> [[1]]
#> SNP03 SNP01 SNP02 SNP05 SNP07 SNP06 SNP04 SNP09 SNP08 SNP11 SNP12 SNP10 
#>     0     0     1     1     0     0     1     1     1     0     1     1 
#> 
myInd$generateGametes(2)
#> [[1]]
#> SNP03 SNP01 SNP02 SNP05 SNP07 SNP06 SNP04 SNP09 SNP08 SNP11 SNP12 SNP10 
#>     1     0     0     1     0     0     1     1     1     0     1     1 
#> 
#> [[2]]
#> SNP03 SNP01 SNP02 SNP05 SNP07 SNP06 SNP04 SNP09 SNP08 SNP11 SNP12 SNP10 
#>     0     0     1     1     0     0     1     1     1     0     1     1 
#>