-
Notifications
You must be signed in to change notification settings - Fork 7
/
Global.R
100 lines (99 loc) · 4.07 KB
/
Global.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
options(shiny.maxRequestSize=200*1024^2)
options(warn=-1)
library(shiny)
library(circlize)
library(bs4Dash)
library(DT)
library(RColorBrewer)
library(shinyWidgets)
library(data.table)
library(shinyBS)
library(sortable)
library(shinyjqui)
library(shinycssloaders)
library(colourpicker)
library(gridBase)
library(ComplexHeatmap)
library(randomcoloR)
library(gtools)
source("plot.R")
source("writeCmd.R")
getmulcolor <- function(colorgroup, colortype, plotType = NULL){
if(is.null(plotType)){ #links
if("color" %in% colnames(colorgroup)){
colorgroup1 <- mixedsort(unique(colorgroup$color))
colnum <- length(colorgroup1)
colortype_fun <- unlist(strsplit(colortype,split = "/"))[1]
colortype_palettes <- unlist(strsplit(colortype,split = "/"))[2]
maxcolnum <- as.numeric(unlist(strsplit(colortype,split = "/"))[3])
if(colortype_fun == "grDevices::rainbow"){
color <- rainbow(colnum)
}else if(colortype_fun == "RColorBrewer::brewer.pal"){
if(colnum <= maxcolnum){
color <- sample(brewer.pal(maxcolnum, colortype_palettes),replace = FALSE,size = colnum)
}else{
color <- c(rep(brewer.pal(maxcolnum, colortype_palettes),colnum %/% maxcolnum) , brewer.pal(colnum %% maxcolnum, colortype_palettes))
}
}
return(paste0(paste0(colorgroup1,":",color),collapse = ";"))
}else{
return("")
}
}else if(plotType == "heatmap-discrete"){
colorgroup1 <- mixedsort(unique(c(as.matrix(colorgroup[,-c(1:3)]))))
colnum <- length(colorgroup1)
colortype_fun <- unlist(strsplit(colortype,split = "/"))[1]
colortype_palettes <- unlist(strsplit(colortype,split = "/"))[2]
maxcolnum <- as.numeric(unlist(strsplit(colortype,split = "/"))[3])
if(colortype_fun == "grDevices::rainbow"){
color <- rainbow(colnum)
}else if(colortype_fun == "RColorBrewer::brewer.pal"){
if(colnum <= maxcolnum){
color <- sample(brewer.pal(maxcolnum, colortype_palettes),replace = FALSE,size = colnum)
}else{
color <- c(rep(brewer.pal(maxcolnum, colortype_palettes),colnum %/% maxcolnum) , brewer.pal(colnum %% maxcolnum, colortype_palettes))
}
}
return(paste0(paste0(colorgroup1,":",color),collapse = ";"))
}else if(plotType == "rect-discrete"){
colorgroup1 <- mixedsort(unique(colorgroup[,4]))
colnum <- length(colorgroup1)
colortype_fun <- unlist(strsplit(colortype,split = "/"))[1]
colortype_palettes <- unlist(strsplit(colortype,split = "/"))[2]
maxcolnum <- as.numeric(unlist(strsplit(colortype,split = "/"))[3])
if(colortype_fun == "grDevices::rainbow"){
color <- rainbow(colnum)
}else if(colortype_fun == "RColorBrewer::brewer.pal"){
if(colnum <= maxcolnum){
color <- sample(brewer.pal(maxcolnum, colortype_palettes),replace = FALSE,size = colnum)
}else{
color <- c(rep(brewer.pal(maxcolnum, colortype_palettes),colnum %/% maxcolnum) , brewer.pal(colnum %% maxcolnum, colortype_palettes))
}
}
return(paste0(paste0(colorgroup1,":",color),collapse = ";"))
}else{
if("color" %in% colnames(colorgroup) | "stack" %in% colnames(colorgroup)){
if("color" %in% colnames(colorgroup)){
colorgroup1 <- mixedsort(unique(colorgroup$color))
}else{
colorgroup1 <- mixedsort(unique(colorgroup$stack))
}
colnum <- length(colorgroup1)
colortype_fun <- unlist(strsplit(colortype,split = "/"))[1]
colortype_palettes <- unlist(strsplit(colortype,split = "/"))[2]
maxcolnum <- as.numeric(unlist(strsplit(colortype,split = "/"))[3])
if(colortype_fun == "grDevices::rainbow"){
color <- rainbow(colnum)
}else if(colortype_fun == "RColorBrewer::brewer.pal"){
if(colnum <= maxcolnum){
color <- sample(brewer.pal(maxcolnum, colortype_palettes),replace = FALSE,size = colnum)
}else{
color <- c(rep(brewer.pal(maxcolnum, colortype_palettes),colnum %/% maxcolnum) , brewer.pal(colnum %% maxcolnum, colortype_palettes))
}
}
return(paste0(paste0(colorgroup1,":",color),collapse = ";"))
}else{
return("")
}
}
}