Skip to contents

population object store specific information about group of several individuals

Public fields

name

[string] Name of the population

specie

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

inds

[list] list of population's individuals

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)

af

[named vector] allele frequency

maf

[named vector] minor allele frequency

Methods


Method new()

Create a new population object.

Usage

population$new(name = NULL, inds = list(), verbose = TRUE)

Arguments

name

[string] name of the population

inds

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

verbose

[boolean] display information

Returns

A new `population` 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:
rawHaplo1 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo1) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo1 <- haplotype$new(SNPinfo = SNPs,
                       haplo = rawHaplo1)
rawHaplo2 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo2) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo2 <- haplotype$new(SNPinfo = SNPs,
                       haplo = rawHaplo2)


# create individuals:
myInd1 <-  individual$new(name = "Ind 1",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo1,
                         verbose = FALSE)
myInd2 <-  individual$new(name = "Ind 2",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo2,
                         verbose = FALSE)
myPop <- population$new(name = "My Population 1",
                        inds = list(myInd1, myInd2),
                        verbose = FALSE)


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

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

# add individual
print(myPop)
myPop$addInds(myInd3)
print(myPop)


Method remInds()

Remove individuals from the population

Usage

population$remInds(indsNames)

Arguments

indsNames

[character] character vetcor of the individuals' names

Examples

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


Method writeVcf()

Write a gzip compressed VCF file with population's individuals information

Usage

population$writeVcf(file)

Arguments

file

[character] path of the output file.


Method print()

Display informations about the object

Usage

population$print()


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 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:
rawHaplo1 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo1) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo1 <- haplotype$new(SNPinfo = SNPs,
                       haplo = rawHaplo1)
rawHaplo2 <- matrix(sample(c(0, 1), (3 + 4 + 5) * 2, replace = TRUE),
                    nrow = 2)
colnames(rawHaplo2) <- sprintf(fmt = paste0("SNP%0", 2,"i"),
                              1:(3 + 4 + 5))
haplo2 <- haplotype$new(SNPinfo = SNPs,
                       haplo = rawHaplo2)


# create individuals:
myInd1 <-  individual$new(name = "Ind 1",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo1,
                         verbose = FALSE)
myInd2 <-  individual$new(name = "Ind 2",
                         specie = mySpec,
                         parent1 = "OkaaSan",
                         parent2 = "OtouSan",
                         haplo = haplo2,
                         verbose = FALSE)
myPop <- population$new(name = "My Population 1",
                        inds = list(myInd1, myInd2),
                        verbose = FALSE)

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

# create new individual

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

# add individual
print(myPop)
#> Population: My Population 1
#> Species: Undefinded
#> Number of individuals: 2
myPop$addInds(myInd3)
print(myPop)
#> Population: My Population 1
#> Species: Undefinded
#> Number of individuals: 3

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

print(myPop)
#> Population: My Population 1
#> Species: Undefinded
#> Number of individuals: 3
myPop$remInds("Ind 2")
print(myPop)
#> Population: My Population 1
#> Species: Undefinded
#> Number of individuals: 2