Mercurial > repos > artbio > ngsplot
annotate lib/plotlib.r @ 0:3ca58369469c draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
author | artbio |
---|---|
date | Wed, 06 Dec 2017 19:01:53 -0500 |
parents | |
children |
rev | line source |
---|---|
0
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
1 #### plotlib.r #### |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
2 # This contains the library for plotting related functions. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
3 # |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
4 # Authors: Li Shen, Ningyi Shao |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
5 # |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
6 # Created: Feb 19, 2013 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
7 # Last updated: May 21, 2013 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
8 # |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
9 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
10 SetupHeatmapDevice <- function(reg.list, uniq.reg, ng.list, pts, font.size=12, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
11 unit.width=4, reduce.ratio=30) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
12 # Configure parameters for heatmap output device. The output is used by |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
13 # external procedures to setup pdf device ready for heatmap plotting. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
14 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
15 # reg.list: region list as in config file. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
16 # uniq.reg: unique region list. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
17 # ng.list: number of genes per heatmap in the order as config file. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
18 # pts: data points (number of columns of heatmaps). |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
19 # font.size: font size. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
20 # unit.width: image width per heatmap. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
21 # reduce.ratio: how compressed are genes in comparison to data points? This |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
22 # controls image height. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
23 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
24 # Number of plots per region. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
25 reg.np <- sapply(uniq.reg, function(r) sum(reg.list==r)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
26 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
27 # Number of genes per region. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
28 reg.ng <- sapply(uniq.reg, function(r) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
29 ri <- which(reg.list==r)[1] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
30 ng.list[ri] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
31 }) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
32 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
33 # Adjustment ratio. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
34 origin.fs <- 12 # default font size. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
35 fs.adj.ratio <- font.size / origin.fs |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
36 # Margin size (in lines) adjusted by ratio. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
37 m.bot <- fs.adj.ratio * 2 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
38 m.lef <- fs.adj.ratio * 1.5 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
39 m.top <- fs.adj.ratio * 2 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
40 m.rig <- fs.adj.ratio * 1.5 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
41 key.in <- fs.adj.ratio * 1.0 # colorkey in inches. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
42 m.lef.diff <- (fs.adj.ratio - 1) * 1.5 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
43 m.rig.diff <- (fs.adj.ratio - 1) * 1.5 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
44 # Setup image size. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
45 hm.width <- (unit.width + m.lef.diff + m.rig.diff) * max(reg.np) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
46 ipl <- .2 # inches per line. Obtained from par->'mai', 'mar'. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
47 # Convert #gene to image height. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
48 reg.hei <- sapply(reg.ng, function(r) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
49 c(key.in, # colorkey + margin. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
50 r * unit.width / pts / reduce.ratio + |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
51 m.bot * ipl + m.top * ipl) # heatmap + margin. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
52 }) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
53 reg.hei <- c(reg.hei) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
54 hm.height <- sum(reg.hei) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
55 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
56 # Setup layout of the heatmaps. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
57 lay.mat <- matrix(0, ncol=max(reg.np), nrow=length(reg.np) * 2) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
58 fig.n <- 1 # figure plotting number. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
59 for(i in 1:length(reg.np)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
60 row.upper <- i * 2 - 1 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
61 row.lower <- i * 2 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
62 for(j in 1:reg.np[i]) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
63 lay.mat[row.upper, j] <- fig.n; |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
64 fig.n <- fig.n + 1 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
65 lay.mat[row.lower, j] <- fig.n; |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
66 fig.n <- fig.n + 1 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
67 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
68 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
69 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
70 list(reg.hei=reg.hei, hm.width=hm.width, hm.height=hm.height, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
71 lay.mat=lay.mat, heatmap.mar=c(m.bot, m.lef, m.top, m.rig) * ipl) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
72 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
73 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
74 SetPtsSpline <- function(pint, lgint) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
75 # Set data points for spline function. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
76 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
77 # pint: tag for point interval. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
78 # Return: list of data points, middle data points, flanking data points. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
79 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
80 pts <- 100 # data points to plot: 0...pts |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
81 if(pint){ # point interval. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
82 m.pts <- 1 # middle part points. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
83 f.pts <- pts / 2 # flanking part points. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
84 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
85 if(lgint) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
86 m.pts <- pts / 5 * 3 + 1 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
87 f.pts <- pts / 5 + 1 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
88 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
89 m.pts <- pts / 5 + 1 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
90 f.pts <- pts / 5 * 2 + 1 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
91 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
92 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
93 list(pts=pts, m.pts=m.pts, f.pts=f.pts) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
94 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
95 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
96 CreatePlotMat <- function(pts, ctg.tbl) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
97 # Create matrix for avg. profiles. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
98 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
99 # pts: data points. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
100 # ctg.tbl: configuration table. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
101 # Return: avg. profile matrix initialized to zero. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
102 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
103 regcovMat <- matrix(0, nrow=pts + 1, ncol=nrow(ctg.tbl)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
104 colnames(regcovMat) <- ctg.tbl$title |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
105 regcovMat |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
106 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
107 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
108 CreateConfiMat <- function(se, pts, ctg.tbl){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
109 # Create matrix for standard errors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
110 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
111 # se: tag for standard error plotting. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
112 # pts: data points. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
113 # ctg.tbl: configuration table. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
114 # Return: standard error matrix initialized to zero or null. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
115 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
116 if(se){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
117 confiMat <- matrix(0, nrow=pts + 1, ncol=nrow(ctg.tbl)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
118 colnames(confiMat) <- ctg.tbl$title |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
119 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
120 confiMat <- NULL |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
121 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
122 confiMat |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
123 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
124 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
125 col2alpha <- function(col2use, alpha){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
126 # Convert a vector of solid colors to semi-transparent colors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
127 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
128 # col2use: vector of colors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
129 # alpha: represents degree of opacity - [0,1] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
130 # Return: vector of transformed colors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
131 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
132 apply(col2rgb(col2use), 2, function(x){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
133 rgb(x[1], x[2], x[3], alpha=alpha*255, maxColorValue=255) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
134 }) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
135 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
136 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
137 smoothvec <- function(v, radius, method=c('mean', 'median')){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
138 # Given a vector of coverage, return smoothed version of coverage. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
139 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
140 # v: vector of coverage |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
141 # radius: fraction of org. vector size. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
142 # method: smooth method |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
143 # Return: vector of smoothed coverage. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
144 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
145 stopifnot(is.vector(v)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
146 stopifnot(length(v) > 0) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
147 stopifnot(radius > 0 && radius < 1) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
148 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
149 halfwin <- ceiling(length(v) * radius) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
150 s <- rep(NA, length(v)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
151 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
152 for(i in 1:length(v)){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
153 winpos <- (i - halfwin) : (i + halfwin) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
154 winpos <- winpos[winpos > 0 & winpos <= length(v)] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
155 if(method == 'mean'){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
156 s[i] <- mean(v[winpos]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
157 }else if(method == 'median'){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
158 s[i] <- median(v[winpos]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
159 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
160 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
161 s |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
162 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
163 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
164 smoothplot <- function(m, radius, method=c('mean', 'median')){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
165 # Smooth the entire avg. profile matrix using smoothvec. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
166 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
167 # m: avg. profile matrix |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
168 # radius: fraction of org. vector size. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
169 # method: smooth method. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
170 # Return: smoothed matrix. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
171 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
172 stopifnot(is.matrix(m) || is.vector(m)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
173 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
174 if(is.matrix(m)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
175 for(i in 1:ncol(m)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
176 m[, i] <- smoothvec(m[, i], radius, method) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
177 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
178 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
179 m <- smoothvec(m, radius, method) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
180 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
181 m |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
182 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
183 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
184 genXticks <- function(reg2plot, pint, lgint, pts, flanksize, flankfactor, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
185 Labs) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
186 # Generate X-ticks for plotting. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
187 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
188 # reg2plot: string representation of region. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
189 # pint: point interval. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
190 # lgint: tag for large interval. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
191 # pts: data points. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
192 # flanksize: flanking region size in bps. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
193 # flankfactor: flanking region factor. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
194 # Labs: character vector of labels of the genomic region. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
195 # Return: list of x-tick position and label. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
196 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
197 if(pint){ # point interval. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
198 mid.lab <- Labs[1] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
199 tick.pos <- c(0, pts / 4, pts / 2, pts / 4 * 3, pts) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
200 tick.lab <- as.character(c(-flanksize, -flanksize/2, mid.lab, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
201 flanksize/2, flanksize)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
202 }else{ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
203 left.lab <- Labs[1] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
204 right.lab <- Labs[2] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
205 tick.pos <- c(0, pts / 5, pts / 5 * 2, pts / 5 * 3, pts / 5 * 4, pts) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
206 if(lgint){ # large interval: fla int int int fla |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
207 if(flankfactor > 0){ # show percentage at x-tick. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
208 tick.lab <- c(sprintf("%d%%", -flankfactor*100), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
209 left.lab, '33%', '66%', right.lab, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
210 sprintf("%d%%", flankfactor*100)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
211 } else{ # show bps at x-tick. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
212 tick.lab <- c(as.character(-flanksize), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
213 left.lab, '33%', '66%', right.lab, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
214 as.character(flanksize)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
215 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
216 } else { # small interval: fla fla int fla fla. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
217 if(flankfactor > 0){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
218 tick.lab <- c(sprintf("%d%%", -flankfactor*100), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
219 sprintf("%d%%", -flankfactor*50), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
220 left.lab, right.lab, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
221 sprintf("%d%%", flankfactor*50), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
222 sprintf("%d%%", flankfactor*100)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
223 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
224 tick.lab <- c(as.character(-flanksize), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
225 as.character(-flanksize/2), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
226 left.lab, right.lab, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
227 as.character(flanksize/2), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
228 as.character(flanksize)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
229 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
230 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
231 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
232 list(pos=tick.pos, lab=tick.lab) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
233 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
234 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
235 plotmat <- function(regcovMat, title2plot, plot.colors, bam.pair, xticks, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
236 pts, m.pts, f.pts, pint, shade.alp=0, confiMat=NULL, mw=1, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
237 misc.options=list(yscale='auto', legend=T, box=T, vline=T, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
238 xylab=T, line.wd=3)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
239 # Plot avg. profiles and standard errors around them. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
240 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
241 # regcovMat: matrix for avg. profiles. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
242 # title2plot: profile names, will be shown in figure legend. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
243 # plot.colors: vector of color specifications for all curves. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
244 # bam.pair: boolean for bam-pair data. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
245 # xticks: X-axis ticks. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
246 # pts: data points |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
247 # m.pts: middle part data points |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
248 # f.pts: flanking part data points |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
249 # pint: tag for point interval |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
250 # shade.alp: shading area alpha |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
251 # confiMat: matrix for standard errors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
252 # mw: moving window size for smoothing function. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
253 # misc.options: list of misc. options - y-axis scale, legend, box around plot, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
254 # verticle lines, X- and Y-axis labels, line width. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
255 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
256 # Smooth avg. profiles if specified. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
257 if(mw > 1){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
258 regcovMat <- as.matrix(runmean(regcovMat, k=mw, alg='C', |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
259 endrule='mean')) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
260 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
261 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
262 # Choose colors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
263 if(any(is.na(plot.colors))) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
264 ncurve <- ncol(regcovMat) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
265 if(ncurve <= 8) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
266 suppressMessages(require(RColorBrewer, warn.conflicts=F)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
267 col2use <- brewer.pal(ifelse(ncurve >= 3, ncurve, 3), 'Dark2') |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
268 col2use <- col2use[1:ncurve] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
269 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
270 col2use <- rainbow(ncurve) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
271 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
272 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
273 col2use <- plot.colors |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
274 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
275 col2use <- col2alpha(col2use, 0.8) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
276 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
277 # Plot profiles. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
278 ytext <- ifelse(bam.pair, "log2(Fold change vs. control)", |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
279 "Read count Per Million mapped reads") |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
280 xrange <- 0:pts |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
281 y.lim <- NULL |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
282 if(length(misc.options$yscale) == 2) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
283 y.lim <- misc.options$yscale |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
284 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
285 matplot(xrange, regcovMat, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
286 xaxt='n', type="l", col=col2use, ylim=y.lim, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
287 lty="solid", lwd=misc.options$line.wd, frame.plot=F, ann=F) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
288 if(misc.options$xylab) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
289 title(xlab="Genomic Region (5' -> 3')", ylab=ytext) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
290 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
291 axis(1, at=xticks$pos, labels=xticks$lab, lwd=3, lwd.ticks=3) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
292 if(misc.options$box) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
293 # box around plot. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
294 box() |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
295 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
296 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
297 # Add shade area. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
298 if(shade.alp > 0){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
299 for(i in 1:ncol(regcovMat)){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
300 v.x <- c(xrange[1], xrange, xrange[length(xrange)]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
301 v.y <- regcovMat[, i] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
302 v.y <- c(0, v.y, 0) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
303 col.rgb <- col2rgb(col2use[i]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
304 p.col <- rgb(col.rgb[1, 1], col.rgb[2, 1], col.rgb[3, 1], |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
305 alpha=shade.alp * 255, maxColorValue=255) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
306 polygon(v.x, v.y, density=-1, border=NA, col=p.col) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
307 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
308 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
309 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
310 # Add standard errors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
311 if(!is.null(confiMat)){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
312 v.x <- c(xrange, rev(xrange)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
313 for(i in 1:ncol(confiMat)){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
314 v.y <- c(regcovMat[, i] + confiMat[, i], |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
315 rev(regcovMat[, i] - confiMat[, i])) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
316 col.rgb <- col2rgb(col2use[i]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
317 p.col <- rgb(col.rgb[1, 1], col.rgb[2, 1], col.rgb[3, 1], |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
318 alpha=0.2 * 255, maxColorValue=255) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
319 polygon(v.x, v.y, density=-1, border=NA, col=p.col) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
320 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
321 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
322 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
323 if(misc.options$vline) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
324 # Add gray lines indicating feature boundaries. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
325 if(pint) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
326 abline(v=f.pts, col="gray", lwd=2) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
327 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
328 abline(v=f.pts - 1, col="gray", lwd=2) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
329 abline(v=f.pts + m.pts - 2, col="gray", lwd=2) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
330 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
331 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
332 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
333 if(misc.options$legend) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
334 # Legend. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
335 legend("topright", title2plot, text.col=col2use) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
336 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
337 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
338 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
339 spline_mat <- function(mat, n=100){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
340 # Calculate splined coverage for a matrix. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
341 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
342 # mat: each column represents a profile to be interpolated. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
343 # n: number of data points to be interpolated. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
344 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
345 foreach(r=iter(mat, by='row'), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
346 .combine='rbind', .multicombine=T) %dopar% { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
347 spline(1:length(r), r, n)$y |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
348 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
349 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
350 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
351 RankNormalizeMatrix <- function(mat, low.cutoff) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
352 # Rank-based normalization for a data matrix. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
353 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
354 # mat: data matrix. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
355 # low.cutoff: low value cutoff. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
356 # Return: rank normalized matrix. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
357 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
358 stopifnot(is.matrix(mat)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
359 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
360 concat.dat <- c(mat) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
361 low.mask <- concat.dat < low.cutoff |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
362 concat.r <- rank(concat.dat) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
363 concat.r[low.mask] <- 0 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
364 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
365 matrix(concat.r, nrow=nrow(mat)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
366 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
367 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
368 OrderGenesHeatmap <- function(enrichList, lowCutoffs, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
369 method=c('total', 'max', 'prod', 'diff', 'hc', |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
370 'none', 'km'), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
371 go.paras=list(knc=5, max.iter=20, nrs=30)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
372 # Order genes with a list of heatmap data. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
373 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
374 # enrichList: heatmap data in a list. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
375 # lowCutoffs: low count cutoff for normalized count data. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
376 # method: algorithm used to order genes. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
377 # go.paras: gene ordering parameters. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
378 # Returns: a vector of REVERSED gene orders. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
379 # NOTE: due to the design of image function, the order needs to be reversed |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
380 # so that the genes will be shown correctly. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
381 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
382 rankList <- mapply(RankNormalizeMatrix, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
383 mat=enrichList, low.cutoff=lowCutoffs, SIMPLIFY=F) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
384 np <- length(enrichList) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
385 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
386 if(method == 'hc') { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
387 rankCombined <- do.call('cbind', rankList) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
388 # Clustering and order genes. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
389 hc <- hclust(dist(rankCombined, method='euclidean'), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
390 method='complete') |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
391 memb <- cutree(hc, k = go.paras$knc) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
392 list(rev(hc$order), memb) # reversed! |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
393 } else if(method == 'km') { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
394 rankCombined <- do.call('cbind', rankList) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
395 km <- kmeans(rankCombined, centers=go.paras$knc, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
396 iter.max=go.paras$max.iter, nstart=go.paras$nrs) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
397 list(rev(order(km$cluster)), km$cluster) # reversed! |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
398 } else if(method == 'total' || method == 'diff' && np == 1) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
399 list(order(rowSums(rankList[[1]])), NULL) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
400 } else if(method == 'max') { # peak enrichment value of the 1st profile. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
401 list(order(apply(rankList[[1]], 1, max)), NULL) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
402 } else if(method == 'prod') { # product of all profiles. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
403 rs.mat <- sapply(rankList, rowSums) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
404 g.prod <- apply(rs.mat, 1, prod) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
405 list(order(g.prod), NULL) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
406 } else if(method == 'diff' && np > 1) { # difference between 2 profiles. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
407 list(order(rowSums(rankList[[1]]) - rowSums(rankList[[2]])), NULL) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
408 } else if(method == 'none') { # according to the order of input gene list. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
409 # Because the image function draws from bottom to top, the rows are |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
410 # reversed to give a more natural look. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
411 list(rev(1:nrow(enrichList[[1]])),NULL) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
412 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
413 # pass. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
414 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
415 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
416 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
417 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
418 plotheat <- function(reg.list, uniq.reg, enrichList, v.low.cutoff, go.algo, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
419 go.paras, title2plot, bam.pair, xticks, flood.q=.02, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
420 do.plot=T, hm.color="default", color.distr=.6, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
421 color.scale='local') { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
422 # Plot heatmaps with genes ordered according to some algorithm. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
423 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
424 # reg.list: factor vector of regions as in configuration. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
425 # uniq.reg: character vector of unique regions. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
426 # enrichList: list of heatmap data. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
427 # v.low.cutoff: low count cutoff for normalized count data. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
428 # go.algo: gene order algorithm. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
429 # go.paras: gene ordering parameters. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
430 # title2plot: title for each heatmap. Same as the legends in avgprof. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
431 # bam.pair: boolean tag for bam-pair. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
432 # xticks: info for X-axis ticks. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
433 # flood.q: flooding percentage. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
434 # do.plot: boolean tag for plotting heatmaps. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
435 # hm.color: string for heatmap colors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
436 # color.distr: positive number for color distribution. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
437 # color.scale: string for the method to adjust color scale. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
438 # Returns: ordered gene names for each unique region as a list. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
439 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
440 # Setup basic parameters. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
441 ncolor <- 256 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
442 if(bam.pair) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
443 if(hm.color != "default") { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
444 tri.colors <- unlist(strsplit(hm.color, ':')) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
445 neg.color <- tri.colors[1] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
446 if(length(tri.colors) == 2) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
447 neu.color <- 'black' |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
448 pos.color <- tri.colors[2] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
449 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
450 neu.color <- tri.colors[2] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
451 pos.color <- tri.colors[3] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
452 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
453 enrich.palette <- colorRampPalette(c(neg.color, neu.color, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
454 pos.color), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
455 bias=color.distr, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
456 interpolate='spline') |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
457 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
458 enrich.palette <- colorRampPalette(c('blue', 'black', 'yellow'), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
459 bias=color.distr, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
460 interpolate='spline') |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
461 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
462 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
463 if(hm.color != "default") { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
464 enrich.palette <- colorRampPalette(c('snow', hm.color)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
465 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
466 enrich.palette <- colorRampPalette(c('snow', 'red2')) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
467 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
468 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
469 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
470 hm_cols <- ncol(enrichList[[1]]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
471 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
472 # Adjust X-axis tick position. In a heatmap, X-axis is [0, 1]. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
473 # Assume xticks$pos is from 0 to N(>0). |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
474 xticks$pos <- xticks$pos / tail(xticks$pos, n=1) # scale to the same size. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
475 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
476 # Define a function to calculate color breaks. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
477 ColorBreaks <- function(max.e, min.e, bam.pair, ncolor) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
478 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
479 # max.e: maximum enrichment value to be mapped to color. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
480 # min.e: minimum enrichment value to be mapped to color. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
481 # bam.pair: boolean tag for bam-pair. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
482 # ncolor: number of colors to use. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
483 # Returns: vector of color breaks. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
484 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
485 # If bam-pair is used, create breaks for positives and negatives |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
486 # separately. If log2 ratios are all positive or negative, use only |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
487 # half of the color space. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
488 if(bam.pair) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
489 max.e <- ifelse(max.e > 0, max.e, 1) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
490 min.e <- ifelse(min.e < 0, min.e, -1) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
491 c(seq(min.e, 0, length.out=ncolor / 2 + 1), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
492 seq(0, max.e, length.out=ncolor / 2 + 1)[-1]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
493 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
494 seq(min.e, max.e, length.out=ncolor + 1) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
495 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
496 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
497 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
498 if(grepl(",", color.scale)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
499 scale.pair <- unlist(strsplit(color.scale, ",")) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
500 scale.min <- as.numeric(scale.pair[1]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
501 scale.max <- as.numeric(scale.pair[2]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
502 if(scale.min >= scale.max) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
503 warning("Color scale min value is >= max value.\n") |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
504 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
505 flood.pts <- c(scale.min, scale.max) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
506 brk.use <- ColorBreaks(scale.max, scale.min, bam.pair, ncolor) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
507 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
508 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
509 # If color scale is global, calculate breaks and quantile here. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
510 if(color.scale == 'global') { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
511 flood.pts <- quantile(c(enrichList, recursive=T), c(flood.q, 1-flood.q)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
512 brk.use <- ColorBreaks(flood.pts[2], flood.pts[1], bam.pair, ncolor) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
513 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
514 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
515 # Go through each unique region. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
516 # Do NOT use "dopar" in the "foreach" loops here because this will disturb |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
517 # the image order. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
518 go.list <- vector('list', length(uniq.reg)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
519 go.cluster <- vector('list', length(uniq.reg)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
520 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
521 names(go.list) <- uniq.reg |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
522 names(go.cluster) <- uniq.reg |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
523 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
524 for(ur in uniq.reg) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
525 # ur <- uniq.reg[i] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
526 plist <- which(reg.list==ur) # get indices in the config file. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
527 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
528 # Combine all profiles into one. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
529 # enrichCombined <- do.call('cbind', enrichList[plist]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
530 enrichSelected <- enrichList[plist] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
531 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
532 # If color scale is region, calculate breaks and quantile here. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
533 if(color.scale == 'region') { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
534 flood.pts <- quantile(c(enrichSelected, recursive=T), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
535 c(flood.q, 1-flood.q)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
536 brk.use <- ColorBreaks(flood.pts[2], flood.pts[1], bam.pair, ncolor) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
537 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
538 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
539 # Order genes. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
540 if(is.matrix(enrichSelected[[1]]) && nrow(enrichSelected[[1]]) > 1) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
541 if(bam.pair) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
542 lowCutoffs <- 0 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
543 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
544 lowCutoffs <- v.low.cutoff[plist] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
545 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
546 g.order.list <- OrderGenesHeatmap(enrichSelected, lowCutoffs, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
547 go.algo, go.paras) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
548 g.order <- g.order.list[[1]] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
549 g.cluster <- g.order.list[[2]] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
550 if(is.null(g.cluster)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
551 go.cluster[[ur]] <- NA |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
552 } else{ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
553 go.cluster[[ur]] <- rev(g.cluster[g.order]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
554 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
555 go.list[[ur]] <- rev(rownames(enrichSelected[[1]][g.order, ])) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
556 } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
557 go.cluster[[ur]] <- NULL |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
558 go.list[[ur]] <- NULL |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
559 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
560 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
561 if(!do.plot) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
562 next |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
563 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
564 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
565 # Go through each sample and do plot. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
566 for(pj in plist) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
567 if(!is.null(g.order)) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
568 enrichList[[pj]] <- enrichList[[pj]][g.order, ] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
569 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
570 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
571 # If color scale is local, calculate breaks and quantiles here. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
572 if(color.scale == 'local') { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
573 flood.pts <- quantile(c(enrichList[[pj]], recursive=T), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
574 c(flood.q, 1-flood.q)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
575 brk.use <- ColorBreaks(flood.pts[2], flood.pts[1], bam.pair, |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
576 ncolor) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
577 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
578 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
579 # Flooding extreme values. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
580 enrichList[[pj]][ enrichList[[pj]] < flood.pts[1] ] <- flood.pts[1] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
581 enrichList[[pj]][ enrichList[[pj]] > flood.pts[2] ] <- flood.pts[2] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
582 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
583 # Draw colorkey. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
584 image(z=matrix(brk.use, ncol=1), col=enrich.palette(ncolor), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
585 breaks=brk.use, axes=F, useRaster=T, main='Colorkey') |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
586 axis(1, at=seq(0, 1, length.out=5), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
587 labels=format(brk.use[seq(1, ncolor + 1, length.out=5)], |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
588 digits=1), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
589 lwd=1, lwd.ticks=1) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
590 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
591 # Draw heatmap. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
592 image(z=t(enrichList[[pj]]), col=enrich.palette(ncolor), |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
593 breaks=brk.use, axes=F, useRaster=T, main=title2plot[pj]) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
594 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
595 axis(1, at=xticks$pos, labels=xticks$lab, lwd=1, lwd.ticks=1) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
596 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
597 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
598 list(go.list,go.cluster) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
599 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
600 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
601 trim <- function(x, p){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
602 # Trim a numeric vector on both ends. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
603 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
604 # x: numeric vector. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
605 # p: percentage of data to trim. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
606 # Return: trimmed vector. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
607 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
608 low <- quantile(x, p) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
609 hig <- quantile(x, 1 - p) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
610 x[x > low & x < hig] |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
611 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
612 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
613 CalcSem <- function(x, rb=.05){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
614 # Calculate standard error of mean for a numeric vector. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
615 # Args: |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
616 # x: numeric vector |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
617 # rb: fraction of data to trim before calculating sem. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
618 # Return: a scalar of the standard error of mean |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
619 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
620 if(rb > 0){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
621 x <- trim(x, rb) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
622 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
623 sem <- sd(x) / sqrt(length(x)) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
624 ifelse(is.na(sem), 0, sem) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
625 # NOTE: this should be improved to handle exception that "sd" calculation |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
626 # emits errors. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
627 } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
628 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
629 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
630 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
631 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
632 ## Leave for future reference. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
633 # |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
634 # Set the antialiasing. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
635 # type <- NULL |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
636 # if (capabilities()["aqua"]) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
637 # type <- "quartz" |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
638 # } else if (capabilities()["cairo"]) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
639 # type <- "cairo" |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
640 # } else if (capabilities()["X11"]) { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
641 # type <- "Xlib" |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
642 # } |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
643 # Set the output type based on capabilities. |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
644 # if (is.null(type)){ |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
645 # png(plot.name, width, height, pointsize=pointsize) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
646 |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
647 # } else { |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
648 # png(plot.name, width, height, pointsize=pointsize, type=type) |
3ca58369469c
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff
changeset
|
649 # } |