diff --git a/R/get_components_annotations.R b/R/get_components_annotations.R index 790ebdbad6819475cd96ff34cebaf60155eefa52..2dafc5d26944d255d1de0a3a005a38f5660c7ce8 100644 --- a/R/get_components_annotations.R +++ b/R/get_components_annotations.R @@ -6,7 +6,8 @@ #' Results correspond to the list of diagrams in a map. #' #' @param map_components (`list`) a list returned by the `minervar::get_map_components` function -#' @param annotation_type (`character`) the type of annotation to retrieve +#' @param annotation_types (`character`) a vector of types of annotation to retrieve +#' @param simple ('logical) if to simplify the output to just identifiers #' #' @return (`list`) a list of data frames with annotations for all components having this given type #' @examples @@ -14,7 +15,7 @@ #' get_components_annotations(example_map_components, "UNIPROT") #' #' @export -get_components_annotations <- function(map_components, annotation_type) { +get_components_annotations <- function(map_components, annotation_types, simple = TRUE) { ### Check correctness of 'map_components' if(!eval_map_components(map_components, required_element_names = "references")) { @@ -22,10 +23,22 @@ get_components_annotations <- function(map_components, annotation_type) { return(NULL) } - ### Get MINERVA references as a named list - message(paste0("Retrieving ", annotation_type, " identifiers for this MINERVA collection")) + ### Get MINERVA references as a named list of data frames with element id's and their filtered annotations + message(paste0("Retrieving ", paste(annotation_types, collapse = ", "), " identifiers for this MINERVA collection")) ### Apply get_annotation function - mnv_refs <- lapply(map_components$map_elements, function(x) sapply(x$references, get_annotation, annotation_type) ) + mnv_refs <- purrr::map(map_components$map_elements, + function(edf) dplyr::select(edf, "id", "references") %>% + dplyr::filter(purrr::map_lgl(.data[["references"]], ~ nrow(.) > 0)) %>% + dplyr::mutate(references = purrr::map(.data[["references"]], + function(rdf) + dplyr::filter(rdf, .data[["type"]] %in% annotation_types) %>% + dplyr::select("type", "resource") %>% + dplyr::distinct())) %>% + dplyr::filter(purrr::map_lgl(.data[["references"]], ~ nrow(.) > 0)) + ) + if(simple) { + mnv_refs <- purrr::map(mnv_refs, ~ purrr::map_chr(.[["references"]], function(ref) ref[["resource"]])) + } names(mnv_refs) <- map_components$models$name return(mnv_refs) } diff --git a/man/get_components_annotations.Rd b/man/get_components_annotations.Rd index aa190d6b035e4e28319e8c77534a6eca5b6dfb5d..cef6175a8ccfe4b414bec0786325e0a79f0ee8b7 100644 --- a/man/get_components_annotations.Rd +++ b/man/get_components_annotations.Rd @@ -4,12 +4,14 @@ \alias{get_components_annotations} \title{Get all element annotations from a \code{map_components} list} \usage{ -get_components_annotations(map_components, annotation_type) +get_components_annotations(map_components, annotation_types, simple = TRUE) } \arguments{ \item{map_components}{(\code{list}) a list returned by the \code{minervar::get_map_components} function} -\item{annotation_type}{(\code{character}) the type of annotation to retrieve} +\item{annotation_types}{(\code{character}) a vector of types of annotation to retrieve} + +\item{simple}{('logical) if to simplify the output to just identifiers} } \value{ (\code{list}) a list of data frames with annotations for all components having this given type