Skip to content

Commit

Permalink
In readFam() catch 0 and negative alleles
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusdv committed May 11, 2023
1 parent 31ed7cf commit d5ea255
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions R/readFam.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,37 @@ readFam = function(famfile, useDVI = NA, Xchrom = FALSE, prefixAdded = "added_",
als = x[als.lines]
frqs = as.numeric(x[als.lines + 1])

if("0" %in% als) {
warning(sprintf("Illegal allele '0' at locus %s. Changing to '00'.", loc.name), call. = FALSE)
als[als == "0"] = "00"
}

# Check for illegal alleles, including "Rest allele", with stepwise models
if(model.idx.mal > 1 || model.idx.fem > 1) {
change = FALSE
alsNum = suppressWarnings(as.numeric(als))
if(any(is.na(alsNum))) {
change = TRUE
warning(sprintf("Non-numerical allele '%s' at locus %s incompatible with stepwise model. Changing to proportional model.",
als[is.na(alsNum)][1], loc.name), call. = FALSE)
if(model.idx.mal > 1) model.idx.mal = 1
if(model.idx.fem > 1) model.idx.fem = 1
}
else if(any(alsNum < 1)) {
change = TRUE
warning(sprintf("Database error: Allele '%s' at locus %s is incompatible with stepwise model. Changing to proportional model.",
als[alsNum < 1][1], loc.name), call. = FALSE)
}
else {
badMicro = round(alsNum, 1) != alsNum
if(any(badMicro)) {
change = TRUE
warning(sprintf("Database error: Illegal microvariant '%s' at locus %s. Changing to proportional model.",
als[badMicro][1], loc.name), call. = FALSE)
if(model.idx.mal > 1) model.idx.mal = 1
if(model.idx.fem > 1) model.idx.fem = 1
}
}
if(change) {
if(model.idx.mal > 1) model.idx.mal = 1
if(model.idx.fem > 1) model.idx.fem = 1
}
}

# After checks, associate alleles with freqs
Expand Down

0 comments on commit d5ea255

Please sign in to comment.