population: R6 class representing a population

populationR Documentation

R6 class representing a population

Description

population object store specific information about multiple individuals

Public fields

name

[string] Name of the population

generation

[integer] Generation of the population

specie

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

traitInfo

[traitInfo class] Specific information of traits (see:traitInfo)

crossInfo

[crossInfo class] Information of crossing (including selection scheme) (see:crossInfo)

inds

[list] list of population's individuals

trialInfo

[trialInfo class] Specific information of field trial

phenotypicValues

[array] individual x traits x replication (3-dimensional array) of phenotypic values

verbose

[boolean] display information

Active bindings

nInd

[numeric] number of individual in the population

genoMat

[matrix] matrix of all the genotypes of the population encoded in allele doses. (individuals in row and markers in column)

trueAGVMat

[matrix] matrix of true additive genotypic values

trueDGVMat

[matrix] matrix of true dominant genotypic values

trueEGVMat

[matrix] matrix of true epistatic genotypic values

trueGVMat

[matrix] matrix of true genotypic values

trueAGVETMat

[matrix] matrix of true additive genotypic values specific to each trait

trueDGVETMat

[matrix] matrix of true dominant genotypic values specific to each trait

trueEGVETMat

[matrix] matrix of true epistatic genotypic values specific to each trait

trueGVETMat

[matrix] matrix of true genotypic values specific to each trait

trueAGVCTMat

[matrix] matrix of true additive genotypic values common across trait

trueDGVCTMat

[matrix] matrix of true dominant genotypic values common across trait

trueEGVCTMat

[matrix] matrix of true epistatic genotypic values common across trait

trueGVCTMat

[matrix] matrix of true genotypic values common across trait

haploArray

[array] 3-dimensional array of all the haplotypes of the population encoded with 0, 1. (individuals in row, markers in column, and ploidy in 3rd dimension)

af

[named vector] allele frequency

maf

[named vector] minor allele frequency

heteroRate

[named vector] ratio of heterozygotes

Methods

Public methods


Method new()

Create a new population object.

Usage
population$new(
  name = NULL,
  generation = NA,
  traitInfo = NULL,
  crossInfo = NULL,
  inds = list(),
  verbose = TRUE
)
Arguments
name

[string] name of the population

generation

[integer] Generation of the population

traitInfo

[traitInfo class] Specific information of traits (see:traitInfo)

crossInfo

[crossInfo class] Information of crossing (including selection scheme) (see:crossInfo)

inds

[individual class or list] list of individuals of the population (see:individual)

verbose

[boolean] display information

Returns

A new 'population' object.

Examples
### create simulation information
mySimInfo <- simInfo$new(simName = "Simulation Example",
                         simGeno = TRUE,
                         simPheno = TRUE,
                         nSimGeno = 1,
                         nSimPheno = 3,
                         nCoreMax = 4,
                         nCorePerGeno = 1,
                         nCorePerPheno = 3,
                         saveDataFileName = NULL)
### create specie information
mySpec <- specie$new(nChr = 3,
                     lChr = c(100, 150, 200),
                     specName = "Example 1",
                     ploidy = 2,
                     mutRate = 10^-8,
                     recombRate = 10^-6,
                     chrNames = c("C1", "C2", "C3"),
                     nLoci = c(3, 4, 5),
                     effPopSize = 3,
                     simInfo = mySimInfo,
                     verbose = TRUE)
### create lociInfo object
myLoci <- lociInfo$new(genoMap = NULL, specie = mySpec)
### create traitInfo object
myTrait <- traitInfo$new(lociInfo = myLoci,
                         nMarkers = c(2, 4, 3),
                         nTraits = 2,
                         nQTLs = matrix(c(1, 0, 2,
                                          1, 0, 1),
                                        nrow = 2,
                                        byrow = TRUE),
                         actionTypeEpiSimple = TRUE,
                         qtlOverlap = TRUE,
                         nOverlap = c(1, 0, 1),
                         effCor = 0.6,
                         propDomi = 0.2,
                         interactionMean = c(1, 0))
plot(myTrait, alphaMarker = 0.4)
### simulate haplotype
rawHaplo1 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo1) <- paste0("Locus_", 1:(3 + 4 + 5))
myHaplo1 <- myBreedSimulatR::haplotype$new(lociInfo = myLoci,
                                           haplo = rawHaplo1)
