# Create bi-allelic base data set.
Mnb <- matrix(c(
"A-", NA, "GG", "CC", "AT", "CC", "AA", "AA",
"AAA", NA, "GG", "AC", "AT", "CG", "AA", "AT",
"AA", NA, "GG", "CC", "AA", "CG", "AA", "AA",
"AA", NA, "GG", "AA", "AA", NA, "AA", "AA",
"AT", NA, "GG", "AA", "TT", "CC", "AT", "TT",
"AA", NA, NA, "CC", NA, "GG", "AA", "AA",
"AA", NA, NA, "CC", "TT", "CC", "AA", "AT",
"TT", NA, "GG", "AA", "AA", "CC", "AA", "AA"),
ncol = 8, byrow = TRUE, dimnames = list(paste0("ind", 1:8),
paste0("m", 1:8)))
Mnb
# Recode without map (but map is created).
Mr <- snp.recode(M = Mnb, na.string = NA)
Mr$Mrecode
Mr$map
# Create map.
mapnb <- data.frame(
marker = paste0("m", 1:8),
reference = c("A", "T", "G", "C", "T", "C", "A", "T"),
alternative = c("T", "G", "T", "A", "A", "G", "T", "A")
)
mapnb
# Recode with map without alternative allele.
Mr <- snp.recode(M = Mnb, map = mapnb, marker = "marker", ref = "reference",
na.string = NA, rename.markers = TRUE)
Mr$Mrecode
Mr$map
# Notice that the alternative allele is in the map as a regular variable,
# but in the names it is inferred from data (which might be 0 (missing)).
# Recode with map with alternative allele.
Mr <- snp.recode(M = Mnb, map = mapnb, marker = "marker",
ref = "reference", alt = "alternative",
na.string = NA, rename.markers = TRUE)
Mr$Mrecode
Mr$map # Now the alternative is also on the names.
# We can also recode without renaming the markers.
Mr <- snp.recode(M = Mnb, map = mapnb, marker = "marker", ref = "reference",
na.string = NA, rename.markers = FALSE)
Mr$Mrecode
Mr$map # Now the alternative is also on the names.
Run the code above in your browser using DataLab