Skip to content

Commit

Permalink
more check
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengxwen committed Oct 7, 2023
1 parent dae7695 commit 5eeca9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: HIBAG
Type: Package
Title: HLA Genotype Imputation with Attribute Bagging
Version: 1.36.3
Date: 2023-09-09
Version: 1.36.4
Date: 2023-10-05
Depends: R (>= 3.2.0)
Imports: methods, RcppParallel
Suggests: parallel, ggplot2, reshape2, gdsfmt, SNPRelate, SeqArray, knitr,
Expand Down
16 changes: 8 additions & 8 deletions R/HIBAG.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ hlaAttrBagging <- function(hla, snp, nclassifier=100L,
hla.allele2 <- hla$value$allele2[samp.flag]
if (na.rm)
{
if (any(is.na(c(hla.allele1, hla.allele2))))
if (anyNA(c(hla.allele1, hla.allele2)))
{
warning("There are missing HLA alleles, ",
"and the corresponding samples have been removed.")
Expand All @@ -93,10 +93,8 @@ hlaAttrBagging <- function(hla, snp, nclassifier=100L,
hla.allele2 <- hla$value$allele2[samp.flag]
}
} else {
if (any(is.na(c(hla.allele1, hla.allele2))))
{
if (anyNA(c(hla.allele1, hla.allele2)))
stop("There are missing HLA alleles!")
}
}

# SNP genotypes
Expand Down Expand Up @@ -1108,8 +1106,10 @@ hlaModelFromObj <- function(obj)
# add individual classifiers
for (tree in obj$classifiers)
{
if (is.null(tree$haplos$haplo))
stop("No 'haplo' component. The model may be used by the higher version of HIBAG.")
hla <- match(tree$haplos$hla, obj$hla.allele) - 1L
if (any(is.na(hla)))
if (anyNA(hla))
stop("Invalid HLA alleles in the individual classifier.")
if (is.null(tree$samp.num))
snum <- rep.int(1L, obj$n.samp)
Expand Down Expand Up @@ -1260,15 +1260,15 @@ hlaOutOfBag <- function(model, hla, snp, call.threshold=NaN, verbose=TRUE)
if (is.null(model$sample.id))
stop("There is no sample ID in the model.")
samp.idx <- match(model$sample.id, snp$sample.id)
if (any(is.na(samp.idx)))
if (anyNA(samp.idx))
stop("Some of sample.id in the model do not exist in SNP genotypes.")
hla.samp.idx <- match(model$sample.id, hla$value$sample.id)
if (any(is.na(hla.samp.idx)))
if (anyNA(hla.samp.idx))
stop("Some of sample.id in the model do not exist in HLA types.")

# map SNPs
snp.idx <- match(model$snp.id, snp$snp.id)
if (any(is.na(snp.idx)))
if (anyNA(snp.idx))
stop("Some of snp.id in the model do not exist in SNP genotypes.")

# genotypes and the number of classifiers
Expand Down

0 comments on commit 5eeca9c

Please sign in to comment.