Skip to content

Commit

Permalink
Incremental error handling improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
brgew committed May 10, 2024
1 parent 8940443 commit 5363351
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
30 changes: 15 additions & 15 deletions R/io.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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' )
Expand Down Expand Up @@ -359,23 +357,25 @@ 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'), '.'),
tmpdir=matrix_control_res[['matrix_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)
Expand Down Expand Up @@ -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') {
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions R/matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down

0 comments on commit 5363351

Please sign in to comment.