Skip to contents

Can both

  1. Convert character genotype 0/0, 0/1, 1/0, 1/1 to 0, 1, 2 notation.

  2. Convert haplotypes c(0, 0), c(0, 1), c(1, 0), c(1, 1) to 0, 1, 2 notation.

Usage

to012(x)

Arguments

x

genotypes, e.g. from sample_profiles_without_error()

Details

Note that input is a list of loci, each element matrix n x 2 where n is number of individuals. Output here is n x loci matrix.

Examples

to012(c("0/0", "0/1", "1/0", "1/1"))
#> [1] 0 1 1 2

Z <- sample_profiles_without_error(n = 10, p = list(
  c(0.25, 0.25, 0.5), c(0.01, 0.01, 0.98)))
Z
#> [[1]]
#>       [,1] [,2]
#>  [1,]    0    1
#>  [2,]    1    1
#>  [3,]    0    1
#>  [4,]    0    0
#>  [5,]    1    1
#>  [6,]    1    1
#>  [7,]    1    0
#>  [8,]    0    1
#>  [9,]    1    1
#> [10,]    0    0
#> 
#> [[2]]
#>       [,1] [,2]
#>  [1,]    1    1
#>  [2,]    1    1
#>  [3,]    1    1
#>  [4,]    1    1
#>  [5,]    1    1
#>  [6,]    1    1
#>  [7,]    1    1
#>  [8,]    1    1
#>  [9,]    1    1
#> [10,]    1    1
#> 
to012(Z)
#>       [,1] [,2]
#>  [1,]    1    2
#>  [2,]    2    2
#>  [3,]    1    2
#>  [4,]    0    2
#>  [5,]    2    2
#>  [6,]    2    2
#>  [7,]    1    2
#>  [8,]    1    2
#>  [9,]    2    2
#> [10,]    0    2