annotate lib/coverage.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 # Function to check if the range exceeds coverage vector boundaries.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
2 checkBound <- function(start, end, range, chrlen){
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
3 if(end + range > chrlen || start - range < 1)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
4 return(FALSE) # out of boundary.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
5 else
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
6 return(TRUE)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
7 }
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 Bin <- function(v, n) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
10 # Function to bin a coverage vector.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
11 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
12 # v: coverage vector.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
13 # n: number of bins.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
14 # Return: vector of binned values.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
15
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
16 bin.bound <- seq(1, length(v), length.out=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
17 sapply(1:n, function(i) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
18 mean(v[bin.bound[i]:bin.bound[i + 1]])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
19 })
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
20 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
21
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
22 SplineRev3Sec <- function(cov.list, v.fls, pts.list, v.strand, algo="spline") {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
23 # For 3 sections of continuous coverage, spline each according to specified
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
24 # data points and return concatenated, interpolated curves.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
25 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
26 # cov.list: a list of coverage vectors. Each vector represents a gene.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
27 # v.fls: vector of flanking region size.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
28 # pts.list: a list of three integers for 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
29 # v.strand: factor vector of strands.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
30 # algo: algorithm used to normalize coverage vectors (spline, bin).
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
31 # Return: matrix of interpolated coverage: each row represents a gene; each
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
32 # column represents a data point. Coverage from exons are concatenated.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
33 # Notes: the names of cov.list and pts.list must be the same for index purpose.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
34 # Suggested: use 'l', 'm', and 'r' for the names.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
35
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
36 # Create an empty coveage matrix first.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
37 tot.pts <- sum(unlist(pts.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
38 cov.mat <- matrix(nrow=length(cov.list), ncol=tot.pts)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
39
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
40 for(i in 1:length(cov.list)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
41 left.cov <- head(cov.list[[i]], n=v.fls[i])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
42 right.cov <- tail(cov.list[[i]], n=v.fls[i])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
43 mid.cov <- window(cov.list[[i]], start=v.fls[i] + 1,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
44 width=length(cov.list[[i]]) - 2*v.fls[i])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
45 if(algo == "spline") {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
46 left.cov <- spline(1:length(left.cov), left.cov, n=pts.list$l)$y
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
47 right.cov <- spline(1:length(right.cov), right.cov, n=pts.list$r)$y
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
48 mid.cov <- spline(1:length(mid.cov), mid.cov, n=pts.list$m)$y
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
49 } else if(algo == "bin") {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
50 left.cov <- Bin(left.cov, n=pts.list$l)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
51 right.cov <- Bin(right.cov, n=pts.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
52 mid.cov <- Bin(mid.cov, n=pts.list$m)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
53 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
54 # pass.
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 # Fuse the two points at the boundary and concatenate.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
57 f1 <- (tail(left.cov, n=1) + head(mid.cov, n=1)) / 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 f2 <- (tail(mid.cov, n=1) + head(right.cov, n=1)) / 2
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
59 con.cov <- c(left.cov[-length(left.cov)], f1,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
60 mid.cov[-c(1, length(mid.cov))],
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
61 f2, right.cov[-1])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
62 # browser()
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
63 if(v.strand[i] == '+') {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
64 cov.mat[i, ] <- con.cov
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
65 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
66 cov.mat[i, ] <- rev(con.cov)
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 cov.mat
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
71 }
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 extrCov3Sec <- function(v.chrom, v.start, v.end, v.fls, v.strand, m.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
74 bufsize, algo, ...) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
75 # Extract and interpolate coverage vectors from genomic regions with 3 sections.
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 # v.chrom: factor vector of chromosome names.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
78 # v.start: integer vector of region start.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
79 # v.end: integer vector of region end.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
80 # v.fls: integer vector of 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
81 # v.strand: factor vector of gene strands.
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: data points for middle interval.
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: data points for flanking region.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
84 # bufsize: integer; buffers are added to both ends of each region.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
85 # algo: algorithm used to normalize coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
86 # Return: matrix of interpolated coverage: each row represents a gene; each
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
87 # column represents a data point.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
88
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
89 interflank.gr <- GRanges(seqnames=v.chrom, ranges=IRanges(
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
90 start=v.start - v.fls - bufsize,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
91 end=v.end + v.fls + bufsize))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
92 interflank.cov <- covBamExons(interflank.gr, v.strand, ...)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
93
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
94 # Trim buffers from coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
95 interflank.cov <- lapply(interflank.cov, function(v) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
96 window(v, start=bufsize + 1, width=length(v) - 2 * bufsize)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
97 })
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
98
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
99 # Interpolate and reverse coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
100 SplineRev3Sec(interflank.cov, v.fls, list(l=f.pts, m=m.pts, r=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
101 v.strand, algo)
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
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
104 sub3CovList <- function(all.cov, v.left, v.right) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
105 # For a list of coverage vectors, separate them into three lists.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
106 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
107 # all.cov: list of coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
108 # v.left: integer vector of left flanking size.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
109 # v.right: integer vector of right flanking size.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
110 # Return: list of lists of coverage vectors. The outer list is named as:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
111 # "l", "m", "r".
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
112
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
113 left.cov <- foreach(i=icount(length(all.cov))) %do% {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
114 head(all.cov[[i]], n=v.left[i])
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 mid.cov <- foreach(i=icount(length(all.cov))) %do% {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
117 len <- length(all.cov[[i]])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
118 all.cov[[i]][ (v.left[i] + 1) : (len - v.right[i]) ]
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
119 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
120 right.cov <- foreach(i=icount(length(all.cov))) %do% {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
121 tail(all.cov[[i]], n=v.right[i])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
122 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
123 list(l=left.cov, m=mid.cov, r=right.cov)
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
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
126 extrCovExons <- function(v.chrom, exonranges.list, v.fls, v.strand,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
127 m.pts, f.pts, bufsize, algo, ...) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
128 # Extract coverage vectors for transcripts with exon models.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
129 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
130 # v.chrom: factor vector of chromosome names.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
131 # exonranges.list: list of IRanges objects for exon coordinates.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
132 # v.fls: integer vector of 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
133 # v.strand: factor vector of gene strands.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
134 # m.pts: data points for middle interval.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
135 # f.pts: data points for flanking region.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
136 # bufsize: integer; buffers are added to both ends of each region.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
137 # algo: algorithm used to normalize coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
138 # Return: matrix of interpolated coverage: each row represents a gene; each
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
139 # column represents a data point. Coverage from exons are concatenated.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
140
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
141 # Construct ranges including exon and flanking regions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
142 exonflank.list <- vector('list', length=length(exonranges.list))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
143 for(i in 1:length(exonranges.list)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
144 r.mod <- exonranges.list[[i]] # IRanges object to be modified.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
145 n <- length(r.mod)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
146 # Add flanking and buffer regions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
147 start(r.mod)[1] <- start(r.mod)[1] - v.fls[i] - bufsize
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
148 end(r.mod)[n] <- end(r.mod)[n] + v.fls[i] + bufsize
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
149 exonflank.list[[i]] <- GRanges(seqnames=v.chrom[i], ranges=r.mod)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
150 }
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 exonflank.cov <- covBamExons(exonflank.list, v.strand, ...)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
153
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
154 # Trim buffers from coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
155 exonflank.cov <- lapply(exonflank.cov, function(v) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
156 window(v, start=bufsize + 1, width=length(v) - 2 * bufsize)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
157 })
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
158
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
159 SplineRev3Sec(exonflank.cov, v.fls, list(l=f.pts, m=m.pts, r=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
160 v.strand, algo)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
161 }
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 extrCovMidp <- function(v.chrom, v.midp, flanksize, v.strand, pts, bufsize,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
165 algo, ...) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
166 # Extract coverage vectors with a middle point and symmetric flanking regions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
167 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
168 # v.chrom: factor vector of chromosome names.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
169 # v.midp: integer vector of middle points.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
170 # flanksize: integer of 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
171 # v.strand: factor vector of gene strands.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
172 # pts: data points to spline into.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
173 # bufsize: integer; buffers are added to both ends of each region.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
174 # algo: algorithm used to normalize coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
175 # Return: matrix of interpolated coverage: each row represents a gene; each
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
176 # column represents a data point.
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 granges <- GRanges(seqnames=v.chrom, ranges=IRanges(
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
179 start=v.midp - flanksize - bufsize,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
180 end=v.midp + flanksize + bufsize))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
181 cov.list <- covBamExons(granges, v.strand, ...)
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 # Trim buffers from coverage vectors.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
184 cov.list <- lapply(cov.list, function(v) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
185 window(v, start=bufsize + 1, width=length(v) - 2 * bufsize)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
186 })
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
187
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
188 # Interpolate and reverse coverage vectors and assemble into 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
189 cov.mat <- matrix(nrow=length(cov.list), ncol=pts)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
190 for(i in 1:length(cov.list)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
191 if(is.null(cov.list[[i]])) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
192 cov.mat[i, ] <- vector('integer', length=pts)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
193 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
194 if(algo == "spline") {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
195 cov.mat[i, ] <- spline(1:length(cov.list[[i]]), cov.list[[i]],
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
196 n=pts)$y
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
197 } else if(algo == "bin") {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
198 cov.mat[i, ] <- Bin(cov.list[[i]], n=pts)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
199 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
200 # pass.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
201 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
202 if(v.strand[i] == '-') {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
203 cov.mat[i, ] <- rev(cov.mat[i, ])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
204 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
205 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
206 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
207 cov.mat
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
208 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
209
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
210 scanBamRevOrder <- function(org.gr, sbp) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
211 # ScanBamParam re-arranges the input genomic ranges. Use range info to
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
212 # construct a string vector to find the order to reverse it.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
213 org.grnames <- with(org.gr, paste(seqnames, start, end, sep=':'))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
214 sbw.gr <- as.data.frame(bamWhich(sbp)) # scan-bam-ed
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
215 if('space' %in% names(sbw.gr)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
216 sbw.grnames <- with(sbw.gr, paste(space, start, end, sep=':'))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
217 } else if('group_name' %in% names(sbw.gr)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
218 sbw.grnames <- with(sbw.gr, paste(group_name, start, end, sep=':'))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
219 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
220 stop("Cannot locate chromosome names in extracted short reads. Report
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
221 this problem using issue tracking or discussion forum.\n")
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
222 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
223
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
224 match(org.grnames, sbw.grnames)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
225 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
226
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
227 genZeroList <- function(llen, v.vlen) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
228 # Generate a list of specific length with each element being an Rle vector of
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
229 # zeros with specific length.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
230 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
231 # llen: list length
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
232 # v.vlen: vector of vector lengths.
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 llen <- as.integer(llen)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
235 stopifnot(llen > 0)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
236 res <- vector('list', length=llen)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
237 for(i in 1:llen) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
238 res[[i]] <- Rle(0, v.vlen[i])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
239 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
240 res
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
241 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
242
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
243 covBamExons <- function(granges.dat, v.strand, bam.file, sn.inbam, fraglen,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
244 map.qual=20, bowtie=F,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
245 strand.spec=c('both', 'same', 'opposite')) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
246 # Extract coverage vectors from bam file for a list of transcripts of multiple
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
247 # exons.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
248 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
249 # granges.dat: a GRanges object representing a set of genomic ranges or a
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
250 # list of GRanges objects each representing a set of exonic
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
251 # ranges.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
252 # v.strand: vector of strand info.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
253 # bam.file: character string refers to the path of a bam file.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
254 # sn.inbam: vector of chromosome names in the bam file.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
255 # fraglen: fragment length.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
256 # map.qual: mapping quality to filter reads.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
257 # bowtie: boolean to indicate whether the aligner was Bowtie-like or not.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
258 # strand.spec: string desc. for strand-specific coverage calculation.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
259 # Return: list of coverage vectors, each vector represents a transcript.
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 strand.spec <- match.arg(strand.spec)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
262
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(class(granges.dat) == 'list') {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
264 # Construct a GRanges object representing DNA sequences.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
265 v.seqnames <- sapply(granges.dat,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
266 function(x) as.character(seqnames(x)[1]))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
267 v.start <- sapply(granges.dat, function(x) start(ranges(x))[1])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
268 v.end <- sapply(granges.dat, function(x) tail(end(ranges(x)), 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
269 granges.dna <- GRanges(seqnames=v.seqnames,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
270 ranges=IRanges(start=v.start, end=v.end))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
271 # Obtain mRNA(including flanking) length for each gene.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
272 repr.lens <- sapply(granges.dat, function(g) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
273 sum(end(g) - start(g) + 1)
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 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
276 v.seqnames <- as.character(seqnames(granges.dat))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
277 v.start <- start(granges.dat)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
278 v.end <- end(granges.dat)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
279 granges.dna <- granges.dat
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
280 repr.lens <- v.end - v.start + 1
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
281 granges.dat <- vector('list', length(granges.dna)) # set null tags.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
282 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
283
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
284 # Filter transcripts whose chromosomes do not match bam file.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
285 inbam.mask <- as.character(seqnames(granges.dna)) %in% sn.inbam
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
286 if(!any(inbam.mask)) { # none matches.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
287 return(genZeroList(length(granges.dna), repr.lens))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
288 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
289
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
290 # scanBamWhat: the info that need to be extracted from a bam file.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
291 sbw <- c('pos', 'qwidth', 'mapq', 'strand', 'rname',
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
292 'mrnm', 'mpos', 'isize')
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
293 sbp <- ScanBamParam(what=sbw, which=granges.dna[inbam.mask],
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
294 flag=scanBamFlag(isUnmappedQuery=F,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
295 isNotPassingQualityControls=F,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
296 isDuplicate=F))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
297
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
298 # Scan bam file to retrieve short reads.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
299 sr.in.ranges <- tryCatch(scanBam(bam.file, param=sbp), error=function(e) e)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
300 if(class(sr.in.ranges)[1] == 'simpleError') {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
301 # This is not supposed to happen after those unmatched seqnames are
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
302 # removed. I keep it for safty.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
303 return(genZeroList(length(granges.dna), repr.lens))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
304 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
305
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
306 # Restore the original order.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
307 sr.in.ranges <- sr.in.ranges[scanBamRevOrder(
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
308 as.data.frame(granges.dna[inbam.mask]), sbp)]
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 CalcReadsCov <- function(srg, start, end, gr.rna, repr.len, strand) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
311 # Calculate short read coverage for each gene/region.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
312 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
313 # srg: extracted short reads in gene.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
314 # start: start position of the DNA sequence.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
315 # end: end position of the DNA sequence.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
316 # gr.rna: GRanges object (multiple ranges) representing exon sequences.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
317 # This can be NULL indicating the input ranges are DNAs.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
318 # repr.len: DNA or mRNA sequence length.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
319 # strand: transcript strand (+/-).
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
320 # Returns: a coverage vector for the gene.
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 # browser()
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
323 # Special handling for bowtie mapping.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
324 if(bowtie) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
325 srg <- within(srg, mapq[is.na(mapq)] <- 254) # within!
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
326 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
327 # Filter short reads by mapping quality.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
328 all.mask <- srg$mapq >= map.qual
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
329
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
330 # Subset by strand info.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
331 if(strand.spec != 'both') {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
332 if(strand.spec == 'same') {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
333 s.mask <- srg$strand == as.character(strand)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
334 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
335 s.mask <- srg$strand != as.character(strand)
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 all.mask <- all.mask & s.mask
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
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
340 # If paired, filter reads that are not properly paired.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
341 paired <- all(with(srg, is.na(isize) | isize != 0))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
342 if(paired) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
343 p.mask <- with(srg, rname == mrnm & xor(strand == '+', isize < 0))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
344 all.mask <- all.mask & p.mask
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
345 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
346
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
347 # Apply all the filters on short reads.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
348 srg <- lapply(srg, `[`, which(all.mask))
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 # Calculate coverage.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
351 if(length(srg[[1]]) > 0) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
352 if(paired) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
353 cov.pos <- with(srg, ifelse(isize < 0, mpos, pos))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
354 cov.wd <- abs(srg$isize)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
355 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
356 # Adjust negative read positions for physical coverage.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
357 cov.pos <- with(srg, ifelse(strand == '-',
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
358 pos - fraglen + qwidth, pos))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
359 cov.wd <- fraglen
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
360 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
361 # Shift reads by subtracting start positions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
362 cov.pos <- cov.pos - start + 1
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
363 # Calculate physical coverage on the whole genebody.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
364 covg <- coverage(IRanges(start=cov.pos, width=cov.wd),
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
365 width=end - start + 1, method='sort')
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 if(!is.null(gr.rna)) { # RNA-seq.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
368 # Shift exonic ranges by subtracting start positions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
369 # BE careful with negative start positions! Need to adjust end
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
370 # positions first(or the GRanges lib will emit errors if
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
371 # start > end).
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
372 # Negative start positions happen when flanking region exceeds
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
373 # the chromosomal start.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
374 if(start > 0) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
375 start(gr.rna) <- start(gr.rna) - start + 1
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
376 end(gr.rna) <- end(gr.rna) - start + 1
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
377 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
378 end(gr.rna) <- end(gr.rna) - start + 1
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
379 start(gr.rna) <- start(gr.rna) - start + 1
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
380 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
381 # Concatenate all exon coverages.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
382 covg[ranges(gr.rna)]
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
383 } else { # ChIP-seq.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
384 covg
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 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
387 Rle(0, repr.len)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
388 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
389 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
390
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
391 covg.allgenes <- mapply(CalcReadsCov, srg=sr.in.ranges,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
392 start=v.start, end=v.end, gr.rna=granges.dat,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
393 repr.len=repr.lens, strand=v.strand, 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
394 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
395
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
396 bamFileList <- function(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
397 # Determine the bam files involved in the configuration and whether it is a
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
398 # bam file pair setup.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
399 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
400 # ctg.tbl: coverage-genelist-title table.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
401
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
402 cov.uniq <- unique(ctg.tbl$cov)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
403 cov.list <- strsplit(cov.uniq, ':')
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
404 v.nbam <- sapply(cov.list, length)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
405 v.bbp <- v.nbam == 2
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
406 if(all(v.bbp)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
407 bbp <- T
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(all(!v.bbp)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
409 bbp <- F
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
410 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
411 stop("No mix of bam and bam-pair allowed in configuration.\n")
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
412 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
413
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
414 list(bbp=bbp, bam.list=unique(unlist(cov.list)))
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 estiMapqStyle <- function(bam.file){
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
418 # Estimate the mapping quality style. Return TRUE if it is SAM standard.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
419 # Sample 1000 mapped reads from bam file, and if the mapq of reads
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
420 # over half are NA, then return FALSE, because it is quite possible that
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
421 # the aligner using coding style as bowtie, 255 as highest score.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
422 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
423 # bam.file: bam file to be sampled.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
424
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
425 sbw <- c('pos', 'qwidth', 'mapq', 'strand')
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
426 sbp <- ScanBamParam(what=sbw, flag=scanBamFlag(
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
427 isUnmappedQuery=F, isDuplicate=F))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
428 samp <- BamSampler(bam.file, yieldSize=500)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
429 samp.reads <- scanBam(samp, param=sbp)[[1]]
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
430 samp.len <- length(samp.reads[["mapq"]])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
431 mapq.255 <- sum(is.na(samp.reads[["mapq"]]))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
432 if(mapq.255/samp.len >= 0.5){
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
433 return(FALSE)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
434 }else{
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
435 return(TRUE)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
436 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
437 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
438
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
439 headerIndexBam <- function(bam.list) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
440 # Read bam header to determine mapping method.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
441 # Index bam files if not done yet.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
442 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
443 # ctg.tbl: coverage-genelist-title table.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
444
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
445 v.map.bowtie <- vector('logical', length=length(bam.list))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
446 for(i in 1:length(bam.list)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
447 bam.file <- bam.list[i]
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
448
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
449 # Index bam file.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
450 if(!file.exists(paste(bam.file, ".bai", sep=""))) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
451 indexBam(bam.file)
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
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
454 # Derive mapping program.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
455 header <- scanBamHeader(bam.file)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
456 map.prog <- try(strsplit(header[[1]]$text$'@PG'[[1]], ':')[[1]][2],
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
457 silent=T)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
458 if(class(map.prog) != "try-error") {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
459 map.style <- grepl('tophat|bowtie|bedtools|star', map.prog,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
460 ignore.case=T)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
461 if(map.style){
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
462 v.map.bowtie[i] <- TRUE
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
463 next
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
464 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
465 map.style <- grepl('bwa|casava|gem', map.prog, ignore.case=T)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
466 if(map.style) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
467 v.map.bowtie[i] <- FALSE
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
468 next
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 # if(estiMapqStyle(bam.file)){
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
471 # warning(sprintf("Aligner for: %s cannot be determined. Style of
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
472 # standard SAM mapping score will be used.", bam.file))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
473 # v.map.bowtie[i] <- FALSE
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
474 # }else{
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
475 # warning(sprintf("Aligner for: %s cannot be determined. Style of
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
476 # Bowtie-like SAM mapping score will be used. Would you mind to tell us what
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
477 # aligner you are using?", bam.file))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
478 # v.map.bowtie[i] <- TRUE
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
479 # }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
480 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
481 # else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
482 # cat("\n")
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
483 # if(estiMapqStyle(bam.file)){
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
484 # warning(sprintf("Aligner for: %s cannot be determined. Style of
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
485 # standard SAM mapping score will be used.", bam.file))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
486 # v.map.bowtie[i] <- FALSE
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
487 # }else{
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
488 # warning(sprintf("Aligner for: %s cannot be determined. Style of
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
489 # Bowtie-like SAM mapping score will be used.", bam.file))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
490 # v.map.bowtie[i] <- TRUE
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
491 # }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
492 # }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
493 warning(sprintf("Aligner for: %s cannot be determined. Style of
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
494 standard SAM mapping score will be used. Would you mind submitting an issue
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
495 report to us on Github? This will benefit people using the same aligner.",
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
496 bam.file))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
497 v.map.bowtie[i] <- FALSE
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
498 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
499 names(v.map.bowtie) <- bam.list
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
500
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
501 v.map.bowtie
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
502 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
503
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
504 libSizeBam <- function(bam.list) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
505 # Obtain library sizes by counting qualified bam records.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
506 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
507 # ctg.tbl: coverage-genelist-title table.
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 # Count only reads that are mapped, primary, passed quality control and
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
510 # un-duplicated.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
511 sbp <- ScanBamParam(flag=scanBamFlag(isUnmappedQuery=F, isSecondaryAlignment=F,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
512 isNotPassingQualityControls=F, isDuplicate=F))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
513 v.lib.size <- vector('integer', length=length(bam.list))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
514 for(i in 1:length(bam.list)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
515 bfn <- bam.list[i] # bam file name.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
516 cfn <- paste(basename(bfn), '.cnt', sep='') # count file name.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
517 if(file.exists(cfn)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
518 v.lib.size[i] <- as.integer(readLines(cfn, 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
519 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
520 cnt.bam <- countBam(bfn, param=sbp)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
521 v.lib.size[i] <- cnt.bam$records
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
522 writeLines(as.character(v.lib.size[i]), cfn)
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 names(v.lib.size)[i] <- bfn
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
525 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
526
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
527 v.lib.size
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
528 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
529
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
530 seqnamesBam <- function(bam.list) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
531 # Obtain chromosome names for each bam file. This list must be used to filter
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
532 # genomic regions before scanBam or it terminates immaturely.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
533 # ctg.tbl: coverage-genelist-title table.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
534
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
535 # browser()
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
536 sn.list <- lapply(scanBamHeader(bam.list), function(h) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
537 names(h$targets)
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 names(sn.list) <- bam.list
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
540
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
541 sn.list
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
542 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
543
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
544 chrTag <- function(sn.inbam) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
545 # Check whether the chromosome name format in the bam file contains 'chr' or not.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
546 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
547 # sn.inbam: seqnames in the bam file.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
548
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
549 n.chr <- length(grep('^chr', sn.inbam))
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(n.chr == 0) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
551 chr.tag <- F
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 if(n.chr == length(sn.inbam)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
553 chr.tag <- T
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
554 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
555 return("Inconsistent chromosome names in bam file. Check bam header.")
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
556 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
557
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
558 chr.tag
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 chunkIndex <- function(tot.gene, gcs) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
562 # Create chunk indices according to total number of genes and chunk size.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
563 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
564 # tot.gene: total number of genes.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
565 # gcs: gene chunk size.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
566
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
567 nchk <- ceiling(tot.gene / gcs) # number of chunks.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
568 chkidx.list <- vector('list', length=nchk) # chunk indices list.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
569 chk.start <- 1 # chunk start.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
570 i.chk <- idiv(tot.gene, chunkSize=gcs)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
571 for(i in 1:nchk) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
572 chk.size <- nextElem(i.chk)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
573 chkidx.list[[i]] <- c(chk.start, chk.start + chk.size - 1)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
574 chk.start <- chk.start + chk.size
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
575 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
576
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
577 chkidx.list
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
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
580 covMatrix <- function(debug, chkidx.list, coord, rnaseq.gb, exonmodel, libsize,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
581 spit.dot=T, ...) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
582 # Function to generate a coverage matrix for all genes.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
583 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
584 # debug: boolean tag for debugging.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
585 # chkidx.list: list of (start, end) indices for each chunk.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
586 # coord: dataframe of gene coordinates.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
587 # rnaseq.gb: boolean for RNA-seq genebody plot.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
588 # exonmodel: exon model data object.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
589 # libsize: total read count for this bam file.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
590 # spit.dot: boolean to control sptting '.' to consoles.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
591 # Return: normalized coverage matrix for all genes, each row represents a gene.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
592
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
593
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
594 if(!debug) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
595 # Extract coverage and combine into 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
596 result.matrix <- foreach(chk=chkidx.list, .combine='rbind',
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
597 .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
598 if(spit.dot) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
599 cat(".")
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 i <- chk[1]:chk[2] # chunk: start -> end
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
602 # If RNA-seq, retrieve exon ranges.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
603 if(rnaseq.gb) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
604 exonranges.list <- unlist(exonmodel[coord[i, ]$tid])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
605 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
606 exonranges.list <- NULL
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 doCov(coord[i, ], exonranges.list, ...)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
609 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
610
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
611 # Floor negative values which are caused by spline.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
612 result.matrix[result.matrix < 0] <- 0
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
613 result.matrix / libsize * 1e6 # normalize to RPM.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
614
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
615 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
616 for(c in 1:length(chkidx.list)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
617 chk <- chkidx.list[[c]]
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
618 i <- chk[1]:chk[2] # chunk: start -> end
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
619 cat(".")
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 RNA-seq, retrieve exon ranges.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
621 if(rnaseq.gb) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
622 exonranges.list <- unlist(exonmodel[coord[i, ]$tid])
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
623 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
624 exonranges.list <- NULL
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
625 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
626 cov <- doCov(coord[i, ], exonranges.list, ...)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
627 if(c == 1) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
628 result.matrix <- matrix(0, nrow=nrow(coord), ncol=ncol(cov))
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 result.matrix[i, ] <- cov
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 # Floor negative values which are caused by spline.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
633 # browser()
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
634 result.matrix[result.matrix < 0] <- 0
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
635 result.matrix / libsize * 1e6 # normalize to RPM.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
636
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
637 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
638 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
639
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
640
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
641 doCov <- function(coord.mat, exonranges.list, chr.tag, pint, reg2plot,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
642 flanksize, flankfactor, m.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
643 # Extract coverage from bam file into a matrix. According to the parameter
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
644 # values, call corresponding functions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
645 # Args:
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
646 # coord.mat: matrix of genomic coordinates to extract coverage.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
647 # exonranges.list: list of IRanges objects, each represents a group of exons.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
648 # pint: boolean of 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
649 # reg2plot: string of region to plot.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
650 # flanksize: flanking region size.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
651 # 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
652 # m.pts: data points for middle interval.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
653 # f.pts: data points for flanking region.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
654 # Return: matrix of interpolated coverage: each row represents a gene; each
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
655 # column represents a data point. Coverage from exons are concatenated.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
656
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
657 v.chrom <- coord.mat$chrom
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
658 # if(!chr.tag) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
659 # v.chrom <- sub('chr', '', v.chrom)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
660 # }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
661 v.chrom <- as.factor(v.chrom)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
662 v.strand <- as.factor(coord.mat$strand)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
663
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
664 # Figure out interval region sizes and calculate flanking region sizes.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
665 if(!pint) { # interval regions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
666 if(!is.null(exonranges.list)) { # RNA-seq
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
667 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
668 v.fls <- sapply(exonranges.list, function(t) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
669 sum(end(t) - start(t) + 1) * flankfactor
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
670 })
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
671 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
672 v.fls <- rep(flanksize, length=nrow(coord.mat))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
673 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
674 extrCovExons(v.chrom, exonranges.list, v.fls, v.strand,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
675 m.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
676 } else { # ChIP-seq with intervals.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
677 v.start <- coord.mat$start
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
678 v.end <- coord.mat$end
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
679 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
680 v.fls <- round((v.end - v.start + 1) * flankfactor)
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
681 } else {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
682 v.fls <- rep(flanksize, length=nrow(coord.mat))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
683 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
684 extrCov3Sec(v.chrom, v.start, v.end, v.fls, v.strand,
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
685 m.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
686 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
687 } else { # point center with flanking regions.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
688 v.midp <- vector('integer', length=nrow(coord.mat))
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
689 for(r in 1:nrow(coord.mat)) {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
690 if(reg2plot == 'tss' && v.strand[r] == '+' ||
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
691 reg2plot == 'tes' && v.strand[r] == '-') {
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
692 # the left site is center.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
693 v.midp[r] <- coord.mat$start[r]
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
694 } else { # this also includes BED supplied point center.
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
695 v.midp[r] <- coord.mat$end[r]
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
696 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
697 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
698 # browser()
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
699 extrCovMidp(v.chrom, v.midp, flanksize, v.strand, m.pts + f.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
700 }
3ca58369469c planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/ngsplot commit b'e9fcc157a7f2f2fa9d6ac9a58d425ff17c975f5c\n'
artbio
parents:
diff changeset
701 }