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