Giter VIP home page Giter VIP logo

nglviewer's Introduction

NGLVieweR - Visualize and interact with Protein Data Bank (PDB) and structural files in R and Shiny

R-CMD-check Lifecycle: experimental CRAN status Metacran downloads

Click here to view a Shiny application integrating most features of NGLVieweR.

Description

NGLvieweR provides an R interface to the NGL.js JavaScript library. It can be used to visualize and interact with protein data bank (PDB) and structural files in R and Shiny applications. It includes a set of API functions to manipulate the viewer after creation and makes it possible to retrieve data from the visualization into R.

Installation

You can install the released version of NGLVieweR from CRAN with:

install.packages("NGLVieweR")

And the development version from GitHub with:

install.packages("remotes")
remotes::install_github("nvelden/NGLVieweR")

Basics

You can load a PDB (or any other supported structural file) directly or use a PDB code of a structure on RCSB.org. The below minimal example loads the PDB file and displays the structure in a "cartoon" representation.

#Load local pdb file
NGLVieweR("C:/7CID.pdb") %>%
addRepresentation("cartoon")

#Load protein by PDB code
NGLVieweR("7CID") %>%
addRepresentation("cartoon")

Functionality

There are functions provided to:

  • Overlay different representation styles
  • Alter the stage parameters (e.g. background, zoom- and rotation speed)
  • Zoom to specific selections
  • Add labels
  • Add contacts between residues
  • Auto rotate/rock

In Shiny apps, you can manipulate the NGLVieweR widget after creation using specific "API"" calls. Users can for instance add/remove representations, make snapshots, add labels or highlight specific regions. See the Get started section for a complete overview.

nglviewer's People

Contributors

nvelden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nglviewer's Issues

only color more than 2 residues in shiny (cartoon)?

Hello there,
I am trying to use NGLViewer in Shiny.
I want to color a specific amino acid in the cartoon representation. However, it seems that NGL is only able to color the selection if I select more than one residue. Is anybody having the same issue?
Here is the code im using:

library(shiny)
library(NGLVieweR)


ui <- fluidPage(
          NGLVieweROutput("structure")
  )
server <- function(input, output) {
   output$structure <- renderNGLVieweR({
     NGLVieweR("3RY2") %>%
        addRepresentation("cartoon",
                         param = list(
                           name = "test",
                           colorValue = "red",
                           colorScheme = "element",
                           sele = "( 20 or 30 or 100 )"
                         )
       )
       
    
   })
  
 }
shinyApp(ui, server)

Also, do you know how to color by residue in a ball+stick or surface representation? I would like to color all atoms in a residue using the same color in any of those two representations.

Thank you in advance, NGLVieweR rocks!!

How to make a video?

Hi there,
I'm currently making very beautiful NGLVieweR spinning representations displayed within the Rstudio Viewer panel.
I see I can save it as HTML but then I don't know how to convert it to a GIF or a video.
Is there any way I can save it as such directly?
Thank you in advance!
Best,
Luca

server site NGLVieweR_proxy function?

Hi,

I used NGLVieweR a lot during the last days to build a shiny for our structure of interest and allow to easily select modification sites from a dropdown. This works pretty well thanks to your software.

I used the recommended commands to add and change data and finally refresh the picture. Overall this relies on NGLVieweR_proxy and it works amazing if I work locally. Using the App from a Rstudio-Server via VPN or even worse via Shiny-Server (VPN and local Browser) does not work: unfortunately you need a rather good internet connection to up/download data. But I can confirm that it works again very well if I login via remote to a PC in the same local network.

My question is: can I change the way NGLVieweR exchanges data? Is there something like a server site update function available similar to https://shiny.rstudio.com/articles/selectize.html?

Best,
Christian

User Interaction - NGL Viewer Picking Proxy

We are trying to only show residue contacts of a specific residue whenever a user clicks on it. Is there any way to make the Rstudio viewer interactive based on what the user clicks?
Thank you for building the package!

