Guest User

Untitled

a guest
Feb 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. # from "test_exp_raw" file.
  2. # first - identify those problematic samples and delete
  3.  
  4. source("quant_assist.R")
  5. ## note: higher level functions are depreciated here,
  6. ## since being straight is more than being neat.
  7.  
  8. # load raw file SRRX*SYM
  9. exp_raw <- read_rds('test_exp_raw.rds')
  10. m_raw <- read_rds('test_m_raw.rds')
  11.  
  12. # load the smaple dictionary
  13. homo <- read_rds("srr_withgtfs.rds")
  14. h <- homo %>% dplyr::select(wecall, sra_acc)
  15. h$source_abbr <- mapply(function(a,b) gsub(paste0("_",a), "", b), a = h$sra_acc, b = h$wecall)
  16.  
  17. # split into three matrices
  18. m_ip_raw <- m_raw[h$sra_acc[grepl("_ip_", h$wecall)],]
  19. m_input_raw <- m_raw[h$sra_acc[grepl("_input_", h$wecall)],]
  20.  
  21. # identify the samples to be deleted, e.g. humanBrain
  22. srrs_to_delete <- c('SRR456936','SRR456937')
  23. exp_del <- delete.from.matrix(exp_raw, srrs_to_delete)
  24. m_ip_del <- delete.from.matrix(m_ip_raw, srrs_to_delete)
  25. m_input_del <- delete.from.matrix(m_input_raw, srrs_to_delete)
  26.  
  27. # for display and check by eyes (only differ by 'BR' ids, presumably bio-reps)
  28. # check_abbr(input_rep_srrs)
  29. # check_abbr(ip_rep_srrs)
  30.  
  31. exp_merge <- merge_reps(input_rep_srrs, exp_del, "_input")
  32. ip_merge <- merge_reps(ip_rep_srrs, m_ip_del, "_ip")
  33. input_merge <- merge_reps(input_rep_srrs, m_input_del, "_input")
  34.  
  35. # calculate the methylation level
  36. meth_merge <- log2((ip_merge + 0.01) / (input_merge + 0.01))
  37. Note <- "here the three stored matrices have gone thorough stringtie quantification, reading from gtf files and merging the techreps and bioreps. However these data has not been normalised. Start your journey here!"
  38. save(exp_merge, ip_merge, input_merge, Note, file = "raw_merge.RData")
  39.  
  40.  
  41. ### ---------------- ######
  42. # remove the entire workspace except three matrices
  43. #rm(ls()[!ls() %in% c("meth_merge", "exp_merge")])
  44.  
  45. # filter by mean/sd quantile, and normalize by experiments
  46. meth_norm <- norm_merge(meth_merge, 0.5, 0.25) # dim = 38*31705
  47. exp_norm <- norm_merge(exp_merge, 0.75, 0.75) # dim = 38*16356
  48.  
  49. # merge the sites by expression correlation and physical location
  50.  
  51.  
  52. g <- merge_sites(m = meth_norm, mdict0 = refer_18w, distance_cutoff = 200, cor_cutoff = 0.7)
  53. write_rds(g, "try-graph.rds")
  54. #
  55.  
  56.  
  57. # find the clusters
  58. g <- read_rds("try-graph.rds")
  59.  
  60. # make meth_exp
  61. g_list <- cluster_fast_greedy(g) %>% communities()
  62. single_groupings <- unlist(g_list[lengths(g_list) == 1]) %>% unname()
  63. multi_groupings <- g_list[! lengths(g_list) == 1]
  64. cs <- comb_site(multi_groupings, meth_norm)
  65. ss <- meth_norm[,colnames(meth_norm) %in% single_groupings]
  66. meth_exp <- cbind(cs, ss) %>% reorder
  67.  
  68.  
  69. # make network
  70. met_exp_adj <- adjmake(x = meth_exp, y = exp_norm, quant = 0.05, pcut = 0.01)
  71.  
  72.  
  73.  
  74. # characterize network
  75.  
  76.  
  77. # play with test_exp and test_m
  78. nmf(meth_exp + 18, rank = 3) -> res
Add Comment
Please, Sign In to add comment