load_wig: the function to load tracks

Description Usage Arguments Examples

View source: R/calbed.R

Description

the function to load tracks

Usage

1
load_wig(wigfile, resolution = 2000, chrom = "chr2L", chrTotSize, chrstart, chrend)

Arguments

wigfile
resolution
chrom
chrTotSize
chrstart
chrend

Examples

 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
##---- 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 (wigfile, resolution = 2000, chrom = "chr2L", chrTotSize,
    chrstart, chrend)
{
    tmp_wig <- read.table(file = wigfile, fill = TRUE, stringsAsFactors = FALSE,
        skip = 1)
    ooo <- data.frame(seg.name = character(chrTotSize), seg.po = numeric(chrTotSize),
        value = numeric(chrTotSize), stringsAsFactors = FALSE)
    ooo_num <- data.frame(wig_num = numeric(chrTotSize))
    sec = NULL
    sec = rbind(sec, tmp_wig[tmp_wig[, 1] == chrom, ])
    sec[, 2] = as.numeric(sec[, 2])
    sec[, 3] = as.numeric(sec[, 3])
    sec[, 4] = as.numeric(sec[, 4])
    if (chrend > 0) {
        sec = sec[which(sec[, 3] < chrend), ]
        sec[, 2] = sec[, 2] - chrstart
        sec[, 3] = sec[, 3] - chrstart
        sec = sec[which(sec[, 2] > 0), ]
    }
    secdim = dim(sec)[1]
    if (is.null(secdim)) {
        return(NULL)
    }
    else if (secdim < 2) {
        return(NULL)
    }
    else {
        ooo[, 1] = chrom
        ooo[, 2:3] = 0
        ooo_num[, 1] = 0
        wig_bin = 1
        sec_num = dim(sec)[1]
        for (i in 1:sec_num) {
            wig_bin = ceiling((sec[i, 2] + sec[i, 3])/(2 * resolution))
            if (wig_bin > chrTotSize) {
                wig_bin = chrTotSize
            }
            ooo[wig_bin, 3] = ooo[wig_bin, 3] + sec[i, 4]
            ooo_num[wig_bin, 1] = ooo_num[wig_bin, 1] + 1
            ooo[wig_bin, 2] = wig_bin
        }
        for (i in 1:chrTotSize) {
            if (ooo[i, 2] == 0) {
                ooo[i, 2] = i
            }
            if (ooo_num[i, 1] > 0) {
                ooo[i, 3] = (ooo[i, 3])/(ooo_num[i, 1])
            }
            else {
                ooo[i, 3] = 0
            }
        }
        return(ooo)
    }
  }

HBP documentation built on July 7, 2017, 9:02 a.m.

Related to load_wig in HBP...