1 | deconvoluteMutCounts(input_mutCounts, params)
|
input_mutCounts |
|
params |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (input_mutCounts, params)
{
num_totIterations <- params$num_totIterations
num_processesToExtract <- params$num_processesToExtract
distanceFunction <- params$distanceFunction
thresh_removeWeakMutTypes <- params$thresh_removeWeakMutTypes
num_parallelCores <- params$num_parallelCores
guided <- params$guided
num_totReplicates <- params$num_totReplicates
thresh_removeLastPercent <- params$thresh_removeLastPercent
colnames(input_mutCounts) <- NULL
rownames(input_mutCounts) <- NULL
input_mutCounts <- as.matrix(input_mutCounts)
bckgrnd.removed.mutCounts <- removeWeak(input_mutCounts,
params)
bckgrnd.removed.mutset <- bckgrnd.removed.mutCounts$removed.mutset
bckgrnd.removed.mutCounts <- bckgrnd.removed.mutCounts$output.mutCounts
total.mutationTypes <- nrow(bckgrnd.removed.mutCounts)
total.samples <- ncol(bckgrnd.removed.mutCounts)
if (guided) {
guide.W <- extractSignatures(mutCountMatrix = bckgrnd.removed.mutCounts,
params = params, bootStrap = FALSE)
guide.W <- guide.W$Wk
}
else {
guide.W <- 0
}
if (num_parallelCores < 2) {
muCounts.checkDF <- tryCatch(lapply(1:num_totIterations,
(function(j) {
if (j %in% as.integer(seq(1, num_totIterations,
length.out = 100))) {
message(paste("(", j, ")", sep = ""), appendLF = FALSE)
}
tmp.out <- extractSignatures(mutCountMatrix = bckgrnd.removed.mutCounts,
bootStrap = TRUE, params = params)
if (guided) {
re.ORD <- rep(0, num_processesToExtract)
for (ki in 1:num_processesToExtract) {
my.i <- order(apply(abs(tmp.out$Wk - guide.W[,
ki]), 2, sum))
if (ki > 1) {
my.i[re.ORD[1:(ki - 1)]] <- max(my.i) +
1
}
re.ORD[ki] <- which.min(my.i)
}
}
else {
re.ORD <- 1:num_processesToExtract
}
if (num_processesToExtract > 1) {
tmp.out$Wk <- tmp.out$Wk[, re.ORD]
tmp.out$Hk <- tmp.out$Hk[re.ORD, ]
}
else {
tmp.out$Wk <- tmp.out$Wk
tmp.out$Hk <- rbind(tmp.out$Hk)
}
tmp.out
})), error = (function(e) {
print(e)
}))
message("Done!", appendLF = TRUE)
}
else {
max.cores <- parallel::detectCores()
max.cores <- max.cores - 1
max.cores <- ifelse(max.cores < 1, 1, max.cores)
use.cores <- ifelse(1 <= num_parallelCores & num_parallelCores <=
max.cores, num_parallelCores, max.cores)
cl <- suppressMessages(parallel::makeCluster(use.cores,
outfile = ""))
print(paste("Extracting", num_processesToExtract, "mutational signatures X",
num_totIterations, "iterations using", use.cores,
"cores"))
suppressMessages(doParallel::registerDoParallel(cl))
stuffToExp <- c("alexaNMF", "leadZeros", "extractSignatures",
"frequencize", "bootstrapCancerGenomes", "chihJenNMF",
"params")
suppressMessages(parallel::clusterExport(cl, stuffToExp))
muCounts.checkDF <- tryCatch(foreach::foreach(j = (1:num_totIterations),
.verbose = TRUE, .packages = "stats") %dopar% {
if (j %in% as.integer(seq(1, num_totIterations, length.out = 100))) {
message(paste("(", j, ")", sep = ""), appendLF = FALSE)
}
tmp.out <- extractSignatures(mutCountMatrix = bckgrnd.removed.mutCounts,
params = params)
if (guided) {
re.ORD <- rep(0, num_processesToExtract)
for (ki in 1:num_processesToExtract) {
my.i <- order(apply(abs(tmp.out$Wk - guide.W[,
ki]), 2, sum))
if (ki > 1) {
my.i[re.ORD[1:(ki - 1)]] <- max(my.i) + 1
}
re.ORD[ki] <- which.min(my.i)
}
}
else {
re.ORD <- 1:num_processesToExtract
}
if (num_processesToExtract > 1) {
tmp.out$Wk <- tmp.out$Wk[, re.ORD]
tmp.out$Hk <- tmp.out$Hk[re.ORD, ]
}
else {
tmp.out$Wk <- tmp.out$Wk
tmp.out$Hk <- rbind(tmp.out$Hk)
}
tmp.out
}, error = (function(e) {
print(e)
}), finally = (function(f) {
parallel::stopCluster(cl)
}))
message("Done!", appendLF = TRUE)
}
W.all <- do.call(cbind, lapply(muCounts.checkDF, (function(tmp) {
tmp$Wk
})))
H.all <- do.call(rbind, lapply(muCounts.checkDF, (function(tmp) {
tmp$Hk
})))
errors.all <- lapply(muCounts.checkDF, (function(tmp) {
tmp$mutCounts.errors
}))
reconstruct.all <- lapply(muCounts.checkDF, (function(tmp) {
tmp$mutCounts.reconstructed
}))
fltr.mutCounts.data <- filterOutIterations(wall = W.all,
hall = H.all, cnt_errors = errors.all, cnt_reconstructed = reconstruct.all,
params)
stability.check <- evaluateStability(wall = fltr.mutCounts.data$Wall,
hall = fltr.mutCounts.data$Hall, params)
final.mutCounts.data <- addWeak(mutationTypesToAddSet = bckgrnd.removed.mutset,
processes_I = stability.check$centroids, processesStd_I = stability.check$centroidStd,
Wall_I = fltr.mutCounts.data$Wall, genomeErrors_I = fltr.mutCounts.data$mutCounts.errors,
genomesReconstructed_I = fltr.mutCounts.data$mutCounts.reconstructed)
deconvoluted.results <- list()
deconvoluted.results$Wall <- final.mutCounts.data$Wall
deconvoluted.results$Hall <- fltr.mutCounts.data$Hall
deconvoluted.results$mutCountErrors <- final.mutCounts.data$mutCountErrors
deconvoluted.results$mutCountReconstructed <- final.mutCounts.data$mutCountReconstructed
deconvoluted.results$idx <- stability.check$idx
deconvoluted.results$idxS <- stability.check$idxS
deconvoluted.results$processes <- final.mutCounts.data$processes
deconvoluted.results$processesStd <- final.mutCounts.data$processesStd
deconvoluted.results$exposure <- stability.check$exposure
deconvoluted.results$exposureStd <- stability.check$exposureStd
deconvoluted.results$processStab <- stability.check$processStab
deconvoluted.results$processStabAvg <- stability.check$processStabAvg
deconvoluted.results$clusterCompactness <- stability.check$clusterCompactness
return(deconvoluted.results)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.