Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. library(cobs)
  2. library(quantreg)
  3. library(parallel)
  4. library(gplots)
  5.  
  6. interpolate<-function(dat,curve){
  7.  
  8. interpolate_points<-function(row,dat,curve){
  9. MY_X=dat[row,1]
  10. MY_Y=dat[row,2]
  11. VAL1=tail(which(curve[,1]<MY_X),1)
  12. VAL2=VAL1+1
  13. X <- curve[c(VAL1,VAL2),1]
  14. Y <- curve[c(VAL1,VAL2),2]
  15. INTERP_Y=approx(X,Y,xout=MY_X)$y
  16. INTERP_Y
  17. }
  18. res<-unlist(mclapply(seq(nrow(dat)),interpolate_points,dat=dat,curve=curve,mc.cores=8))
  19. res
  20. }
  21.  
  22. ################################################
  23. # 1Mbp bins
  24. ################################################
  25. x<-read.table("SRP199233.1e6_fmt.tsv",header=T,row.names=1)
  26. x<-x[which(rowSums(x)>=10),]
  27. x<-sweep(x, 2, colSums(x), FUN="/")*1000000
  28. mysd<-apply(x,1,sd)
  29. mean<-apply(x,1,mean)
  30. y<-data.frame(log10(mean),mysd/mean)
  31. colnames(y)=c("logMean","cv")
  32. Rbs.9 <- cobs(y$logMean,y$cv, nknots=20,constraint="none",tau=0.99)
  33. Rbs.median <- cobs(y$logMean,y$cv,nknots=20,constraint="none",tau=0.5)
  34. pred<-data.frame(predict(Rbs.9))
  35.  
  36. y$interpolated<-interpolate(y,pred)
  37. y$diff=y$cv-y$interpolated
  38. yy <- y[which(y$diff>0.05),]
  39. yy <- yy[order(-yy$diff),]
  40.  
  41. write.table(yy,file="SRP199233.1e6_regions.tsv")
  42.  
  43. png("plots/SRP199233.1e6_cv.png",height=960,width=960)
  44. plot(y$logMean,y$cv,pch=18,cex=0.5,xlab="log10(mean)",ylab="CV")
  45. lines(predict(Rbs.9), col = "red", lwd = 1.0)
  46. lines(predict(Rbs.median), col = "blue", lwd = 1.0)
  47. points(yy$logMean,yy$cv)
  48. text(yy$logMean,yy$cv+0.02,labels=rownames(yy),cex=0.8)
  49. dev.off()
  50.  
  51. png("plots/SRP199233.1e6_hm1.png",height=960,width=960)
  52. my_palette <- colorRampPalette(c("blue", "white", "red"))(n = 25)
  53. zz<-x[which(rownames(x) %in% rownames(yy)),]
  54. heatmap.2(as.matrix(zz),margin=c(8, 22),cexRow=0.65,trace="none",
  55. cexCol=0.8,col=my_palette,scale="row")
  56. dev.off()
  57.  
  58. png("plots/SRP199233.1e6_hm2.png",height=960,width=960)
  59. heatmap.2(cor(t(zz)),trace="none",scale="none",margins=c(12,12),
  60. cexRow=0.8, cexCol=0.8)
  61. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement