Answers.Body: <p>I managed to find the solution. After @gringer mentioned that they had not seen the <code>flatten</code> command I decided to dig deeper. Turns out the command has been superseded  in purrr 1.0.0. So I will be posting the new script for anyone who seeks an updated version of the one in the old thread.</p>
  <pre><code># load packages
  library(tidyverse)
  library(rentrez)
  library(bold)    # API interface to BOLD
  library(taxize)  # for NCBI taxonomy lookup
  library(seqinr)  # for FASTA output
  library(rBLAST)  
  
  
  set_entrez_key(&quot;d00fee673c4499df4c2479ba5fd71850b308&quot;) #my ncbi api key, this is essential for pulling the taxonomy through ncbi
  
  # get class-level taxa within &quot;Mollusca&quot; from NCBI taxonomy
  taxa &lt;- downstream(&quot;Mollusca&quot;, db = &quot;ncbi&quot;, downto = &quot;class&quot;) #setting the taxonomic level of the search. it will pull sequences for all mollusca but seperately for each class. if the search is large change to a lower taxonomic level
  
  # check if taxa present in BOLD
  checks &lt;- bold_tax_name(taxa<span class="math-container">$Mollusca$</span>childtaxa_name) 
  taxa_bold &lt;- checks[!is.na(checks<span class="math-container">$taxon),]$</span>taxon
  
  # Download sequences from BOLD for each class-level taxon
  sequences &lt;- map(taxa_bold, bold_seq, marker = 'COI-5P') 
  # Convert the list of sequences to a data frame
  sequences_df &lt;- do.call(rbind, sequences)
  
  
  
  
  # Filter sequences based on the &quot;COI-5P&quot; marker. Despite the markes parameter, some files may have integrated multiple loci. The other sequences are removed from the R object
  coi5p_sequences &lt;- sequences_df %&gt;% 
    filter(marker == &quot;COI-5P&quot;)
  
  # Write sequences to a file
  write.fasta(
    sequences = as.list(coi5p_sequences<span class="math-container">$sequence), 
    names = as.list(coi5p_sequences$</span>id), 
    nbchar = 60, 
    file.out = 'coi5p_Mollusca.fasta'
  )
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-29T15:49:12.197Z
Answers.LastActivityDate: 2023-10-29T15:49:12.197Z
Answers.UserDisplayName: Nickmofoe
Body: <p>So I wanted to download massive amounts of COX1 (or COI) sequences from any available database. I found this script in <a href="https://bioinformatics.stackexchange.com/a/13187/16657">https://bioinformatics.stackexchange.com/a/13187/16657</a> this comment that achieves just that using the <code>bold</code> R package. I changed the script to fit my data preference:</p>
  <pre><code># load packages
  library(tidyverse)
  library(rentrez)
  library(bold)    # API interface to BOLD
  library(taxize)  # for NCBI taxonomy lookup
  library(seqinr)  # for FASTA output
  
  set_entrez_key()
  
  # get class-level taxa within &quot;Mollusca&quot; from NCBI taxonomy
  taxa &lt;- downstream(&quot;Mollusca&quot;, db = &quot;ncbi&quot;, downto = &quot;order&quot;)
  # check if taxa present in BOLD
  checks &lt;- bold_tax_name(taxa<span class="math-container">$Mollusca$</span>childtaxa_name)
  taxa_bold &lt;- checks[!is.na(checks<span class="math-container">$taxon),]$</span>taxon
  
  # Download sequences from BOLD for each class-level taxon
  sequences &lt;- map(taxa_bold, bold_seq, marker = 'COI-5P') %&gt;%
    flatten() %&gt;%
    bind_rows()
  
  # Convert the list of sequences to a data frame
  sequences_df &lt;- do.call(rbind, sequences)
  
  
  # Write sequences to a file
  write.fasta(
    sequences = as.list(sequences_df<span class="math-container">$sequence), 
    names = as.list(sequences_df$</span>id), 
    nbchar = 80, 
    file.out = 'coi5p.fasta'
  )
  
  </code></pre>
  <p>In the aforementioned thread, this script worked but now that I ran it I got the following error:</p>
  <pre><code>Error in `bind_rows()`:
  ! Argument 1 must be a data frame or a named atomic vector.
  Run `rlang::last_trace()` to see where the error occurred.
  </code></pre>
  <p>I am not sure what to do for this. I commented on the original thread but since it is kind of old I decided to post about it here.</p>
  <p>Note: the <code>set_entrez_key()</code> requires a NCBI API key which you can get by registering on NCBI.</p>
  <p>Edit #1: The <code>sequences</code> object before the <code>flatten()</code> command is a large list containing 53 elements. After the command, the object becomes a large list with 257 elements.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-29T07:23:38.160Z
