saeyslab / multinichenetr

MultiNicheNet: a flexible framework for differential cell-cell communication analysis from multi-sample multi-condition single-cell transcriptomics data
GNU General Public License v3.0
113 stars 14 forks source link

inner_join Issue in "Intercellular regulatory network systems view" #43

Closed Mialn20 closed 9 months ago

Mialn20 commented 10 months ago

Hi multinichenetr team!

I have followed the following vignette and really like the package: https://github.com/saeyslab/multinichenetr/blob/main/vignettes/paired_analysis_SCC.md

Everything has worked perfectly until the last part with "Intercellular regulatory network systems view" This is the code and error.

group_oi = "ASpecificCondition" receiver_oi = "ASpecificCelltype"

prioritized_tbl_oi = get_top_n_lr_pairs(multinichenet_output$prioritization_tables, 150, rank_per_group = FALSE)

lr_target_prior_cor_filtered = multinichenet_output$prioritization_tables$group_prioritization_tbl$group %>% unique() %>% lapply(function(group_oi){ + lr_target_prior_cor_filtered = multinichenet_output$lr_target_prior_cor %>% inner_join(multinichenet_output$ligand_activities_targets_DEgenes$ligand_activities %>% distinct(ligand, target, direction_regulation, contrast)) %>% inner_join(contrast_tbl) %>% filter(group == group_oi) + lr_target_prior_cor_filtered_up = lr_target_prior_cor_filtered %>% filter(direction_regulation == "up") %>% filter( (rank_of_target < top_n_target) & (pearson > 0.50 | spearman > 0.50)) + lr_target_prior_cor_filtered_down = lr_target_prior_cor_filtered %>% filter(direction_regulation == "down") %>% filter( (rank_of_target < top_n_target) & (pearson < -0.50 | spearman < -0.50)) + lr_target_prior_cor_filtered = bind_rows(lr_target_prior_cor_filtered_up, lr_target_prior_cor_filtered_down) + }) %>% bind_rows()

Output i get

Joining with by = join_by(receiver, ligand, target) Warning in inner_join(., multinichenet_output$ligand_activities_targets_DEgenes$ligand_activities %>% : Detected an unexpected many-to-many relationship between x and y. ℹ Row 16 of x matches multiple rows in y. ℹ Row 107338 of y matches multiple rows in x. ℹ If a many-to-many relationship is expected, set relationship = "many-to-many" to silence this warning. Joining with by = join_by(contrast) Joining with by = join_by(receiver, ligand, target) Warning in inner_join(., multinichenet_output$ligand_activities_targets_DEgenes$ligand_activities %>% : Detected an unexpected many-to-many relationship between x and y. ℹ Row 16 of x matches multiple rows in y. ℹ Row 107338 of y matches multiple rows in x. ℹ If a many-to-many relationship is expected, set relationship = "many-to-many" to silence this warning. Joining with by = join_by(contrast)

I also get error when plotting in the next step: Warning in max(f) : no non-missing arguments to max; returning -Inf Error in ggraph::geom_edge_loop(): ! Problem while computing stat. ℹ Error occurred in the 2nd layer. Caused by error in seq_len(): ! argument must be coercible to non-negative integer Backtrace:

  1. base (local) <fn>(x)
  2. ggplot2:::print.ggplot(x)
  3. ggplot2:::ggplot_build.ggplot(x)
  4. ggplot2:::by_layer(...)
    1. ggplot2 (local) f(l = layers[[i]], d = data[[i]]) ...
    2. ggplot2 (local) compute_statistic(..., self = self)
    3. self$stat$compute_layer(data, self$computed_stat_params, layout)
    4. ggplot2 (local) compute_layer(..., self = self)
    5. ggplot2:::dapply(...)
    6. ggplot2:::split_with_index(seq_len(nrow(df)), ids)

Error in ggraph::geom_edge_loop(aes(color = direction_regulation), edge_width = 1, : ℹ Error occurred in the 2nd layer. Caused by error in seq_len(): ! argument must be coercible to non-negative integer

browaeysrobin commented 10 months ago

Hi @Mialn20

This issue seems to be the same as #10 . Can you check the solution I provided there and close this issue if it works?

Mialn20 commented 10 months ago

Hi @browaeysrobin It seems to have solved the issue!

Can you help me understand how to read the plot or where i can find an elaboration of this explanation: "As last plot, we can generate a ‘systems’ view of these intercellular feedback and cascade processes than can be occuring between the different cell populations involved. In this plot, we will draw links between ligands of sender cell types their ligand/receptor-annotated target genes in receiver cell types. So links are ligand-target links (= gene regulatory links) and not ligand-receptor protein-protein interactions!"

It should be noted that i am just a bachelor student so sorry if this is a very basic question.

Thanks a lot

browaeysrobin commented 9 months ago

Hi @Mialn20

It is always recommended to be more specific when you do not understand something. Now, I cannot know which parts of the explanation you don't understand and where I should focus on in a detailed explanation. Everything you need to know is in theory in the NicheNet and MultiNicheNet papper.

I will be closing this issue. You can always send a mail with more specific questions.