Skip to content

make_ligand_activity_target_plot fails when only one ligand is selected #127

Description

@KurayiChawatama

Summary

The plotting helper for ligand activity and ligand-target combinations fails when the input is filtered down to a single ligand. This appears to be an edge case in the plotting code rather than a problem with the downstream analysis itself.

Expected behavior

The plot should render successfully even when the user requests a single ligand for a specific group and receiver combination.

group_oi = "Tumor"
receiver_oi = "CLEC9A"
ligands_oi = c("CSF1") # or alternatively "CSF1"
prioritized_tbl_ligands_oi = get_top_n_lr_pairs(
  multinichenet_output$prioritization_tables, 
  10000, 
  groups_oi = group_oi, 
  receivers_oi = receiver_oi
  ) %>% filter(ligand %in% ligands_oi) # ligands should still be in the output tables of course

then

combined_plot = make_ligand_activity_target_plot(
  group_oi, 
  receiver_oi, 
  prioritized_tbl_ligands_oi, 
  multinichenet_output$prioritization_tables, 
  multinichenet_output$ligand_activities_targets_DEgenes, 
  contrast_tbl, 
  multinichenet_output$grouping_tbl, 
  multinichenet_output$celltype_info, 
  ligand_target_matrix, 
  plot_legend = FALSE)

Actual behavior

The call fails with:

Error in dimnames(x) <- dn: length of 'dimnames' [1] not equal to array extent

Why this seems to happen

The helper appears to assume a multi-ligand input when it reshapes the ligand-target matrix and assigns row names. When only one ligand is present in the filtered table, that assumption breaks and the matrix dimensions no longer match the expected dimnames assignment.

Notes

  • The receiver and group names are valid.
  • The filtered table is not empty.
  • The failure occurs specifically when the filtered ligand set contains only one unique ligand.

Suggested fix

Handle the single-ligand case explicitly in make_ligand_activity_target_plot, or guard the matrix reshaping / rowname assignment so it works for both one-ligand and multi-ligand inputs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions