Package 'HiCBricks'

Title: Framework for Storing and Accessing Hi-C Data Through HDF Files
Description: HiCBricks is a library designed for handling large high-resolution Hi-C datasets. Over the years, the Hi-C field has experienced a rapid increase in the size and complexity of datasets. HiCBricks is meant to overcome the challenges related to the analysis of such large datasets within the R environment. HiCBricks offers user-friendly and efficient solutions for handling large high-resolution Hi-C datasets. The package provides an R/Bioconductor framework with the bricks to build more complex data analysis pipelines and algorithms. HiCBricks already incorporates example algorithms for calling domain boundaries and functions for high quality data visualization.
Authors: Koustav Pal [aut, cre], Carmen Livi [ctb], Ilario Tagliaferri [ctb]
Maintainer: Koustav Pal <[email protected]>
License: MIT + file LICENSE
Version: 1.23.0
Built: 2024-09-14 05:09:15 UTC
Source: https://github.com/bioc/HiCBricks

Help Index


Store a ranges object in the Brick store.

Description

Brick_add_ranges loads a GRanges object into the Brick store.

Usage

Brick_add_ranges(
    Brick,
    ranges,
    rangekey,
    resolution = NA,
    all_resolutions = FALSE,
    num_cpus = 1
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

ranges

Required. An object of class ranges specifying the ranges to store in the Brick.

rangekey

Required. The name to use for the ranges within the Brick store.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

all_resolutions

Optional. Default FALSE If resolution is not defined and all_resolutions is TRUE, the resolution parameter will be ignored and the function is executed on all files listed in the Brick container

num_cpus

Optional. Default 1 When an object of class BrickContainer is provided, num_cpus defines the maximum number of parallel jobs that will be run.

Details

With this function it is possible to associate other ranges objects with the Brick store. If metadata columns are present, the are also loaded into the Brick store. Although not explicitly asked for, the metadata columns should not be of type list as this may create complications down the line. We ask for ranges objects, so if the same ranges object is later retrieved two additional columns will be present. These are the strand and width columns that are obtained when a ranges is converted into a data.frame. Users can ignore these columns.

Value

Returns TRUE if completed successfully.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "add_ranges_test")

dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Chrom <- c("chrS","chrS","chrS","chrS","chrS")
Start <- c(10000,20000,40000,50000,60000)
End <- c(10001,20001,40001,50001,60001)
Test_ranges <- Brick_make_ranges(chrom = Chrom, start = Start, end = End)
Brick_add_ranges(Brick = My_BrickContainer, ranges = Test_ranges,
rangekey = "test_ranges", all_resolutions = TRUE)

Identify compartments in the Hi-C data

Description

Brick_call_compartments identifies compartments in Hi-C data. Reference Lieberman-Aiden et al. 2009.

Usage

Brick_call_compartments(Brick, chr, resolution)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr

Required. A string specifying the chromosome for the cis Hi-C matrix from which values will be retrieved at a certain distance.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

A dataframe containing the chromosome genomic coordinates and the first three principal components.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_vector_val_test")
if(!file.exists(out_dir)){
    dir.create(out_dir)
}

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Compartments_df <- Brick_call_compartments(Brick = My_BrickContainer, 
chr = "chr2L", resolution = 100000)

Export an entire resolution from a given BrickContainer as a upper triangle sparse matrix

Description

Brick_export_to_sparse will accept as input an object of class BrickContainer, a string of length 1 as resolution and a path specifying the output file to write. It writes the content of the all loaded Brick objects as a upper triangle sparse matrix (col > row) containing non-zero values.

Usage

Brick_export_to_sparse(
    Brick,
    out_file,
    remove_file = FALSE,
    resolution,
    sep = " "
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

out_file

Path to the output file to write.

remove_file

Default FALSE. If a file by the same name is present that file will be removed.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

sep

column delimiter in output file. Default single space.

Value

Returns a data.frame corresponding to the head of the output file

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "write_file")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
  bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
  experiment_name = "Vignette Test", resolution = 100000,
  remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_export_to_sparse(Brick = My_BrickContainer, 
out_file = file.path(out_dir, "example_out.txt"), 
resolution = 100000)

Returns the position of the supplied ranges in the binning table associated to the Hi-C experiment.

Description

Brick_fetch_range_index constructs a ranges object using Brick_make_ranges, creates an overlap operation using GenomicRanges::findOverlaps, where the constructed ranges is the subject and the Hi-C experiment associated binning table is the query. The return of this object is a list of ranges with their corresponding indices in the binning table.

Usage

Brick_fetch_range_index(
    Brick = NA,
    chr = NA,
    start = NA,
    end = NA,
    names = NA,
    resolution = NA,
    type = "any"
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr

Required. A character vector of length N specifying the chromosomes to select from the ranges.

start

Required. A numeric vector of length N specifying the start positions in the chromosome

end

Required. A numeric vector of length N specifying the end positions in the chromosome

names

Optional. A character vector of length N specifying the names of the chromosomes. If absent, names will take the form chr:start:end.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

type

Optional. Default any Type of overlap operation to do. It should be one of two, any or within. any considers any overlap (atleast 1 bp) between the provided ranges and the binning table.

Value

Returns a GenomicRanges object of same length as the chr, start, end vectors provided. The object is returned with an additional column, Indexes. Indexes is a column of class IRanges::IntegerList, which is part of the larger IRanges::AtomicList superset. This "Indexes" column can be accessed like a normal GRanges column with the additional list accessor [[]] in place of the normal vector accessor [].

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "fetch_range_index_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
  bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
  experiment_name = "Vignette Test", resolution = 100000,
  remove_existing = TRUE)

Chrom <- c("chr2L","chr2L")
Start <- c(1,40000)
End <- c(1000000,2000000)

Test_Run <- Brick_fetch_range_index(Brick = My_BrickContainer, 
chr = Chrom, start = Start, end = End, resolution = 100000)
Test_Run$Indexes[[1]]

Return row or col vectors.

Description

Brick_fetch_row_vector will fetch any given rows from a matrix. If required, the rows can be subsetted on the columns and transformations applied. Vice versa is also true, wherein columns can be retrieved and rows subsetted.

Usage

