Skip to content

Commit

Permalink
Merge pull request #74 from PixelgenTechnologies/exe-2108-read-edgeli…
Browse files Browse the repository at this point in the history
…st-bug-fix

Minor bug fixes
  • Loading branch information
ludvigla authored Jan 28, 2025
2 parents 274cb8e + 3accf91 commit b331429
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
17 changes: 12 additions & 5 deletions R/read_edgelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,28 @@ ReadMPX_arrow_edgelist <- function(
}

# Extract the edgelist parquet file
edge_list_dir <- fs::path_temp()
if (!is.null(edge_list_file)) {
# Validate path string
assert_single_value(edge_list_file, type = "string")
assert_file_ext(edge_list_file, ext = "parquet")
} else {
edge_list_dir <- fs::path_temp()
if (verbose && check_global_verbosity()) {
cli_alert_info("Extracting edgelist.parquet file to {col_br_blue(file.path(edge_list_dir, 'edgelist.parquet'))}")
}
edge_list_file <- fs::path(edge_list_dir, "edgelist.parquet")
}

if (verbose && check_global_verbosity()) {
cli_alert_info("Extracting edgelist.parquet file to {.file {edge_list_file}}")
}

# Extract the edgelist.parquet file
utils::unzip(pxl_file, files = "edgelist.parquet", exdir = edge_list_dir)
if (!is.null(edge_list_file)) {
# Move the file to the desired location if edge_list_file is provided
fs::file_move(fs::path(edge_list_dir, "edgelist.parquet"), edge_list_file)
}

# Read the parquet file
ds <- arrow::open_dataset(fs::path(edge_list_dir, "edgelist.parquet"))
ds <- arrow::open_dataset(edge_list_file)

# Convert selected columns uint64 to string
sel_fields <- grep(pattern = "^umi", names(ds), value = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/types_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ assert_file_ext <- function(
)
if (fs::path_ext(x) != ext) {
cli::cli_abort(
c("x" = "File {.file {x}} is not a PXL file"),
c("x" = "File {.file {x}} is not a {ext} file"),
call = call
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ abort_if_not <- function(
.validate_or_set_assay <- function(object, assay = NULL, call = caller_env()) {
# Use default assay if assay = NULL
if (!is.null(assay)) {
assert_single_value(assay, type = "character", call = call)
assert_single_value(assay, type = "string", call = call)
} else {
assay <- DefaultAssay(object)
}
Expand Down
4 changes: 2 additions & 2 deletions man/CellGraphAssay5-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions tests/testthat/test-ReadMPX_edgelist.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
pxl_file <- system.file("extdata/five_cells", "five_cells.pxl", package = "pixelatorR")

test_that("ReadMPX_arrow_edgelist works as expected", {
el <- ReadMPX_arrow_edgelist(system.file("extdata/five_cells", "five_cells.pxl", package = "pixelatorR"))
el <- ReadMPX_arrow_edgelist(pxl_file)
expect_type(el, type = "environment")
expect_equal(names(el), c(
"upia", "upib", "marker", "count",
"component"
))
expect_no_error({
msg <- capture_messages({
el <- ReadMPX_arrow_edgelist(system.file("extdata/five_cells", "five_cells.pxl", package = "pixelatorR"))
el <- ReadMPX_arrow_edgelist(pxl_file)
})
})

tmp_f <- fs::path_temp("test.parquet")
expect_no_error({
el <-
ReadMPX_arrow_edgelist(
pxl_file,
edge_list_file = tmp_f,
verbose = FALSE
)
})
expect_true(fs::file_exists(tmp_f))
expect_true(basename(tmp_f) == "test.parquet")
})


Expand All @@ -19,4 +33,8 @@ test_that("ReadMPX_arrow_edgelist fails when invalid input is provided", {
outdir = tempdir()
)
})
expect_error({
el <- ReadMPX_arrow_edgelist("Invalid file", edge_list_file = fs::path_temp("test.pxl")
)
})
})

0 comments on commit b331429

Please sign in to comment.