Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulty: “key_error” in dot plot for CellphoneDB output #73

Open
ums2026 opened this issue Jul 9, 2024 · 5 comments
Open

Difficulty: “key_error” in dot plot for CellphoneDB output #73

ums2026 opened this issue Jul 9, 2024 · 5 comments

Comments

@ums2026
Copy link

ums2026 commented Jul 9, 2024

Hello,

I am trying to create a dot plot for a Cellphone DB output, but am consistently receiving a “key_error”: “cell_type”.

My h5ad counts file looks like this one (from the CellphoneDB documentation) when I open it in a notebook:

image

Given that it looks like it is formatted properly, I am not sure why it says that I am missing something - when I run adata.obs_keys(), I do get an empty list in my data, but if that is the issue, I am not sure how to fix that. All the analyses are running correctly with this file in CellphoneDB. Is there any way to also input the metadata file to the plotting to fix this issue? Or is there some other problem causing the cell_type error?

Here is the exact error:

image

Thank you in advance!

@zktuong
Copy link
Owner

zktuong commented Jul 9, 2024

hi @ums2026, yes so basically you need to have cell_type in adata.obs and this is something that you can manually do like in the cellphonedb tutorial, do something like:

# read in the metadata file as per original tutorial
metadata = pd.read_csv(meta_file_path, sep = '\t')
# check the first 3 rows
# metadata.head(3)
# set the indices so that they match the adata.obs_names
metadata.set_index("barcode_sample", inplace=True) 
# now simply transfer
adata.obs["cell_type"] = metadata["cell_type"]

In a real-life scenario, the adata.obs would already contain this column if you were working with adata to begin with.

@luzgaral is aware of the same issue and would be pushing out an updated notebook shortly on cellphonedb's repo

@ums2026
Copy link
Author

ums2026 commented Jul 18, 2024

This is odd - we have worked with the same adata variable and were able to run the analysis on it, but it did not have the column.

I tried running it like this, with a new transfer, only this time, I ended up with a new error, that says "ValueError: No significant results found." I'm not sure how to fix that - do you have any suggestions? I am able to get a heatmap, but for some reason, I am getting this issue with a dot plot.

Thank you for the help!
Uma

@zktuong
Copy link
Owner

zktuong commented Jul 18, 2024

This is odd - we have worked with the same adata variable and were able to run the analysis on it, but it did not have the column.

yes that's because cellphonedb expects the 2 files (adata.h5ad and meta.txt) separately, but does not require that the adata.obs to contain the information in the meta.txt, whereas ktplotspy expects that that column already exists. I can certainly put in the option for ktplotspy to accept the meta.txt as well, to keep things simple.

I tried running it like this, with a new transfer, only this time, I ended up with a new error, that says "ValueError: No significant results found." I'm not sure how to fix that - do you have any suggestions? I am able to get a heatmap, but for some reason, I am getting this issue with a dot plot.

Can you show me the full command you used? did you specify genes/gene familites?

@ums2026
Copy link
Author

ums2026 commented Jul 22, 2024

Here is the command:


kpy.plot_cpdb(
    adata=adata,
    cell_type1="Oligo1",
    cell_type2=".", 
    means=means,
    pvals=pvalues,
    celltype_key="cell_type",
    figsize=(13, 4),
    title="interactions",
    keep_id_cp_interaction=True,
)

But I have also tried without specifying any cell types, this way:

kpy.plot_cpdb(
    adata=adata,
    cell_type1=".",
    cell_type2=".",  # this means all cell-types
    means=means,
    pvals=pvalues,
    celltype_key="cell_type",
    figsize=(13, 4),
    title="interacting interactions!",
    keep_id_cp_interaction=True,
)

I did not specify genes/gene families. Is this a requirement?

Thank you!

@zktuong
Copy link
Owner

zktuong commented Jul 22, 2024

hmm would you be able to share your input files and h5ad so that i can do some tests? if it's not too big, you can send them to my email [email protected] or we can find a more secure solution?

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

No branches or pull requests

2 participants