-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lalo-caballero
committed
Jan 25, 2024
1 parent
66d41a6
commit 8f2aff3
Showing
10 changed files
with
133 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
align_pow <- function(x, | ||
lambdas = pracma::logspace(-2, 4, 31), | ||
p = 10, | ||
max_it = 1000){ | ||
rics <- x$getRIC() | ||
idx_y <- Align::select_reference(rics) | ||
X <- as.matrix(rics[-idx_y,]) | ||
y <- as.matrix(rics[idx_y,]) | ||
n_samples <- nrow(X) | ||
m <- length(y) | ||
v <- rep(1,m) | ||
iv <- seq(2, m - 1, by = p) | ||
v[iv] <- 0 | ||
W <- Matrix::Diagonal(x = v) | ||
val<-Align::compute_val_error(X,y,W,iv,lambdas) | ||
opar <- Align::optimize_params(n_samples, lambdas, val$ti_ix, val$e_ix) | ||
best_lambdas2 <- opar$best_params | ||
#' Align a [GCIMSDataset] using the POW algorithm | ||
#' | ||
#' Uses the POW algorithm to generate waprs and align the samples | ||
#' | ||
#' @param object A [GCIMSDataset] object, modified in-place | ||
#' @param lambdas vector of lambdas to be tested for the POW algorithm | ||
#' @param p points to be taken for validation for the POW algorithm | ||
#' @param max_it maximum iterations for applying the POW algorithm | ||
#' @return The modified [GCIMSDataset] | ||
#' @export | ||
|
||
w<-mapply(Align::pow,x=as.list(data.frame(t(X))), lambda2=as.list(best_lambdas2),MoreArgs = list(y=y,max_it = max_it)) | ||
w<-as.list((as.data.frame(w))) | ||
w<-append(w,list(1:m),idx_y-1) | ||
names(w)<-x$sampleNames | ||
methods::setMethod( | ||
"align_pow", | ||
"GCIMSDataset", | ||
function(object, | ||
lambdas = pracma::logspace(-2, 4, 31), | ||
p = 10, | ||
max_it = 1000){ | ||
rics <- object$getRIC() | ||
idx_y <- Align::select_reference(rics) | ||
X <- as.matrix(rics[-idx_y,]) | ||
y <- as.matrix(rics[idx_y,]) | ||
n_samples <- nrow(X) | ||
m <- length(y) | ||
v <- rep(1,m) | ||
iv <- seq(2, m - 1, by = p) | ||
v[iv] <- 0 | ||
W <- Matrix::Diagonal(x = v) | ||
val<-Align::compute_val_error(X,y,W,iv,lambdas) | ||
opar <- Align::optimize_params(n_samples, lambdas, val$ti_ix, val$e_ix) | ||
best_lambdas2 <- opar$best_params | ||
|
||
delayed_op <- DelayedOperation( | ||
name = "align_pow", | ||
fun = align_pow_sample, | ||
params_iter = list(w=w) | ||
) | ||
x$appendDelayedOp(delayed_op) | ||
x <- GCIMS:::extract_RIC_and_TIS(x) | ||
invisible(x) | ||
} | ||
w<-mapply(Align::pow,x=as.list(data.frame(t(X))), lambda2=as.list(best_lambdas2),MoreArgs = list(y=y,max_it = max_it)) | ||
w<-as.list((as.data.frame(w))) | ||
w<-append(w,list(1:m),idx_y-1) | ||
names(w)<-object$sampleNames | ||
|
||
delayed_op <- DelayedOperation( | ||
name = "align_pow", | ||
fun = align_pow, | ||
params_iter = list(w=w) | ||
) | ||
object$appendDelayedOp(delayed_op) | ||
object <- GCIMS:::extract_RIC_and_TIS(object) | ||
invisible(object) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
align_pow_sample <- function(x,w){ | ||
int <- GCIMS::intensity(x) | ||
inter <- t(apply(int, 1, Align::interpolation, w = w, return = FALSE)) | ||
sel <- !is.na(inter[1,]) | ||
x@retention_time <- x@retention_time[sel] | ||
x@data <- inter[,sel] | ||
return(x) | ||
} | ||
#' Warp a GCIMSSample | ||
#' | ||
#' Warps a GCIMSSample with the provided warp | ||
#' | ||
#' @param object A [GCIMSSample] object, modified in-place | ||
#' @param w warp to be applied to the GCIMSSample | ||
#' @return The modified [GCIMSSample] | ||
#' @export | ||
|
||
methods::setMethod( | ||
"align_pow", | ||
"GCIMSSample", | ||
function(object,w){ | ||
int <- GCIMS::intensity(object) | ||
inter <- t(apply(int, 1, Align::interpolation, w = w, return = FALSE)) | ||
sel <- !is.na(inter[1,]) | ||
object@retention_time <- object@retention_time[sel] | ||
object@data <- inter[,sel] | ||
return(object) | ||
} | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters