Create the spatial distance matrix for given 3D coordinates.

boundaryScore calculate the boundary score for a distance matrix. Please note that, this boundary score is the reverse of insulation score because we are using the distance matrix but not the interaction matrix.

boundaryScoreTAD assign the TAD boundaries via boundary score.

hierarchicalClusteringTAD assign the TAD boundaries via hierarchical clustering.

compartment calculate the compartment by principal component analysis.

spatialDistanceHeatmap will use base R to plot the spatial distance matrix.

spatialDistanceMatrix(xyz, output = "matrix", fill_NA = FALSE, ...)

boundaryScore(spatialDistances, window = 5, background = 10, ...)

boundaryScoreTAD(
  spatialDistances,
  bin_size,
  window = 5,
  Z_cutoff = 2.3,
  norm = FALSE,
  boundaryScores,
  ...
)

hierarchicalClusteringTAD(spatialDistances, bin_size, window = 5, k, ...)

compartment(xyz.gr, genome, minWidth = 1)

spatialDistanceHeatmap(
  spatialDistances,
  components = c("compartment", "boundaryScoreTAD", "hierarchicalClusteringTAD"),
  col = hcl.colors(n = 12, "OrRd"),
  at = seq(0, 1, length.out = 2),
  label_unit = "M",
  window = 5,
  background = 10,
  d_cutoff = Inf,
  Z_cutoff = 2.3,
  norm = FALSE,
  Gaussian_blur = FALSE,
  useRaster = FALSE,
  ...
)

Arguments

xyz

A GRanges object with x, y, z coordinates

output

"matrix" or "dist".

fill_NA

Fill the missing value or not.

...

Parameters could be used by downstream function.

spatialDistances

The output of spatialDistanceMatrix or the input of spatialDistanceMatrix.

window

The window size for boundary score.

background

The background window size for local background.

bin_size

The bin size.

Z_cutoff

The Z_cutoff value for boundary.

norm

Normalize the boundary score or not.

boundaryScores

The output of boundaryScore.

k

The cluster number. The final TAD numbers will be no greater than this number.

xyz.gr

A GRanges object with x,y,z coordinates.

genome

A BSgenome object

minWidth

The minimal width of input region.

components

The components to plot.

col

a list of colors such as that generated by hcl.colors, gray.colors or similar functions.

at

The label position of X, and Y axis.

label_unit

unit for labels. 'M', 1e6; 'K', 1e3, 'G', 1e9.

d_cutoff

The maximal cutoff value of distance matrix.

Gaussian_blur

Do Gaussian blur or not.

useRaster

logical; if TRUE a bitmap raster is used to plot the image instead of polygons.

Value

A matrix of Euclidean distance with fixed bins.

boundaryScore return a data frame with the boundary score and the Z scores.

boundaryScoreTAD return a list of the index or the positions of coordinates.

hierarchicalClusteringTAD return a list of the index or the positions of coordinates.

compartment return a GRanges object with A,B annotations.

Examples

xyz.gr <- readRDS(system.file('extdata', '4DNFI1UEG1HD.chr21.FLAMINGO.res.rds',
 package='geomeTriD'))
bin_size <- 5000 #width(xyz.gr)[1]
sdm <- spatialDistanceMatrix(xyz.gr)
spatialDistanceHeatmap(sdm)

head(boundaryScoreTAD(sdm, bin_size=bin_size))
#>   first second    coor1    coor2
#> 1     1     24 31370001 31490000
#> 2     1     34 31370001 31540000
#> 3     1     43 31370001 31585000
#> 4     6     24 31395001 31490000
#> 5     6     34 31395001 31540000
#> 6     6     43 31395001 31585000
head(hierarchicalClusteringTAD(sdm, bin_size=bin_size))
#>          first second    coor1    coor2
#>              1     49 31370001 31615000
#> 31617500    50     84 31615001 31790000
#> 31792500    85    126 31790001 32000000
#> 32002500   127    181 32000001 32275000
#> 32277500   182    205 32275001 32395000
#> 32397500   206    247 32395001 32605000
library(BSgenome.Hsapiens.UCSC.hg19)
#> Loading required package: BSgenome
#> Loading required package: Biostrings
#> Loading required package: XVector
#> 
#> Attaching package: 'Biostrings'
#> The following object is masked from 'package:base':
#> 
#>     strsplit
#> Loading required package: BiocIO
#> Loading required package: rtracklayer
compartment(xyz.gr, genome=BSgenome.Hsapiens.UCSC.hg19)
#> GRanges object with 12 ranges and 4 metadata columns:
#>     seqnames            ranges strand | compartment       label        type
#>        <Rle>         <IRanges>  <Rle> | <character> <character> <character>
#>   B    chr21 31370001-32000000      * |           B           B compartment
#>   A    chr21 32000001-32355000      * |           A           A compartment
#>   B    chr21 32355001-32370000      * |           B           B compartment
#>   A    chr21 32370001-32385000      * |           A           A compartment
#>   B    chr21 32385001-32395000      * |           B           B compartment
#>   .      ...               ...    ... .         ...         ...         ...
#>   A    chr21 32790001-32795000      * |           A           A compartment
#>   B    chr21 32795001-32820000      * |           B           B compartment
#>   A    chr21 32820001-32825000      * |           A           A compartment
#>   B    chr21 32825001-32830000      * |           B           B compartment
#>   A    chr21 32830001-32985000      * |           A           A compartment
#>             col
#>     <character>
#>   B     #179281
#>   A     #EA262E
#>   B     #179281
#>   A     #EA262E
#>   B     #179281
#>   .         ...
#>   A     #EA262E
#>   B     #179281
#>   A     #EA262E
#>   B     #179281
#>   A     #EA262E
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths