Skip to contents

This function performs a request for data from the UniProt REST API, fetches the results using the stream endpoint, and saves them to a file or into memory.

You likely won't use this function directly, but rather one of the wrapper functions: uniprot_map(), uniprot_search(), or uniprot_single().

Things to note:

  1. The stream endpoint is expensive for the API to process. If this endpoint has too many requests a 429 status error will occur. In this case use fetch_paged() or try again later.

  2. Up to 10,000,000 results can be fetched via stream. If you want to get more results you should use fetch_paged(), or consider downloading some datasets from UniProt's FTP website.

Usage

fetch_stream(req, format = "tsv", parse = TRUE, path = NULL, verbosity = NULL)

Arguments

req

httr2_request object, generated by e.g. httr2::request() or uniprot_request().

format

string, data format to fetch. Can be one of "tsv", "json" or "fasta".

parse

logical, should the response body be parsed e.g. into a data.frame or should the httr2_response object be returned instead? Default is TRUE. Does nothing if path is provided.

path

string (optional), file path to save the results, e.g. "path/to/results.tsv". The file must not already exist, otherwise an error is thrown.

verbosity

integer (optional), how much information to print?

  • 0: no output

  • NULL (default): minimal output

  • 1: show request headers

  • 2: show request headers and bodies

  • 3: show request headers, bodies, and curl status messages

Value

By default, returns an object whose type depends on format:

If parse = FALSE, returns an httr2_response. If path is specified, saves the parsed results to the file path indicated, and returns NULL

invisibly.

Examples

if (FALSE) {
  req <- uniprot_request(
    "https://rest.uniprot.org/uniref/stream",
    query = "P99999",
    format = "tsv",
    fields = "id,name,count"
  )

  fetch_stream(req)
}