Comments.Text: Can you please show the object as it appears before and after the 'flatten' command? It's unusual for me to see that command in R code, and this is just before the `bind_rows` command that you're concerned about, so it will probably be important for working out what's going wrong.
Comments.UserDisplayName: gringer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-29T07:55:27.293Z
Comments.Text: @gringer I edited the question with the details about the object.
Comments.UserDisplayName: Nickmofoe
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-29T11:30:57.237Z
Comments.Text: Please show the head of the object, or the first few lines of output. Your text description is not detailed enough for me to understand what's going on.
Comments.UserDisplayName: gringer
Tags: <database>
Title: How can I resolve `bind_rows()` error?
ThreadText: # How can I resolve `bind_rows()` error?
  
  (Asked by: username_0 on 2023-10-28)
  
  So I wanted to download massive amounts of COX1 (or COI) sequences from any available database. I found this script in <https://bioinformatics.stackexchange.com/a/13187/16657> this comment that achieves just that using the `bold` R package. I changed the script to fit my data preference:
  
  ```
  # load packages
  library(tidyverse)
  library(rentrez)
  library(bold)    # API interface to BOLD
  library(taxize)  # for NCBI taxonomy lookup
  library(seqinr)  # for FASTA output
  
  set_entrez_key()
  
  # get class-level taxa within "Mollusca" from NCBI taxonomy
  taxa <- downstream("Mollusca", db = "ncbi", downto = "order")
  # check if taxa present in BOLD
  checks <- bold_tax_name(taxa$Mollusca$childtaxa_name)
  taxa_bold <- checks[!is.na(checks$taxon),]$taxon
  
  # Download sequences from BOLD for each class-level taxon
  sequences <- map(taxa_bold, bold_seq, marker = 'COI-5P') %>%
    flatten() %>%
    bind_rows()
  
  # Convert the list of sequences to a data frame
  sequences_df <- do.call(rbind, sequences)
  
  # Write sequences to a file
  write.fasta(
    sequences = as.list(sequences_df$sequence), 
    names = as.list(sequences_df$id), 
    nbchar = 80, 
    file.out = 'coi5p.fasta'
  )
  
  ```
  
  In the aforementioned thread, this script worked but now that I ran it I got the following error:
  
  ```
  Error in `bind_rows()`:
  ! Argument 1 must be a data frame or a named atomic vector.
  Run `rlang::last_trace()` to see where the error occurred.
  
  ```
  
  I am not sure what to do for this. I commented on the original thread but since it is kind of old I decided to post about it here.
  
  Note: the `set_entrez_key()` requires a NCBI API key which you can get by registering on NCBI.
  
  Edit #1: The `sequences` object before the `flatten()` command is a large list containing 53 elements. After the command, the object becomes a large list with 257 elements.
  
  **Tags:** database
  
  > **Comments:**
  > **username_1**: Can you please show the object as it appears before and after the 'flatten' command? It's unusual for me to see that command in R code, and this is just before the `bind_rows` command that you're concerned about, so it will probably be important for working out what's going wrong.  
  > **username_0**: @username_1 I edited the question with the details about the object.  
  > **username_1**: Please show the head of the object, or the first few lines of output. Your text description is not detailed enough for me to understand what's going on.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-10-29. Score: 2 | Accepted answer
  
  I managed to find the solution. After @username_1 mentioned that they had not seen the `flatten` command I decided to dig deeper. Turns out the command has been superseded in purrr 1.0.0. So I will be posting the new script for anyone who seeks an updated version of the one in the old thread.
  
  ```
  # load packages
  library(tidyverse)
  library(rentrez)
  library(bold)    # API interface to BOLD
  library(taxize)  # for NCBI taxonomy lookup
  library(seqinr)  # for FASTA output
  library(rBLAST)  
  
  set_entrez_key("d00fee673c4499df4c2479ba5fd71850b308") #my ncbi api key, this is essential for pulling the taxonomy through ncbi
  
  # get class-level taxa within "Mollusca" from NCBI taxonomy
  taxa <- downstream("Mollusca", db = "ncbi", downto = "class") #setting the taxonomic level of the search. it will pull sequences for all mollusca but seperately for each class. if the search is large change to a lower taxonomic level
  
  # check if taxa present in BOLD
  checks <- bold_tax_name(taxa$Mollusca$childtaxa_name) 
  taxa_bold <- checks[!is.na(checks$taxon),]$taxon
  
  # Download sequences from BOLD for each class-level taxon
  sequences <- map(taxa_bold, bold_seq, marker = 'COI-5P') 
  # Convert the list of sequences to a data frame
  sequences_df <- do.call(rbind, sequences)
  
  # Filter sequences based on the "COI-5P" marker. Despite the markes parameter, some files may have integrated multiple loci. The other sequences are removed from the R object
  coi5p_sequences <- sequences_df %>% 
    filter(marker == "COI-5P")
  
  # Write sequences to a file
  write.fasta(
    sequences = as.list(coi5p_sequences$sequence), 
    names = as.list(coi5p_sequences$id), 
    nbchar = 60, 
    file.out = 'coi5p_Mollusca.fasta'
  )
  
  ```
  
  
  ---
  
  