# NOT RUN {
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (bedfile, bin = 2000, chrom_list = "chr2L", tot_size = 0,
bed_window = 2000)
{
if (tot_size == 0) {
print("please input tot_size")
}
else {
cmap = matrix(data = 0, nrow = tot_size, ncol = 1)
sec = NULL
for (j in 1:length(chrom_list)) {
sec = rbind(sec, bedfile[bedfile$chr == chrom_list[j],
])
}
ordereduniques = sec
count = 0
for (i in 1:dim(ordereduniques)[1]) {
st = (ceiling(ordereduniques[i, 2]/bin))
ed = (ceiling(ordereduniques[i, 3]/bin))
st1 = (ceiling((ordereduniques[i, 2] - bed_window)/bin))
ed1 = (ceiling((ordereduniques[i, 3] + bed_window)/bin))
if (st < 1) {
st = 1
}
if (st1 < 1) {
st1 = 1
}
if (ed < 1) {
ed = 1
}
if (ed1 < 1) {
ed1 = 1
}
if (st > tot_size) {
st = tot_size
}
if (st1 > tot_size) {
st1 = tot_size
}
if (ed > tot_size) {
ed = tot_size
}
if (ed1 > tot_size) {
ed1 = tot_size
}
if (st != ed) {
cmap[st, 1] = cmap[st, 1] + 1
count = count + 1
cmap[ed, 1] = cmap[ed, 1] + 1
count = count + 1
if (st1 != st) {
cmap[st1, 1] = cmap[st1, 1] + 1
count = count + 1
}
if (ed1 != ed) {
cmap[ed1, 1] = cmap[ed1, 1] + 1
count = count + 1
}
}
else {
cmap[ed, 1] = cmap[ed, 1] + 1
count = count + 1
if (st1 != st) {
cmap[st1, 1] = cmap[st1, 1] + 1
count = count + 1
}
if (ed1 != ed) {
cmap[ed1, 1] = cmap[ed1, 1] + 1
count = count + 1
}
}
}
}
cat(sprintf("Mapped Fragments: %s\n", count))
return(cmap)
}
# }
Run the code above in your browser using DataLab