Custom coloring per residue

Hi,

I really like this package! I am trying to build a shiny app which show different color mapping on the structure. I am hoping to map each residue with a specific color. My current approach is looping through each residue/selection with addSelection function. The example below is showing with 2 selections.

if (interactive()) {
  library(shiny)
  library(NGLVieweR)
  library(dplyr)
  
  ui = fluidPage(
    titlePanel("Viewer with API inputs"),
    sidebarLayout(
      sidebarPanel(
        actionButton("update_color", "Update color")
      ),
      mainPanel(
        NGLVieweROutput("structure")
      )
    )
  )
  server = function(input, output) {
    output$structure <- renderNGLVieweR({
      NGLVieweR("7CID") %>%
        addRepresentation("ball+stick", param = list(name = "ball+stick", color="white")) %>%
        setQuality("high") %>%
        setFocus(0)
    })
    observeEvent(input$update_color, {
      NGLVieweR_proxy("structure") %>%
        addSelection("cartoon", param = list(
          name = "a", sele = "20-50",
          color = "#FF0000"
        )) %>%
        addSelection("cartoon", param = list(
          name = "b", sele = "81-150",
          color = "yellow"
        )) 
    })

  }
  shinyApp(ui, server)
}

I wonder if there is any way to assign each residue for a unique color with out looping?
NGL manual mentioned there is a feature call addSelectionScheme, which kind of does this. But I am not sure if this is implemented in the current version of NGLViewR library.
I appreciate the help!

NGLVieweR snapshot

Hi,

is it possible to prepare a snapshot in vector graphics format such as SVG or PDF in NGLVieweR? As far as I see only PNG is supported.

Thank you,
Christian

How to rotate the view?

Hi Niels,

Thank you for sharing this wonderful package. It's a joy to be able to visualize PDB structures with just a few lines of R code.

I'm writing to ask for your help with a simple question: how can we rotate the view of our structure?

Here is the example I am working with:

library(NGLVieweR)
library(magrittr)
my_sele <- "9:A"
NGLVieweR("2bvp") %>%
  stageParameters(backgroundColor = "white", zoomSpeed = 1) %>%
  addRepresentation(
    type = "cartoon"
  ) %>%
  addRepresentation(
    type = "ball+stick",
    param = list(
      sele = my_sele
    )
  ) %>%
  addRepresentation(
    type = "label",
    param = list(
      sele = my_sele,
      labelType = "format",
      labelFormat = "[%(resname)s]%(resno)s", # or enter custom text
      labelGrouping = "residue", # or "atom" (eg. sele = "20:A.CB")
      color = "black",
      fontFamiliy = "sans-serif",
      xOffset = 1,
      yOffset = 0,
      zOffset = 0,
      fixedSize = TRUE,
      radiusType = 1,
      radiusSize = 5.5, # Label size
      showBackground = TRUE
      # backgroundColor="black",
      # backgroundOpacity=0.5
    )
  ) %>%
  zoomMove(
    center = my_sele,
    zoom = my_sele,
    duration = 0, # animation time in ms
    z_offSet = -20
  )

Below, the left panel shows the view that I see. The right panel shows the view that I want, after using the mouse to rotate the view 180 degrees.

In other words, I am seeing the "back" of the structure when I want to see the "front" instead.

Back of the structure (default output) Front of the structure (after rotating 180 degrees with the mouse)

What's the simplest way to rotate the view?

Feature Request

Hi,
Thanks for providing this package, it works great!

I just wanted to see if it would be possible to add something to 'remove' a viewer instance. I have the package running as part of a Shiny app that:

  1. Takes in user data table (proteomics),
  2. Grabs a Uniprot ID from table and populates a dropdown with all the unique uniprot IDs
  3. Queries a database to get a vector of PDB models associated with that Uniprot ID selected by user
  4. Populates a dropdown based on those PDB IDs to generate the model using your package, along with some other representations.

