Guest User

Untitled

a guest
Oct 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. ###### FROM BEFORE, FIND THIS SECTION
  2.  
  3. Index = which(pns %in% keep_pns)
  4. newP = p[Index,]
  5. newchr=chr[Index];newpos=pos[Index]
  6. newpns = clusterMaker(newchr,newpos)
  7. cat("\n")
  8.  
  9. ###############
  10. # NEW BELOW - ADD
  11.  
  12. coi = pd$Age # what I'm trying, not sure what youre looking at
  13. # make groups into factors
  14. if(is.character(coi) | is.factor(coi)) {
  15. groups = factor(coi)
  16. gNames= levels(groups)
  17. }
  18. gIndexes=split(1:length(groups),groups)
  19.  
  20. coiName = "Aging"
  21. plotGaps=1e6
  22.  
  23. outPath = getwd()
  24.  
  25.  
  26.  
  27. #############################
  28. # covariate info
  29. cat("Averaging Methylation in Probe Groups.")
  30.  
  31. Indexes = splitit(newpns)
  32. expMat = matrix(nr = length(Indexes), nc = length(coi))
  33. colnames(expMat) = colNames(newP)
  34.  
  35. for(i in seq(along=Indexes)) {
  36. if(i %% 10000 == 0) cat(".")
  37. Index = Indexes[[i]]
  38. if(length(Index) > 1) {
  39. expMat[i,] = colMeans(newP[Index,])
  40. } else {
  41. expMat[i,] = as.numeric(newP[Index,])
  42. }
  43. }
  44.  
  45. cat("\n")
  46. # make stuff to loop over
  47. chrIndexes = sort(unique(newchr))
  48. # chrIndexes = chrIndexes[-grep("random",chrIndexes)]
  49. # chrIndexes = chrIndexes[-grep("chrM",chrIndexes)]
  50.  
  51. ##########
  52. # make some plots
  53. cat("plotting","\n")
  54. pdf(paste(outPath,"/",coiName,"_blocks.pdf",sep=""),
  55. height = 6, width = 16)
  56. mypar(1,1)
  57.  
  58. for(i in 1:length(chrIndexes)) {
  59. Index = which(newMat$chr %in% chrIndexes[i])
  60. tmp = newMat[Index,]
  61. ppos = rowMeans(tmp[,2:3])
  62. tmpp = expMat[Index,]
  63.  
  64. # do the centomeres? or just break it up
  65. cc = clusterMaker(tmp$chr,ppos,maxGap = plotGaps)
  66. Indexes = splitit(cc)
  67. for(j in seq(along=Indexes)) {
  68. Index2 = Indexes[[j]]
  69. if(length(Index2) > 20) {
  70. xx = ppos[Index2]
  71. pp = tmpp[Index2,]
  72. matplot(x = xx, y = pp,type = "p",
  73. col = as.numeric(factor(coi)), pch = 19, cex = 0.7,
  74. xlab = "position", ylab = "methylation",
  75. main = paste(chrIndexes[i], "- chunk",
  76. names(Indexes)[j]), ylim = c(0,1))
  77. for(k in seq(along = gIndexes)) {
  78. if(length(gIndexes[[k]]) == 1) yy=pp[,gIndexes[[k]]]
  79. if(length(gIndexes[[k]]) > 1) yy=rowMeans(pp[,gIndexes[[k]]])
  80. fit1=loess(yy~xx,degree=1,span=0.2, family="symmetric")
  81. lines(xx,fit1$fitted,col=k,lwd=2)
  82. }
  83. legend("topleft",legend=gNames,col=1:length(gNames),
  84. lty=1, lwd = 4,cex=1)
  85. }
  86. }
  87. }
  88. dev.off()
Add Comment
Please, Sign In to add comment