Skip to content
Snippets Groups Projects

improved get_map_contents

Merged Marek Ostaszewski requested to merge Rcode into master
2 files
+ 22
7
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -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)
}
Loading