motif.p: a function to calculate a rank correlation p-value for a...

Usage Arguments Examples

View source: R/motif.p.R

Usage

1
motif.p(seqlist, motif, overlap = TRUE, mode = "bb", cores = 1, sub.method = "p.value", order = 1, exact = TRUE, ...)

Arguments

seqlist

A list of ranked sequences in which the motif rank correlation is calculated. The sequence list should be a list object containing 'seq' objects or character strings.

motif

A motif defined as a regular expression, e.g. "A(G|A)G*(C|T)CT". Must be a character string.

overlap

Logical, are motifs allowed to overlap in the sequences.

mode

One of "bb", "rw" or "msr" depending on the correlation evaluation method.

cores

Number of cores to use in parallel.

sub.method
order

1 or 2 for mono-nucleotide or di-nucleotide dependency of sequence specific p-value calculation.

exact
...

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
##---- 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 (seqlist, motif, overlap = TRUE, mode = "bb", cores = 1, 
    sub.method = "p.value", order = 1, exact = TRUE, ...) 
{
    if (!(mode %in% c("bb", "mw", "rw", "mhg"))) {
        stop("mode should be one of 'bb'(default), 'mw' 'rw' or 'mhg'")
    }
    if (mode == "mhg") {
        if (is.list(motif)) 
            motif <- motif$pattern
        if (is.list(seqlist)) 
            seqlist <- unlist(mclapply(seqlist, function(x) x$sequence, 
                mc.cores = cores))
        res <- mhg.motif.p(seqlist = seqlist, motif = motif, 
            ...)
        names(res) <- motif
        return(res)
    }
    if (class(seqlist[[1]]) == "character") {
        seqlist <- seq.list.con(seqlist, cores = cores)
    }
    if (class(seqlist[[1]]) != "seq") {
        stop("sequences should be character vector or 'seq' object")
    }
    if (class(motif) == "character") {
        motif <- pat.con(motif)
    }
    if (class(motif) != "pattern") {
        stop("motif should be character vector or 'pattern' object")
    }
    if (mode %in% c("rs", "bb")) {
        if (order == 1) {
            p.values <- par.list.prob(seqlist, motif, cores = cores, 
                overlap = overlap, ...)
        }
        else {
            if (order == 2) 
                p.values <- unlist(mclapply(seqlist, function(x) {
                  prob.dist.di(motif, x, mode = mode, overlap = overlap, 
                    ...)$prob.n.or.more
                }, mc.cores = cores))
        }
    }
    else if (mode == "mw") {
        if (order == 1) {
            values <- mclapply(seqlist, function(x) {
                prob.dist(motif, x)
            }, mc.cores = cores)
        }
        else {
            if (order == 2) {
                values <- mclapply(seqlist, function(x) {
                  prob.dist.di(motif, x)
                }, mc.cores = cores)
            }
        }
        p.values <- sapply(values, function(x) return(x$prob.1.or.more))
        n.obs <- sapply(values, function(x) return(x$n.obs.patterns))
    }
    if (mode == "rw") {
        if (order == 1) {
            p.values <- unlist(mclapply(seqlist, function(x) {
                rw.draw.p(prob.dist(motif, x, mode = mode, overlap = overlap, 
                  ...))
            }, mc.cores = cores))
        }
        else {
            if (order == 2) {
                p.values <- unlist(mclapply(seqlist, function(x) {
                  rw.draw.p(prob.dist.di(motif, x, mode = mode, 
                    overlap = overlap, ...))
                }, mc.cores = cores))
            }
        }
    }
    if (mode == "rw") {
        if (sub.method == "p.value") 
            return(rw.motif.p(p.values, ...)$p.value)
        else return(rw.motif.p(p.values, ...))
    }
    if (mode == "bb") {
        if (sub.method == "p.value") 
            return(bb.motif.p(p.values, exact = exact)$p.value)
        else return(bb.motif.p(p.values, exact = exact))
    }
    if (mode == "rs") {
        if (sub.method == "p.value") 
            return(rs.motif.p(p.values))
        else return(rs.motif.p(p.values, rs.out = "all"))
    }
    if (mode == "mw") {
        return(wcmod.p(p.values, n.obs))
    }
  }

muhligs/Regmex documentation built on Sept. 5, 2020, 1:11 a.m.