R/shaman.R
shaman_shuffle_hic_track.Rdshaman_shuffle_hic_track
shaman_shuffle_hic_track(
track_db,
obs_track_nm,
work_dir,
exp_track_nm = paste0(obs_track_nm, "_shuffle"),
max_jobs = 25,
shuffle = 80,
grid_small = 500000,
grid_high = 1000000,
grid_step_iter = 40,
dist_resolution = NA,
smooth = NA,
seed = NULL
)Directory of the misha database.
Name of observed 2D genomic track for the hic data.
Centralized directory to store temporary files.
Name of expected 2D genomic track.
Maximal number of qsub or local jobs - for optimal performance provide the number of chromosomes.
Average number of shuffling transitions for each observed point in the chromosomal contact matrix.
Initial size of maximum distance between contact pairs considered for switching
Final size of maximum distance between contact pairs considered for switching
Number of iterations in each grid size
Number of bins in each log2 distance unit. If NA, value is determined based on observed data (recommended).
Number of bins to use for smoothing the MCMC target function: the decay curve. If NA, value is determined based on observed data (recommended).
Seed for the shuffler: NULL (default) seeds each chromosome from the time (in seconds) its
shuffle starts. With a whole number, chromosome i of gintervals.all() is shuffled with seed + i - 1
(modulo 2^31), so the same seed gives the same track. The seed each chromosome was shuffled with is
stored in the track attribute seed (NA for chromosomes this call did not shuffle).
A chromosome's seed depends on its position in gintervals.all(), so the same seed reproduces a
track only in a database with the same chromosomes; the seed attribute reproduces each chromosome.
No return value, called for side effects: creates the 2D track exp_track_nm in track_db, with the
seeds in its attribute seed.
This function generates an expected 2D hic track based on observed hic data.
Each chromosome is shuffled separately, to generate an expected shuffled contact matrix.
Note that this function requires sge (qsub) or multicore to be enabled.
Parameter can be set via shaman.sge_support or shaman.mc_support in shaman.conf file.
Sun Grid Engine mode, options(shaman.sge_support = 1), is preferred; work_dir must then be
accessible by all jobs. Multi-core mode is options(shaman.mc_support = 1).
Each step creates temporary files of the shuffled matrices which are then joined to a track. Temporary files are deleted upon track creation. If the shuffle of a chromosome fails (an error, or its process or job is killed), no track is imported and work_dir keeps the shuffled chromosomes, so a rerun with the same work_dir shuffles only the others.
# The example below runs on the test misha db provided with shaman.
# Note that this is a toy db sampled from K562 ela data - shuffling the observed track
# will not produce the expected track.
library(misha)
track_db <- shaman_get_test_track_db()
gsetroot(track_db)
old_opts <- options(shaman.mc_support = 1) # configuring multi-core mode
if (gtrack.exists("hic_obs_shuffle")) {
gtrack.rm("hic_obs_shuffle", force = TRUE)
gdb.reload()
}
ret <- shaman_shuffle_hic_track(track_db,
obs_track_nm = "hic_obs",
# work_dir can be tempdir() only in multi-core mode.
# For sge mode, work_dir must be accessible by all jobs.
work_dir = tempdir(),
shuffle = 1, # default is set to 80
grid_step_iter = 1, # default is set to 40
max_jobs = 2, # optimally set to number of chromosomes
seed = 1 # the same seed gives the same track
)
#> writing 48810 raw data, dist resolution= 13
#> chr2
gdb.reload()
gtrack.ls("hic_obs_shuffle") # new shuffled track that was created
#> [1] "hic_obs_shuffle"
gtrack.attr.get("hic_obs_shuffle", "seed") # the seed of each chromosome
#> [1] "chr2:1"
options(old_opts)