Description Arguments Examples
convert the bed file to matrix file for the next analysis
bedfile |
|
bin |
|
chrom_list |
|
tot_size |
|
bed_window |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | ##---- 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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.