rawHaplo2 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo2) <- paste0("Locus_", 1:(3 + 4 + 5))
myHaplo2 <- myBreedSimulatR::haplotype$new(lociInfo = myLoci,
                                           haplo = rawHaplo2)
### create individuals:
myInd1 <-  individual$new(name = "Ind 1",
                          specie = myTrait$lociInfo$specie,
                          traitInfo = myTrait,
                          parent1 = "OkaaSan1",
                          parent2 = "OtouSan1",
                          haplo = myHaplo1,
                          verbose = TRUE)
myInd2 <-  individual$new(name = "Ind 2",
                          specie = myTrait$lociInfo$specie,
                          traitInfo = myTrait,
                          parent1 = "OkaaSan2",
                          parent2 = "OtouSan2",
                          haplo = myHaplo2,
                          verbose = TRUE)
myInd3 <-  individual$new(name = "Ind 3",
                          specie = myTrait$lociInfo$specie,
                          traitInfo = myTrait,
                          parent1 = "OkaaSan1",
                          parent2 = "OtouSan1",
                          haplo = myHaplo1,
                          verbose = TRUE)
myPop <- population$new(name = "My Population 1",
                        generation = 1,
                        traitInfo = myTrait,
                        inds = list(myInd1, myInd2, myInd3),
                        verbose = FALSE)
myPop$trueEGVMat
myPop$plot(plotTarget = "trueAGV",
           plotType = "violin")
myPop$plot(plotTarget = "trueGV",
           plotType = "scatter",
           scatterAxes = c(2, 1))

Method addInds()

Add individuals to the population

Usage
population$addInds(inds)
Arguments
inds

[individual class or list] list of individuals of the population (see:individual)

Examples
# create new individual

rawHaplo4 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo4) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo4 <- haplotype$new(lociInfo = myLoci,
                       haplo = rawHaplo4)
myInd4 <-  individual$new(name = "Ind 4",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo4,
                         verbose = FALSE)

# add individual
print(self)
self$addInds(myInd4)
print(self)

Method remInds()

Remove individuals from the population

Usage
population$remInds(indNames)
Arguments
indNames

[character] character vetcor of the individuals' names

Examples
print(self)
self$remInds("Ind 2")
print(self)

Method inputTrialInfo()

Remove individuals from the population

Usage
population$inputTrialInfo(
  trialInfoNow = NULL,
  herit = NULL,
  nRep = NULL,
  multiTraitsAsEnvs = FALSE,
  envSpecificEffects = NULL,
  residCor = NULL,
  seedResid = NA
)
Arguments
trialInfoNow

[trialInfo class] trialInfo class object

herit

[numeric] Heritability for each trait (plot-based/line-based)

nRep

[numeric] Replication of the field trial (common to all traits)

multiTraitsAsEnvs

[logical] Treat multiple traits as multiple environments or not

envSpecificEffects

[numeric] Effects specific to each environments / treatments. If 'multiTraitsAsEnvs = FALSE', envSpecificEffects will be 0 for all traits.

residCor

[matrix] Residual correlation between traits

seedResid

[numeric] Random seed for selecting residuals

Examples
print(self$trialInfo)
self$inputTrialInfo()
print(self$trialInfo)

Method inputPhenotypicValues()

Input phenotypic values

Usage
population$inputPhenotypicValues(phenotypicValues = NULL)
Arguments
phenotypicValues

[array] individual x traits x replication (3-dimensional array) of phenotypic values If you use real phenotypic data, please specify your phenotypic values. If you simulate phenotypic data, please set 'phenotypicValues = NULL'.


Method print()

Display informations about the object

Usage
population$print()

Method plot()

Draw figures for visualization of each data (GVs, phenotypes, and GRM)

Usage
population$plot(
  plotTarget = "trueGV",
  plotType = "box",
  scatterAxes = 1:min(2, self$traitInfo$nTraits)
)
Arguments
plotTarget

[character] Target of figure, select either one of "trueAGV", "trueDGV", "trueEGV", "trueGV", "trueAGVET", "trueDGVET", "trueEGVET", "trueGVET", "trueAGVCT", "trueDGVCT", "trueEGVCT", "trueGVCT", "phenotypicValues".

plotType

[character] We offer "box", "violin", "scatter" (or "scatter3d") to draw figures for genotypic/phenotypic values.

scatterAxes

