annotate minfi_TCGA_pipeline.R @ 1:3cd8ea4f7079 draft default tip

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