From 60d05345a0413c18215a2892c031367ed28fe05a Mon Sep 17 00:00:00 2001 From: Ivo Kwee Date: Wed, 8 Nov 2023 16:51:30 +0100 Subject: [PATCH] fix: bug related to updateDatasetFolder() and dimension error (CRITICAL) --- R/pgx-files.R | 16 ++++++++++++---- R/pgx-signature.R | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/R/pgx-files.R b/R/pgx-files.R index ba44b3de..876a0057 100644 --- a/R/pgx-files.R +++ b/R/pgx-files.R @@ -821,18 +821,21 @@ pgxinfo.updateDatasetFolder <- function(pgx.dir, fc.add <- any(!colnames(allFC) %in% cn) fc.del <- any(!cn %in% colnames(allFC)) if (fc.add) { - dbg("[pgxinfo.updateDatasetFolder] adding sigDB (full create)") pgx.createSignatureDatabaseH5.fromMatrix(sigdb.file, X = allFC) - } + cn <- rhdf5::h5read(sigdb.file, "data/colnames") ## new size + } + if (fc.del) { del <- which(!cn %in% colnames(allFC)) ## cn[del] <- paste("[DELETED]", sub(".*\\] ", "", cn[del])) cn[del] <- paste("[DELETED]", cn[del]) rhdf5::h5delete(sigdb.file, "data/colnames") rhdf5::h5write(cn, sigdb.file, "data/colnames") + Sys.sleep(0.1) ## time to write... if (delete.old) { dbg("[pgxinfo.updateDatasetFolder] deleting sigDB entry") sigdb.removeDataset(sigdb.file, "DELETED") + Sys.sleep(0.1) ## allow write time } else { dbg("[pgxinfo.updateDatasetFolder] deletions tagged but not removed") } @@ -846,12 +849,17 @@ pgxinfo.updateDatasetFolder <- function(pgx.dir, if (!file.exists(tsne.file) || pgxfc.changed) { cn <- rhdf5::h5read(sigdb.file, "data/colnames") tsne <- rhdf5::h5read(sigdb.file, "clustering/tsne2d") + length(cn) + dim(tsne) + if(length(cn) != nrow(tsne)) { + dbg("[pgxinfo.updateDatasetFolder] ***ERROR**** length mismatch!") + } rownames(tsne) <- cn - colnames(tsne) <- paste0("tsne.", 1:2) + colnames(tsne) <- paste0("tsne.", 1:ncol(tsne)) utils::write.csv(tsne, file = tsne.file) } } - + dbg("[pgxinfo.updateDatasetFolder] done!") return() } diff --git a/R/pgx-signature.R b/R/pgx-signature.R index 2db1a41c..a59b60af 100644 --- a/R/pgx-signature.R +++ b/R/pgx-signature.R @@ -372,6 +372,9 @@ pgx.createSignatureDatabaseH5.fromMatrix <- function(h5.file, X, update.only = F rhdf5::h5write(pos[["pca2d"]], h5.file, "clustering/pca2d") ## can write list?? rhdf5::h5write(pos[["tsne2d"]], h5.file, "clustering/tsne2d") ## can write list?? rhdf5::h5write(pos[["umap2d"]], h5.file, "clustering/umap2d") ## can write list?? + + dbg("[pgx.createSignatureDatabaseH5.fromMatrix] dim.tsne2d = ", dim(pos[["tsne2d"]])) + dbg("[pgx.createSignatureDatabaseH5.fromMatrix] clustering done") } ## -------------------------------------------------- @@ -380,6 +383,7 @@ pgx.createSignatureDatabaseH5.fromMatrix <- function(h5.file, X, update.only = F pgx.addEnrichmentSignaturesH5(h5.file, X = X, mc.cores = 0, methods = "rankcor") ## done! + dbg("[pgx.createSignatureDatabaseH5.fromMatrix] done!") rhdf5::h5closeAll() }