Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Updating CellChatDB by adding ligand-receptor pairs from OmniPath #260

Open
superman2412 opened this issue Aug 9, 2021 · 3 comments
Open

Comments

@superman2412
Copy link

superman2412 commented Aug 9, 2021

Hello again Dr. Jin @sqjin!

Hope you are doing well. I was wondering if you could help me update CellChatDB by adding ligand-receptor pairs using data from OmniPath?

OmniPath contains a remarkably high number of, manually curated, high quality interactions that will increase the quality of CellChatDB significantly. I have attached the data here below.

all_interactions.csv

I did come across a function to be able to add Omnipath data to CellChat using the function in this post: https://github.com/saezlab/OmnipathR/issues/28#issuecomment-830045576.

The function is:

`#' Helper Function to Format to CellChatDB
#' @param ccDB Inbuilt cellchatDB object
#' @param op_resource omnipath resource
#' @param exclude_anns annotations to exclude
#' @import tibble
#' @importFrom magrittr %>%
#' @importFrom stringr str_glue str_detect str_replace str_replace_all
cellchat_formatDB <- function(ccDB, op_resource, exclude_anns){
# get complexes and interactions from omnipath
complex_interactions <- op_resource %>%
select(
"genesymbol_intercell_source" = target,
"genesymbol_intercell_target" = source,
"ligand" = source_genesymbol,
"receptor" = target_genesymbol,
"evidence" = sources,
category_intercell_source,
category_intercell_target,
is_directed,
is_stimulation,
is_inhibition
) %>%
unite("annotation",
c(category_intercell_source, category_intercell_target),
sep="-") %>%
unite("interaction_name", c(ligand, receptor), remove = FALSE) %>%
mutate(pathway_name = "",
agonist = "",
antagonist = "",
co_A_receptor = "",
co_I_receptor = "") %>%
mutate_at(vars(everything()), ~ replace(., is.na(.), ""))

# Get OmniPath directed info
omni_directions <- complex_interactions %>%
    select(interaction_name,
           is_directed,
           is_stimulation,
           is_inhibition,
           co_A_receptor,
           co_I_receptor
    ) %>%
    mutate(direction = pmap(., function(interaction_name,
                                        is_directed,
                                        is_stimulation,
                                        is_inhibition,
                                        co_A_receptor,
                                        co_I_receptor
    ){

        log_trace(interaction_name)

        if(co_A_receptor=="" & co_I_receptor==""){

            if(is_directed==1){
                if(is_stimulation==1 & is_inhibition==1){
                    return("Both")
                } else if(is_stimulation==1){
                    return("Stimulation")
                } else if(is_inhibition==1){
                    return("Inhibition")
                }
            }
        } else{
            return(NA)
        }
    }
    )) %>% unnest(direction)

# get complex type of interaction from OmniPath
omni_interactions <- complex_interactions %>%
    # set LR interactions as rowname
    left_join(., (omni_directions %>%
                      select(interaction_name,
                             direction)),
              by = "interaction_name") %>%
    mutate_at(vars(everything()), ~ replace(., is.na(.), "")) %>%
    mutate(co_A_receptor = ifelse(.data$co_A_receptor == "" & (direction == "Stimulation") | (direction == "both"),
                                  "Stimulation", .data$co_A_receptor),
           co_I_receptor = ifelse(.data$co_I_receptor == "" & (direction == "Inhibition") | (direction == "both"),
                                  "Inhibition", .data$co_I_receptor)) %>%
    # remove duplicates and assign to colnames
    mutate("interaction_name2" = interaction_name) %>%
    distinct_at(.vars="interaction_name2", .keep_all = TRUE) %>%
    column_to_rownames("interaction_name2") %>%
    # NOTE: ligand - (subunit_1 + subunit_2)
    mutate(interaction_name_2 = str_glue("{ligand} - {receptor}")) %>%
    mutate(interaction_name_2 = ifelse(str_detect(.data$receptor, "^COMPLEX"),
                                       str_glue("{ligand} -", "{str_split(receptor, pattern='_')}"), interaction_name_2)) %>%
    mutate(interaction_name_2 = ifelse(str_detect(.data$ligand, "^COMPLEX"),
                                       str_glue("{ligand} -", "{str_split(ligand, pattern='_')}"), interaction_name_2)) %>%
    mutate(interaction_name_2 = str_replace(interaction_name_2, "c", "")) %>%
    mutate(interaction_name_2 = str_replace(interaction_name_2, "COMPLEX:", "")) %>%
    mutate(interaction_name_2 = str_replace(interaction_name_2, "-", "- ")) %>%
    mutate(interaction_name_2 = str_replace_all(interaction_name_2, ", ", "+")) %>%
    mutate(interaction_name_2 = str_replace_all(interaction_name_2, '"', ""))

# Get Omni Complexes
omni_complexes <- complex_interactions %>%
    filter(str_detect(ligand, "_") |
               str_detect(receptor, "_")) %>%
    select(ligand, receptor)

# Convert to CellChat format
omni_complexes <- union(omni_complexes$ligand,
                        omni_complexes$receptor) %>%
    enframe() %>%
    separate(col=value, sep="_",
             into = c("subunit_1", "subunit_2",
                      "subunit_3", "subunit_4", "subunit_5"), remove=FALSE) %>%
    mutate_at(vars(everything()), ~ replace(., is.na(.), "")) %>%
    select(-name) %>%
    column_to_rownames("value")

# Replace Default DB with OmniPath Resource
ccDB$interaction <- omni_interactions %>%
    filter(!(annotation %in% exclude_anns))

ccDB$complex <- omni_complexes

return(ccDB)}`

However, I just cannot seem to implement it, probably because it is outdated and not compatible with the current version of OmniPath. After running the function it always gives me the same output as CellChatDB, nothing gets updated.

Can you please help me add all the interactions from Omnipath to CellChatDB?

Adding OmniPath will not only increase the range of interactions that CellChat can detect but this will immensely useful to the whole research community!

@superman2412
Copy link
Author

@sqjin Would be very grateful to you if you could shed some light upon this issue.

@sqjin
Copy link
Owner

sqjin commented Aug 14, 2021

@superman2412 Have you checked https://github.com/saezlab/liana? I think the convert function they provided could solve your issue. If you still have some issues, you can directly contact the first author of liana

@superman2412
Copy link
Author

@sqjin Thank you for your response. Unfortunately, that facility is not available in Omnipath / LIANA at this stage. More information can be obtained by the developers of Omnipath / LIANA on the following link.

saezlab/OmnipathR#28 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants