annotate heatmap_viz.R @ 3:8756766e5b5c draft

planemo upload commit 89cd1b5f2ca7b135abfe2d9ed18bf2478a59e099-dirty
author proteore
date Tue, 05 Mar 2019 11:23:56 -0500
parents 2a04fffda914
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
1 #!/usr/bin/Rscript
2
2a04fffda914 planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents: 1
diff changeset
2 options(warn=-1) #TURN OFF WARNINGS !!!!!!
0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
3
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
4 suppressMessages(library('plotly',quietly = T))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
5 suppressMessages(library('heatmaply',quietly = T))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
6
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
7 #packageVersion('plotly')
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
8
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
9 get_args <- function(){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
10
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
11 ## Collect arguments
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
12 args <- commandArgs(TRUE)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
13
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
14 ## Default setting when no arguments passed
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
15 if(length(args) < 1) {
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
16 args <- c("--help")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
17 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
18
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
19 ## Help section
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
20 if("--help" %in% args) {
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
21 cat("Pathview R script
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
22 Arguments:
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
23 --help Print this test
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
24 --input path of the input file (must contains a colum of uniprot and/or geneID accession number)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
25 --output Output file
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
26 --type type of output file, could be html, pdf, jpg or png
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
27 --cols Columns to use for heatmap, exemple : '3:8' to use columns from the third to the 8th
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
28 --row_names Column which contains row names
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
29 --header True or False
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
30 --col_text_angle Angle of columns label ; from -90 to 90 degres
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
31 --dist_fun function used to compute the distance
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
32
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
33 Example:
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
34 ./heatmap_viz.R --input='dat.nucl.norm.imputed.tsv' --output='heatmap.html' --cols='3:8' --row_names='2' --header=TRUE --col_text_angle=0 \n\n")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
35
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
36 q(save="no")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
37 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
38
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
39 parseArgs <- function(x) strsplit(sub("^--", "", x), "=")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
40 argsDF <- as.data.frame(do.call("rbind", parseArgs(args)))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
41 args <- as.list(as.character(argsDF$V2))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
42 names(args) <- argsDF$V1
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
43
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
44 return(args)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
45 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
46
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
47 read_file <- function(path,header){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
48 file <- try(read.csv(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="",fill=TRUE,check.names = F),silent=TRUE)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
49 if (inherits(file,"try-error")){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
50 stop("File not found !")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
51 }else{
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
52 return(file)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
53 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
54 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
55
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
56 #convert a string to boolean
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
57 str2bool <- function(x){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
58 if (any(is.element(c("t","true"),tolower(x)))){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
59 return (TRUE)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
60 }else if (any(is.element(c("f","false"),tolower(x)))){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
61 return (FALSE)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
62 }else{
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
63 return(NULL)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
64 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
65 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
66
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
67 #remove remaining quote
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
68 #only keep usefull columns
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
69 #remove lines with at least one empty cell in a matrix between two defined columns
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
70 clean_df <- function(mat,cols,rownames_col){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
71 uto = mat[,cols]
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
72 uto <- as.data.frame(apply(uto,c(1,2),function(x) gsub(",",".",x)))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
73 uto <- as.data.frame(apply(uto,c(1,2),function(x) {ifelse(is.character(x),as.numeric(x),x)}))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
74 rownames(uto) <- mat[,rownames_col]
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
75 #bad_lines <- which(apply(uto, 1, function(x) any(is.na(x))))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
76 #if (length(bad_lines) > 0) {
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
77 # uto <- uto[- bad_lines,]
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
78 # print(paste("lines",bad_lines, "has been removed: at least one non numeric content"))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
79 #}
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
80 return(uto)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
81 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
82
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
83 get_cols <-function(input_cols) {
1
b8a5139cf5b9 planemo upload commit 5dd4a8814abf4a735409189a4c7cfe3ffd207c62-dirty
proteore
parents: 0
diff changeset
84 input_cols <- gsub("c","",gsub("C","",gsub(" ","",input_cols)))
0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
85 if (grepl(":",input_cols)) {
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
86 first_col=unlist(strsplit(input_cols,":"))[1]
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
87 last_col=unlist(strsplit(input_cols,":"))[2]
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
88 cols=first_col:last_col
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
89 } else {
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
90 cols = as.integer(unlist(strsplit(input_cols,",")))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
91 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
92 return(cols)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
93 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
94
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
95 #get args
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
96 args <- get_args()
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
97
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
98 #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/heatmap_viz/args.rda")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
99 #load("/home/dchristiany/proteore_project/ProteoRE/tools/heatmap_viz/args.rda")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
100
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
101 header=str2bool(args$header)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
102 output <- rapply(strsplit(args$output,"\\."),c) #remove extension
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
103 output <- paste(output[1:length(output)-1],collapse=".")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
104 output <- paste(output,args$type,sep=".")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
105 cols = get_cols(args$cols)
1
b8a5139cf5b9 planemo upload commit 5dd4a8814abf4a735409189a4c7cfe3ffd207c62-dirty
proteore
parents: 0
diff changeset
106 rownames_col = as.integer(gsub("c","",gsub("C","",gsub(" ","",args$row_names))))
0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
107 if (length(cols) <=1 ){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
108 stop("You need several colums to build a heatmap")
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
109 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
110 dist=args$dist
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
111 clust=args$clust
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
112 dendrogram=args$dendrogram
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
113
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
114 #cleaning data
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
115 uto <- read_file(args$input,header)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
116 uto <- clean_df(uto,cols,rownames_col)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
117 uto <- uto[rowSums(is.na(uto)) != ncol(uto), ] #remove emptylines
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
118
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
119 if (header) {
1
b8a5139cf5b9 planemo upload commit 5dd4a8814abf4a735409189a4c7cfe3ffd207c62-dirty
proteore
parents: 0
diff changeset
120 col_names = names(uto)
0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
121 } else {
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
122 col_names = cols
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
123 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
124
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
125 #building heatmap
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
126 if (dist %in% c("pearson","spearman","kendall")){
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
127 heatmaply(uto, file=output, margins=c(100,50,NA,0), plot_method="plotly", labRow = rownames(uto), labCol = col_names, distfun=dist,
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
128 hclust_method = clust, dendrogram = dendrogram, grid_gap = 0,cexCol = 1, column_text_angle = as.numeric(args$col_text_angle),
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
129 width = 1000, height=1000, colors = c('blue','green','yellow','red'))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
130 } else {
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
131 heatmaply(uto, file=output, margins=c(100,50,NA,0), plot_method="plotly", labRow = rownames(uto), labCol = col_names, dist_method = dist,
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
132 hclust_method = clust, dendrogram = dendrogram, grid_gap = 0,cexCol = 1, column_text_angle = as.numeric(args$col_text_angle),
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
133 width = 1000, height=1000, colors = c('blue','green','yellow','red'))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
134 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
135
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
136 ####heatmaply
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
137
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
138 simulateExprData <- function(n, n0, p, rho0, rho1){ row
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
139 # n: total number of subjects
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
140 # n0: number of subjects with exposure 0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
141 # n1: number of subjects with exposure 1
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
142 # p: number of genes
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
143 # rho0: rho between Z_i and Z_j for subjects with exposure 0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
144 # rho1: rho between Z_i and Z_j for subjects with exposure 1
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
145
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
146 # Simulate gene expression values according to exposure 0 or 1,
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
147 # according to a centered multivariate normal distribution with
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
148 # covariance between Z_i and Z_j being rho^|i-j|
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
149 n1 <- n - n0
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
150 times <- 1:p
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
151 H <- abs(outer(times, times, "-"))
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
152 V0 <- rho0^H
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
153 V1 <- rho1^H
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
154
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
155 # rows are people, columns are genes
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
156 genes0 <- MASS::mvrnorm(n = n0, mu = rep(0,p), Sigma = V0)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
157 genes1 <- MASS::mvrnorm(n = n1, mu = rep(0,p), Sigma = V1)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
158 genes <- rbind(genes0,genes1)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
159 return(genes)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
160 }
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
161
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
162 #genes <- simulateExprData(n = 50, n0 = 25, p = 100, rho0 = 0.01, rho1 = 0.95)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
163
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
164 #heatmaply(genes, k_row = 2, k_col = 2)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
165
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
166 #heatmaply(cor(genes), k_row = 2, k_col = 2)
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
167
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
168
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
169
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
170
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
171
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
172
edbb84a94a36 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents:
diff changeset
173