Mercurial > repos > xuebing > sharplabtool
comparison tools/mytools/genomeview_notused @ 0:9071e359b9a3
Uploaded
author | xuebing |
---|---|
date | Fri, 09 Mar 2012 19:37:19 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9071e359b9a3 |
---|---|
1 | |
2 caloffset = function(genome){ | |
3 total_len = sum(as.numeric(genome[,2])) | |
4 offset = 0 | |
5 for (i in 1:nrow(genome)) { | |
6 offset = c(offset,offset[i]+genome[i,2]) | |
7 } | |
8 offset | |
9 } | |
10 | |
11 coverage = function(intervals,genome,offset,resolution) { | |
12 | |
13 nChr = length(offset) - 1 | |
14 total_len = offset[nChr+1] | |
15 nbin = as.integer(total_len / resolution) | |
16 | |
17 pos = numeric(0) | |
18 cov = numeric(0)#coverage | |
19 col = numeric(0)#color | |
20 for (i in 1:nChr) { | |
21 d = x[x[,1]==as.character(genome[i,1]),2:3] | |
22 d = ceiling(((d[,1]+d[,2])/2+offset[i])*nbin/total_len) | |
23 t = table(d) | |
24 pos = c(pos,as.numeric(row.names(t))) | |
25 cov = c(cov, as.numeric(t)) | |
26 col = c(col,numeric(length(t))+i) | |
27 } | |
28 list(nbin=nbin,pos=pos,cov=cov,col=col) | |
29 } | |
30 | |
31 # plot coverage | |
32 # res = genomeView(x,genome,100000) | |
33 plotcov = function(res,genome,offset,title,uselog) { | |
34 if (uselog == 'log'){ | |
35 res$cov = log10(res$cov+1) | |
36 } | |
37 ymax = max(res$cov) | |
38 par(mar=c(5,5,5,1)) | |
39 plot(res$pos,res$cov,type='h',cex=0.1,cex.axis=2,cex.lab=2,cex.main=3,col=res$col,xaxt='n',main=title,xlab='chromosome',ylab='coverage',frame.plot=F,xlim=c(0,res$nbin),ylim=c(0,ymax)) | |
40 xticks = numeric(nrow(genome)) | |
41 for (i in 1:nrow(genome)){ | |
42 xticks[i] = (offset[i]+offset[i+1])/2*res$nbin/offset[length(offset)] | |
43 } | |
44 mtext(genome[,1],side=1,at=xticks,adj=1,las=2,col=seq(nrow(genome))) | |
45 } |