annotate help/minfi_pipeline_test.R @ 0:84361ce36a11 draft

planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
author nturaga
date Tue, 19 Apr 2016 11:10:25 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
1 # setup R error handling to go to stderr
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
2 options(show.error.messages=F, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)})
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
3
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
4 # we need that to not crash galaxy with an UTF8 error on German LC settings.
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
5 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
6
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
7 library("getopt")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
8 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
9 args <- commandArgs(trailingOnly = TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
10
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
11 # get options, using the spec as defined by the enclosed list.
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
12 # we read the options from the default: commandArgs(TRUE).
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
13 spec <- matrix(c(
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
14 'quiet', 'q', 2, "logical",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
15 'help' , 'h', 0, "logical",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
16 "preprocess","p",1,"character",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
17 "numPositions","n",2,"integer",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
18 "shrinkVar","s",2,"logical",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
19 "b_permutations","b",2,"integer",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
20 "smooth","m",2,"logical",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
21 "cutoff","t",2,"float",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
22 "l_value","l",2,"integer",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
23 "cores","c",1,"integer")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
24 ,byrow=TRUE, ncol=4)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
25 opt <- getopt(spec)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
26
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
27
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
28 # If help was asked for print a friendly message
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
29 # and exit with a non-zero error code
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
30 if (!is.null(opt$help)) {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
31 cat(getopt(spec, usage=TRUE))
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
32 q(status=1)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
33 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
34
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
35
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
36 ## Set verbose mode
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
37 verbose = if(is.null(opt$quiet)){TRUE}else{FALSE}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
38 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
39 cat("Verbose mode is ON\n\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
40 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
41
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
42 # Enforce the following required arguments
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
43 if (is.null(opt$preprocess)) {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
44 cat("'preprocess' is required\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
45 q(status=1)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
46 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
47
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
48 # Load required libraries
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
49
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
50 suppressPackageStartupMessages({
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
51 library("minfi")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
52 library("FlowSorted.Blood.450k")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
53 library("doParallel")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
54 library("TxDb.Hsapiens.UCSC.hg19.knownGene")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
55 })
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
56
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
57
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
58 ## Parse cheetah code and make dataframe for creating tmp dir
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
59 minfi_config_file = "/Users/nturaga/Documents/workspace/minfi_galaxy/galaxy/database/job_working_directory/000/43/minfi_temp/minfi_config.txt"
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
60 minfi_config = read.table(minfi_config_file)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
61 colnames(minfi_config) = c("status","green","red","name")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
62
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
63 if ( verbose ) {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
64 cat("Minfi configuration file:\n\n ");
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
65 print(minfi_config)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
66 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
67
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
68 ## Make the tmpdir for symlinking data
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
69 base_dir = paste0("/Users/nturaga/Documents/workspace/minfi_galaxy/galaxy/database/job_working_directory/000/73/minfi_temp","/base")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
70
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
71
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
72 ### Make symlinks of files
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
73 #for (i in 1:nrow(minfi_config)){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
74 #stopifnot(nrow(minfi_config) == nrow(minfi_config["name"]))
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
75
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
76 ### Make green idat file symlinks
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
77 #file_green = paste0(base_dir,"/",as.character(minfi_config[i,"name"]),"_Grn.idat")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
78 #cmd_green = paste("ln -s",as.character(minfi_config[i,"green"]),file_green,sep=" ")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
79 #cat("Reading file ",i,"GREEN Channel ", file_green)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
80 #system(cmd_green)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
81
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
82 ### Make red idat file symlinks
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
83 #file_red = paste0(base_dir,"/",as.character(minfi_config[i,"name"]),"_Red.idat")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
84 #cmd_red = paste("ln -s",as.character(minfi_config[i,"red"]),file_red,sep=" ")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
85 #cat("Reading file ",i,"RED Channel ", file_red)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
86 #system(cmd_red)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
87 #}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
88
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
89 ## Make dataframe with Basenames
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
90 Basename = paste0(base_dir,"/",unique(substr(list.files(base_dir),1,17)))
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
91 status = minfi_config[match(gsub(".+/","",Basename), minfi_config$name),"status"]
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
92 targets = data.frame(Basename=Basename,status=status)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
93
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
94 if ( verbose ) {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
95 cat("Minfi targets file:\n\n ")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
96 print(targets)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
97 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
98
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
99 ## Read 450k files
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
100 RGset = read.450k.exp(targets=targets,verbose=FALSE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
101
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
102 if (verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
103 cat("RGset has been read: \n\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
104 print(RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
105 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
106
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
107
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
108 ## Preprocess data with the normalization method chosen
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
109 if(opt$preprocess == "quantile"){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
110 normalized_RGset = preprocessQuantile(RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
111 if (verbose){cat("Preprocessed using Quantile normalization")};
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
112 } else if (opt$preprocess == "noob"){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
113 normalized_RGset = preprocessNoob(RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
114 if (verbose){cat("Preprocessed using Noob normalization")};
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
115 } else if (opt$preprocess == "raw"){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
116 normalized_RGset = preprocessRaw(RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
117 if (verbose){print("Preprocessed using Raw normalization")};
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
118 } else if (opt$preprocess == "illumina"){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
119 normalized_RGset = preprocessIllumina(RGset,bg.correct = TRUE, normalize = c("controls", "no"),reference = 1)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
120 if(verbose){print("Preprocessed using Illumina normalization")}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
121 } else if (opt$preprocess == "preprocessFunnorm"){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
122 normalized_RGset = preprocessFunnorm(RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
123 if(verbose){print("Preprocessed using Functional normalization")}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
124 } else {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
125 normalized_RGset = RGset
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
126 if(verbose){print("Preprocessed using NO normalization")}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
127 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
128
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
129
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
130 ## Get beta values from Proprocessed data
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
131 beta = getBeta(normalized_RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
132 ## Set phenotype data
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
133 pd=pData(normalized_RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
134
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
135
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
136 ## QC REPORT
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
137 files = gsub(".+/","",pd$filenames)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
138 ## Produce PDF file
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
139 if (!is.null(RGset)) {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
140 # Make PDF of QC report
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
141 minfi::qcReport(rgSet=RGset,sampNames=files,sampGroups=pd$status,pdf="qc_report.pdf")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
142 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
143
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
144 ## MDS Plot
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
145 ## Set phenotype data
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
146 files = gsub(".+/","",pd$filenames)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
147
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
148 ## Produce PDF file
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
149 if (!is.null(RGset)) {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
150 ## Make PDF of density plot
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
151 pdf("mds_plot.pdf")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
152 minfi::mdsPlot(dat=RGset,sampNames=files,sampGroups=pd$status,main="Beta MDS",numPositions = opt$numPositions,pch=19)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
153 dev.off()
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
154 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
155
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
156
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
157 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
158 cat("Made plot of QC report and MDS plot\n\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
159 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
160
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
161
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
162 #Estimate Cell counts
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
163 #if(!is.null(RGset)){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
164 #cell_counts = minfi::estimateCellCounts(rgSet=RGset,meanPlot=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
165 #write.csv(cell_counts,file="estimated_cell_counts.csv",quote=FALSE,row.names=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
166 #}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
167 #if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
168 #cat("Cell Counts estimated\n\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
169 #}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
170
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
171 ## DMP finder
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
172 dmp = dmpFinder(dat=beta,pheno=pd$status,type="categorical",shrinkVar=opt$shrinkVar)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
173 write.csv(dmp,file="dmps.csv",quote=FALSE,row.names=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
174 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
175 cat("DMP Finder successful \n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
176 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
177
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
178
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
179 # Model Matrix to pass into the bumphunter function
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
180 pd=pData(normalized_RGset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
181 T1= levels(pd$status)[2]
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
182 T2= levels(pd$status)[1]
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
183
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
184 stopifnot(T1!=T2)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
185 keep=pd$status%in%c(T1,T2)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
186 tt=factor(pd$status[keep],c(T1,T2))
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
187 design=model.matrix(~tt)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
188
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
189 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
190 cat("Model matrix is: \n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
191 design
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
192 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
193
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
194 # Start bumphunter in a parallel environment
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
195 # Parallelize over cores on machine
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
196 registerDoParallel(cores = opt$cores)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
197
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
198 ## Bumphunter Run with normalized_RGset processed with Quantile Normalization
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
199
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
200 res=bumphunter(normalized_RGset[,keep],design,B=opt$b_permutations,smooth=opt$smooth,cutoff= opt$cutoff,type="Beta")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
201 bumps= res$tab
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
202
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
203 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
204 cat("Bumphunter result", "\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
205 head(bumps)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
206 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
207
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
208 ## Choose DMR's of a certain length threshold.
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
209 ## This helps reduce the size of DMRs early, and match
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
210 ## with genes closest to region
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
211 bumps = bumps[bumps$L>opt$l_value,]
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
212 genes <- annotateTranscripts(TxDb.Hsapiens.UCSC.hg19.knownGene)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
213 tab=matchGenes(bumps,genes)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
214 result=cbind(bumps,tab)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
215
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
216 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
217 cat("Match with annotation\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
218 head(result)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
219 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
220
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
221 # Save result, which contains DMR's and closest genes
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
222 write.csv(result,file = "dmrs.csv",quote=FALSE,row.names=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
223
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
224 # Garbage collect
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
225 gc()
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
226
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
227 # Block finder
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
228 #library(sva)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
229 #pheno <- pData(GRset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
230 #mod <- model.matrix(~as.factor(status), data=pheno)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
231 #mod0 <- model.matrix(~1, data=pheno)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
232 #sva.results <- sva(mval, mod, mod0)