Skip to contents

This function gets FASTA data from an httr2_response and either saves it to a file or parses it in memory into a Biostrings::AAStringSet or named character vector.

Usage

resp_body_fasta(resp, con = NULL, encoding = NULL)

Arguments

resp

httr2_response object, generated by e.g. httr2::req_perform() or fetch_stream()/fetch_paged().

con

string or base::connection object (optional), the file in which to save the data.

encoding

string (optional), character encoding of the body text. If not specified, will use the encoding specified by the content-type, falling back to "UTF8" with a warning if it cannot be found. The resulting string is always re-encoded to UTF-8.

Value

By default, returns a Biostrings::AAStringSet object. If the Biostrings package is not installed, returns a named character vector. If con is not NULL, returns nothing and saves the FASTA sequences to the file specified by con.

Examples

resp <- structure(
  list(method = "GET", url = "https://example.com",
       body = charToRaw(">Protein1\nAAA\n>Protein2\nCCC")),
  class = "httr2_response"
)

resp_body_fasta(resp)
#> AAStringSet object of length 2:
#>     width seq                                               names               
#> [1]     3 AAA                                               Protein1
#> [2]     3 CCC                                               Protein2