zktuong / ktplots

Some tools for plotting single-cell data
https://zktuong.github.io/ktplots/
MIT License
162 stars 31 forks source link

plot_cpdb: Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length #101

Closed jreimertz closed 7 months ago

jreimertz commented 7 months ago

Hello! I keep getting the following error when trying to run plot_cpdb():

Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length

image

This is how I've been calling the function:

plot_cpdb(
    scdata=dura,
    cell_type1="immature B",
    cell_type2=".", 
    celltype_key="cell_type",
    means=means3,
    pvals=pvals3,
    degs_analysis = T,
    title="interacting interactions!"
)

So far in attempting to resolve this issue I've tried:

Running the function with the results of method 2 instead of method 3 resulted in the following error: image

I haven't been able to reproduce this error with the sample kidneyimmune dataset which makes me think the issue might be with my CellPhoneDB results but I'm not sure what could be causing the issue. Thank you in advance!

zktuong commented 7 months ago

hi @jreimertz yes this is a known issue at the moment but i haven't been able to find time to work on a good fix. tried it at #97 #99 to address #91 but not working at the moment

My current guess is that the issue is the pvals/relevant interaction file has different dimensions to the means file because the newer versions of cellphonedb trims the output.

The current manual fix is to try and duplicate the means file and pad the missing rows/columns with 1 or 0 (depending on whether it's statistical or deg mode respectively) like the suggested fix at https://github.com/zktuong/ktplotspy/issues/51

Would you be able to help me check if adding the missing row/columns for your data works?

jreimertz commented 7 months ago

I can confirm that pvals and means have different dimensions

> dim(means3)
[1] 2088  337
> dim(pvals3)
[1] 851 337

Unfortunately padding the missing rows in pvals led to a different error image

I've included the code I used to pad the rows in pvals

mat <- matrix(0, 1237, 337)
colnames(mat) <- colnames(pvals3)
pvals_test <- bind_rows(pvals3, as_tibble(mat) %>%
  mutate(across(everything(), ~ `class<-`(.x, class(pvals3[[cur_column()]])))))
> dim(means3) == dim(pvals_test)
[1] TRUE TRUE
zktuong commented 7 months ago

What about slicing means to contain the same interactions?

zktuong commented 7 months ago

oh i think your attempt to pad the rows throwing your issues because you didn't account for the first 11 or 15 columns where there's the usual information about the LR.

zktuong commented 7 months ago

hi @jreimertz , can you try installing the PR at

devtools::install_github("zktuong/ktplots", ref="fix-uneven-rows-and-columns")

and see if that helps?

or just install the master branch if you see that i've merged this in the coming few days

jreimertz commented 7 months ago

Hi @zktuong, I've installed the PR you referenced but attempting to run plot_cpdb() led to the following error: image Which was the error I got originally when trying to run the results from the second method

Slicing means to contain the same number of rows as pvals led to the original error: image

zktuong commented 7 months ago

Hmm puzzling. Could you send me your cellphonedb output files so that i can do some more testing? You can send them to z.tuong@uq.edu.au

zktuong commented 7 months ago

ok the issue is with tidyverse was used to read in the means and relevant_interactions files.