Coder Social home page Coder Social logo

shinycardinal's Introduction

ShinyCardinal v0.3.5

Shiny App for Mass Spectrometry Imaging.

TOC

News

2024-07-21: Release of v0.3.5

  • Fix bug in calculating of number of workers.

2024-05-14: Release of v0.3.4

  • This version makes it easier for users to select MSI files using method 1.

Installation

You can use one of the following ways to use and install ShinyCardinal.

(a) Install as a standalone App

Note

This is the easiest way to install and use ShinyCardinal (recommended)

Download

(b) Inatall as an R package

remotes::install_github("YonghuiDong/ShinyCardinal")

Note

After installation, you can use library(ShinyCardinal); run_app() or ShinyCardinal::run_app() to start the app.

(c) Use online web version

https://gincpm.shinyapps.io/ShinyCardinal

Note

  1. No installation needed; you can use the web version directly.
  2. It can be slowly and it may not work for MSI data over 2GB.

Usage

Please watch our Tutorial Videos.

Contribution

You are very welcome to contribute by submitting new features, pull requests, and suggestions, all of which are greatly appreciated.

Acknowledgements

ShinyCardinal wouldn't be possible without the solid foundation laid by Cardinal. My heartfelt gratitude to the developers of Cardinal. ❤️ ❤️ ❤️

Citation

If you use ShinyCardinal, please cite the following references:

  • Dong.Y., and Heinig, W., 2024. Mass Spectrometry Imaging Data Analysis with ShinyCardinal. Link

  • Bemis, K.A., Foell, M.C., Guo, D., Lakkimsetty, S.S., and Vitek, O., 2023. Cardinal v.3: a versatile open-source software for mass spectrometry imaging analysis. Nature Methods, 20, 1883-1886. Link

shinycardinal's People

Contributors

yonghuidong avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

shinycardinal's Issues

Add option to enlarge image

See example below:

library(shiny)

ui <- fluidPage(
  titlePanel("Enlarge Plot Demo"),
  sidebarLayout(
    sidebarPanel(
      actionButton("enlargeButton", "Enlarge")
    ),
    mainPanel(
      plotOutput("plot")
    )
  )
)

server <- function(input, output) {
  output$plot <- renderPlot({
    plot(cars)
  })
  
  observeEvent(input$enlargeButton, {
    showModal(modalDialog(
      tags$head(tags$style(HTML(".modal-dialog { width: 100vw; }"))),
      plotOutput("enlargedPlot", height = "1000px"),
    ))
    
    output$enlargedPlot <- renderPlot({
      plot(cars)
    })
  })
}

shinyApp(ui, server)

Allow not to specify mass tolerance when plotting MSI images

When plotting MS images, the image function will recenter the m/z values if the user entered values ± a mass tolerance fall out of a specific range .

It could be misleading sometime because the generated MS images can be very different from the "real images" of the user entered m/z values.

If plusminus parameter is not specified in image(), then the read m/z value will be displayed in the plot.

Therefore I have added the option to allow the users not to specific the m/z value just to check the variations of user entered m/z value and real m/z value.

Allow to choose BPPARAM for parallel computation

Currently I implemented SnowParam(), as it works for all OS.

But it can be slow in some cases.

Ideas:

  1. Allow users to choose the operating system (global variable)
  2. Remove parallel computation for some steps.
  3. If worker = 1, use SerialParam(). (need to test the speed of different BPPARAM).
  4. use by = 2 for 20 blocks (default).

Replace observeEvent() with bindEvent()

bindEvent() has two unique advantages compared to observeEvent():

  1. It allows efficiently display the feed back message using validate(). (In observeEvent sometimes I need to use req to check the input, but there is no feedback message).
  2. It is more efficient in isolating input, especially when there are many reactive inputs.

One disadvantage I can think of right now is that the code will become a bit redundant when the event is linked with many outputs.

My current plan is to replace replace all observeEvent() with bindEvent() in data preprocessing module, because heavy computation is needed there, I can better isolate the interactive inputs.

Remove background noise and matrix peaks

Add the option to remove background noise and matrix peaks before performing image segmentation and statistics, this could improve the image segmentation result.

colocalization should work, but it may be a bit time consuming.

Deisotoing

Only for high mass resolution MSI data.

Idea:

  • colocalization + mass tolerance for 13C deisotoping. (slow but accurate)
  • or PCA + mass tolerance for 13C deisotoping. (fast but less accurate)

Conclusion:

  • Finally choose colocalization + mass tolerance for 13C deisotoping. (slow but accurate)

Analyse ROIs

Todo

  • 1. Perform meansTest()
  • 2. Provide mean intensity values()
  • 3. Intensity profiles alone the pixels