Largely this works fine. However, I have detected that there are instances when a user selects a protein and the model loads correctly, but when the user selects a new protein and the models available are (from what I can see) empty, the package reloads the previous model that was working and overlays the data for the newly selected protein, which is incorrect until the user selects a non-empty model. Here is the server code.

output$proteinViewer <- renderNGLVieweR({
req(input$modelSelection, peptideData(), input$groupSelection)

# Get group-peptide coverage
df <- peptideData()
coverage_string <- prot_coverage(df = df, selectedProt = input$selectedProtein, expGroup = input$groupSelection)
print(paste("Fetching model", input$modelSelection, "for group", input$groupSelection))

# Visualize in NGLVieweR using the selected PDB model
NGLVieweR(data = input$modelSelection) %>%
  stageParameters(backgroundColor = "white", zoomSpeed = 1) %>%
  addRepresentation("ribbon", param = list(name = "main", color = "skyblue")) %>%
  addRepresentation("ribbon", param = list(name = "coverage", sele = coverage_string, color = "green"))})

Some of this cant be helped due to the lack of information I can get from API about model prior to rendering, but Ideally when this happens it would be nice to have a method to tie to a actionButton that could 'clear' the current model till a new one is selected.

NGLVieweR - fullscreen

Hi!

I'm using the NGLVieweR in a Shiny-based webpage that includes molecular visualization. I would like to know if there's a way to fullscreen the NGL display? I mean, just the molecular visualization display, without the other components of the page. The updateFullscreen function seems to fullscreen the entire screen.

Thanks!

Background colour not working

I tried the code lines in the documentation but backgroundColor just doesn't work.
I keep on getting a black background. Any help will be appreciated.

Tried this

NGLVieweR("7CID") %>%
  stageParameters(backgroundColor = "white", zoomSpeed = 1) %>%
  addRepresentation("cartoon",
    param = list(name = "cartoon", colorScheme = "residueindex")
  ) %>%
  setSpin()

and this

NGLVieweR("7CID") %>%
 stageParameters(backgroundColor = "white", zoomSpeed = 1) %>%
 addRepresentation("cartoon", param = list(name = "cartoon", colorScheme="residueindex"))

if (interactive()) {
  library(shiny)
  ui <- fluidPage(NGLVieweROutput("structure"))
  server <- function(input, output) {
    output$structure <- renderNGLVieweR({
      NGLVieweR("7CID") %>%
        stageParameters(backgroundColor = "white", zoomSpeed = 1) %>%
        addRepresentation("cartoon",
          param = list(name = "cartoon", colorScheme = "residueindex")
        )
    })
  }
  shinyApp(ui, server)
}

Using PDB file as R variable for visualization

Hello,
Thank you for the tool. It works amazing.
Is it possible to use it to visualize a PDB files that stored as a variable (data.frame, matrix, character etc.)?
I am using ESM API to have the structure and I am writing it as a PDB file then I use it for visualization. Is it possible to use directly the request result?

My code goes like this:

`
seq <- "CKGADGAHGVNGCPGTAGAAGSVGGPGCDGGHGGNGGNGNPGCAGGVGGAGGASGGTGVGGRGGKGGSGTPKGADGAPGAP"
headers <- c('Content-Type'='application/x-www-form-urlencoded')
response <- POST('https://api.esmatlas.com/foldSequence/v1/pdb/', body = seq , headers=headers)

structure <- enc2utf8(rawToChar(response$content))
`

Is it possible to do it with NGLVieweR?
Thank you in advance

Is there any way to display a grid view?

Hi,

I wonder if there is a way to show molecules as grid view (pymol grid mode)? I would like to color the same protein with different metrics and show them side by side. When I rotate or zoom on one panel, the other ones rotate at the same time. Something like this:
b0140

Thanks,
Chen

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.