shaman_score_hic_mat_for_track

shaman_score_hic_mat_for_track(
  track_db,
  work_dir,
  obs_track_nms,
  exp_track_nms,
  points_track_nms,
  chrom,
  start1,
  end1,
  start2,
  end2,
  expand = 2000000,
  k = 100,
  min_dist = 1024
)

Arguments

track_db

Directory of the misha database.

work_dir

Centralized directory to store temporary files.

obs_track_nms

Names of observed 2D genomic tracks for the hic data. Pooling of multiple observed tracks is supported.

exp_track_nms

Names of expected (shuffled) 2D genomic tracks. Pooling of multiple expected tracks is supported.

points_track_nms

Names of 2D genomic tracks that contain points on which to compute normalized score. Pooling points from multiple tracks is supported.

chrom

The chromosome of the matrix.

start1

The start coordinate of the first dimension.

end1

The end coordinate of the first dimension.

start2

The start coordinate of the second dimension.

end2

The end coordinate of the second dimension.

expand

Size of expansion, points to include outside the matrix for accurate computing of the score. Note that for each observed point, its k-nearest neighbors must be included in the expanded matrix.

k

The number of neighbor distances used for the score. For higher resolution maps, increase k. For lower resolution maps, decrease k.

min_dist

The minimum distance between points.

Value

0, 1 or -1 per matrix.

Details

This function extracts observed data and expected data in an expanded matrix and computes the score for each observed point. The score for a point is the KS D-statistic of the distances to its k nearest neighbors in the observed data compared to the expected data.

chrom, start1, end1, start2 and end2 can be vectors, to score several matrices in one call. Matrices with the same chrom, start1 and end1 then share one extraction of each track over the union of their expanded intervals, instead of one extraction per matrix (each extraction of a 2D track reads the whole chromosome pair). The output files are the same as scoring the matrices one by one.

options(shaman.score.threads = N) computes the kNN distances and scores on N threads (default 1).

Examples


# The example below runs on the test misha db provided with shaman.
# Called by shaman_score_hic_track() for each matrix of its grid; here it scores the
# observed contacts of chr2:176.7e06-176.8e06.
library(misha)
track_db <- shaman_get_test_track_db()
gsetroot(track_db)
work_dir <- tempfile("shaman_score_")
dir.create(work_dir)
shaman_score_hic_mat_for_track(track_db, work_dir,
    obs_track_nms = "hic_obs", exp_track_nms = "hic_exp", points_track_nms = "hic_obs",
    chrom = "chr2", start1 = 176.7e06, end1 = 176.8e06, start2 = 176.7e06, end2 = 176.8e06
)
#> kk norm on 10306 points
#> obs =  hic_obs
#> n_obs = 97618, n_exp = 200292, k_exp = 200
#> [1] 1
# the score of each observed contact (start1 <= start2) in the matrix
scores <- read.delim(list.files(work_dir, full.names = TRUE))
head(scores)
#>   chrom1    start1      end1 chrom2    start2      end2 score
#> 1   chr2 176714635 176714636   chr2 176797395 176797396   9.3
#> 2   chr2 176715492 176715493   chr2 176797394 176797395   8.3
#> 3   chr2 176715492 176715493   chr2 176798938 176798939  -8.8
#> 4   chr2 176716348 176716349   chr2 176797822 176797823  -7.3
#> 5   chr2 176716939 176716940   chr2 176798838 176798839 -11.3
#> 6   chr2 176718398 176718399   chr2 176798622 176798623 -11.3
unlink(work_dir, recursive = TRUE)