[numeric/character] If you select "scatter" option for 'plotType', you should design which traits will be assigned to each axis. You can define by indices of traits or trait names.


Method clone()

The objects of this class are cloneable with this method.

Usage
population$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `population$new`
## ------------------------------------------------

### create simulation information
mySimInfo <- simInfo$new(simName = "Simulation Example",
                         simGeno = TRUE,
                         simPheno = TRUE,
                         nSimGeno = 1,
                         nSimPheno = 3,
                         nCoreMax = 4,
                         nCorePerGeno = 1,
                         nCorePerPheno = 3,
                         saveDataFileName = NULL)
### create specie information
mySpec <- specie$new(nChr = 3,
                     lChr = c(100, 150, 200),
                     specName = "Example 1",
                     ploidy = 2,
                     mutRate = 10^-8,
                     recombRate = 10^-6,
                     chrNames = c("C1", "C2", "C3"),
                     nLoci = c(3, 4, 5),
                     effPopSize = 3,
                     simInfo = mySimInfo,
                     verbose = TRUE)
### create lociInfo object
myLoci <- lociInfo$new(genoMap = NULL, specie = mySpec)
### create traitInfo object
myTrait <- traitInfo$new(lociInfo = myLoci,
                         nMarkers = c(2, 4, 3),
                         nTraits = 2,
                         nQTLs = matrix(c(1, 0, 2,
                                          1, 0, 1),
                                        nrow = 2,
                                        byrow = TRUE),
                         actionTypeEpiSimple = TRUE,
                         qtlOverlap = TRUE,
                         nOverlap = c(1, 0, 1),
                         effCor = 0.6,
                         propDomi = 0.2,
                         interactionMean = c(1, 0))
plot(myTrait, alphaMarker = 0.4)
### simulate haplotype
rawHaplo1 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo1) <- paste0("Locus_", 1:(3 + 4 + 5))
myHaplo1 <- myBreedSimulatR::haplotype$new(lociInfo = myLoci,
                                           haplo = rawHaplo1)
rawHaplo2 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo2) <- paste0("Locus_", 1:(3 + 4 + 5))
myHaplo2 <- myBreedSimulatR::haplotype$new(lociInfo = myLoci,
                                           haplo = rawHaplo2)
### create individuals:
myInd1 <-  individual$new(name = "Ind 1",
                          specie = myTrait$lociInfo$specie,
                          traitInfo = myTrait,
                          parent1 = "OkaaSan1",
                          parent2 = "OtouSan1",
                          haplo = myHaplo1,
                          verbose = TRUE)
myInd2 <-  individual$new(name = "Ind 2",
                          specie = myTrait$lociInfo$specie,
                          traitInfo = myTrait,
                          parent1 = "OkaaSan2",
                          parent2 = "OtouSan2",
                          haplo = myHaplo2,
                          verbose = TRUE)
myInd3 <-  individual$new(name = "Ind 3",
                          specie = myTrait$lociInfo$specie,
                          traitInfo = myTrait,
                          parent1 = "OkaaSan1",
                          parent2 = "OtouSan1",
                          haplo = myHaplo1,
                          verbose = TRUE)
myPop <- population$new(name = "My Population 1",
                        generation = 1,
                        traitInfo = myTrait,
                        inds = list(myInd1, myInd2, myInd3),
                        verbose = FALSE)
myPop$trueEGVMat
myPop$plot(plotTarget = "trueAGV",
           plotType = "violin")
myPop$plot(plotTarget = "trueGV",
           plotType = "scatter",
           scatterAxes = c(2, 1))

## ------------------------------------------------
## Method `population$addInds`
## ------------------------------------------------

# create new individual

rawHaplo4 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo4) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo4 <- haplotype$new(lociInfo = myLoci,
                       haplo = rawHaplo4)
myInd4 <-  individual$new(name = "Ind 4",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo4,
                         verbose = FALSE)

# add individual
print(self)
self$addInds(myInd4)
print(self)

## ------------------------------------------------
## Method `population$remInds`
## ------------------------------------------------

print(self)
self$remInds("Ind 2")
print(self)

## ------------------------------------------------
## Method `population$inputTrialInfo`
## ------------------------------------------------

print(self$trialInfo)
self$inputTrialInfo()
print(self$trialInfo)

KosukeHamazaki/myBreedSimulatR documentation built on Aug. 31, 2024, 3:55 p.m.