---
title: "PFC Dashboards"
author: "Cao Lab"
server: shiny
format: 
  dashboard:
    logo: https://zhenghu159.github.io/picx-images-hosting/PFCapp/Logo.1756dx3zx7.webp
    nav-buttons:
      - icon: github
        href: https://github.com/GangCaoLab/mPFC-web
---



# Home

<p style="font-size: 50px; font-weight: bold; text-align: center;">A single-cell resolution spatial-transcriptome-connectome integrated  multi-omic atlas of prefrontal cortex</p>

<br>

<img src="https://zhenghu159.github.io/picx-images-hosting/PFCapp/main.77dcin4jph.webp" style="width: 100%;">

<br>
<br>

<p style="font-size: 30px; font-weight: bold; text-align: left;">
Abstract
</p>

<p style="font-size: 20px; text-align: justify;">
Medial prefrontal cortex (mPFC) is the high-level center of brain cognitive function, which regulates emotion, memory, decision-making, behavior, neuroendocrine and other brain functions. mPFC has a wide range of projections in the cerebral cortex, thalamus, hypothalamus, basal ganglia, midbrain and other brain regions, forms extremely complex projection circuits. Analyzing these numerous projection circuits structures is an urgent problem in neuroscience. The conventional method is using neurotropic viruses to express fluorescent proteins for nucleus labeling. However, due to the limitation of fluorescent protein types and spectral crossover, it is time-consuming and labor-intensive to realize multiple nucleus labeling and tracing. The ideal circuits analysis solution is to break through the limit of fluorescent protein types and can label multiple brain regions. On the basis of multi-brain circuits labeling, it can also analyze the expression of neuron-related genes in the circuits, so as to better interpret the mechanism by which specific circuits perform their functions.
</p>


<br>

<p style="font-size: 30px; font-weight: bold; text-align: left;">
Interactively exploring the data
</p>

<a style="font-size: 20px; font-weight: bold; text-align: left;">
scRNAseq
</a>

- Cell cluster UMAP
- Feature plot in UMAP

<a style="font-size: 20px; font-weight: bold; text-align: left;">
Spatial data
</a>





```{r}
#| context: setup
#| warning: false
#| message: false

library(ggplot2)
library(scCustomize)
library(shiny)
library(rgl)
#library(wholebrain)
#attach(loadNamespace('wholebrain'), warn.conflicts = FALSE)
source("R/Palettes.R")
source('R/includes.R')
Adult.Ex <- readRDS('data/Adult.Ex.rds')
sp.PFC <- readRDS('data/sp.PFC.rds')
options(rgl.useNULL = TRUE)
```



# scRNAseq

## Row

### Column

```{r}
selectInput('cluster', 'Select Cluster', c("SubType_Layer","SubType"))
plotOutput('cluster_plot')
```

### Column

```{r}
selectInput('gene', 'Select Gene', rownames(Adult.Ex))
plotOutput('gene_plot')
```


```{r}
#| context: server

output$cluster_plot <- renderPlot({
  DimPlot_scCustom(
    seurat_object = Adult.Ex,
    reduction = 'umap',
    group.by = input$cluster,
    colors_use = col_cluster[[input$cluster]],
    label = T
  ) +
    coord_fixed()
})

output$gene_plot <- renderPlot({
  FeaturePlot_scCustom(
    seurat_object = Adult.Ex,
    features = input$gene) +
    coord_fixed()
})
```






# Spatial

TO DO ...




# 3D

## Row

### Column

```{r}
selectInput('subtype', 'Select SubType', sort(unique(sp.PFC$SubType)))
rglwidgetOutput('spatial_subtype', width = "100%")
```


```{r}
#| context: server

output$spatial_subtype <- renderRglwidget({
  open3d()
  bg3d(color = "black")
  par3d(userMatrix = rotationMatrix(-pi/6, -1, 1, 0), zoom = 0.6)
  acr.list <- c("MOs","PL","ORBm","ACAd","ILA","DP","ACAv")
  for(acr in acr.list){
    mesh <- mesh3d.allen.annot.from.id(get.id.from.acronym(acr))
    #to.del <- which(mesh$vb[1,] < 0)
    #to.del <- NA
    #mesh$it <- mesh$it[,!is.element(mesh$it[1,], to.del) & !is.element(mesh$it[2,], to.del) & !is.element(mesh$it[3,], to.del)]
    #col <- color.from.acronym(acr)
    col <- "lightgray"
    #col <- col_Region[acr]
    shade3d(mesh, col = col, material = list(lit=FALSE), alpha = 0.1)
  }
  
  df_plot <- sp.PFC@meta.data[which(sp.PFC$SubType == input$subtype),]
  
  spheres3d(x = df_plot$ML_new, 
            y = df_plot$DV_new,
            z = df_plot$AP_new,
            col = col_cluster[["SubType"]][input$subtype], radius=0.01, alpha=1)
  rglwidget()
})
```





