Skip to content

Commit

Permalink
pre-commit run --all-files
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Aug 9, 2024
1 parent 79a89bc commit 7b08a14
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 53 deletions.
40 changes: 20 additions & 20 deletions R/hictkR-exports.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ loadModule(module = "hictkR", TRUE)
#' File("interactions.mcool", 100000)
#' File("interactions.hic", 100000)
#' }

File <-
function(path,
resolution = NULL,
Expand All @@ -50,7 +49,6 @@ File <-
#' \dontrun{
#' MultiResFile("interactions.mcool")
#' }

MultiResFile <- function(path) {
return(new(RcppMultiResFile, path))
}
Expand All @@ -63,7 +61,6 @@ MultiResFile <- function(path) {
#' \dontrun{
#' SingleCellFile("interactions.scool")
#' }

SingleCellFile <- function(path) {
return(new(RcppSingleCellFile, path))
}
Expand Down Expand Up @@ -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 = "",
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 12 additions & 10 deletions tests/testthat/test-fetch-dense.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -43,15 +45,15 @@ 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)

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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions tests/testthat/test-fetch-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)
})

}
4 changes: 2 additions & 2 deletions tests/testthat/test-file-accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-hictkR-open.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-multiresolution-file-accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
16 changes: 10 additions & 6 deletions tests/testthat/test-singlecell-file-accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
})

0 comments on commit 7b08a14

Please sign in to comment.