annotate R/heatmaply.R @ 14:5a5c9a6b047b draft

Uploaded
author dereeper
date Tue, 10 Dec 2024 16:20:53 +0000
parents e42d30da7a74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/R
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
2
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
3 library(heatmaply)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
4 library("optparse")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6 option_list = list(
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7 make_option(c("-f", "--file"), type="character", default=NULL,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8 help="dataset file name", metavar="character"),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9 make_option(c("-o", "--out"), type="character", default="out.txt",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 help="output file name [default= %default]", metavar="character"),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 make_option(c("-r", "--rowmetadata"), type="character", default=NULL,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 help="metadata for rows", metavar="character"),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 make_option(c("-c", "--colmetadata"), type="character", default=NULL,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 help="metadata for cols", metavar="character")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15 );
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 opt_parser = OptionParser(option_list=option_list);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17 opt = parse_args(opt_parser);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 if (is.null(opt$file)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 print_help(opt_parser)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 stop("At least one argument must be supplied (input file).\n", call.=FALSE)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 if (is.null(opt$out)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 print_help(opt_parser)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 stop("At least one argument must be supplied (out file).\n", call.=FALSE)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 mydata <- read.table(opt$file, header=TRUE,sep="\t",row.names="Gene")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 #colmetadata <- read.table(opt$colmetadata,sep="\t")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 #rowmetadata <- read.table(opt$rowmetadata,sep="\t")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 #metadata_tooltips <- read.table(paste(opt$file,"metadata_tooltips.txt",sep = "."),sep="\t")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 #mat <- metadata_tooltips
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 #mat <- mydata
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 #mat[] <- paste("\nCountry: ", rowmetadata[, 2], "\nContinent: ", rowmetadata[, 3], "\nCOG: ", colmetadata)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 heatmaply(mydata,file = "heatmaply.html")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 #heatmaply(
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 #t(mydata), file = opt$out,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 #custom_hovertext = mat,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 #col_side_colors = colmetadata[, 3],
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 #row_side_colors = rowmetadata[, 2:4],
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 #scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 # low = "white" , mid="#E7E4EA", high = "#471777", limits = c(0, 1))
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 #)