Spaces:
Sleeping
Sleeping
JiawenChenn
commited on
Commit
·
61960e2
1
Parent(s):
cc7d6bd
update
Browse files- .gitignore +3 -0
- GSE197023_GSM5907096.csv +0 -0
- app.R +42 -14
.gitignore
CHANGED
|
@@ -1,2 +1,5 @@
|
|
| 1 |
.DS_Store
|
| 2 |
.Rproj.user
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
.DS_Store
|
| 2 |
.Rproj.user
|
| 3 |
+
.Rhistory
|
| 4 |
+
.RData
|
| 5 |
+
temp.R
|
GSE197023_GSM5907096.csv
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.R
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
library(shiny)
|
| 3 |
library(bslib)
|
| 4 |
library(dplyr)
|
|
@@ -21,8 +21,9 @@ library(readr)
|
|
| 21 |
|
| 22 |
|
| 23 |
alter_method_name = function(method_vector){
|
| 24 |
-
input_name = c('Binspect','MoranI','SpaGene','RayleighSelection','scGCO','Spanve','HRG','SINFONIA',
|
| 25 |
-
'SpaGCN','SpaGFT','SPARK','SPARKX','
|
|
|
|
| 26 |
'SpatialDE2')
|
| 27 |
# check if all method in input_name
|
| 28 |
input = unique(method_vector)
|
|
@@ -33,7 +34,9 @@ alter_method_name = function(method_vector){
|
|
| 33 |
}
|
| 34 |
method_vector = case_when(
|
| 35 |
method_vector == 'Binspect' ~ 'Binspect',
|
|
|
|
| 36 |
method_vector == 'MoranI' ~ 'Moran\'s I',
|
|
|
|
| 37 |
method_vector == 'SpaGene' ~ 'SpaGene',
|
| 38 |
method_vector == 'RayleighSelection' ~ 'RayleighSelection',
|
| 39 |
method_vector == 'scGCO' ~ 'scGCO',
|
|
@@ -44,14 +47,18 @@ alter_method_name = function(method_vector){
|
|
| 44 |
method_vector == 'SpaGFT' ~ 'SpaGFT',
|
| 45 |
method_vector == 'SPARK' ~ 'SPARK',
|
| 46 |
method_vector == 'SPARKX' ~ 'SPARK-X',
|
|
|
|
| 47 |
method_vector == 'singleCellHaystack' ~ 'singleCellHaystack',
|
|
|
|
| 48 |
method_vector == 'nnsvg' ~ 'nnSVG',
|
|
|
|
| 49 |
method_vector == 'SOMDE' ~ 'SOMDE',
|
| 50 |
method_vector == 'SpatialDE' ~ 'SpatialDE',
|
| 51 |
method_vector == 'SpatialDE2_test_stat' ~ 'SpatialDE2',
|
| 52 |
method_vector == 'SpatialDE2' ~ 'SpatialDE2',
|
| 53 |
method_vector == 'HEARTSVG' ~ 'HEARTSVG',
|
| 54 |
method_vector == 'Sepal' ~ 'Sepal',
|
|
|
|
| 55 |
method_vector == 'BSP' ~ 'BSP',
|
| 56 |
TRUE ~ method_vector
|
| 57 |
)
|
|
@@ -97,7 +104,8 @@ ui <- navbarPage(
|
|
| 97 |
checkboxInput("show_anno", "Show annotation", FALSE),
|
| 98 |
selectizeInput('anno_name','Annotation column',c(''), selected = '',multiple=FALSE),
|
| 99 |
hr(), # Add a horizontal rule
|
| 100 |
-
checkboxInput("show_gene_exp", "Show gene expression (take a while to load the data)", FALSE),
|
|
|
|
| 101 |
selectizeInput('gene_name','Gene',c(''), selected = '',multiple=TRUE),
|
| 102 |
tags$style(type = 'text/css',".selectize-input { word-wrap : break-word;}.selectize-dropdown {word-wrap : break-word;} "),
|
| 103 |
tags$style(htmltools::HTML("
|
|
@@ -142,6 +150,7 @@ ui <- navbarPage(
|
|
| 142 |
numericInput("digits", "Number of digits", value = 2, min = 0, max = 20)
|
| 143 |
),
|
| 144 |
mainPanel(
|
|
|
|
| 145 |
DTOutput("dataset_table")
|
| 146 |
)
|
| 147 |
)
|
|
@@ -170,7 +179,8 @@ ui <- navbarPage(
|
|
| 170 |
server <- function(input, output, session) {
|
| 171 |
|
| 172 |
|
| 173 |
-
slide_data =
|
|
|
|
| 174 |
req(input$slide_name)
|
| 175 |
slide_name0 = input$slide_name
|
| 176 |
tech = (meta_file %>% filter(slide==slide_name0))$tech
|
|
@@ -226,11 +236,10 @@ server <- function(input, output, session) {
|
|
| 226 |
|
| 227 |
output$scatter <- renderPlot(
|
| 228 |
{
|
| 229 |
-
if(input$show_gene_exp){
|
| 230 |
data = slide_data()
|
| 231 |
data = data %>% select(xaxis,yaxis,input$gene_name)
|
| 232 |
data = reshape2::melt(data,id.vars = c('xaxis','yaxis'))
|
| 233 |
-
print(data)
|
| 234 |
p <- ggplot(data)+geom_point(aes(x=xaxis,y=yaxis,color=value),size = input$point_size)+
|
| 235 |
theme_article()+scale_y_reverse()+scale_color_viridis_c(name='Gene expression')+
|
| 236 |
facet_wrap(~variable)+
|
|
@@ -239,9 +248,6 @@ server <- function(input, output, session) {
|
|
| 239 |
axis.ticks = element_blank())+
|
| 240 |
coord_fixed()
|
| 241 |
p
|
| 242 |
-
}else{
|
| 243 |
-
NULL
|
| 244 |
-
}
|
| 245 |
},
|
| 246 |
res = 100
|
| 247 |
)
|
|
@@ -315,10 +321,32 @@ server <- function(input, output, session) {
|
|
| 315 |
},
|
| 316 |
res = 100
|
| 317 |
)
|
| 318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
output$dataset_table <- renderDT({
|
| 320 |
-
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
# round the numeric columns to specified digits
|
| 323 |
num_cols = sapply(output_table, is.numeric)
|
| 324 |
output_table[, (which(num_cols)) := lapply(.SD, round, digits = input$digits), .SDcols = which(num_cols)]
|
|
@@ -326,4 +354,4 @@ server <- function(input, output, session) {
|
|
| 326 |
})
|
| 327 |
}
|
| 328 |
|
| 329 |
-
shinyApp(ui, server)
|
|
|
|
| 1 |
+
.libPaths('/Users/chenjiawen/Desktop/Rlibs-4.0')
|
| 2 |
library(shiny)
|
| 3 |
library(bslib)
|
| 4 |
library(dplyr)
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
alter_method_name = function(method_vector){
|
| 24 |
+
input_name = c('Binspect','BinSpect','MoranI',"Moran's I",'SpaGene','RayleighSelection','scGCO','Spanve','HRG','SINFONIA',
|
| 25 |
+
'SpaGCN','SpaGFT','SPARK','SPARKX','SPARK-X','singleCellHaystack','singlecellHaystack',
|
| 26 |
+
'nnsvg','nnSVG','SOMDE','SpatialDE','SpatialDE2_test_stat','HEARTSVG','Sepal','sepal','BSP',
|
| 27 |
'SpatialDE2')
|
| 28 |
# check if all method in input_name
|
| 29 |
input = unique(method_vector)
|
|
|
|
| 34 |
}
|
| 35 |
method_vector = case_when(
|
| 36 |
method_vector == 'Binspect' ~ 'Binspect',
|
| 37 |
+
method_vector == 'BinSpect' ~ 'Binspect',
|
| 38 |
method_vector == 'MoranI' ~ 'Moran\'s I',
|
| 39 |
+
method_vector == 'Moran\'s I' ~ 'Moran\'s I',
|
| 40 |
method_vector == 'SpaGene' ~ 'SpaGene',
|
| 41 |
method_vector == 'RayleighSelection' ~ 'RayleighSelection',
|
| 42 |
method_vector == 'scGCO' ~ 'scGCO',
|
|
|
|
| 47 |
method_vector == 'SpaGFT' ~ 'SpaGFT',
|
| 48 |
method_vector == 'SPARK' ~ 'SPARK',
|
| 49 |
method_vector == 'SPARKX' ~ 'SPARK-X',
|
| 50 |
+
method_vector == 'SPARK-X' ~ 'SPARK-X',
|
| 51 |
method_vector == 'singleCellHaystack' ~ 'singleCellHaystack',
|
| 52 |
+
method_vector == 'singlecellHaystack' ~ 'singleCellHaystack',
|
| 53 |
method_vector == 'nnsvg' ~ 'nnSVG',
|
| 54 |
+
method_vector == 'nnSVG' ~ 'nnSVG',
|
| 55 |
method_vector == 'SOMDE' ~ 'SOMDE',
|
| 56 |
method_vector == 'SpatialDE' ~ 'SpatialDE',
|
| 57 |
method_vector == 'SpatialDE2_test_stat' ~ 'SpatialDE2',
|
| 58 |
method_vector == 'SpatialDE2' ~ 'SpatialDE2',
|
| 59 |
method_vector == 'HEARTSVG' ~ 'HEARTSVG',
|
| 60 |
method_vector == 'Sepal' ~ 'Sepal',
|
| 61 |
+
method_vector == 'sepal' ~ 'Sepal',
|
| 62 |
method_vector == 'BSP' ~ 'BSP',
|
| 63 |
TRUE ~ method_vector
|
| 64 |
)
|
|
|
|
| 104 |
checkboxInput("show_anno", "Show annotation", FALSE),
|
| 105 |
selectizeInput('anno_name','Annotation column',c(''), selected = '',multiple=FALSE),
|
| 106 |
hr(), # Add a horizontal rule
|
| 107 |
+
#checkboxInput("show_gene_exp", "Show gene expression (take a while to load the data)", FALSE),
|
| 108 |
+
input_task_button("show_gene_exp", "Show gene expression (take a while to load the data)"),
|
| 109 |
selectizeInput('gene_name','Gene',c(''), selected = '',multiple=TRUE),
|
| 110 |
tags$style(type = 'text/css',".selectize-input { word-wrap : break-word;}.selectize-dropdown {word-wrap : break-word;} "),
|
| 111 |
tags$style(htmltools::HTML("
|
|
|
|
| 150 |
numericInput("digits", "Number of digits", value = 2, min = 0, max = 20)
|
| 151 |
),
|
| 152 |
mainPanel(
|
| 153 |
+
tableOutput("SVG_message"),
|
| 154 |
DTOutput("dataset_table")
|
| 155 |
)
|
| 156 |
)
|
|
|
|
| 179 |
server <- function(input, output, session) {
|
| 180 |
|
| 181 |
|
| 182 |
+
slide_data = eventReactive(
|
| 183 |
+
input$show_gene_exp,{
|
| 184 |
req(input$slide_name)
|
| 185 |
slide_name0 = input$slide_name
|
| 186 |
tech = (meta_file %>% filter(slide==slide_name0))$tech
|
|
|
|
| 236 |
|
| 237 |
output$scatter <- renderPlot(
|
| 238 |
{
|
|
|
|
| 239 |
data = slide_data()
|
| 240 |
data = data %>% select(xaxis,yaxis,input$gene_name)
|
| 241 |
data = reshape2::melt(data,id.vars = c('xaxis','yaxis'))
|
| 242 |
+
#print(data)
|
| 243 |
p <- ggplot(data)+geom_point(aes(x=xaxis,y=yaxis,color=value),size = input$point_size)+
|
| 244 |
theme_article()+scale_y_reverse()+scale_color_viridis_c(name='Gene expression')+
|
| 245 |
facet_wrap(~variable)+
|
|
|
|
| 248 |
axis.ticks = element_blank())+
|
| 249 |
coord_fixed()
|
| 250 |
p
|
|
|
|
|
|
|
|
|
|
| 251 |
},
|
| 252 |
res = 100
|
| 253 |
)
|
|
|
|
| 321 |
},
|
| 322 |
res = 100
|
| 323 |
)
|
| 324 |
+
|
| 325 |
+
output$SVG_message = renderTable({
|
| 326 |
+
req(input$atlas_slide_name)
|
| 327 |
+
req(input$atlas_method)
|
| 328 |
+
SVG_table_rank = fread("rank_threshold.csv")
|
| 329 |
+
#print(input$atlas_method)
|
| 330 |
+
method_message = SVG_table_rank%>%
|
| 331 |
+
mutate(Method_alter = alter_method_name(Method)) %>%
|
| 332 |
+
filter(Method_alter==input$atlas_method)
|
| 333 |
+
#paste0('Method: ', method_message$Method_alter, ' Order: ', method_message$`Rank order`,
|
| 334 |
+
# ' Rank Variable Name: ', method_message$`Rank Variable Name`,
|
| 335 |
+
# ' SVG Threshold Name: ', method_message$`SVG Threshold Name`,
|
| 336 |
+
# ' Threshold Value: ', method_message$`Threshold Value`)\
|
| 337 |
+
method_message = method_message %>% select(-Method,-Language) %>% select(Method_alter,everything())
|
| 338 |
+
colnames(method_message) = c('Method','Rank order','Rank Variable Name','SVG Threshold Name','Threshold Value')
|
| 339 |
+
method_message
|
| 340 |
+
})
|
| 341 |
+
|
| 342 |
output$dataset_table <- renderDT({
|
| 343 |
+
req(input$atlas_slide_name)
|
| 344 |
+
req(input$atlas_method)
|
| 345 |
+
output_table = request(paste0('https://huggingface.co/datasets/jiawennnn/STimage-benchmark-data/resolve/main/SVG/',input$atlas_method,'/',input$atlas_slide_name,'_organized.csv')) |>
|
| 346 |
+
req_perform()|>
|
| 347 |
+
resp_body_string() |> # get text body as string
|
| 348 |
+
read_csv(show_col_types = FALSE) %>% as.data.table()
|
| 349 |
+
colnames(output_table)[1:3] = c('Gene','.SVG','.SVG_rank')
|
| 350 |
# round the numeric columns to specified digits
|
| 351 |
num_cols = sapply(output_table, is.numeric)
|
| 352 |
output_table[, (which(num_cols)) := lapply(.SD, round, digits = input$digits), .SDcols = which(num_cols)]
|
|
|
|
| 354 |
})
|
| 355 |
}
|
| 356 |
|
| 357 |
+
shinyApp(ui, server)
|