annotate minfi_TCGA_pipeline.R @ 1:a78f84fc4873 draft default tip

planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
author nturaga
date Tue, 19 Apr 2016 12:20:29 -0400
parents 84361ce36a11
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 'tarfile','f',1,"character",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
17 "cores","c",1,"integer",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
18 "b_permutations","b",2,"integer",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
19 "smooth","m",2,"logical",
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
20 "l_value","l",2,"integer")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
21 ,byrow=TRUE, ncol=4)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
22 opt <- getopt(spec)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
23
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
24 ## If help was asked for print a friendly message
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
25 ## and exit with a non-zero error code
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
26 if (!is.null(opt$help)) {
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
27 cat(getopt(spec, usage=TRUE))
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
28 q(status=1)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
29 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
30
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
31
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
32 ## Set verbose mode
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
33 verbose = if(is.null(opt$quiet)){TRUE}else{FALSE}
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
34 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
35 cat("Verbose mode is ON\n\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
36 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
37
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
38 ## Load required libraries
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
39 suppressPackageStartupMessages({
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
40 library("minfi")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
41 library("FlowSorted.Blood.450k")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
42 library("TxDb.Hsapiens.UCSC.hg19.knownGene")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
43 library("doParallel")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
44 library("tools")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
45 })
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 config_file = "tcga_temp/config.txt"
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
49 conf = read.csv(config_file,stringsAsFactors=FALSE,header=F)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
50 tarfile_name = gsub(".+/","",conf$V2)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
51 dataset_path = conf$V1
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
52
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
53 cmd = paste("ln -s",dataset_path,tarfile_name,sep=" ")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
54 cat("Command : ", cmd,"\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
55 system(cmd)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
56
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
57 tarfile = tarfile_name
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
58 cat ("tarfile name: ",tarfile," file ext: ",file_ext(tarfile))
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
59 ## UNtar files in R first
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
60 if (file_ext(tarfile) == "tar"){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
61 cat("Entering IF statment")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
62 tar_contents = untar(tarfile,list=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
63 cat("regex failing here")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
64 f = as.character(tar_contents[grep(".data.txt",fixed=TRUE,x=tar_contents)])
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
65 if (!is.null(f)){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
66 cat("Untar being attempted")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
67 untar(tarfile, exdir = ".",files=f)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
68 cat("Untar succcess")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
69 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
70 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
71 ## Move file from sub directory to main directory
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
72 from = list.files(pattern=".data.txt",recursive=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
73 to = gsub(".+/","",from)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
74 rename_success = file.rename(from=from, to=to)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
75
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
76
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
77 # This should pass only if steps have been successful
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
78 stopifnot(rename_success)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
79 if (rename_success){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
80 input_file = to
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
81 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
82
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
83 ### Read the TCGA data
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
84 GRset = readTCGA(input_file, sep = "\t", keyName = "Composite Element REF", Betaname = "Beta_value", pData = NULL, array = "IlluminaHumanMethylation450k",showProgress=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
85
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
86 ### Get beta values
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
87 beta = getBeta(GRset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
88 pd = pData(GRset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
89 CN = getCN(GRset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
90 chr = seqnames(GRset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
91 pos = start(GRset)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
92 chr = as.character(chr)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
93
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
94
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
95 # Assign phenotype information
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
96 ## Based on TCGA sample naming, TCGA-2E-A9G8-01A-11D-A409-05, char 14,15 represent
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
97 ## phenotypic status of sample, 01 = cancer, 11=normal
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
98 pd$status = ifelse(test= (substr(rownames(pd),14,15) == "01"),yes="cancer",no="normal")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
99
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
100 ### DMP finder
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
101 dmp = dmpFinder(dat=beta,pheno=pd$status,type="categorical")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
102 write.csv(dmp,file="dmps.csv",quote=FALSE,row.names=TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
103 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
104 cat("DMP Finder successful \n")
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 ## Make design matrix for bumphunting
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
109 #Model Matrix
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
110 T1="normal";T2="cancer"
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
111 ## Introduce error if levels are different
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
112 stopifnot(T1!=T2)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
113 keep=pd$status%in%c(T1,T2)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
114 tt=factor(pd$status[keep],c(T1,T2))
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
115 design=model.matrix(~tt)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
116
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
117
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
118 ## Start bumphunter in a parallel environment
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
119 ## Parallelize over cores on machine
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
120 library(doParallel)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
121 registerDoParallel(cores = opt$cores)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
122
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
123 # Bumphunter Run with object processed with default Quantile Normalization
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
124 # provided along with TCGA data
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
125 dmrs = bumphunter(beta[,keep],chr=chr,pos=pos,design=design,B=opt$b_permutations,smooth=opt$smooth,pickCutoff =TRUE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
126 bumps = dmrs$tab
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
127
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
128 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
129 cat("Bumphunter result", "\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
130 head(bumps)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
131 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
132
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
133
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
134 ### Choose DMR's of a certain length threshold.
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
135 ### This helps reduce the size of DMRs early, and match
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
136 ### with genes closest to region
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
137 bumps = bumps[bumps$L > opt$l_value,]
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
138 genes <- annotateTranscripts(TxDb.Hsapiens.UCSC.hg19.knownGene)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
139 tab=matchGenes(bumps,genes)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
140 annotated_dmrs=cbind(bumps,tab)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
141
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
142 if(verbose){
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
143 cat("Match with annotation\n")
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
144 head(annotated_dmrs)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
145 }
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
146
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
147 ## Save result, which contains DMR's and closest genes
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
148 write.csv(annotated_dmrs,file = "dmrs.csv",quote=FALSE,row.names=FALSE)
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
149
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
150 ## Garbage collect
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
151 gc()
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
152
84361ce36a11 planemo upload commit fb90aafc93e5e63acfcdac4c27cfd865cdf06c5a-dirty
nturaga
parents:
diff changeset
153