---
title: "2.G: UniProt & rbioapi"
author: "Moosa Rezwani"
description: >
 Connect to UniProt in R with rbioapi package.
date: "`r Sys.Date()`"
output:
  rmarkdown::html_vignette:
    toc: true
    anchor_sections: true
    number_sections: true
    self_contained: true
    dev: png
    encoding: 'UTF-8'

vignette: >
  %\VignetteIndexEntry{2.G: UniProt & rbioapi}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r message=FALSE, include=FALSE, results="hide", setup, echo=FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  eval = TRUE,
  message = FALSE,
  warning = FALSE,
  collapse = TRUE,
  tidy = FALSE,
  cache = FALSE,
  dev = "png",
  comment = "#>"
)
library(rbioapi)
rba_options(timeout = 30, skip_error = TRUE)
```


# Introduction {#introduction}

Directly quoting from [UniProt](https://www.uniprot.org "Universal Protein Resource (UniProt)"):

> The Universal Protein Resource (UniProt) is a comprehensive resource for protein sequence and annotation data. The UniProt databases are the [UniProt Knowledgebase (UniProtKB)](https://www.uniprot.org/help/uniprotkb), the [UniProt Reference Clusters (UniRef)](https://www.uniprot.org/help/uniref), and the [UniProt Archive (UniParc)](https://www.uniprot.org/help/uniparc). The UniProt consortium and host institutions EMBL-EBI, SIB and PIR are committed to the long-term preservation of the UniProt databases.
>
> (source: <https://www.uniprot.org/help/about>)

------------------------------------------------------------------------

# Search vs Retrieve {#search-vs-retrieve}

Most of rbioapi UniProt functions have two variants. one to retrieve data using a proper accession, and the second one (which have a `_search` suffix) is to search using any combination of arguments. We first demonstrate this using an example, then provide a list of such functions in rbioapi.

Suppose we are interested in Human CD40 ligand protein, and we know that it's UniProt accession is "P29965". We can simply do as the following:

```{r rba_uniprot_proteins}
## 1 We can retrieve CD40 protein's information by qurying it's UniProt accession:
cd40 <- rba_uniprot_proteins(accession = "P29965")

## 2 We use str() to inspect our object's structure
str(cd40, 1)
```

This is the equivalent of the page that UniProt have on this accession ([UniProtKB - P29965](https://www.uniprot.org/uniprot/P29965 "UniProtKB - P29965 (CD40L_HUMAN)")). But what if we didn't know the UniProt accession? Or simply want to perform a search using certain parameters? We can use the function with `_search` suffix:

```{r rba_uniprot_proteins_search}
## 1 From the available arguments, we fill only those which we think is pertinent
cd40_search <- rba_uniprot_proteins_search(
  protein = "CD40 ligand",
  organism = "human",
  reviewed = TRUE
)

## 2 As always, we use str() to inspect our object's structure
str(cd40_search, 2)
```

This is the equivalent of '[advanced search](https://www.uniprot.org/help/advanced_search "UniProtKB advanced search options")' in UniProt web portal. See function `rba_uniprot_proteins_search`'s manual for more information. Remember that in `*_search` functions, you are not required to fill every argument, you can use any combination of arguments you see fit to build your search query.

The applications of `*_search` variants are not limited to what the title 'search' implies. These functions will also retrieve the search hits in their response; Thus you can use them for mass-retrieving. If you see the "argument" section in the functions' manuals, you would see that many arguments accept a vector of values. consider the following examples:

```{r rba_uniprot_proteins_search1_2}
## 1 As the simplest scenario, we can retrieve multiple proteins in one call
multi_prs1 <- rba_uniprot_proteins_search(
  accession = c("P04637", "P38398", "P24941", "P60953", "P06493", "Q02241")
)
## As always, we use str() to inspect our object's structure
str(multi_prs1, 1)

## 2 Or alternatively, search using Gene names, also we want to exclude isoforms and only retrieve swiss-prot entries
multi_prs2 <- rba_uniprot_proteins_search(
  gene = c("KIF23", "BRCA1", "TP53", "CDC42"),
  reviewed = TRUE,
  taxid = 9606,
  isoform = 0
)

str(multi_prs2, 1)
```

```{r rba_uniprot_proteins_search3}
## 3 Search for every proteins with chemokines keyword
multi_prs3 <- rba_uniprot_proteins_search(
  keyword = "chemokines"
)

str(multi_prs3, 1)
```

```{r rba_uniprot_proteins_search4}
## 4 Search for every protein of "SARS-CoV-2" virus in Swiss-Prot
multi_prs4 <- rba_uniprot_proteins_search(
  organism = "SARS-CoV-2",
  reviewed = TRUE
)

