magnusdv / pedtools

Tools for working with pedigrees in R
GNU General Public License v3.0
23 stars 3 forks source link

`custom` mutation model #20

Closed thoree closed 5 years ago

thoree commented 5 years ago

Is it possible to also set the custom model. I unsuccessfully tried:

library(pedtools)
library(pedmut, quietly = TRUE)
mutmat = matrix(c(0.99, 0.1, 0.01, 0.9), ncol = 2, dimnames = list(1:2, 1:2)) 
locus = list(list(name = "M", alleles = 1:2, mutmod = "custom", matrix = mutmat))
x = setMarkers(nuclearPed(1), locus = locus)
#> Error: The "custom" model requires the argument `matrix` to be non-NULL

Created on 2019-07-31 by the reprex package (v0.3.0)

magnusdv commented 5 years ago

Yes, but you need to create the mutation model as a separate object first:

library(pedtools)

# Create the mutation model object
mutmat = matrix(c(0.99, 0.1, 0.01, 0.9), ncol = 2, dimnames = list(1:2, 1:2)) 
mutmod = pedmut::mutationModel(model = "custom", matrix = mutmat)

# Now this can be included as a locus annotation
locus = list(name = "M", alleles = 1:2, mutmod = mutmod)
x = setMarkers(nuclearPed(1), locus = list(locus))

# Inspect:
mutmod(x, marker = 1)
#> Unisex mutation matrix:
#>      1    2
#> 1 0.99 0.01
#> 2 0.10 0.90
#> 
#> Model: custom 
#> Rate: NA 
#> 
#> Lumpable: Always

Created on 2019-08-01 by the reprex package (v0.3.0)

thoree commented 5 years ago

Fine - thanks!