-
Notifications
You must be signed in to change notification settings - Fork 1
/
Demo_CellCheck.R
133 lines (110 loc) · 6.54 KB
/
Demo_CellCheck.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
##### To-do list ######
# - [x] 3 Main Function
# - [ ] Better simulation demo
# - [ ] Debug: build all metrics
# - [x] Debug: FilterSet1
# - [ ] Combine two dataframe
# - [ ] Multiple lineplot (Group)
# - [ ] BeautifyPlots: Modify color in different group
# - [ ] R, RMSDm mAD
# - [ ] Anova, T-test
#
# - [ ] Goodness of fit index(GFI)
# - [ ] Clean up the code
##### Presetting ######
rm(list = ls()) # Clean variable
memory.limit(150000)
##### Load Packages #####
## Check whether the installation of those packages is required
Package.set <- c("tidyverse","caret","cvms","DescTools","devtools","ggthemes") # library(Seurat)
for (i in 1:length(Package.set)) {
if (!requireNamespace(Package.set[i], quietly = TRUE)){
install.packages(Package.set[i])
}
}
## Load Packages
lapply(Package.set, library, character.only = TRUE)
rm(Package.set,i)
## install CellCheck
# Install the CellCheck package
detach("package:CellCheck", unload = TRUE)
devtools::install_github("Charlene717/CellCheck")
## Load CellCheck
library(CellCheck)
##### Current path and new folder setting* #####
ProjectName = "CC"
Version = paste0(Sys.Date(),"_",ProjectName,"_Demo")
Save.Path = paste0(getwd(),"/",Version)
dir.create(Save.Path) # Create folder
##### Load simulation datafrme* #####
# #### Load simulation datafrme by RData ####
# load(paste0("./DemoFile/Create_simulation_datafrme3.RData"))
# load("Create_simulation_datafrme3.RData")
# write.table(Simu_Anno.df, file=paste0(Save.Path,"/",ProjectName,"_Simu_Anno.tsv"),sep="\t",
# row.names=F, quote = FALSE)
# write.table(Simu_Bi2.df, file=paste0(Save.Path,"/",ProjectName,"_Simu_Bi.tsv"),sep="\t",
# row.names=F, quote = FALSE)
# write.table(Simu_DisMult.df, file=paste0(Save.Path,"/",ProjectName,"_Simu_DisMult.tsv"),sep="\t",
# row.names=F, quote = FALSE)
# write.table(Simu_Conti.df, file=paste0(Save.Path,"/",ProjectName,"_Simu_Conti.tsv"),sep="\t",
# row.names=F, quote = FALSE)
#### Load simulation datafrme by tsv ####
Simu_Anno.df <-read.delim(file=paste0("./DemoFile/",ProjectName,"_Simu_Anno.tsv"),sep="\t")
Simu_Bi.df <-read.delim(file=paste0("./DemoFile/",ProjectName,"_Simu_Bi.tsv"),sep="\t")
Simu_DisMult.df <-read.delim(file=paste0("./DemoFile/",ProjectName,"_Simu_DisMult.tsv"),sep="\t")
Simu_Conti.df <-read.delim(file=paste0("./DemoFile/",ProjectName,"_Simu_Conti.tsv"),sep="\t")
#####-----------------------------------(Binary data)-----------------------------------#####
## For one prediction
CMSet.lt <- list(Mode = "One", Actual = "Actual", Predict = "Predict2" , Remark = "_Predict2") # Mode = c("One","Multiple")
BarChartSet.lt <- list(Mode = "One", Metrics = "Accuracy", XValue = "Type", Group = "Tool", Remark = "_Tool")
LinePlotSet.lt <- list(Mode = "One", Metrics = "Accuracy", XValue = "PARM", Group = "Tool", Remark = "_Tool")
CCR_cm_Bi.lt <- CellCheck_Bi(Simu_Bi.df, Simu_Anno.df,
CMSet.lt = CMSet.lt,
BarChartSet.lt = BarChartSet.lt,
LinePlotSet.lt = LinePlotSet.lt,
Save.Path = Save.Path, ProjectName = ProjectName)
## For multiple prediction
CMSet.lt <- list(Mode = "Multiple", Remark = "_All") # Mode = c("One","Multiple")
BarChartSet.lt <- list(Mode = "Multiple", XValue = "Type", Group = "Tool", Remark = "_All")
LinePlotSet.lt <- list(Mode = "Multiple", XValue = "PARM", Group = "Tool", Remark = "_All")
CCR_Sum_Bi.df <- CellCheck_Bi(Simu_Bi.df, Simu_Anno.df,
CMSet.lt = CMSet.lt,
BarChartSet.lt = BarChartSet.lt,
LinePlotSet.lt=LinePlotSet.lt,
Save.Path = Save.Path, ProjectName = ProjectName)
#####--------------------------(Discrete Multiple data)--------------------------#####
## For one prediction
DisCMSet.lt = list(Mode = "One", Actual = "Actual", Predict = "Predict2" , FilterSet1 = "Tool", FilterSet2 = "ToolA" , Remark = "") # Mode = c("One","Multiple")
BarChartSet.lt <- list(Mode = "One", Metrics = "Balanced.Accuracy", XValue = "Type", Group = "Tool", Remark = "")
LinePlotSet.lt <- list(Mode = "One", Metrics = "Balanced.Accuracy", XValue = "PARM", Group = "Tool", Remark = "")
cm_DisMult.lt <- CellCheck_DisMult(Simu_DisMult.df, Simu_Anno.df,
DisCMSet.lt = DisCMSet.lt,
BarChartSet.lt = BarChartSet.lt,
LinePlotSet.lt=LinePlotSet.lt,
Save.Path = Save.Path, ProjectName = ProjectName)
## For multiple prediction
DisCMSet.lt = list(Mode = "Multiple", Actual = "Actual", FilterSet1 = "Tool", FilterSet2 = "ToolA" , Remark = "_All") # Mode = c("One","Multiple")
BarChartSet.lt <- list(Mode = "Multiple", XValue = "Type", Group = "Tool", Remark = "_All")
LinePlotSet.lt <- list(Mode = "Multiple", XValue = "PARM", Group = "Tool", Remark = "_All")
Sum_DisMult.df <- CellCheck_DisMult(Simu_DisMult.df, Simu_Anno.df,
DisCMSet.lt = DisCMSet.lt,
BarChartSet.lt = BarChartSet.lt,
LinePlotSet.lt=LinePlotSet.lt,
Save.Path = Save.Path, ProjectName = ProjectName)
#####---------------------------------(Continuous data)---------------------------------#####
## For one index
BarChartSet.lt = list(Mode = "One", Metrics = "RMSE", XValue = "Type", Group = "Tool", Remark = "") # Mode = c("One","Multiple")
LinePlotSet.lt = list(Mode = "One", Metrics = "RMSE", XValue = "PARM", Group = "Tool", Remark = "")
cm_Conti.lt <- CellCheck_Conti(Simu_Bi.df, Simu_Anno.df,
BarChartSet.lt = BarChartSet.lt,
LinePlotSet.lt = LinePlotSet.lt,
Save.Path = Save.Path, ProjectName = ProjectName)
## For multiple index
BarChartSet.lt <- list(Mode = "Multiple", XValue = "Type", Group = "Tool", Remark = "_All")
LinePlotSet.lt <- list(Mode = "Multiple", XValue = "PARM", Group = "Tool", Remark = "_All")
Sum_Conti.df <- CellCheck_Conti(Simu_Bi.df, Simu_Anno.df,
BarChartSet.lt = BarChartSet.lt,
LinePlotSet.lt = LinePlotSet.lt,
Save.Path = Save.Path, ProjectName = ProjectName)
#### Export RData files ####
save.image(paste0(Save.Path,"/",ProjectName,"Demo_CellTypeAnno.RData"))