R/prepare_bold_res.R

library("tidyverse")

#' @export
prepare_bold_res <- function (bold_res, marker_code="", species_names=TRUE, coordinates=TRUE, ambiguities=TRUE, min_length=0, max_length=800) {
  if (marker_code != "") {
    if(!marker_code %in% bold_res$data$markercode) {
      print(paste0("WARNING: markercode ",marker_code ," not found in colon 'markercode' of ",bold_res))
    }
  }
  filteredBold <- bold_res$data %>% 
    { if (species_names) dplyr::filter(., species_name != "") } %>%
    { if (marker_code != "") dplyr::filter(., markercode == marker_code) } %>%
    { if (coordinates) dplyr::filter(., !is.na(lat)) %>% dplyr::filter(., !is.na(lon)) } %>%
    dplyr::mutate(sequence=as.character(bold_res$fasta[processid])) %>%
    dplyr::filter(., nchar(sequence) > min_length) %>%
    dplyr::filter(., nchar(sequence) < max_length) %>% 
    { if (ambiguities) dplyr::filter(., !grepl("I",sequence)) }
  return(filteredBold)
}
Grelot/geogendivr documentation built on Sept. 3, 2020, 6:25 p.m.