Skip to content

Commit

Permalink
Add align pow
Browse files Browse the repository at this point in the history
  • Loading branch information
lalo-caballero committed Jan 25, 2024
1 parent e8c41fd commit 66d41a6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
32 changes: 32 additions & 0 deletions R/align_pow-GCIMSDataset.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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

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

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)
}
8 changes: 8 additions & 0 deletions R/align_pow-GCIMSSample.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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)
}

0 comments on commit 66d41a6

Please sign in to comment.