Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Created April 18, 2020 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelnitta/a7268ed7729b3610f163fc749deef95b to your computer and use it in GitHub Desktop.
Save joelnitta/a7268ed7729b3610f163fc749deef95b to your computer and use it in GitHub Desktop.
Write out a list of fasta files in chunks
#' Write out a list of DNA sequences in chunks
#'
#' The list will be split into a list of lists, to
#' save memory when writing out sequences.
#'
#' @param fasta_list The list of DNA sequences
#' @param chunk_size Size of chunks to split up list into.
#' @param out_dir Directory to write to
#'
#' @return List of hashes; digest of each chunk. Externally, the
#' sequences will be written to out_dir
#'
write_fasta_files_chunked <- function(fasta_list, chunk_size = 100, out_dir) {
# Split list of fasta files to write out into chunks
n <- length(fasta_list)
r <- rep(1:ceiling(n/chunk_size), each=chunk_size)[1:n]
fasta_list_split <- split(fasta_list, r)
# Write out in chunks
purrr::map(fasta_list_split, ~baitfindR::write_fasta_files(., out_dir = out_dir))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment