Student Details

Story URL

https://www.sciencedaily.com/releases/2017/11/171128091422.htm

Data URL

https://archive.ics.uci.edu/ml/datasets/Mice+Protein+Expression

Visualisation URL

https://alistairgj.shinyapps.io/miceproteinexpression/

Code

library(shiny)
library(ggplot2)
library(shinyjs)
library(readxl)
library(png)

ds <- read_excel("ds.xls")
MouseID <- gsub("\\_.*", "", ds$MouseID)
ds$MouseID <- MouseID

proteins <- sort(colnames(ds)[2:78]) # Selecting the protein columns from ds
classes <- unique(ds$class) # Extracting the unique values from ds$class
facets <- c('Genotype','Behavior','Treatment') # Creating a list of the facets
mouseIDs <- sort(unique(ds$MouseID)) # Sorting the MouseID values in the lists

chunk1 <- "The chosen data set ‘Mice Protein Expression Data Set’ was generated from experiments by Higuera et al and Ahmed et al. These projects aimed to understand the impacts of Down Syndrome on learning through analysis of protein expression in mice. Down Syndrome (DS) has a prevalence globally of 1 in a 1000 live human births, and is the most common genetically defined cause of intellectual disabilities. DS in humans is caused by the presence of an additional chromosome 21, referred to as trisomy. Protein expression is disrupted by human trisomy 21, leading to the physical and intellectual manifestations associated with DS. Due to its prevalence and health implications, a strong imperative exists to further understand and treat the condition." 

chunk2 <- "Davisson et al., successfully manipulated a mouse genome to produce several models of DS in rodents. Known as 'Ts65Dn' this mouse is the best-characterized of the DS rodent models. In generating the 'Mice Protein Expression Data Set' Higuera et al employed Ts65Dn and normal mice in experimental and control groups, exposing them to a range of variables. The rodents were then euthanized and their cortex protein levels were analysed in a quantitative fashion. From three binary variables, eight classes of mice were used to generate the data set. The work of Higuera et al and Ahmed et al aimed to assess the efficacy of pharmacotherapies for treatment of DS - an avenue of treatment that has never been successfully implemented."

chunk3 <- "Using this dashboard, the ‘Mice Protein Expression Data Set’ may be explored for protein expression levels and relationships in a qualitative fashion."

ui <- fluidPage(
  useShinyjs(),
  tabsetPanel(
    tabPanel(
      title = "About",
      h4("News URL"),
      a(href="https://www.sciencedaily.com/releases/2017/11/171128091422.htm", "Science Daily - Trisomy 21: Research breaks new ground"),
      br(),
      h4("Data Source"),
      a(href="https://archive.ics.uci.edu/ml/datasets/Mice+Protein+Expression", "UCI Machine Learning - Mice Protein Expression Dataset"),
      br(),
      br(),
      p(chunk1),
      p(chunk2),
      p(chunk3),
      HTML('<center><img src="http://journals.plos.org/plosone/article/figure/image?size=medium&id=10.1371/journal.pone.0129126.g001" width="400" height="400"></center>'),
      br()
    ),
    tabPanel(
      title = "XY Scatter & Density",
      br(), 
      sidebarLayout(
        sidebarPanel(
          proteinH <- selectInput(inputId = "proteinH",
                                  label = "Select Target Protein A",
                                  choices = proteins),
          proteinV <- selectInput(inputId = "proteinV",
                                  label = "Select Target Protein B",
                                  choices = proteins),
          checkboxGroupInput(inputId = "classes", 
                             label = "Show Classes", 
                             choices = classes,
                             selected = classes),
          uiOutput("adjustDensityUI"),
          uiOutput("adjustFillUI"),
          uiOutput("geomSmoothUI")
        ),
        mainPanel(
          plotOutput(outputId = "scatterplot")
        )
      )
    ),
    tabPanel(
      title = "Facet XY Scatter & Density",
      br(), 
      sidebarLayout(
        sidebarPanel(
          selectInput(inputId = "faceted_proteinH",
                      label = "Select Target Protein A",
                      choices = proteins),
          selectInput(inputId = "faceted_proteinV",
                      label = "Select Target Protein B",
                      choices = proteins),
          checkboxGroupInput(inputId = "facets", 
                             label = "Facet By", 
                             choices = facets),
          uiOutput("faceted_adjustDensityUI"),
          uiOutput("faceted_adjustFillUI"),
          uiOutput("faceted_geomSmoothUI")
        ),
        mainPanel(
          plotOutput(outputId = "faceted_scatterplot")
        )
      )
    ),
    tabPanel(
      title = "Select Individual Mice",
      h4("Select Mice ID to begin"),
      sidebarLayout(
        sidebarPanel(
          selectInput(inputId = "mouse_proteinH",
                      label = "Select Target Protein A",
                      choices = proteins),
          selectInput(inputId = "mouse_proteinV",
                      label = "Select Target Protein B",
                      choices = proteins),
          selectInput(inputId = "mouseID",
                      label = "Select Mice ID(s)",
                      choices = mouseIDs,
                      multiple = TRUE),
          uiOutput("mouse_adjustDensityUI"),
          uiOutput("mouse_adjustFillUI"),
          uiOutput("mouse_geomSmoothUI")
        ),
        mainPanel(
          plotOutput(outputId = "mouse_scatterplot")
        )
      )
    )
  )
)

