Skip to content

Commit

Permalink
removed code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
smuellerd committed Apr 11, 2024
1 parent fc62e55 commit d405bb6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
45 changes: 18 additions & 27 deletions R/utils-omnipath.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,37 +165,28 @@ get_collectri <- function(organism='human', split_complexes=FALSE, load_meta=FAL
stringr::str_detect(source_genesymbol, "NFKB") ~ "NFKB")
)
}


collectri <- base::rbind(collectri_interactions, collectri_complex) %>%
dplyr::distinct(source_genesymbol, target_genesymbol,
.keep_all = TRUE) %>%
dplyr::mutate(weight = dplyr::case_when(
is_stimulation == 1 ~ 1,
is_stimulation == 0 ~ -1
)) %>%
dplyr::rename("source" = source_genesymbol,
"target" = target_genesymbol,
"mor" = weight)

if (!load_meta){
collectri <- base::rbind(collectri_interactions, collectri_complex) %>%
dplyr::distinct(source_genesymbol, target_genesymbol,
.keep_all = TRUE) %>%
dplyr::mutate(weight = dplyr::case_when(
is_stimulation == 1 ~ 1,
is_stimulation == 0 ~ -1
)) %>%
dplyr::select(source_genesymbol, target_genesymbol,
weight) %>%
dplyr::rename("source" = source_genesymbol,
"target" = target_genesymbol,
"mor" = weight)
collectri <- collectri %>%
dplyr::select(source, target, mor)
} else {
collectri <- base::rbind(collectri_interactions, collectri_complex) %>%
dplyr::distinct(source_genesymbol, target_genesymbol,
.keep_all = TRUE) %>%
dplyr::mutate(weight = dplyr::case_when(
is_stimulation == 1 ~ 1,
is_stimulation == 0 ~ -1
)) %>%
dplyr::select(source_genesymbol, target_genesymbol,
weight, sources, references, sign_decision, TF_category) %>%
collectri <- collectri %>%
dplyr::mutate(references = stringr::str_extract_all(references, "\\d+")) %>%
dplyr::mutate(references = purrr::map_chr(references, ~paste(.x, collapse = ";"))) %>%
dplyr::rename("source" = source_genesymbol,
"target" = target_genesymbol,
"mor" = weight,
"resources" = sources,
"PMIDs" = references)
dplyr::rename("resources" = sources,
"PMIDs" = references) %>%
dplyr::select(source, target, mor, resources, PMIDs, sign_decision, TF_category)
}

return(collectri)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-omnipath.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ test_that("test get_collectri", {
testthat::expect_true(nrow(df) > 0)
df_split <- get_collectri(split_complexes=TRUE)
testthat::expect_true(nrow(df) < nrow(df_split))
df_split <- get_collectri(load_meta=TRUE)
testthat::expect_true(ncol(df) < ncol(df_split))
df_meta <- get_collectri(load_meta=TRUE)
testthat::expect_true(ncol(df) < ncol(df_meta))
})

0 comments on commit d405bb6

Please sign in to comment.