str(multi_prs4, 1)
```

------------------------------------------------------------------------

# Functions with `*_search` variant {#functions-with-star-search-variant}

The search variants are not limited to the above. Here is a list of the function that have both a retrieve and search variants. See their manuals for detailed guides and examples.

1.  `rba_uniprot_proteins()` & `rba_uniprot_proteins_search()`

2.  `rba_uniprot_features()` & `rba_uniprot_features_search()`

3.  `rba_uniprot_variation()` & `rba_uniprot_variation_search()`

4.  `rba_uniprot_proteomics()` & `rba_uniprot_proteomics_search()`

5.  `rba_uniprot_antigens()` & `rba_uniprot_antigens_search()`

6.  `rba_uniprot_epitope()` & `rba_uniprot_epitope_search()`

7.  `rba_uniprot_rna_edit()` & `rba_uniprot_rna_edit_search()`

8.  `rba_uniprot_proteomes()` & `rba_uniprot_proteomes_search()`

9.  `rba_uniprot_ptm()` & `rba_uniprot_ptm_search()`

10.  `rba_uniprot_mutagenesis()` & `rba_uniprot_mutagenesis_search()`

11.  `rba_uniprot_proteomics_hpp()` &  `rba_uniprot_proteomics_hpp_search()`
 
12.  `rba_uniprot_proteomics_non_ptm()` & `rba_uniprot_proteomics_non_ptm_search()`
 
13.  `rba_uniprot_proteomics_ptm()` & `rba_uniprot_proteomics_ptm_search()`

14.  `rba_uniprot_genecentric()` & `rba_uniprot_genecentric_search()`

15.  `rba_uniprot_uniparc()` & `rba_uniprot_uniparc_search()`

------------------------------------------------------------------------

# UniProt functions categories {#uniprot-functions-categories}

The UniProt API endpoints are organized into 5 group. Here are those categories and rbioapi functions that correspond to each one. See the functions' manuals for more details.

## Proteins {#proteins}

### Proteins: {#proteins-proteins}

-   `rba_uniprot_proteins()`

-   `rba_uniprot_proteins_search()`

-   `rba_uniprot_proteins_crossref()`

### Features {#proteins-features}

-   `rba_uniprot_features()`

-   `rba_uniprot_features_search()`

### Variation {#proteins-variation}

`rba_uniprot_variation()`

`rba_uniprot_variation_search()`

### Antigens {#antigens}

-   `rba_uniprot_antigens()`

-   `rba_uniprot_antigens_search()`

### Epitopes {#epitopes}

-   `rba_uniprot_epitope()`

-   `rba_uniprot_epitope_search()`

### Mutagenesis {#mutagenesis}

-   `rba_uniprot_mutagenesis()`

-   `rba_uniprot_mutagenesis_search()`

### RNA-Editing {#rna-editing}

-   `rba_uniprot_rna_edit()`

-   `rba_uniprot_rna_edit_search()`

## Proteomics {#proteomics}

-   `rba_uniprot_proteomics_species()`

-   `rba_uniprot_proteomics_hpp()`
 
-   `rba_uniprot_proteomics_hpp_search()`
 
-   `rba_uniprot_proteomics_non_ptm()`
 
-   `rba_uniprot_proteomics_non_ptm_search()`
 
-   `rba_uniprot_proteomics_ptm()`
 
-   `rba_uniprot_proteomics_ptm_search()`

## Proteomes {#proteomes}

-   `rba_uniprot_proteomes()`

-   `rba_uniprot_proteomes_search()`

-   `rba_uniprot_genecentric()`

-   `rba_uniprot_genecentric_search()`

## Taxonomy {#taxonomy}

-   `rba_uniprot_taxonomy()`

-   `rba_uniprot_taxonomy_lca()`

-   `rba_uniprot_taxonomy_lineage()`

-   `rba_uniprot_taxonomy_name()`

-   `rba_uniprot_taxonomy_path()`

-   `rba_uniprot_taxonomy_relationship()`

## Coordinates {#coordinates}

-   `rba_uniprot_coordinates()`

-   `rba_uniprot_coordinates_search()`

-   `rba_uniprot_coordinates_location()`

-   `rba_uniprot_coordinates_sequence()`

-   `rba_uniprot_genome_coordinates_sequence()`

## UniParc {#uniparc}

-   `rba_uniprot_uniparc()`

-   `rba_uniprot_uniparc_search()`

-   `rba_uniprot_uniparc_bestguess()`

-   `rba_uniprot_uniparc_sequence()`

------------------------------------------------------------------------

# How to Cite? {#citations}

To cite UniProt (Please see <https://www.uniprot.org/help/publications>):

-   The UniProt Consortium , UniProt: the Universal Protein Knowledgebase in 2025, *Nucleic Acids Research*, 2024;, gkae1010, <https://doi.org/10.1093/nar/gkae1010>
-   Andrew Nightingale, Ricardo Antunes, Emanuele Alpi, Borisas Bursteinas, Leonardo Gonzales, Wudong Liu, Jie Luo, Guoying Qi, Edd Turner, Maria Martin, The Proteins API: accessing key integrated protein and genome information, *Nucleic Acids Research*, Volume 45, Issue W1, 3 July 2017, Pages W539--W544, <https://doi.org/10.1093/nar/gkx237>

To cite rbioapi:

-   Moosa Rezwani, Ali Akbar Pourfathollah, Farshid Noorbakhsh, rbioapi: user-friendly R interface to biologic web services' API, Bioinformatics, Volume 38, Issue 10, 15 May 2022, Pages 2952--2953, <https://doi.org/10.1093/bioinformatics/btac172>

------------------------------------------------------------------------

# Links {#links}

-   [This article in rbioapi documentation site](https://rbioapi.moosa-r.com/articles/rbioapi_uniprot.html "2.F: UniProt & rbioapi")

-   [Functions references in rbioapi documentation site](https://rbioapi.moosa-r.com/reference/index.html#section-uniprot-rba-uniprot- "rbioapi reference")

-   [rbioapi vignette index](rbioapi.html "rbioapi: User-Friendly R Interface to Biologic Web Services' API")

------------------------------------------------------------------------

# Session info {#session-info}

```{r sessionInfo, echo=FALSE}
sessionInfo()
```