server <- function(input, output) {
  output$adjustDensityUI = renderUI({
    if (input$proteinH == input$proteinV)
    {
      sliderInput(inputId = "adjustDensity", 
                    label = "Adjust Bandwidth", 
                    min = 0.05, 
                    max = 2,
                    value = 0.5, 
                    step = 0.05)
    }
    else
    {
      shinyjs::disabled(sliderInput(inputId = "adjustDensity", 
            label = "Adjust Bandwidth", 
            min = 0.05, 
            max = 2,
            value = 0.5, 
            step = 0.05))
    }
  })
  
  output$adjustFillUI = renderUI({
    if (input$proteinH == input$proteinV)
    {
      sliderInput(inputId = "adjustFill", 
                    label = "Adjust Fill", 
                    min = 0.0, 
                    max = 1,
                    value = 0.1, 
                    step = 0.05)
    }
    else
    {
      shinyjs::disabled(sliderInput(inputId = "adjustFill", 
            label = "Adjust Fill", 
            min = 0.0, 
            max = 1,
            value = 0.1, 
            step = 0.05))
    }
  })
  
  
  output$faceted_adjustDensityUI = renderUI({
    if (input$faceted_proteinH == input$faceted_proteinV)
    {
      sliderInput(inputId = "faceted_adjustDensity", 
                    label = "Adjust Bandwidth", 
                    min = 0.05, 
                    max = 2,
                    value = 0.5, 
                    step = 0.05)
    }
    else
    {
      shinyjs::disabled(sliderInput(inputId = "faceted_adjustDensity", 
            label = "Adjust Bandwidth", 
            min = 0.05, 
            max = 2,
            value = 0.5, 
            step = 0.05))
    }
  })
  
  output$faceted_adjustFillUI = renderUI({
    if (input$faceted_proteinH == input$faceted_proteinV)
    {
      sliderInput(inputId = "faceted_adjustFill", 
                    label = "Adjust Fill", 
                    min = 0.0, 
                    max = 1,
                    value = 0.1, 
                    step = 0.05)
    }
    else
    {
      shinyjs::disabled(sliderInput(inputId = "faceted_adjustFill", 
            label = "Adjust Fill", 
            min = 0.0, 
            max = 1,
            value = 0.1, 
            step = 0.05))
    }
  })
    
  output$mouse_adjustDensityUI = renderUI({
    if (input$mouse_proteinH == input$mouse_proteinV)
    {
      sliderInput(inputId = "mouse_adjustDensity", 
                    label = "Adjust Bandwidth", 
                    min = 0.05, 
                    max = 2,
                    value = 0.5, 
                    step = 0.05)
    }
    else
    {
      shinyjs::disabled(sliderInput(inputId = "mouse_adjustDensity", 
            label = "Adjust Bandwidth", 
            min = 0.05, 
            max = 2,
            value = 0.5, 
            step = 0.05))
    }
  })
  
  output$mouse_adjustFillUI = renderUI({
    if (input$mouse_proteinH == input$mouse_proteinV)
    {
      sliderInput(inputId = "mouse_adjustFill", 
                    label = "Adjust Fill", 
                    min = 0.0, 
                    max = 1,
                    value = 0.1, 
                    step = 0.05)
    }
    else
    {
      shinyjs::disabled(sliderInput(inputId = "mouse_adjustFill", 
            label = "Adjust Fill", 
            min = 0.0, 
            max = 1,
            value = 0.1, 
            step = 0.05))
    }
  })
  
  output$geomSmoothUI = renderUI({
    if (input$proteinH != input$proteinV)
    {
      checkboxInput(inputId = "geomSmooth", 
                    label = "View Smoothed Line")
    }
    else
    {
      shinyjs::disabled(checkboxInput(inputId = "geomSmooth", 
            label = "View Smoothed Line"))
    }
  })
  
  output$faceted_geomSmoothUI = renderUI({
    if (input$faceted_proteinH != input$faceted_proteinV)
    {
      checkboxInput(inputId = "faceted_geomSmooth", 
                    label = "View Smoothed Line")
    }
    else
    {
      shinyjs::disabled(checkboxInput(inputId = "faceted_geomSmooth", 
            label = "View Smoothed Line"))
    }
  })
    
  output$mouse_geomSmoothUI = renderUI({
    if (input$mouse_proteinH != input$mouse_proteinV)
    {
      checkboxInput(inputId = "mouse_geomSmooth", 
                    label = "View Smoothed Line")
    }
    else
    {
      shinyjs::disabled(checkboxInput(inputId = "mouse_geomSmooth", 
            label = "View Smoothed Line"))
    }
  })
  
  
  output$scatterplot <- renderPlot({
    dsx <- ds[ds$class %in% input$classes,]
    if (dim(dsx)[1] == 0)
    {
      p <- NULL
    }
    else if (input$proteinH == input$proteinV)
    {
      p <- ggplot(data=dsx, aes(x=dsx[input$proteinH], colour=class, fill=class)) +
        labs(x = "Target Protein A")
      p <- p + geom_density(adjust=input$adjustDensity, alpha=input$adjustFill)
    }
    else
    {
      p <- ggplot(data = dsx, 
         aes(x = dsx[input$proteinH], y = dsx[input$proteinV], colour = class)) +
        labs(x = "Target Protein A", y = "Target Protein B") +
        geom_point() 
      if (input$geomSmooth)
      {
        p <- p + geom_smooth()
      }
    }
    p
  })
  

  
  output$faceted_scatterplot <- renderPlot({
    # Create Facet String
    facets <- "."
    for (facet in input$facets)
    {
      facets <- paste(facets, facet, sep = " ~ ")
    }
    
    dsx <- ds
    
    if (input$faceted_proteinH == input$faceted_proteinV)
    {
      p <- ggplot(data=dsx, aes(x=dsx[input$proteinH], colour=class, fill=class)) +
         labs(x = "Target Protein A")
      p <- p + geom_density(adjust=input$faceted_adjustDensity, alpha=input$faceted_adjustFill)
    }
    else
    {
      p <- ggplot(data = dsx, 
             aes(x = dsx[input$faceted_proteinH], y = dsx[input$faceted_proteinV], colour = class)) +
         labs(x = "Target Protein A", y = "Target Protein B") +
        geom_point()
      if (input$faceted_geomSmooth)
      {
        p <- p + geom_smooth()
      }
    }
    
    if (facets != ".")
    {
      p <- p + facet_grid(facets)
    }
    p
  })
  
  output$mouse_scatterplot <- renderPlot({
    
    dsx <- ds[ds$MouseID %in% input$mouseID,]
    
    if (dim(dsx)[1] == 0)
    {
      p <- NULL
    }
    else if (input$mouse_proteinH == input$mouse_proteinV)
    {
      p <- ggplot(data=dsx, aes(x=dsx[input$proteinH], colour=class, fill=class)) +
         labs(x = "Target Protein A")
      p <- p + geom_density(adjust=input$mouse_adjustDensity, alpha=input$mouse_adjustFill)
    }
    else
    {
      p <- ggplot(data = dsx, aes(x = dsx[input$mouse_proteinH], y = dsx[input$mouse_proteinV], colour = MouseID)) +
         labs(x = "Target Protein A", y = "Target Protein B") +
        geom_point()
      if (input$mouse_geomSmooth)
      {
        p <- p + geom_smooth()
      }
    }
    p
  })
}

shinyApp(ui = ui, server = server, options=list(height = 800)) # Run the application