From d1771421321f67a6b7ec0a4bf1c3f54de171c310 Mon Sep 17 00:00:00 2001 From: Daniel Keitley Date: Sat, 9 Jan 2021 12:15:10 +0000 Subject: [PATCH 1/2] Moved as.matrix outside of lapply. --- R/interWeights.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/interWeights.R b/R/interWeights.R index 22cecf6..827bfd3 100644 --- a/R/interWeights.R +++ b/R/interWeights.R @@ -19,13 +19,16 @@ interWeights <- function(expDataBatch, trajCond, winSz, numPts){ expDataBatch = expDataBatch[,-which(is.na(trajCond))] trajCond = trajCond[-which(is.na(trajCond))] } + + expDataBatchDense <- as.matrix(expDataBatch) + #generate equally-spaced points along the trajectory: trajValNewPts = seq(from=min(trajCond), to=max(trajCond), length.out = numPts) #length - numPts ValNewPts = do.call('cbind',lapply(trajValNewPts, function(trajPt){ dist2Others = trajCond - trajPt #length - samples number weightedData = exp(-(dist2Others^2)/(winSz^2)) weightedData = weightedData/sum(weightedData) - return(as.matrix(expDataBatch) %*% weightedData) + return(expDataBatchDense %*% weightedData) })) #sapply on the traj - for each real data point, find the closest interpolated point: a = 1 From c9850668134b22191cbd3f27b5c6b4978a4231ea Mon Sep 17 00:00:00 2001 From: Daniel Keitley Date: Sat, 9 Jan 2021 12:32:24 +0000 Subject: [PATCH 2/2] Repeated for errPerGene --- R/interWeights.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/interWeights.R b/R/interWeights.R index 827bfd3..82bdcfd 100644 --- a/R/interWeights.R +++ b/R/interWeights.R @@ -38,12 +38,13 @@ interWeights <- function(expDataBatch, trajCond, winSz, numPts){ return(abs(expDataBatch[rowInd,] - ValNewPts[rowInd,closestInt])) })) + errPerGeneDense <- as.matrix(errPerGene) #interpolate the error at each interpolated point: errInterpolated = do.call('cbind',lapply(trajValNewPts, function(trajPt){ dist2Others = trajCond - trajPt #length - samples number weightedData = exp(-(dist2Others^2)/(winSz^2)) weightedData = weightedData/sum(weightedData) - return(as.matrix(errPerGene) %*% weightedData) + return(errPerGeneDense %*% weightedData) })) rownames(errInterpolated) = rownames(ValNewPts)