Brick_fetch_row_vector(
    Brick,
    chr1,
    chr2,
    resolution,
    by = c("position", "ranges"),
    vector,
    regions = NULL,
    force = FALSE,
    flip = FALSE,
    FUN = NULL
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

by

Required. One of two possible values, "position" or "ranges". A one-dimensional numeric vector of length 1 specifying one of either position or ranges.

vector

Required. If by is position, a 1 dimensional numeric vector containing the rows to be extracted is expected. If by is ranges, a 1 dimensional character vector containing the names of the bintable is expected. This function does not do overlaps. Rather it returns any given row or column based on their position or names in the bintable.

regions

Optional. Default NULL A character vector of length vector is expected. Each element must be of the form chr:start:end. These regions will be converted back to their original positions and the corresponding rows will be subsetted by the corresponding region element. If the length of regions does not match, the subset operation will not be done and all elements from the rows will be returned.

force

Optional. Default FALSE If true, will force the retrieval operation when matrix contains loaded data until a certain distance.

flip

Optional. Default FALSE If present, will flip everything. This is equivalent to selecting columns, and subsetting on the rows.

FUN

Optional. Default NULL If provided a data transformation with FUN will be applied before the matrix is returned.

Value

Returns a list of length vector. Each list element will be of length chr2 binned length or if regions is present the corresponding region length. This may differ based on the operations with FUN.

See Also

Brick_get_matrix_within_coords to get matrix by using matrix genomic coordinates, Brick_get_values_by_distance to get values separated at a certain distance, Brick_fetch_row_vector to get values in a certain row/col and subset them, Brick_get_matrix to get matrix by using matrix coordinates.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_row_vector_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
  bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
  experiment_name = "Vignette Test", resolution = 100000,
  remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Coordinate <- c("chr2L:1:100000","chr2L:100001:200000")
Test_Run <- Brick_fetch_row_vector(Brick = My_BrickContainer,
chr1 = "chr2L", chr2 = "chr2L", resolution = 100000, 
by = "ranges", vector = Coordinate,
regions = c("chr2L:1:1000000", "chr2L:40001:2000000"))

Returns the binning table associated to the Hi-C experiment.

Description

Brick_get_bintable makes a call to Brick_get_ranges to retrieve the binning table of the associated Brick store. This is equivalent to passing the argument rangekey = "bintable" in Brick_get_ranges

Usage

Brick_get_bintable(Brick, chr = NA, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr

Optional. A chr string specifying the chromosome to select from the ranges.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns a GRanges object containing the binning table associated to the Brick store.

See Also

Brick_get_ranges

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "list_get_bintable_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Brick_get_bintable(Brick = My_BrickContainer, resolution = 100000)

Get the chrominfo for the Hi-C experiment.

Description

Brick_get_chrominfo fetches the associated chrominfo table for the Brick it is associated to.

Usage

Brick_get_chrominfo(Brick, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

A three column data.frame containing chromosomes, nrows and length.

chromosomes corresponds to all chromosomes in the provided bintable.

nrows corresponds to the number of entries in the bintable or dimension for that chromosome in a Hi-C matrix.

Length is the total bp length of the same chromosome (max value for that chromosome in the bintable).

Examples

Bintable_path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "HiCBricks_chrominfo_test")

dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable_path, 
bin_delim=" ", remove_existing=TRUE, output_directory = out_dir, 
file_prefix = "HiCBricks_vignette_test", resolution = 100000,
experiment_name = "HiCBricks vignette test")

Brick_get_chrominfo(Brick = My_BrickContainer, resolution = 100000)

Return an entire matrix for provided chromosome pair for a resolution.

Description

Brick_get_entire_matrix will return the entire matrix for the entire chromosome pair provided an object of class BrickContainer, and values for chr1, chr2 and resolution values.

Usage

Brick_get_entire_matrix(Brick, chr1, chr2, resolution)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns an object of class matrix with dimensions corresponding to chr1 binned length by chr2 binned length.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_vector_val_test")
if(!file.exists(out_dir)){
    dir.create(out_dir)
}

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Entire_matrix <- Brick_get_entire_matrix(Brick = My_BrickContainer, 
chr1 = "chr2L", chr2 = "chr2L", resolution = 100000)

Return a matrix subset.

Description

Brick_get_matrix will fetch a matrix subset between row values ranging from min(x_coords) to max(x_coords) and column values ranging from min(x_coords) to max(x_coords)

Usage

Brick_get_matrix(
    Brick,
    chr1,
    chr2,
    x_coords,
    y_coords,
    resolution,
    force = FALSE,
    FUN = NULL
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

x_coords

Required. A one-dimensional numeric vector specifying the rows to subset.

y_coords

Required. A one-dimensional numeric vector specifying the columns to subset.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

force

Optional. Default FALSE If true, will force the retrieval operation when matrix contains loaded data until a certain distance.

FUN

Optional. If provided a data transformation with FUN will be applied before the matrix is returned.

Value

Returns a matrix of dimension x_coords length by y_coords length. This may differ based on the operations with FUN.

See Also

Brick_get_matrix_within_coords to get matrix by using matrix genomic coordinates, Brick_get_values_by_distance to get values separated at a certain distance, Brick_fetch_row_vector to getvalues in a certain row/col and subset them, Brick_get_vector_values to get values using matrix coordinates.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_matrix_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_get_matrix(Brick = My_BrickContainer, chr1 = "chr2L", chr2 = "chr2L",
x_coords = c(1:10), y_coords = c(1:10), resolution = 100000)

Get the matrix metadata columns in the Brick store.

Description

Brick_get_matrix_mcols will get the specified matrix metadata column for a chr1 vs chr2 Hi-C data matrix. Here, chr1 represents the rows and chr2 represents the columns of the matrix. For cis Hi-C matrices, where chr1 == chr2, chr2_bin_coverage and chr2_col_sums equals chr1_bin_coverage and chr1_row_sums respectively.

Usage

Brick_get_matrix_mcols(
    Brick,
    chr1,
    chr2,
    resolution,
    what = c("chr1_bin_coverage", "chr2_bin_coverage", "chr1_row_sums", "chr2_col_sums")
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

what

Required A character vector of length 1 specifying the matrix metric to retrieve

Details

These metadata columns are:

  • chr1_bin_coverage: Percentage of rows containing non-zero values

  • chr2_bin_coverage: Percentage of columns containing non-zero values

  • chr1_row_sums: Total signal (if normalised) or number of reads (if counts) in each row.

  • chr2_col_sums: Total signal (if normalised) or number of reads (if counts) in each column.

Value

Returns a 1xN dimensional vector containing the specified matrix metric

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_matrix_mcols_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_get_matrix_mcols(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000, what = "chr1_bin_coverage")

Return a matrix subset between two regions.

Description

Brick_get_matrix_within_coords will fetch a matrix subset after creating an overlap operation between both regions and the bintable associated to the Brick store. This function calls Brick_get_matrix.

Usage

Brick_get_matrix_within_coords(
    Brick,
    x_coords,
    y_coords,
    resolution,
    force = FALSE,
    FUN = NULL
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

x_coords

Required. A string specifying the region to subset on the rows. It takes the form chr:start:end. An overlap operation with the associated bintable will be done to identify the bins to subset on the row

y_coords

Required. A string specifying the region to subset on the rows. It takes the form chr:start:end. An overlap operation with the associated bintable will be done to identify the bins to subset on the column

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

force

Optional. Default FALSE If true, will force the retrieval operation when matrix contains loaded data until a certain distance.

FUN

Optional. If provided a data transformation with FUN will be applied before the matrix is returned.

Value

Returns a matrix of dimension x_coords binned length by y_coords binned length. This may differ based on FUN.

See Also

Brick_get_matrix to get matrix by using matrix coordinates, Brick_get_values_by_distance to get values separated at a certain distance, Brick_fetch_row_vector to get values in a certain row/col and subset them, Brick_get_vector_values to get values using matrix coordinates.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_matrix_coords_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_get_matrix_within_coords(Brick = My_BrickContainer,
x_coords = "chr2L:1:1000000",
y_coords = "chr2L:1:1000000",
resolution = 100000)

Brick_get_matrix_within_coords(Brick = My_BrickContainer,
x_coords = "chr2L:1:1000000",
y_coords = "chr2L:1:1000000",
resolution = 100000,
FUN = mean)

Fetch the ranges associated to a rangekey or chromosome.

Description

Brick_get_ranges will get a ranges object if present in the Brick store and return a GRanges object.

Usage

Brick_get_ranges(Brick = NA, chr = NA, rangekey = NA, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr

Optional. A chr string specifying the chromosome to select from the ranges.

rangekey

Required. A string specifying the name of the ranges.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Details

If a rangekey is present, the ranges will be retrieve and a GRanges constructed. Metadata columns will also be added. If these are rangekeys other than "Bintable", and had been added using Brick_add_ranges the width and Strand columns may appear as metadata columns. These will most likely be artifacts from converting the original ranges object to a data.frame.

Value

Returns a GRanges object with the associated metadata columns that may have been present in the Ranges object.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "list_get_ranges_test")

dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Brick_get_ranges(Brick = My_BrickContainer, chr = "chr2L", 
rangekey = "Bintable", resolution = 100000)

Return values separated by a certain distance.

Description

Brick_get_values_by_distance can fetch values with or without transformation or subsetted by a certain distance. Please note, this module is not an iterable module.

Usage

Brick_get_values_by_distance(
    Brick,
    chr,
    distance,
    resolution,
    constrain_region = NULL,
    batch_size = 500,
    FUN = NULL
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr

Required. A string specifying the chromosome for the cis Hi-C matrix from which values will be retrieved at a certain distance.

distance

Required. 0 based. Fetch values separated by distance.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

constrain_region

Optional. A character vector of length 1 with the form chr:start:end specifying the region for which the distance values must be retrieved.

batch_size

Optional. Default 500 A numeric vector of length 1 specifying the size of the chunk to retrieve for diagonal selection.

FUN

Optional. If provided a data transformation with FUN will be applied before values are returned.

Value

Returns a numeric vector of length N depending on the presence of constrain_region, FUN and distance from the main diagonal.

See Also

Brick_get_matrix_within_coords to get matrix by using matrix coordinates, Brick_fetch_row_vector to get values in a certain row/col and subset them, Brick_get_vector_values to get values using matrix coordinates, Brick_get_matrix to get matrix by using matrix coordinates.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "val_by_dist_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_get_values_by_distance(Brick = My_BrickContainer, chr = "chr2L",
distance = 0, resolution = 100000)

Failsafe_median <- function(x){
     x[is.nan(x) | is.infinite(x) | is.na(x)] <- 0
     return(median(x))
}

Brick_get_values_by_distance(Brick = My_BrickContainer, chr = "chr2L", 
resolution = 100000, distance = 4, FUN = Failsafe_median)

Return a N dimensional vector selection.

Description

Brick_get_vector_values is the base function being used by all other matrix retrieval functions.

Usage

Brick_get_vector_values(
    Brick,
    chr1,
    chr2,
    resolution,
    xaxis,
    yaxis,
    FUN = NULL,
    force = FALSE
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

xaxis

Required. A 1 dimensional vector containing the rows to retrieve. Gaps in this vector may result in unexpected behaviour as the values which are considered are min(xaxis) and max(xaxis) for retrieval.

yaxis

Required. A 1 dimensional vector containing the columns to retrieve. Gaps in this vector may result in unexpected behaviour as the values which are considered are min(yaxis) and max(yaxis) for retrieval.

FUN

Optional. Default NULL If provided a data transformation with FUN will be applied before the vector is returned.

force

Optional. Default FALSE If true, will force the retrieval operation when matrix contains loaded data until a certain distance.

Value

Returns a vector of length yaxis if length of xaxis is 1. Else returns a matrix of dimension xaxis length by yaxis length.

Note

Whatever the length of xaxis or yaxis may be, the coordinates under consideration will range from min(xaxis) to max(xaxis) on the rows or min(yaxis) to max(yaxis) on the columns.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_vector_val_test")

if(!file.exists(out_dir)){
    dir.create(out_dir)
}

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_get_vector_values(Brick = My_BrickContainer, chr1 = "chr2L",
chr2 = "chr2L", resolution = 100000, xaxis = c(1:10), yaxis = c(1:10))

List the matrix pairs present in the Brick store.

Description

Brick_list_matrices will list all chromosomal pair matrices from the Brick store, with their associated filename, value range, done status and sparse

Usage

Brick_list_matrices(
    Brick,
    chr1 = NA,
    chr2 = NA,
    resolution = NA,
    all_resolutions = FALSE
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

all_resolutions

Optional. Default FALSE If resolution is not defined and all_resolutions is TRUE, the resolution parameter will be ignored and the function is executed on all files listed in the Brick container

Value

Returns a data.frame object with columns chr1, chr2 corresponding to chromosome pairs, and the associated attributes. filename corresponds to the name of the file that was loaded for the pair. min and max specify the minimum and maximum values in the matrix, done is a logical value specifying if a matrix has been loaded and sparsity specifies if a matrix is defined as a sparse matrix.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "list_matrices_test")

dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Brick_list_matrices(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

List the matrix metadata columns in the Brick store.

Description

Brick_get_matrix_mcols will list the names of all matrix metadata columns.

Usage

Brick_list_matrix_mcols()

Value

Returns a vector containing the names of all matrix metadata columns

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "list_matrix_mcols_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Brick_list_matrix_mcols()

Get all available normalisations in an mcool file.

Description

Brick_list_mcool_normalisations lists the names available for accessing the various normalisation factors in an mcool file. Please note, this only lists the mapping of the columns to their respective names. It does not check for the availability of that particular column in the mcool file

Usage

Brick_list_mcool_normalisations(names.only = FALSE)

Arguments

names.only

Optional. Default FALSE A parameter specifying whether to list only the human readable names without their respective column names in the mcool file.

Value

A named vector listing all possible normalisation factors.

Examples

Brick_list_mcool_normalisations()

Get all available normalisations in an mcool file.

Description

Brick_list_mcool_resolutions lists all available resolutions in the mcool file.

Usage

Brick_list_mcool_resolutions(mcool)

Arguments

mcool

Required. A parameter specifying the name of an mcool file

Value

A named vector listing all possible resolutions in the file.

Examples

## Not run: 
require(curl)
out_dir <- file.path(tempdir(),"mcool_test_dir")
dir.create(path = out_dir)

curl_download(url = paste("https://data.4dnucleome.org/",
"files-processed/4DNFI7JNCNFB/",
"@download/4DNFI7JNCNFB.mcool", sep = ""),
destfile = file.path(out_dir,"H1-hESC-HiC-4DNFI7JNCNFB.mcool"))

mcool <- file.path(out_dir,"H1-hESC-HiC-4DNFI7JNCNFB.mcool")

Brick_list_mcool_resolutions(mcool)


## End(Not run)

List the ranges tables stored within the Brick.

Description

Brick_list_rangekeys lists the names of all ranges associated to a Brick.

Usage

Brick_list_rangekeys(Brick, resolution = NA, all_resolutions = FALSE)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

all_resolutions

Optional. Default FALSE If resolution is not defined and all_resolutions is TRUE, the resolution parameter will be ignored and the function is executed on all files listed in the Brick container

Value

A one dimensional character vector of length x specifying the names of all ranges currently present in the file.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "list_rangekeys_test")

dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Brick_list_rangekeys(Brick = My_BrickContainer, resolution = 100000)

Find out what metadata columns are associated to a ranges with a certain name

Description

Brick_list_ranges_mcols will list the metadata columns of the specified ranges if it is present in the Brick store.

Usage

Brick_list_ranges_mcols(Brick, rangekey = NULL, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

rangekey

Optional. A string specifying the name of the ranges. If not present, the metadata columns of all ranges will be listed.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

if no metadata columns are present, NA. If metadata columns are present, a data.frame object containing the name of the ranges and the associated metadata column name.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "list_ranges_mcols_test")

dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Brick_list_ranges_mcols(Brick = My_BrickContainer, rangekey = "Bintable",
resolution = 100000)

Load a NxN dimensional sub-distance cis matrix into the Brick store.

Description

Load a NxN dimensional sub-distance cis matrix into the Brick store.

Usage

Brick_load_cis_matrix_till_distance(
    Brick = NA,
    chr = NA,
    resolution = NA,
    matrix_file,
    delim = " ",
    distance,
    remove_prior = FALSE,
    num_rows = 2000,
    is_sparse = FALSE,
    sparsity_bins = 100
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr

Required. A character vector of length 1 specifying the chromosome corresponding to the rows and cols of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

matrix_file

Required. A character vector of length 1 specifying the name of the file to load as a matrix into the Brick store.

delim

Optional. Default " " The delimiter of the matrix file.

distance

Required. Default NULL. For very high-resolution matrices, read times can become extremely slow and it does not make sense to load the entire matrix into the data structure, as after a certain distance, the matrix will become extremely sparse. This ensures that only interactions upto a certain distance from the main diagonal will be loaded into the data structure.

remove_prior

Optional. Default FALSE If a matrix was loaded before, it will not be replaced. Use remove_prior to override and replace the existing matrix.

num_rows

Optional. Default 2000 Number of rows to insert per write operation in the HDF file.

is_sparse

Optional. Default FALSE If true, designates the matrix as being a sparse matrix, and computes the sparsity.index. The sparsity index measures the proportion of non-zero rows or columns at a certain distance from the diagonal (100) in cis interaction matrices.

sparsity_bins

Optional. Default 100 With regards to computing the sparsity.index, this parameter decides the number of bins to scan from the diagonal.

Value

Returns TRUE if all went well.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_load_dist_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
  bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
  experiment_name = "Vignette Test", resolution = 100000,
  remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_cis_matrix_till_distance(Brick = My_BrickContainer, 
chr = "chr2L", resolution = 100000, matrix_file = Matrix_file, 
delim = " ", distance = 30, remove_prior = TRUE)

Load a NxN dimensional matrix into the Brick store from an mcool file.

Description

Read an mcool contact matrix coming out of 4D nucleome projects into a Brick store.

Usage

Brick_load_data_from_mcool(
    Brick,
    mcool,
    resolution = NULL,
    matrix_chunk = 2000,
    cooler_read_limit = 1e+07,
    remove_prior = FALSE,
    norm_factor = "Iterative-Correction"
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

mcool

Required. Path to an mcool file.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

matrix_chunk

Optional. Default 2000. The nxn matrix square to fill per iteration in a mcool file.

cooler_read_limit

Optional. Default 10000000. cooler_read_limit sets the upper limit for the number of records per matrix chunk. If the number of records per chunk is higher than this value, the matrix_chunk value will be re-evaluated dynamically.

remove_prior

Optional. Default FALSE If a matrix was loaded before, it will not be replaced. Use remove_prior to override and replace the existing matrix.

norm_factor

Optional. Default "Iterative-Correction". The normalization factor to use for normalization from an mcool file. norm_factor currently accepts one of "Iterative-Correction", "Knight-Ruitz", "Vanilla-coverage", "Vanilla-coverage-square-root" and NULL. If NULL, the function will load only counts from the mcool file.

Value

Returns TRUE if all went well.

See Also

Create_many_Bricks_from_mcool to create matrix from an mcool file, Brick_list_mcool_resolutions to list available resolutions in an mcool file, Brick_list_mcool_normalisations to list available normalisation factors in the mcool file.

Examples

## Not run: 

require(curl)
out_dir <- file.path(tempdir(),"mcool_load_test")
dir.create(path = out_dir)
curl_download(url = paste("https://data.4dnucleome.org/",
"files-processed/4DNFI7JNCNFB/",
"@download/4DNFI7JNCNFB.mcool", sep = ""),
destfile = file.path(out_dir,"H1-hESC-HiC-4DNFI7JNCNFB.mcool"))

mcool <- file.path(out_dir,"H1-hESC-HiC-4DNFI7JNCNFB.mcool")

My_BrickContainer <- Create_many_Bricks_from_mcool(
output_directory = out_dir,
file_prefix = "Test",
mcool = mcool,
resolution = 50000,
experiment_name = "A random 4DN dataset")

Brick_load_data_from_mcool(Brick = My_BrickContainer, mcool = mcool,
resolution = 50000, matrix_chunk = 2000, remove_prior = TRUE,
norm_factor = "Iterative-Correction")


## End(Not run)

Identify compartments in the Hi-C data

Description

Brick_load_data_from_sparse loads data from a table like file, such as sparse matrices.

Usage

Brick_load_data_from_sparse(
    Brick,
    table_file,
    delim = " ",
    resolution = NULL,
    batch_size = 1e+06,
    matrix_chunk = 2000,
    col_index = c(1, 2, 3),
    remove_prior = FALSE
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

table_file

Path to the file that will be loaded

delim

Optional. Default " " The delimiter of the matrix file.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

batch_size

Optional Default 1000000 Number of rows to read with each iteration from a sparse matrix.

matrix_chunk

Optional Default 2000 The nxn matrix square to fill per iteration to a Brick object.

col_index

Optional. Default "c(1,2,3)". A character vector of length 3 containing the indexes of the required columns in the table file. the first index, corresponds to bin1, the second to bin2 and the third to the signal value.

remove_prior

Optional. Default FALSE If a matrix was loaded before, it will not be replaced. Use remove_prior to override and replace the existing matrix.

Value

A dataframe containing the chromosome genomic coordinates and the first three principal components.

Examples

## Not run: 
Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "get_vector_val_test")
if(!file.exists(out_dir)){
    dir.create(out_dir)
}

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_export_to_sparse(Brick = My_BrickContainer, 
out_file = file.path(out_dir, "example_out.txt"), 
remove_file = TRUE, sep = " ", 
resolution = 100000)

Brick_load_data_from_sparse(Brick = My_BrickContainer, 
table_file = file.path(out_dir, "example_out.txt"), 
delim = " ", resolution = 100000, col_index = c(3,4,5))
    

## End(Not run)

Load a NxM dimensional matrix into the Brick store.

Description

Load a NxM dimensional matrix into the Brick store.

Usage

Brick_load_matrix(
    Brick = NA,
    chr1 = NA,
    chr2 = NA,
    resolution = NA,
    matrix_file = NA,
    delim = " ",
    remove_prior = FALSE,
    num_rows = 2000,
    is_sparse = FALSE,
    sparsity_bins = 100
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

matrix_file

Required. A character vector of length 1 specifying the name of the file to load as a matrix into the Brick store.

delim

Optional. Default " " The delimiter of the matrix file.

remove_prior

Optional. Default FALSE If a matrix was loaded before, it will not be replaced. Use remove_prior to override and replace the existing matrix.

num_rows

Optional. Default 2000 Number of rows to read, in each chunk.

is_sparse

Optional. Default FALSE If true, designates the matrix as being a sparse matrix, and computes the sparsity.index. The sparsity index measures the proportion of non-zero rows or columns at a certain distance from the diagonal (100) in cis interaction matrices.

sparsity_bins

Optional. Default 100 With regards to computing the sparsity.index, this parameter decides the number of bins to scan from the diagonal.

Value

Returns TRUE if all went well.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_load_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Do TAD Calls with Local Score Differentiator on a Hi-C matrix

Description

Local_score_differentiator calls topologically associated domains on Hi-C matrices. Local score differentiator at the most fundamental level is a change point detector, which detects change points in the directionality index using various thresholds defined on a local directionality index distributions. The directionality index (DI) is calculated as defined by Dixon et al., 2012 Nature. Next, the difference of DI is calculated between neighbouring bins to get the change in DI distribution in each bin. When a DI value goes from a highly negative value to a highly positive one as expected to occur at domain boundaries, the ensuing DI difference distribution becomes a very flat distribution interjected by very large peaks signifying regions where such a change may take place. We use two difference vectors, one is the difference vector between a bin and its adjacent downstream bin and another is the difference between a bin and its adjacent upstream bin. Using these vectors, and the original directionality index, we define domain borders as outliers.

Usage

Brick_local_score_differentiator(
    Brick,
    chrs = NULL,
    resolution = NA,
    all_resolutions = FALSE,
    min_sum = -1,
    di_window = 200L,
    lookup_window = 200L,
    tukeys_constant = 1.5,
    strict = TRUE,
    fill_gaps = TRUE,
    ignore_sparse = TRUE,
    sparsity_threshold = 0.8,
    remove_empty = NULL,
    chunk_size = 500,
    force_retrieve = TRUE
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chrs

Optional. Default NULL If present, only TAD calls for elements in chrs will be done.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

all_resolutions

Optional. Default FALSE If resolution is not defined and all_resolutions is TRUE, the resolution parameter will be ignored and the function is executed on all files listed in the Brick container

min_sum

Optional. Default -1 Process bins in the matrix with row.sums greater than min_sum.

di_window

Optional. Default 200 Use di_window to define the directionality index.

lookup_window

Optional. Default 200 Use lookup_window local window to call borders. At smaller di_window values we recommend setting this to 2*di_window

tukeys_constant

Optional. Default 1.5 tukeys_constant*IQR (inter-quartile range) defines the lower and upper fence values.

strict

Optional. Default TRUE If TRUE, strict creates an additional filter on the directionality index requiring it to be either greater than or less than 0 on the right tail or left tail respectively.

fill_gaps

Optional. Default TRUE If TRUE, this will affect the TAD stiching process. All Border starts are stiched to the next downstream border ends. Therefore, at times border ends remain unassociated to a border start. These border ends are stiched to the adjacent downstream bin from their upstream border end when fill_gaps is true.

TADs inferred in this way will be annotated with two metadata columns in the GRanges object. gap.fill will hold a value of 1 and level will hold a value 1. TADs which were not filled in will hold a gap.fill value of 0 and a level value of 2.

ignore_sparse

Optional. Default TRUE If TRUE, a matrix which has been defined as sparse during the matrix loading process will be treated as a dense matrix. The sparsity_threshold filter will not be applied. Please note, that if a matrix is defined as sparse and fill_gaps is TRUE, fill_gaps will be turned off.

sparsity_threshold

Optional. Default 0.8 Sparsity threshold relates to the sparsity index, which is computed as the number of non-zero bins at a certain distance from the diagonal. If a matrix is sparse and ignore_sparse is FALSE, bins which have a sparsity index value below this threshold will be discarded from DI computation.

remove_empty

Not implemented. After implementation, this will ensure that the presence of centromeric regions is accounted for.

chunk_size

Optional. Default 500 The size of the matrix chunk to process. This value should be larger than 2x di_window.

force_retrieve

Optional. Default TRUE If TRUE, this will force the retrieval of a matrix chunk even when the retrieval includes interaction points which were not loaded into a Brick store (larger chunks). Please note, that this does not mean that DI can be computed at distances larger than max distance. Rather, this is meant to aid faster computation.

Details

To define an outlier, fences are first defined. The fences are defined using tukeys_constant x inter-quartile range of the directionality index. The upper fence used for detecting domain starts is the 75th quartile + (IQR x tukeys_constant), while the lower fence is the 25th quartile - (IQR x tukeys_constant). For domain starts the DI difference must be greater than or equal to the upper fence, it must be greater than the DI and the DI must be a finite real value. If strict is TRUE, DI will also be required to be greater than 0. Similarly, for domain ends the DI difference must be lower than or equal to the lower fence, it must be lower than the DI and the DI must be a finite real value. If strict is TRUE, DI will also be required to be lower than 0.

After defining outliers, each domain start will be associated to its nearest downstream domain end. If fill_gaps is defined as TRUE and there are domain ends which remain unassociated to a domain start, These domain ends will be associated to the bin adjacent to their nearest upstream domain end. This associations will be marked by metadata columns, gap.fill= 1 and level = 1.

This function provides the capability to call very accurante TAD definitions in a very fast way.

Value

A ranges object containing domain definitions. The starts and ends of the ranges coincide with the starts and ends of their contained bins from the bintable.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "lsd_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr3R.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr3R", 
chr2 = "chr3R", matrix_file = Matrix_file, delim = " ",
remove_prior = TRUE, resolution = 100000)

TAD_ranges <- Brick_local_score_differentiator(Brick = My_BrickContainer, 
chrs = "chr3R", resolution = 100000, di_window = 10, lookup_window = 30, 
strict = TRUE, fill_gaps = TRUE, chunk_size = 500)

Creates a ranges object from provided vectors.

Description

Brick_make_ranges creates a GRanges object from the provided arguments

Usage

Brick_make_ranges(chrom, start, end, strand = NA, names = NA)

Arguments

chrom

Required. A 1 dimensional character vector of size N specifying the chromosomes in the ranges.

start

Required. A 1 dimensional numeric vector of size N specifying the start positions in the ranges.

end

Required. A 1 dimensional numeric vector of size N specifying the end positions in the ranges. Must be less than Start.

strand

Optional. A 1 dimensional character vector of size N specifying the strand of the ranges. If not provided, this will be set to the default *.

names

Optional. A 1 dimensional character vector of size N specifying the names of the ranges. If not provided, this will be set to the default chr:start:end.

Value

A GenomicRanges object with the previous sort order being preserved

Examples

Chrom <- c("chrS","chrS","chrS","chrS","chrS")
Start <- c(10000,20000,40000,50000,60000)
End <- c(10001,20001,40001,50001,60001)
Test_ranges <- Brick_make_ranges(chrom = Chrom, start = Start, end = End)

Return the dimensions of a matrix

Description

Return the dimensions of a matrix

Usage

Brick_matrix_dimensions(Brick, chr1, chr2, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns the dimensions of a Hi-C matrix for any given chromosome pair.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_dimension_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_matrix_dimensions(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

Check if a chromosome pair exists.

Description

Matrices are created when the bintable is loaded and the chromosome names are provided. If a user is in doubt regarding whether a matrix is present or not it is useful to check this function. If the Bintable did not contain a particular chromosome, any matrices for that chromosome would not be present in the file

Usage

Brick_matrix_exists(Brick, chr1, chr2, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns a logical vector of length 1, specifying if the matrix exists or not.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_exists_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_matrix_exists(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

Return the filename of the loaded matrix

Description

Return the filename of the loaded matrix

Usage

Brick_matrix_filename(Brick, chr1, chr2, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns a character vector of length 1 specifying the filename of the currently loaded matrix.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_filename_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_matrix_filename(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

Check if a matrix has been loaded for a chromosome pair.

Description

Check if a matrix has been loaded for a chromosome pair.

Usage

Brick_matrix_isdone(Brick, chr1, chr2, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns a logical vector of length 1, specifying if a matrix has been loaded or not.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_isdone_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_matrix_isdone(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

Check if a matrix for a chromosome pair is sparse.

Description

Check if a matrix for a chromosome pair is sparse.

Usage

Brick_matrix_issparse(Brick, chr1, chr2, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns a logical vector of length 1, specifying if a matrix was loaded as a sparse matrix.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_issparse_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_matrix_issparse(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

Get the maximum loaded distance from the diagonal of any matrix.

Description

If values beyond a certain distance were not loaded in the matrix, this distance parameter is useful. This package by default will check this param to make sure that it is not returning non-existent data.

Usage

Brick_matrix_maxdist(Brick, chr1, chr2, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Details

Brick_matrix_maxdist will return this parameter.

Value

Returns an integer vector of length 1, specifying the maximum distance loaded for that matrix

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_maxdist_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_matrix_maxdist(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

Return the value range of the matrix

Description

Return the value range of the matrix

Usage

Brick_matrix_minmax(Brick, chr1, chr2, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns a numeric vector of length 2, specifying the minimum and maximum finite real values in the matrix.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "matrix_minmax_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr2L.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", matrix_file = Matrix_file, delim = " ", 
remove_prior = TRUE, resolution = 100000)

Brick_matrix_minmax(Brick = My_BrickContainer, chr1 = "chr2L", 
chr2 = "chr2L", resolution = 100000)

Check if a normalisation exists in an mcool file.

Description

Brick_mcool_normalisation_exists checks if a particular normalisation exists in an mcool file.

Usage

Brick_mcool_normalisation_exists(mcool, norm_factor = NULL, resolution = NULL)

Arguments

mcool

Required. Path to an mcool file.

norm_factor

Required. The normalization factor to use for normalization from an mcool file. norm_factor currently accepts one of "Iterative-Correction", "Knight-Ruitz", "Vanilla-coverage", "Vanilla-coverage-square-root".

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

A boolean vector of length 1

Examples

## Not run: 

require(curl)
out_dir <- file.path(tempdir(), "mcool_test_dir")
dir.create(path = out_dir)
curl_download(url = paste("https://data.4dnucleome.org/",
"files-processed/4DNFI7JNCNFB/",
"@download/4DNFI7JNCNFB.mcool", sep = ""),
destfile = file.path(out_dir, "H1-hESC-HiC-4DNFI7JNCNFB.mcool"))

mcool <- file.path(out_dir, "H1-hESC-HiC-4DNFI7JNCNFB.mcool")
Brick_mcool_normalisation_exists(mcool = mcool,
norm_factor = "Iterative-Correction",
resolution = 50000)


## End(Not run)

Check to see if the Brick contains a ranges with a certain name.

Description

Brick_rangekey_exists checks for the presence of a particular ranges with a certain name.

Usage

Brick_rangekey_exists(
    Brick,
    rangekey,
    resolution = NA,
    all_resolutions = FALSE
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

rangekey

Required. A string specifying the name of the ranges to check for.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

all_resolutions

Optional. Default FALSE If resolution is not defined and all_resolutions is TRUE, the resolution parameter will be ignored and the function is executed on all files listed in the Brick container

Value

A logical vector of length 1 with either TRUE or FALSE values.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "list_rangekeys_exists_test")

dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)
Brick_rangekey_exists(Brick = My_BrickContainer, rangekey = "Bintable",
resolution = 100000)

Provides the overlapping position (within) from the bintable.

Description

Brick_return_region_position takes as input a human-readable coordinate format of the form chr:start:end and outputs the overlapping bintable positions. This module does a "within" operation. So only bins which overlap completely with the region will be returned. This is not an iterable module, so the user has to make iterative calls to the module itself.

Usage

Brick_return_region_position(Brick, region, resolution = NA)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Brick.

region

Required. A character vector of length 1 specifying the region to overlap. It must take the form chr:start:end.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

Returns a 1 dimensional vector containing the position of the overlapping regions in the bintable associated the Brick store.

Design choice

This may seem to be a poor design choice at first glance, but I do not think this to be the case. By not being iterable, this function circumvents the problem of how to structure the data for the user. If one more element was accepted, the return object would have become a list, which increases the data structure complexity significantly for users who are just starting out with R. Therefore this problem is left for the users themselves to deal with.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"),
package = "HiCBricks")

out_dir <- file.path(tempdir(), "region_position_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Coordinate <- "chr2L:1:1000000"

Test_Run <- Brick_return_region_position(Brick = My_BrickContainer,
region = Coordinate, resolution = 100000)

Create the entire HDF5 structure and load the bintable

Description

Brick_vizart_plot_heatmap creates various heatmaps and plots TADs.

Usage

Brick_vizart_plot_heatmap(
    File,
    Bricks,
    resolution,
    x_coords,
    y_coords,
    FUN = NULL,
    value_cap = NULL,
    distance = NULL,
    rotate = FALSE,
    x_axis = TRUE,
    x_axis_title = NULL,
    y_axis = TRUE,
    y_axis_title = NULL,
    title = NULL,
    legend_title = NULL,
    return_object = FALSE,
    x_axis_num_breaks = 5,
    y_axis_num_breaks = 5,
    palette,
    col_direction = 1,
    extrapolate_on = NULL,
    x_axis_text_size = 10,
    y_axis_text_size = 10,
    text_size = 10,
    legend_title_text_size = 8,
    legend_text_size = 8,
    title_size = 10,
    tad_ranges = NULL,
    group_col = NULL,
    tad_colour_col = NULL,
    colours = NULL,
    colours_names = NULL,
    cut_corners = FALSE,
    highlight_points = NULL,
    width = 10,
    height = 6,
    line_width = 0.5,
    units = "cm",
    legend_key_width = unit(3, "cm"),
    legend_key_height = unit(0.5, "cm")
)

Arguments

File

Required A character vector containing the output filename to write.

Bricks

Required A list of length 1 (in case of one sample heatmaps) or 2 (in case of two sample heatmaps) specifying the BrickContainers from where to fetch the data.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

x_coords

Required A character vector of length 1 specifying the coordinates from where to fetch the data.

y_coords

Required A character vector of length 1 specifying the coordinates from where to fetch the data.

FUN

Optional. Default NULL If any sort of transformations should be applied to the data before plotting. Such as, log10 or log2 transformations.

value_cap

Optional. Default NULL If present, values beyond a certain quantile will be capped to that quantile. In Hi-C this helps to emphasize structural information. Please note, if this parameter is present the greatest value will have a greater than sign append- -ed to them.

distance

Optional. Default NULL If present, values beyond this distance will be filtered out. Please note, that if a Brick store matrix was loaded until a certain distance, this parameter will result in an error if it is greater than the loaded distance.

rotate

Optional. Default FALSE If TRUE, will rotate the heatmap by 90 degrees.

x_axis

Optional. Default TRUE If FALSE, the x-axis will be removed (ticks, x-axis labels and title).

x_axis_title

Optional. Default NULL If present, will be the x-axis title. Else defaults to the provided x_coords

y_axis

Optional. Default TRUE If FALSE, the y-axis will be removed (ticks, y-axis labels and title).

y_axis_title

Optional. Default NULL If present, will be the y-axis title. Else defaults to the provided y_coords

title

Optional. Default NULL If present, will be the plot title. Else defaults to the provided x_coords vs y_coords

legend_title

Optional. Default NULL If present will be the title of the legend. Else defaults to "Signal".

return_object

Optional. Default FALSE If present the ggplot object will be returned

x_axis_num_breaks

Optional. Default 5 Number of ticks on the x axis

y_axis_num_breaks

Optional. Default 5 Number of ticks on the y axis

palette

Required. Default NULL One of the RColorbrewer or viridis colour palettes

col_direction

Optional. Default 1 If -1, the colour scale will be reversed.

extrapolate_on

Optional. Default NULL If present, colours from the palette will be extrapolated between lightest and darkest to create the gradient. This value cannot be more than 100.

x_axis_text_size

Optional. Default 10 x-axis text size

y_axis_text_size

Optional. Default 10 y-axis text size

text_size

Optional. Default 10 text size of text elements in the plot.

legend_title_text_size

Optional. Default 8 text size of the legend title

legend_text_size

Optional. Default 8 text size of the legend text

title_size

Optional. Default 10 text size of the title

tad_ranges

Optional. Default NULL A GenomicRanges object specifying the start and end coordinates of TADs to be plotted on the heatmap.

group_col

Optional. Default NULL Name of the column which will be used to categorize TADs as belonging to either the first or the second Brick stores. This must be a numeric value ranging from 1 to 2. If NULL, TADs will be plotted on both Hi-C maps.

tad_colour_col

Optional. Default NULL tad_colour_col takes as value the column name in the tad_ranges object corresponding to the column which should be used to define different TAD categories.

colours

Optional. Default NULL If tad_ranges is present, colours expects a hexcode value of length 1. But, if tad_colour_col is specified, it expects colours of the same length as unique tad_ranges$tad_colour_col.

colours_names

Optional. Default NULL If present, will be assigned to colours. Else, will inherit unique tad_colour_col. If tad_colour_col is also absent, will revert to a placehold column name.

cut_corners

Optional. Default FALSE if cut_corners is TRUE, TAD borders will not be truncated, and they will span until the end of visible heatmap.

highlight_points

Optional. Not yet implemented.

width

Optional. Default 10cm Width of the output file units.

height

Optional. Default 6cm Height of the output file in units.

line_width

Optional. Default 0.5 When plotting TADs set the width of the plotted lines

units

Optional. Default cm Defines the units of the output file width and height.

legend_key_width

Optional. Default unit(3,"cm") Defines the legend key width.

legend_key_height

Optional. Default unit(0.5,"cm") Defines the legend key height.

Details

This function provides the capability to plot various types of heatmaps from Hi-C data.

  • One sample heatmap.

  • Two sample heatmap (One sample on upper and other on lower).

  • All of the above with 90 degree rotation.

  • All of the above but with signal capped at a certain value.

  • All of the above but filtered by distance.

  • All of the above with TADs/TAD borders plotted on top.

Value

If return_object is set to TRUE, the constructed ggplot2 object will be returned. Else TRUE.

Examples

FailSafe_log10 <- function(x){
     x[is.na(x) | is.nan(x) | is.infinite(x)] <- 0
     return(log10(x+1))
}

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")

out_dir <- file.path(tempdir(), "vizart_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test",
    experiment_name = "Vignette Test", resolution = 100000,
    remove_existing = TRUE)

Matrix_file <- system.file(file.path("extdata", 
"Sexton2012_yaffetanay_CisTrans_100000_corrected_chr3R.txt.gz"), 
package = "HiCBricks")

Brick_load_matrix(Brick = My_BrickContainer, chr1 = "chr3R", 
chr2 = "chr3R", matrix_file = Matrix_file, delim = " ",
remove_prior = TRUE, resolution = 100000)

Brick_vizart_plot_heatmap(File = "./chr3R-1-10000000.pdf", 
Bricks = list(My_BrickContainer), resolution = 100000, 
x_coords = "chr3R:1:10000000", palette = "Reds", 
y_coords = "chr3R:1:10000000", FUN = FailSafe_log10, 
value_cap = 0.99, width = 10, height = 11, legend_key_width = unit(3,"mm"),
legend_key_height = unit(0.3,"cm"))

Change the location of HDF files in the BrickContainer object

Description

BrickContainer_change_experiment_name changes the location of name of the experiment

Usage

BrickContainer_change_experiment_name(Brick = NULL, experiment_name = NULL)

Arguments

Brick

Required. A string specifying the path to the BrickContainer created using Create_many_Bricks or Load_BrickContainer

experiment_name

Required. Default NULL A string specifying the new experiment name

Value

An object of class BrickContainer where the experiment_name has been changed

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")

out_dir <- file.path(tempdir(), "BrickContainer_expt_name_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
    experiment_name = "Vignette Test", resolution = 100000, 
    remove_existing = TRUE)

BrickContainer_change_experiment_name(Brick = My_BrickContainer, 
experiment_name = "I change my mind")

Change the location of HDF files in the BrickContainer object

Description

BrickContainer_change_output_directory changes the location of associated HDF files

Usage

BrickContainer_change_output_directory(Brick = NULL, output_directory = NULL)

Arguments

Brick

Required. A string specifying the path to the Brick store created with CreateBrick.

output_directory

Required. Default NULL A string specifying new location of the output_directory. Please note, that the location of the HDF files will not be changed.

Value

An object of class BrickContainer where the output_directory has been changed

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")

out_dir <- file.path(tempdir(), "BrickContainer_out_dir_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
    experiment_name = "Vignette Test", resolution = 100000, 
    remove_existing = TRUE)

BrickContainer_change_output_directory(Brick = My_BrickContainer, 
output_directory = tempdir())

Get the path to HDF files present in the Brick container.

Description

BrickContainer_get_path_to_file fetches the list of HDF file paths associated to a particular BrickContainer

Usage

BrickContainer_get_path_to_file(
    Brick = NULL,
    chr1 = NA,
    chr2 = NA,
    type = NA,
    resolution = NA
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Bricks.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

type

A value from one of cis, trans specifying the type of files to list cis will list intra-choromosomal file paths and trans will list inter-chromosomal file paths.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

A vector containing filepaths

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")

out_dir <- file.path(tempdir(), "BrickContainer_list_filepath_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
  bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
  experiment_name = "Vignette Test", resolution = 100000, 
  remove_existing = TRUE)

BrickContainer_get_path_to_file(Brick = My_BrickContainer, chr1 = "chr2L",
chr2 = "chr2L", resolution = 100000)

Return the descriptive name of the BrickContainer

Description

BrickContainer_list_chromosomes returns the chromosomes available in the BrickContainer

Usage

BrickContainer_list_chromosomes(Brick = NULL, lengths = FALSE)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Bricks.

lengths

Default FALSE If TRUE, will also return the chromosomal lengths

Value

If lengths is FALSE, only the chromosome names are returned. If lengths is TRUE, a data.frame containing the chromosome names and their lengths is provided.

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")

out_dir <- file.path(tempdir(), "BrickContainer_list_chromosome_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
    experiment_name = "Vignette Test", resolution = 100000, 
    remove_existing = TRUE)

BrickContainer_list_chromosomes(My_BrickContainer)

Return the descriptive name of the BrickContainer

Description

BrickContainer_list_experiment_name returns the descriptive name of a BrickContainer

Usage

BrickContainer_list_experiment_name(Brick = NULL)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Bricks.

Value

A character string specifying the descriptive name of the BrickContainer

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")

out_dir <- file.path(tempdir(), "BrickContainer_list_expt_name_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
    experiment_name = "Vignette Test", resolution = 100000, 
    remove_existing = TRUE)

BrickContainer_list_experiment_name(My_BrickContainer)

Get the list of HDF files present in the Brick container.

Description

BrickContainer_list_files fetches the list of HDF files associated to a particular BrickContainer

Usage

BrickContainer_list_files(
    Brick = NULL,
    chr1 = NA,
    chr2 = NA,
    type = NA,
    resolution = NA
)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Bricks.

chr1

Required. A character vector of length 1 specifying the chromosome corresponding to the rows of the matrix

chr2

Required. A character vector of length 1 specifying the chromosome corresponding to the columns of the matrix

type

A value from one of cis, trans specifying the type of files to list cis will list intra-choromosomal file paths and trans will list inter-chromosomal file paths.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

Value

A 5 column tibble containing chromosome pairs, Hi-C resolution, the type of Hi-C matrix and the path to a particular Hi-C matrix file.

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")
out_dir <- file.path(tempdir(), "BrickContainer_list_file_test")
dir.create(out_dir)
My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
   bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
   experiment_name = "Vignette Test", resolution = 100000, 
   remove_existing = TRUE)

BrickContainer_list_files(Brick = My_BrickContainer, chr1 = "chr2L",
chr2 = NA)

Return the output directory of the BrickContainer

Description

BrickContainer_list_output_directory returns the location of the associated HDF files

Usage

BrickContainer_list_output_directory(Brick = NULL)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Bricks.

Value

A character string specifying the descriptive name of the BrickContainer

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")

out_dir <- file.path(tempdir(), "BrickContainer_list_out_dir_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
    experiment_name = "Vignette Test", resolution = 100000, 
    remove_existing = TRUE)

BrickContainer_list_output_directory(My_BrickContainer)

Return the descriptive name of the BrickContainer

Description

BrickContainer_list_resolutions returns the resolutions available in the BrickContainer

Usage

BrickContainer_list_resolutions(Brick = NULL)

Arguments

Brick

Required. A string specifying the path to the Brick store created with Create_many_Bricks.

Value

A character string specifying the descriptive name of the BrickContainer

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")

out_dir <- file.path(tempdir(), "BrickContainer_list_resolution_test")
dir.create(out_dir)

My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
    experiment_name = "Vignette Test", resolution = 100000, 
    remove_existing = TRUE)

BrickContainer_list_resolutions(My_BrickContainer)

Create the entire HDF5 structure and load the bintable

Description

Create_many_Bricks creates the HDF file and returns a BrickContainer

Usage

Create_many_Bricks(
    BinTable,
    bin_delim = "\t",
    col_index = c(1, 2, 3),
    impose_discontinuity = TRUE,
    hdf_chunksize = NULL,
    output_directory = NA,
    file_prefix = NA,
    remove_existing = FALSE,
    link_existing = FALSE,
    experiment_name = NA,
    resolution = NA,
    type = c("both", "cis", "trans")
)

Arguments

BinTable

Required A string containing the path to the file to load as the binning table for the Hi-C experiment. The number of entries per chromosome defines the dimension of the associated Hi-C data matrices. For example, if chr1 contains 250 entries in the binning table, the cis Hi-C data matrix for chr1 will be expected to contain 250 rows and 250 cols. Similary, if the same binning table contained 150 entries for chr2, the trans Hi-C matrices for chr1,chr2 will be a matrix with dimension 250 rows and 150 cols.

There are no constraints on the bintable format. As long as the table is in a delimited format, the corresponding table columns can be outlined with the associated parameters. The columns of importance are chr, start and end.

It is recommended to always use binning tables where the end and start of consecutive ranges are not the same. If they are the same, this may lead to unexpected behaviour when using the GenomicRanges "any" overlap function.

bin_delim

Optional. Defaults to tabs. A character vector of length 1 specifying the delimiter used in the file containing the binning table.

col_index

Optional. Default "c(1,2,3)". A character vector of length 3 containing the indexes of the required columns in the binning table. the first index, corresponds to the chr column, the second to the start column and the third to the end column.

impose_discontinuity

Optional. Default TRUE. If TRUE, this parameter ensures a check to make sure that required the end and start coordinates of consecutive entries are not the same per chromosome.

hdf_chunksize

Optional. A numeric vector of length 1. If provided, the HDF dataset will use this value as the chunk size, for all matrices. By default, the ChunkSize is set to matrix dimensions/100.

output_directory

Required A string specifying the location where the HDF files will be created.

file_prefix

Required A string specifying the prefix that is concatenated to the hdf files stored in the output_directory.

remove_existing

Optional. Default FALSE. If TRUE, will remove the HDF file with the same name and create a new one. By default, it will not replace existing files.

link_existing

Optional. Default FALSE. If TRUE, will re-add the HDF file with the same name. By default, this parameter is set to FALSE.

experiment_name

Optional. If provided, this will be the experiment name for the BrickContainer.

resolution

required. A value of length 1 of class character or numeric specifying the resolution of the Hi-C data loaded.

type

optional. Default any A value from one of any, cis, trans specifying the type of matrices to load. Any will load both cis (intra-choromosomal, e.g. chr1 vs chr1) and trans ( inter-chromosomal, e.g. chr1 vs chr2) Hi-C matrices. Whereas cis and trans will load either cis or trans Hi-C matrices.

Details

This function creates the complete HDF data structure, loads the binning table associated to the Hi-C experiment, creates a 2D matrix layout for all specified chromosome pairs and creates a json file for the project. At the end, this function will return a S4 object of class BrickContainer. Please note, the binning table must be a discontinuous one (first range end != secode range start), as ranges overlaps using the "any" form will routinely identify adjacent ranges with the same end and start to be in the overlap. Therefore, this criteria is enforced as default behaviour.

The structure of the HDF file is as follows: The structure contains three major groups which are then hierarchically nested with other groups to finally lead to the corresponding datasets.

  • Base.matrices - group For storing Hi-C matrices

    • chromosome - group

    • chromosome - group

      • attributes - attribute

        • Filename - Name of the file

        • Min - min value of Hi-C matrix

        • Max - max value of Hi-C matrix

        • sparsity - specifies if this is a sparse matrix

        • distance - max distance of data from main diagonal

        • Done - specifies if a matrix has been loaded

      • matrix - dataset - contains the matrix

      • chr1_bin_coverage - dataset - proportion of row cells with values greater than 0

      • chr1_row_sums - dataset - total sum of all values in a row

      • chr2_col_sums - dataset - total sum of all values in a col

      • chr2_bin_coverage - dataset - proportion of col cells with values greater than 0

      • sparsity - dataset - proportion of non-zero cells near the diagonal

  • Base.ranges - group, Ranges tables for quick and easy access. Additional ranges tables are added here under separate group names.

    • Bintable - group - The main binning table associated to a Brick.

      • ranges - dataset - Contains the three main columns chr, start and end.

      • offsets - dataset - first occurence of any given chromosome in the ranges dataset.

      • lengths - dataset - Number of occurences of that chromosome

      • chr.names - dataset - What chromosomes are present in the given ranges table.

  • Base.metadata - group, A place to store metadata info

    • chromosomes - dataset - Metadata information specifying the chromosomes present in this particular Brick file.

    • other metadata tables.

Keep in mind that if the end coordinates and start coordinates of adjacent ranges are not separated by at least a value of 1, then impose.discontinuity = TRUE will likely cause an error to occur. This may seem obnoxious, but GenomicRanges by default will consider an overlap of 1 bp as an overlap. Therefore, to be certain that ranges which should not be, are not being targeted during retrieval operations, a check is initiated to make sure that adjacent ends and starts are not overlapping. To load continuous ranges, use impose.discontinuity = FALSE.

Also note, that col.index determines which columns to use for chr, start and end. Therefore, the original binning table may have 10 or 20 columns, but it only requires the first three in order of chr, start and end.

Value

This function will generate the target Brick file. Upon completion, the function will return an object of class BrickContainer.

Examples

Bintable.path <- system.file(file.path("extdata", "Bintable_100kb.bins"), 
package = "HiCBricks")
out_dir <- file.path(tempdir(), "Creator_test")
dir.create(out_dir)
My_BrickContainer <- Create_many_Bricks(BinTable = Bintable.path, 
    bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
    experiment_name = "Vignette Test", resolution = 100000, 
    remove_existing = TRUE)

Create the entire HDF5 structure and load the bintable from a mcool file

Description

Create_many_Bricks_from_mcool is a wrapper on Create_many_Bricks which creates the Brick data structure from an mcool file.

Usage

Create_many_Bricks_from_mcool(
    output_directory = NA,
    file_prefix = NA,
    mcool = NULL,
    resolution = NULL,
    experiment_name = NA,
    remove_existing = FALSE
)

Arguments

output_directory

Required A string specifying the location where the HDF files will be created.

file_prefix

Required A string specifying the prefix that is concatenated to the hdf files stored in the output_directory.

mcool

Required. Path to an mcool file.

resolution

Optional. Default NA When an object of class BrickContainer is provided, resolution defines the resolution on which the function is executed

experiment_name

Optional. If provided, this will be the experiment name for the BrickContainer.

remove_existing

Optional. Default FALSE. If TRUE, will remove the HDF file with the same name and create a new one. By default, it will not replace existing files.

Details

mcool are a standard 4D nucleome data structure for Hi-C data. Read more about the 4D nucleome project here.

Value

This function will generate the target Brick file. Upon completion, the function will provide the path to the created/tracked HDF file.

See Also

Brick_load_data_from_mcool to load data from the mcool to a Brick store.

Examples

## Not run: 
require(curl)
out_dir <- file.path(tempdir(),"mcool_test_dir")
dir.create(path = out_dir)
curl_download(url = paste("https://data.4dnucleome.org/",
"files-processed/4DNFI7JNCNFB/",
"@download/4DNFI7JNCNFB.mcool", sep = ""),
destfile = file.path(out_dir,"H1-hESC-HiC-4DNFI7JNCNFB.mcool"))

mcool <- file.path(out_dir,"H1-hESC-HiC-4DNFI7JNCNFB.mcool")

Create_many_Bricks_from_mcool(output_directory = out_dir,
file_prefix = "Test",
mcool = mcool,
resolution = 50000,
experiment_name = "A random 4DN dataset")


## End(Not run)

A package for storing, accessing and plotting Hi-C data

Description

HiCBricks is a package allowing users to flexibly import and work with Hi-C data

Details

Using HiCBricks users are able to import Hi-C matrices stored in various formats into an HDF structure. This is the Brick file. You can then access the Hi-C data using accessor functions. Since the data is stored in an HDF file, if you have the Brick (HDF) file, you can keep on accessing the same file an infinite number of times.

Users can also associate different ranges objects with the HDF file.

The HDF file must have the same structure as followed by HiCBricks

Users can then move forward and create analysis pipelines and statistical methods based on HiCBricks HDF files without worrying about the underlying data structure. To showcase this, Local score differentiator (LSD) our novel TAD calling procedure comes packaged with HiCBricks.

You are also able to plot Hi-C data using HiCBricks functions. There are a few types. You can create,

  • a square heatmap

  • a rotated heatmap

  • two group square/rotated heatmaps

  • both heatmaps until a certain distance

  • plot TADs on both heatmaps

Brick creation

Matrix loaders

Matrix Accessors

All of the functions above can be subsetted and contain further value transformations.

Ranges operators

  • Brick_get_bintable - All HiCBricks Brick files contain a binning table containing the coordinate information of the matrix. This fetches the associated binning table.

  • Brick_add_ranges - Add a ranges object to the Brick file.

  • Brick_get_ranges - Get a ranges object associated to a Brick file.

  • Brick_fetch_range_index - Provided a set of coordinate vectors, get the corresponding rows/cols overlapping with those coordinates.

  • Brick_make_ranges - Create a granges object from provided vectors.

  • Brick_return_region_position - Get the row/col number corresponding to coordinates spelled out in human readable format.

Other functions

Utility functions

mcool utility functions


Create a BrickContainer object from a JSON file

Description

load_BrickContainer creates a BrickContainer object from a JSON file

Usage

load_BrickContainer(config_file = NULL, project_dir = NULL)

Arguments

config_file

Default NULL A character string of length 1 specifying the path to the path to the configuration json created using Create_many_bricks

project_dir

Default NULL A character string of length 1 specifying the path to the path to the configuration json created using Create_many_bricks

Value

An object of class BrickContainer

Examples

Bintable.path <- system.file("extdata",
"Bintable_100kb.bins", package = "HiCBricks")
out_dir <- file.path(tempdir(), "BrickContainer_load_test")
dir.create(out_dir)
Create_many_Bricks(BinTable = Bintable.path, 
  bin_delim = " ", output_directory = out_dir, file_prefix = "Test", 
  experiment_name = "Vignette Test", resolution = 100000, 
  remove_existing = TRUE)
My_BrickContainer <- load_BrickContainer(project_dir = out_dir)