Last updated: 2023-06-27

Checks: 7 0

Knit directory: bioinformatics_tips/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200503) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 97b7d02. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/compsci.Rmd
    Untracked:  analysis/framework.Rmd

Unstaged changes:
    Modified:   analysis/security.Rmd
    Modified:   script/run_rstudio.sh

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/restful.Rmd) and HTML (docs/restful.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html e9934e7 davetang 2020-06-07 Security basics
html 17994b6 davetang 2020-05-16 Build site.
Rmd 5e7606d davetang 2020-05-16 Use APIs

Introduction

Representational state transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the Internet. RESTful Web services allow the requesting systems to access and manipulate textual representations of Web resources by using a uniform and predefined set of stateless operations. Other kinds of Web services, such as SOAP Web services, expose their own arbitrary sets of operations.

A client will receive a representation of the state of the requested resource from a server when a RESTful API is called. The representation of the state is typically returned in JSON.

A server requires an identifier for the resource, which is typically the URL of the resource and is also known as the endpoint, and the operation to perform on the resource in the form of an HTTP method:

  1. GET − Provides a read only access to a resource.
  2. POST − Used to create a new resource.
  3. DELETE − Used to remove a resource.
  4. PUT − Used to update a existing resource or create a new resource.

Stateless operations means that each request contains all the information the server requires to perform the operation and does not require information from a previous query.

There are six contraints that must be adhered to in order for an API to be RESTful:

  1. Uniform interface
  2. Client — server separation
  3. Stateless
  4. Layered system
  5. Cacheable
  6. Code-on-demand

See https://www.tutorialspoint.com/restful/restful_introduction.htm for more information.

Purpose

RESTful APIs allow you to programmatically interact with various resources; this ultimately saves you time and promotes reproducibility.

JSON

JSON stands for JavaScript Object Notation and is a syntax for storing and exchanging data. Use the rjson package to parse JSON output.

install.packages("rjson")

Load into data/example.json into R and convert to data frame.

library("rjson")
read_json <- fromJSON(file = "data/example.json")
as.data.frame(read_json)[, 1:5]
        input strand transcript_consequences.gene_id
1 rs116035550      1                 ENSG00000177963
2 rs116035550      1                 ENSG00000177963
  transcript_consequences.sift_score transcript_consequences.cds_end
1                                  0                            1018
2                                  0                            1018

Application

data/example.json was generated by running the following query:

curl -H 'Accept: application/json' \
-H 'Content-type: application/json' -X POST \
-d '{ "ids" : ["rs116035550", "COSM476" ] }' \
https://rest.ensembl.org/vep/human/id/ > example.json

If you wanted to get information for another SNP, e.g. rs17822931, you can just modify the ids field.

curl -H 'Accept: application/json' \
-H 'Content-type: application/json' -X POST \
-d '{ "ids" : ["rs17822931"] }' \
https://rest.ensembl.org/vep/human/id/ > rs17822931.json

If you write a script that can generate the queries, you can easily obtain information on SNP IDs of interest.


sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rjson_0.2.21    workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.4   compiler_4.3.0   promises_1.2.0.1 Rcpp_1.0.10     
 [5] stringr_1.5.0    git2r_0.32.0     callr_3.7.3      later_1.3.0     
 [9] jquerylib_0.1.4  yaml_2.3.7       fastmap_1.1.1    R6_2.5.1        
[13] knitr_1.42       tibble_3.2.1     rprojroot_2.0.3  bslib_0.4.2     
[17] pillar_1.9.0     rlang_1.1.1      utf8_1.2.3       cachem_1.0.7    
[21] stringi_1.7.12   httpuv_1.6.9     xfun_0.39        getPass_0.2-2   
[25] fs_1.6.2         sass_0.4.5       cli_3.6.1        magrittr_2.0.3  
[29] ps_1.7.5         digest_0.6.31    processx_3.8.1   rstudioapi_0.14 
[33] lifecycle_1.0.3  vctrs_0.6.3      evaluate_0.20    glue_1.6.2      
[37] whisker_0.4.1    fansi_1.0.4      rmarkdown_2.21   httr_1.4.5      
[41] tools_4.3.0      pkgconfig_2.0.3  htmltools_0.5.5