Skip to content

Commit 897a7b1

Browse files
committed
fix error critical obs issue #8
1 parent 664bd48 commit 897a7b1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

R/msImpute.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
msImpute <- function(y, method=c("v2-mnar", "v2", "v1"),
6969
group = NULL,
7070
alpha = 0.2,
71-
relax_min_obs=FALSE,
71+
relax_min_obs=FALSE,
7272
rank.max = NULL, lambda = NULL, thresh = 1e-05,
7373
maxit = 100, trace.it = FALSE, warm.start = NULL,
7474
final.svd = TRUE, biScale_maxit=20, gauss_width = 0.3, gauss_shift = 1.8) {
@@ -77,13 +77,16 @@ msImpute <- function(y, method=c("v2-mnar", "v2", "v1"),
7777

7878

7979
if(any(is.nan(y) | is.infinite(y))) stop("Inf or NaN values encountered.")
80-
critical_obs <- NULL
81-
if(relax_min_obs & any(rowSums(!is.na(y)) <= 3)) {
80+
81+
if(relax_min_obs | any(rowSums(!is.na(y)) <= 3)) {
8282

83-
stop("Peptides with excessive NAs are detected. Please revisit your fitering step (at least 4 non-missing measurements are required for any peptide) or set relax_min_obs=TRUE.")}
84-
else{
83+
stop("Peptides with excessive NAs are detected. Please revisit your fitering step (at least 4 non-missing measurements are required for any peptide) or set relax_min_obs=TRUE.")
84+
}
85+
ifelse(!relax_min_obs & any(rowSums(!is.na(y)) <= 3)){
8586
critical_obs <- which(rowSums(!is.na(y)) <= 3)
8687
message("Features with less than 4 non-missing measurements detected. These will be treated as MNAR.")
88+
}else{
89+
critical_obs <- NULL
8790
}
8891

8992
if(any(y < 0, na.rm = TRUE)){
@@ -92,8 +95,8 @@ msImpute <- function(y, method=c("v2-mnar", "v2", "v1"),
9295

9396

9497
if(!is.null(critical_obs)){
95-
y_critical_obs <- y[critical_obs,]
96-
y <- y[-critical_obs,]
98+
y_critical_obs <- y[critical_obs,, drop=FALSE]
99+
y <- y[-critical_obs,, drop=FALSE]
97100
}
98101

99102
if(method=="v1"){

0 commit comments

Comments
 (0)