From 7b08a14536f45ba5b02ea10065c36bdcccca5c10 Mon Sep 17 00:00:00 2001 From: Roberto Rossini <71787608+robomics@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:27:49 +0200 Subject: [PATCH] pre-commit run --all-files --- R/hictkR-exports.R | 40 +++++++++---------- tests/testthat/test-fetch-dense.R | 22 +++++----- tests/testthat/test-fetch-df.R | 19 ++++----- tests/testthat/test-file-accessors.R | 4 +- tests/testthat/test-hictkR-open.R | 10 ++--- .../test-multiresolution-file-accessors.R | 2 +- .../testthat/test-singlecell-file-accessors.R | 16 +++++--- 7 files changed, 60 insertions(+), 53 deletions(-) diff --git a/R/hictkR-exports.R b/R/hictkR-exports.R index 59bad02..eb80790 100644 --- a/R/hictkR-exports.R +++ b/R/hictkR-exports.R @@ -30,7 +30,6 @@ loadModule(module = "hictkR", TRUE) #' File("interactions.mcool", 100000) #' File("interactions.hic", 100000) #' } - File <- function(path, resolution = NULL, @@ -50,7 +49,6 @@ File <- #' \dontrun{ #' MultiResFile("interactions.mcool") #' } - MultiResFile <- function(path) { return(new(RcppMultiResFile, path)) } @@ -63,7 +61,6 @@ MultiResFile <- function(path) { #' \dontrun{ #' SingleCellFile("interactions.scool") #' } - SingleCellFile <- function(path) { return(new(RcppSingleCellFile, path)) } @@ -92,21 +89,25 @@ SingleCellFile <- function(path) { #' @returns a DataFrame or Matrix object with the interactions for the given query. #' @examples #' \dontrun{ -#' f <- File("interactions.hic", -#' 1000000) -#' fetch(f) # Fetch genome-wide interactions -#' fetch(f, "chr2L") # Fetch interactions overlapping a symmetric query +#' f <- File( +#' "interactions.hic", +#' 1000000 +#' ) +#' fetch(f) # Fetch genome-wide interactions +#' fetch(f, "chr2L") # Fetch interactions overlapping a symmetric query +#' fetch( +#' f, +#' "chr2L:0-10,000,000", +#' "chr3L:10,000,000-20,000,000" +#' ) # Fetch interactions overlapping an asymmetric query +#' fetch(f, normalization = "ICE") # Fetch ICE-normalized interactions +#' fetch(f, join = TRUE) # Fetch interactions together with their genomic coordinates #' fetch(f, -#' "chr2L:0-10,000,000", -#' "chr3L:10,000,000-20,000,000") # Fetch interactions overlapping an asymmetric query -#' fetch(f, normalization="ICE") # Fetch ICE-normalized interactions -#' fetch(f, join=TRUE) # Fetch interactions together with their genomic coordinates -#' fetch(f, -#' "chr1\t0\t10000000", -#' query_type="BED") # Fetch interactions given a query in BED format -#' fetch(f, type="dense") # Fetch interactions in dense format (i.e. as a Matrix) +#' "chr1\t0\t10000000", +#' query_type = "BED" +#' ) # Fetch interactions given a query in BED format +#' fetch(f, type = "dense") # Fetch interactions in dense format (i.e. as a Matrix) #' } - fetch <- function(file, range1 = "", @@ -138,11 +139,10 @@ fetch <- #' hictkR_open("interactions.cool") #' hictkR_open("interactions.mcool") #' hictkR_open("interactions.scool") -#' hictkR_open("interactions.mcool", resolution=10000) -#' hictkR_open("interactions.hic", resolution=10000) -#' hictkR_open("interactions.scool", cell="id_0001") +#' hictkR_open("interactions.mcool", resolution = 10000) +#' hictkR_open("interactions.hic", resolution = 10000) +#' hictkR_open("interactions.scool", cell = "id_0001") #' } - hictkR_open <- function(path, resolution = NULL, cell = NULL) { diff --git a/tests/testthat/test-fetch-dense.R b/tests/testthat/test-fetch-dense.R index 9e90cda..2a5f4fa 100644 --- a/tests/testthat/test-fetch-dense.R +++ b/tests/testthat/test-fetch-dense.R @@ -2,15 +2,17 @@ # # SPDX-License-Identifier: MIT -test_files <- c(test_path("..", "data", "hic_test_file.hic"), - test_path("..", "data", "cooler_test_file.mcool")) +test_files <- c( + test_path("..", "data", "hic_test_file.hic"), + test_path("..", "data", "cooler_test_file.mcool") +) for (path in test_files) { test_that("HiCFile: fetch (dense) genome-wide", { f <- File(path, 100000) - m <- fetch(f, type="dense") + m <- fetch(f, type = "dense") shape <- dim(m) sum_ <- sum(m) @@ -22,7 +24,7 @@ for (path in test_files) { test_that("HiCFile: fetch (dense) symmetric cis", { f <- File(path, 100000) - m <- fetch(f, "chr2R:10,000,000-15,000,000", type="dense") + m <- fetch(f, "chr2R:10,000,000-15,000,000", type = "dense") shape <- dim(m) sum_ <- sum(m) @@ -34,7 +36,7 @@ for (path in test_files) { test_that("HiCFile: fetch (dense) asymmetric cis", { f <- File(path, 100000) - m <- fetch(f, "chr2L:0-10,000,000", "chr2L:5,000,000-20,000,000", type="dense") + m <- fetch(f, "chr2L:0-10,000,000", "chr2L:5,000,000-20,000,000", type = "dense") shape <- dim(m) sum_ <- sum(m) @@ -43,7 +45,7 @@ for (path in test_files) { expect_equal(sum_, 6287451) - m <- fetch(f, "chr2L:0-10,000,000", "chr2L:10,000,000-20,000,000", type="dense") + m <- fetch(f, "chr2L:0-10,000,000", "chr2L:10,000,000-20,000,000", type = "dense") shape <- dim(m) sum_ <- sum(m) @@ -51,7 +53,7 @@ for (path in test_files) { expect_equal(shape, c(100, 100)) expect_equal(sum_, 761223) - m <- fetch(f, "chr2L:0-10,000,000", "chr2L:0-15,000,000", type="dense") + m <- fetch(f, "chr2L:0-10,000,000", "chr2L:0-15,000,000", type = "dense") shape <- dim(m) sum_ <- sum(m) @@ -63,7 +65,7 @@ for (path in test_files) { test_that("HiCFile: fetch (dense) cis BED queries", { f <- File(path, 100000) - m <- fetch(f, "chr2R\t10000000\t15000000", type="dense", query_type="BED") + m <- fetch(f, "chr2R\t10000000\t15000000", type = "dense", query_type = "BED") shape <- dim(m) sum_ <- sum(m) @@ -75,7 +77,7 @@ for (path in test_files) { test_that("HiCFile: fetch (dense) trans", { f <- File(path, 100000) - m <- fetch(f, "chr2R:10,000,000-15,000,000", "chrX:0-10,000,000", type="dense") + m <- fetch(f, "chr2R:10,000,000-15,000,000", "chrX:0-10,000,000", type = "dense") shape <- dim(m) sum_ <- sum(m) @@ -87,7 +89,7 @@ for (path in test_files) { test_that("HiCFile: fetch (dense) trans BED queries", { f <- File(path, 100000) - m <- fetch(f, "chr2R\t10000000\t15000000", "chrX\t0\t10000000", type="dense", query_type="BED") + m <- fetch(f, "chr2R\t10000000\t15000000", "chrX\t0\t10000000", type = "dense", query_type = "BED") shape <- dim(m) sum_ <- sum(m) diff --git a/tests/testthat/test-fetch-df.R b/tests/testthat/test-fetch-df.R index 60e7a2e..c4adafe 100644 --- a/tests/testthat/test-fetch-df.R +++ b/tests/testthat/test-fetch-df.R @@ -2,8 +2,10 @@ # # SPDX-License-Identifier: MIT -test_files <- c(test_path("..", "data", "hic_test_file.hic"), - test_path("..", "data", "cooler_test_file.mcool")) +test_files <- c( + test_path("..", "data", "hic_test_file.hic"), + test_path("..", "data", "cooler_test_file.mcool") +) for (path in test_files) { test_that("HiCFile: fetch (DF) genome-wide", { @@ -31,7 +33,7 @@ for (path in test_files) { test_that("HiCFile: fetch (DF) cis bg2", { f <- File(path, 100000) - df <- fetch(f, "chr2R:10,000,000-15,000,000", join=TRUE) + df <- fetch(f, "chr2R:10,000,000-15,000,000", join = TRUE) sum_ <- sum(df$count) num_columns <- length(df) @@ -42,7 +44,7 @@ for (path in test_files) { test_that("HiCFile: fetch (DF) cis BED queries", { f <- File(path, 100000) - df <- fetch(f, "chr2R\t10000000\t15000000", query_type="BED") + df <- fetch(f, "chr2R\t10000000\t15000000", query_type = "BED") nnz <- length(df$count) expect_equal(nnz, 1275) @@ -62,7 +64,7 @@ for (path in test_files) { test_that("HiCFile: fetch (DF) trans bg2", { f <- File(path, 100000) - df <- fetch(f, "chr2R:10,000,000-15,000,000", "chrX:0-10,000,000", join=TRUE) + df <- fetch(f, "chr2R:10,000,000-15,000,000", "chrX:0-10,000,000", join = TRUE) sum_ <- sum(df$count) num_columns <- length(df) @@ -73,7 +75,7 @@ for (path in test_files) { test_that("HiCFile: fetch (DF) cis: BED queries", { f <- File(path, 100000) - df <- fetch(f, "chr2R\t10000000\t15000000", "chrX\t0\t10000000", query_type="BED") + df <- fetch(f, "chr2R\t10000000\t15000000", "chrX\t0\t10000000", query_type = "BED") nnz <- length(df$count) expect_equal(nnz, 4995) @@ -83,14 +85,13 @@ for (path in test_files) { f <- File(path, 100000) if (f$is_cooler) { - df <- fetch(f, "chr2R:10,000,000-15,000,000", normalization="weight") + df <- fetch(f, "chr2R:10,000,000-15,000,000", normalization = "weight") } else { - df <- fetch(f, "chr2R:10,000,000-15,000,000", normalization="ICE") + df <- fetch(f, "chr2R:10,000,000-15,000,000", normalization = "ICE") } sum_ <- sum(df$count) expect_equal(sum_, 59.349524704033215) }) - } diff --git a/tests/testthat/test-file-accessors.R b/tests/testthat/test-file-accessors.R index 7f85fb1..b9a7607 100644 --- a/tests/testthat/test-file-accessors.R +++ b/tests/testthat/test-file-accessors.R @@ -37,7 +37,7 @@ test_that("File: chromosomes accessor", { path2 <- test_path("..", "data", "chromosomes.tsv.gz") chroms <- File(path1, 100000)$chromosomes - expected_chroms <- read.csv(path2, sep="\t") + expected_chroms <- read.csv(path2, sep = "\t") expect_equal(chroms, expected_chroms) }) @@ -48,7 +48,7 @@ test_that("File: bins accessor", { bins1 <- File(path1, 100000)$bins bins2 <- File(path2, 100000)$bins - expected_bins <- read.csv(path3, sep="\t", stringsAsFactors=FALSE) + expected_bins <- read.csv(path3, sep = "\t", stringsAsFactors = FALSE) bins1$chrom <- as.character(bins1$chrom) bins2$chrom <- as.character(bins2$chrom) diff --git a/tests/testthat/test-hictkR-open.R b/tests/testthat/test-hictkR-open.R index 26d172d..4fb3a35 100644 --- a/tests/testthat/test-hictkR-open.R +++ b/tests/testthat/test-hictkR-open.R @@ -5,7 +5,7 @@ hic_file <- test_path("..", "data", "hic_test_file.hic") mcool_file <- test_path("..", "data", "cooler_test_file.mcool") scool_file <- test_path("..", "data", "cooler_test_file.scool") -cool_file <- paste(test_path("..", "data", "cooler_test_file.mcool"), "::/resolutions/100000", sep="") +cool_file <- paste(test_path("..", "data", "cooler_test_file.mcool"), "::/resolutions/100000", sep = "") test_that("hicrkR_open: .hic", { expected <- class(File(hic_file, 100000)) @@ -20,19 +20,19 @@ test_that("hicrkR_open: .cool", { f <- hictkR_open(cool_file) expect_equal(expected, class(f)) - f <- hictkR_open(mcool_file, resolution=100000) + f <- hictkR_open(mcool_file, resolution = 100000) expect_equal(expected, class(f)) - f <- hictkR_open(scool_file, cell="GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool") + f <- hictkR_open(scool_file, cell = "GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool") expect_equal(expected, class(f)) mclr <- MultiResFile(mcool_file) sclr <- SingleCellFile(scool_file) - f <- hictkR_open(mclr, resolution=100000) + f <- hictkR_open(mclr, resolution = 100000) expect_equal(expected, class(f)) - f <- hictkR_open(sclr, cell="GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool") + f <- hictkR_open(sclr, cell = "GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool") expect_equal(expected, class(f)) }) diff --git a/tests/testthat/test-multiresolution-file-accessors.R b/tests/testthat/test-multiresolution-file-accessors.R index e46504a..8fc7015 100644 --- a/tests/testthat/test-multiresolution-file-accessors.R +++ b/tests/testthat/test-multiresolution-file-accessors.R @@ -15,7 +15,7 @@ test_that("MultiResFile: chromosomes accessor", { path2 <- test_path("..", "data", "chromosomes.tsv.gz") chroms <- MultiResFile(path1)$chromosomes - expected_chroms <- read.csv(path2, sep="\t") + expected_chroms <- read.csv(path2, sep = "\t") expect_equal(chroms, expected_chroms) }) diff --git a/tests/testthat/test-singlecell-file-accessors.R b/tests/testthat/test-singlecell-file-accessors.R index d8c6115..3abaea8 100644 --- a/tests/testthat/test-singlecell-file-accessors.R +++ b/tests/testthat/test-singlecell-file-accessors.R @@ -33,10 +33,14 @@ test_that("SingleCellFile: chromosomes accessor", { test_that("SingleCellFile: file cells accessor", { f <- SingleCellFile(scool_file) - expect_equal(f$cells, - c("GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool", - "GSM2687249_41670_GGCTAC-R1-DpnII.100000.cool", - "GSM2687250_41671_TTAGGC-R1-DpnII.100000.cool", - "GSM2687251_41672_AGTTCC-R1-DpnII.100000.cool", - "GSM2687252_41673_CCGTCC-R1-DpnII.100000.cool")) + expect_equal( + f$cells, + c( + "GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool", + "GSM2687249_41670_GGCTAC-R1-DpnII.100000.cool", + "GSM2687250_41671_TTAGGC-R1-DpnII.100000.cool", + "GSM2687251_41672_AGTTCC-R1-DpnII.100000.cool", + "GSM2687252_41673_CCGTCC-R1-DpnII.100000.cool" + ) + ) })