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

CITE-seq scatter plot of pairwise RNA-prot correlations #48

Closed
chris-rands opened this issue Jan 21, 2022 · 3 comments
Closed

CITE-seq scatter plot of pairwise RNA-prot correlations #48

chris-rands opened this issue Jan 21, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@chris-rands
Copy link

Thanks for muon. Following the CITE-seq tutorial, I'd like to do simple scatter plots and regression to show the RNA-prot correlation for particular markers, something like in the Seurat muli-modal tutorial.:
image

I tried sc.pl.scatter(mdata, x="prot:CD3D", y="rna:CD3D") This raises: KeyError: 'There is no key prot:CD3D in MuData .obs or in .obs of any modalities.' Of course the gene/protein names are stored in .var not .obs.

Suggestions appreciated, thank you

@chris-rands chris-rands added the enhancement New feature or request label Jan 21, 2022
gtca added a commit that referenced this issue Feb 8, 2022
@gtca
Copy link
Collaborator

gtca commented Feb 8, 2022

Hey @chris-rands, thanks a lot for your feedback! The reason was the lack of .pl.scatter in muon.
Now mu.pl.scatter(mdata, ...) should work.

Moreover, for this there's now a more sophisticated function under the hood to parse variables so even the following things should work:

mu.pl.scatter(mdata, x="X_umap:1", y="X_umap:2", color="CD8A")
# will produce a plot similar to mu.pl.umap(mdata, color="CD8A")

mu.pl.scatter(mdata, x="CD8A", y="CD8a_TotalSeqB", color="rna:X_umap:1")
# will set the colour to the first UMAP component in the RNA modality

It also seems to me that scverse/scanpy#311 hasn't been actually fixed — is that your experience as well?

Please let me know what you think!

@chris-rands
Copy link
Author

Hi @gtca, thank you very much, I didn't know this would require a new feature! I have tested it and it works. One comment, removing the "rna:" or "prot:" prefixes from the feature names isn't needed in my use case since I already ran mdata.var_names_make_unique() so to get this to work I actually need to double the prefixes, e.g. mu.pl.scatter(mdata, x="prot:prot:CD3D", y="rna:rna:CD3D").

I agree that the scanpy issue does not appear fixed in the sense that the color arg cannot be a list for sc.pl.scatter` it seems

Is it possible to add a regression line to the scatter plot?

@gtca
Copy link
Collaborator

gtca commented Feb 16, 2022

Hey @chris-rands, glad that it works! And thanks for your feedback.
Now it should handle the case when var_names have a modality prefix correctly.
Moreover, now the same functionality should work even when some modalities have cells that are not present in others (e.g. the 'rna' modality has more cells than 'prot' modality does).

With regression, if this was implemented e.g. in sc.pl.scatter, mu.pl.scatter would just work (or we could at least build on top of that). I am not sure this is something coming in sc.pl.scatter though. One might want to overlay other interpolations, or exclude cells with missing values (e.g. with zero CD3E expression in the plot above) from the fit, and all this can be achieved e.g. with matplotlib although would require a few more lines of code:

# Calculate coefficients for the regression line
from numpy.polynomial.polynomial import polyfit
x = mdata["rna"][:,"CD3E"].X.squeeze()
y = mdata["prot"][:,"CD3_TotalSeqB"].X.squeeze()
a, b = polyfit(x, y, deg=1)

# Plot data
mu.pl.scatter(mdata, x="CD3E", y="CD3_TotalSeqB", show=False)
# Plot regression line and display the figure
plt.plot(x, a + b * x, "-")
plt.show()

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

No branches or pull requests

2 participants