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))
})

3 comments on commit d405bb6

@Megan0921
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to use decoupleR for the analysis of my omics data. I have checked the version of decoupleR and OmnipathR. The version of decoupleR and OmnipathR I downloaded is 2.11.0 and 3.13.5 respectively. When I running the command "collecTRI <- decoupleR::get_collectri(organism='human', split_complexes=FALSE)", I am getting the following error message:

[1] TRUE
[2024-07-13 20:57:38] [ERROR] [OmnipathR] only_from can be called only on data frames with evidences column.
[2024-07-13 20:57:39] [WARN] [OmnipathR] Accessing collectri as a static table: this is not the recommended way to access OmniPath data; it is only a backup plan for situations when our server or your computer is experiencing issues.
[2024-07-13 20:57:39] [ERROR] [OmnipathR] only_from can be called only on data frames with evidences column.
Error in do.call(stop, list(m), envir = env) :
only_from can be called only on data frames with evidences column.

How can I fix this problem? Looking forward to your reply. Thanks a lot!

Error message

@deeenes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Megan0921, Here the first error matters, and I think likely it happens due to old cache contents. What happens if you try it with an empty cache?

library(OmnipathR)

omnipath_set_console_loglevel('trace')
omnipath_set_cachedir(tempdir())
ci <- collectri()

@Megan0921
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that worked. Thank you so much @deeenes!

Please sign in to comment.