Skip to content

Instantly share code, notes, and snippets.

@tycheleturner
Last active October 30, 2022 23:43
Show Gist options
  • Save tycheleturner/19d2e7f6886a92ab51702906426a5fbd to your computer and use it in GitHub Desktop.
Save tycheleturner/19d2e7f6886a92ab51702906426a5fbd to your computer and use it in GitHub Desktop.
bulk_AlphaFold_viewer
---
title: "AlphaFold Viewer Final"
author: "Tychele N. Turner, Ph.D."
date: "Created on October 30, 2022"
output:
html_document: default
pdf_document: default
abstract: This document contains the documentation for making the AlphaFold html.
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
### Set up of the environment
```{r}
library("NGLVieweR")
#run interactive
setwd("~/Desktop/pdb_AF")
#list the pdb files
pdb <- list.files(".", pattern="pdb")
#make a function out of the viewer
nglV <- function(x){
NGLVieweR(x) %>% stageParameters(backgroundColor = "white", zoomSpeed = 1) %>% addRepresentation("cartoon", param = list(name = "cartoon", colorScheme = "bfactor") ) %>% setSpin()
}
###list the output from your other file in here to make the final html###
"NP_000132.3.pdb"
nglV(pdb[1])
"NP_000133.1.pdb"
nglV(pdb[2])
"NP_000179.2.pdb"
nglV(pdb[3])
"NP_000255.2.pdb"
nglV(pdb[4])
"NP_000275.1.pdb"
nglV(pdb[5])
"NP_000305.3.pdb"
nglV(pdb[6])
"NP_000453.2.pdb"
nglV(pdb[7])
"NP_000480.3.pdb"
nglV(pdb[8])
"NP_000507.1.pdb"
nglV(pdb[9])
"NP_000710.5.pdb"
nglV(pdb[10])
```
#!/bin/Rscript
#Tychele N. Turner, Ph.D.
#October 30, 2022
library("NGLVieweR")
#get pdb files
pdb <- list.files(".", pattern="pdb")
#loop to print out the name and the funtion running on the name of the file (this is the input to the viewer script)
for(i in 1:length(pdb)){
cat(paste('"', pdb[i], '"', "\n", sep=""))
cat(paste("nglV(pdb[", i, "])", "\n", sep=""))
}
@tycheleturner
Copy link
Author

tycheleturner commented Oct 30, 2022

Tychele N. Turner, Ph.D.
October 30, 2022

I wrote this gist because for some reason when you loop through NGLVieweR to generate AlphaFold 3D structures it does not output the images. However, if you enter them by name it works. This GIST consists of a prep script to generate the input and a R markdown file to run the code to generate multiple 3D figures.

To view multiple pdb files generated by AlphaFold

  1. Put the pdb files you want to visualize in one directory

  2. In the directory containing the pdb files, run the alphafold_viewer_prep.R as follows

Rscript alphafold_viewer_prep.R

Note, you must have R installed and you must have already installed the package NGLVieweR from https://cran.r-project.org/web/packages/NGLVieweR/

  1. The script above will output some text to the screen. Copy that text and paste it in the alphafold_viewer_final.Rmd right under ###list the output from your other file in here to make the final html### Open the Rmd file in Rstudio. You also will want to set your working directory to wherever you have your pdb files.

  2. In Rstudio, run Knit to HTML. An HTML file will generate, and you may see the 3D structures. If you do not see the structures, close the Rstudio version of the HTML and open the HTML file in FireFox. This should show you the images.

Final notes:

  • The NGLVieweR package has tons of options. The wrapper function I wrote assumes that you want coloring by AlphaFold confidence and also assumes you like the images to spin. These can be changed so check out https://cran.r-project.org/web/packages/NGLVieweR/vignettes/NGLVieweR.html if that interest you.
  • I have tested up to 72 structures and have encountered no errors with visualization using FireFox to view the HTML.

Example input files, generated by me, are located here:
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000132.3.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000133.1.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000179.2.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000255.2.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000275.1.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000305.3.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000453.2.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000480.3.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000507.1.pdb
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/NP_000710.5.pdb

Example output html, generated by me, is located here:
https://data.cyverse.org/dav-anon/iplant/home/tycheleturner/AlphaFold/bulk_AlphaFold_viewer/alphafold_viewer_final.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment