From 53633514445a2e99344ae786e6e3a471d7537311 Mon Sep 17 00:00:00 2001 From: brgew Date: Thu, 9 May 2024 18:05:43 -0700 Subject: [PATCH] Incremental error handling improvements. --- R/io.R | 30 +++++++++++++++--------------- R/matrix.R | 12 ++++++------ R/zzz.R | 6 ++++++ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/R/io.R b/R/io.R index 8cbd8fe..585896b 100644 --- a/R/io.R +++ b/R/io.R @@ -1,5 +1,3 @@ -dbar40 <- paste(replicate(40,'-'),collapse='') - #' Build a small cell_data_set. #' @param matrix_control A list used to control how the counts matrix is stored #' in the CDS. By default, Monocle3 stores the counts matrix in-memory as a @@ -318,7 +316,7 @@ load_mm_data <- function( mat_path, error = function(c) { stop(paste0(trimws(c), '\n* error in load_mm_data')) }) cell_annotations <- tryCatch(load_annotations_data( cell_anno_path, cell_metadata_column_names, header, sep, quote=quote, annotation_type='cells' ), - error = function(c) { stop(paste0(trimws(c), '\n* error in load_mm_data', sep='')) }) + error = function(c) { stop(paste0(trimws(c), '\n* error in load_mm_data')) }) assertthat::assert_that( ! any( duplicated( feature_annotations$names ) ), msg='duplicate feature names in feature annotation file' ) assertthat::assert_that( ! any( duplicated( cell_annotations$names ) ), msg='duplicate cell names in cell annotation file' ) @@ -359,11 +357,12 @@ load_mm_data <- function( mat_path, tmpdir=tmpdir, load_bytes=4194304L, sort_bytes=1073741824L), - error = function(c) { stop(paste0(trimws(c), '\n unable to read file ', mat_path, - '\n', dbar40, - '\n', report_path_status(mat_path, dirname(mat_path)), - '\n', dbar40, - '\n* error in load_mm_data')) }) + error = function(c) { stop(paste0(trimws(c), + '\n unable to read file ', mat_path, + '\n', dbar40, + '\n', report_path_status(mat_path, dirname(mat_path)), + '\n', dbar40, + '\n* error in load_mm_data')) }) unlink(tmpdir, recursive=TRUE) outdir_c <- tempfile(pattern=paste0('monocle.bpcells.', format(Sys.Date(), format='%Y%m%d'), '.'), @@ -371,11 +370,12 @@ load_mm_data <- function( mat_path, fileext='.tmp')[[1]] mat <- tryCatch(BPCells::write_matrix_dir(BPCells::convert_matrix_type(tmat, 'double'), outdir_c, compress=FALSE, buffer_size=8192L, overwrite=FALSE), - error = function(c) { stop(paste0(trimws(c), '\n error make row order counts matrix', - '\n', dbar40, - '\n', report_path_status(dirname(outdir_c), dirname(tmat)), - '\n', dbar40, - '\n* error in load_mm_data')) }) + error = function(c) { stop(paste0(trimws(c), + '\n error make row order counts matrix', + '\n', dbar40, + '\n', report_path_status(dirname(outdir_c), dirname(tmat)), + '\n', dbar40, + '\n* error in load_mm_data')) }) unlink(toutdir, recursive=TRUE) push_matrix_path(mat=mat) @@ -816,7 +816,7 @@ load_hnsw_index <- function(nn_index, file_name, metric, ndim) { '\n', dbar40, '\n', report_path_status(file_name, dirname(file_name)), '\n', dbar40, - '\n* error in save_hnsw_index')) }) # bge: read # bge: done + '\n* error in save_hnsw_index')) }) # bge: read # bge: done } else if(metric == 'euclidean') { @@ -828,7 +828,7 @@ load_hnsw_index <- function(nn_index, file_name, metric, ndim) { '\n', dbar40, '\n', report_path_status(file_name, dirname(file_name)), '\n', dbar40, - '\n* error in save_hnsw_index')) }) # bge: read # bge: done + '\n* error in save_hnsw_index')) }) # bge: read # bge: done attr(new_index, "distance") <- "euclidean" } else diff --git a/R/matrix.R b/R/matrix.R index 896d1c3..a51c03e 100644 --- a/R/matrix.R +++ b/R/matrix.R @@ -874,12 +874,12 @@ set_cds_row_order_matrix <- function(cds) { # compress. This is not a big deal because only the indices are compressed. mat_r <- tryCatch( BPCells::transpose_storage_order(matrix=mat_c, outdir=outdir, tmpdir=tmpdir, load_bytes=4194304L, sort_bytes=1073741824L), - error=function(c) { - message('set_cds_row_order_matrix: error running BPCells::transpose_storage_order: ', c) - report_path_status(dirname(tmpdir)) - report_path_status(dirname(outdir)) - stop('exiting') - }) + error=function(c) {stop(paste0(trimws(c), + '\n error running BPCells::transpose_storage_order', + '\n', dbar40, + '\n', report_path_status(out_dir, dirname(tmpdir)), + '\n', dbar40, + '\n* error in set_cds_row_order_matrix')) }) unlink(tmpdir, recursive=TRUE) push_matrix_path(mat=mat_r) diff --git a/R/zzz.R b/R/zzz.R index 0ae6bde..53107ca 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,6 +3,12 @@ # options("sp_evolution_status"=2) + +# Make a horizontal bar of dashes. +# +dbar40 <- paste(replicate(40,'-'),collapse='') + + # # Set up a global-variable-like environment. #