Add more color scales for MSI images

  • add viridis black and cividis black

The reason is the blue background of the MSI image some times looks ugly under darkmode(), so I replace the blue background with black background.

Allow users to select region of interest

The Cardinal function selectROI is not compatible with R shiny.

I need to re-write a function to support shiny.

  • allow free draw selection of a ROI
  • allow to draw a line to display mz profile along the line

Show ROIs in plot

Todo

  • rewrite selectROI() function

The original selecrROI only works in RStudio. It does not support shiny app.
When multiple runs are included, I need to allow subset runs, otherwise, the selected ROIs will be plotted in different runs.

  • Write a makeFactor2() function

I have saved ROIs as a list in the App, unfortunately, do.call(makeFactor, list) does not work when for the list of ROIs are selected from different runs. I need to rewrite makeFactor function.

  • Plot the ROIs.

Drop markdown dependency

includeMarkdown() function requires markdown package

function (path) 
{
    html <- if (packageVersion("markdown") < "1.3") {
        markdown::markdownToHTML(path, fragment.only = TRUE)
    }
    else {
        markdown::mark(path, output = NULL)
    }
    Encoding(html) <- "UTF-8"
    return(HTML(html))
}
<bytecode: 0x7ff55153ea78>
<environment: namespace:htmltools>

I will use includeHTML() function instead.

I only need to convert my md file to HTML file.

Drop igraph dependency

Only to use visNetwork

microbenchmark showed that it is about 4 times slower without using igraph.

plotAllNetwork <- function(PCC, threshold = 0.9, labelSize = 40){
  #(1) Prepare network object --------------------------------------------------
  PCC[upper.tri(PCC, diag = TRUE)] <- 0
  cor_df <- as.data.frame(as.table(PCC))
  cor_df <- cor_df[cor_df$Freq >= threshold, ]
  id <- unique(c(cor_df$Var1, cor_df$Var2))
  nodes <- data.frame(id = id, label = id)
  edges <- data.frame(to = cor_df$Var1, from = cor_df$Var2, value = cor_df$Freq)

  #(2) Plot network ------------------------------------------------------------
  visNetwork::visNetwork(nodes = nodes, edges = edges, width = "100%") %>%
    visNetwork::visNodes(font = list(size = labelSize)) %>%
    visNetwork::visOptions(highlightNearest = TRUE) %>%
    visNetwork::visInteraction(navigationButtons = TRUE) %>%
    visNetwork::visIgraphLayout(randomSeed = 123)
}

Add waiter for each section

Main Reason:

  • To keep the users patiently waiting when the programming is running.

Updata

I decided to use shinycssloaders rather than waiter for the following reasons:

  1. code of waiter is heavier
  2. waiter does not work in textOutput and I need to pre-change the height of textOutput.
  3. waiter image size changed when I use another screen, and the image is distorted.

MSI data become empty if I remove the same background peaks the second time

If I remove the same noise peaks the second time, I get the following result.

An object of class 'MSContinuousImagingExperiment'
  <0 feature, 400 pixel> imaging dataset
    imageData(1): intensity
    featureData(0):
    pixelData(1): circle
    metadata(1): design
    run(1): run0
    raster dimensions: 20 x 20
    coord(2): x = 1..20, y = 1..20
    mass range:  Inf to -Inf 
    centroided: FALSE 
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

Allow to display more than one MSI data

To do

  • Need to remove z so as not to overlay the dataset: coord(combinedData)[, "z"] = NULL

  • Add option to allow users to select which run to display or display all runs.

  • May also need to modify selectROI(). Suppose user select ROI1 from run a, and ROI2 from run b, I need to have the function to subset ROIs according to different runs.

Packages maptools, rgdal, and rgeos will not be on CRAN after October 2023

The legacy packages maptools, rgdal, and rgeos, underpinning this package will retire shortly. Please refer to R-spatial evolution reports on https://r-spatial.org/r/2023/05/15/evolution4.html for details.

I am using package sp, and sp suggests rgdal.

For example, if you run the spTransform() function from the sp package, it used the rgdal package in the background.

In general, my code should not be affected by this change, as I am not using any functions from sp that depends on rgdal .

More details see here

Network analysis bug: Warning: non-unique values when setting 'row.names'

Warning: non-unique values when setting 'row.names': ‘215.1286’, ‘217.0293’, ‘256.2369’, ‘271.0037’, ‘297.2437’, ‘376.2869’, ‘382.1306’, ‘419.2563’, ‘473.2825’, ‘687.545’, ‘700.5267’
Warning: Error in .rowNamesDF<-: duplicate 'row.names' are not allowed

Code review of image view section

To make code style more consistent
Check name consistency
Check possible bugs
Display necessary information (both user guide and output message)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.