Skip to content
This repository was archived by the owner on Aug 18, 2026. It is now read-only.

Tutorial notebook for Pearson residuals - #43

Merged
giovp merged 12 commits into
scverse:masterfrom
jlause:tutorial_pearson_residuals
Mar 16, 2022
Merged

giovp merged 12 commits into
scverse:masterfrom
jlause:tutorial_pearson_residuals

Conversation

@jlause

@jlause jlause commented Jul 27, 2021 •

Copy link
Copy Markdown
Contributor

Hey all!

@giovp asked me over at scverse/scanpy#1715 to create a tutorial/demo notebook for the Pearson residual functions that I wrote for scanpy. Here is the first version I prepared.

In the notebooks I am using two different datasets to demonstrate an example workflow based on Pearson residuals. I borrowed some code/structure from the existing pbmc3k-tutorial, and restricted myself to showing the core functionality of Pearson residuals. For everything not directly demonstrated, I added some info on the optional arguments in the end.

Hope this is along the lines of what you expected - if not I'm happy to adjust :)

Looking forward to your feedback!

Jan

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@jlause jlause changed the title adding initial version of tutorial notebook Tutorial notebook for Pearson residuals Jul 27, 2021
@giovp

giovp commented Aug 1, 2021

Copy link
Copy Markdown
Member

hi @jlause ,

sorry again for late reply , I think the current tutorial look really good! I'd like to have someone else review it as well, I'll ask internally for another pair of eyes as well (should be quicker than mine 😅 ). Will keep you posted here!

Giovanni

@review-notebook-app

review-notebook-app Bot commented Aug 4, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

cartal commented on 2021-08-04T15:50:37Z
----------------------------------------------------------------

Personal preference: I would like to add a header with what the notebook is about and what the goal is.


jlause commented on 2021-08-04T16:10:30Z
----------------------------------------------------------------

Ok, I can add something like that tomorrow!

jlause commented on 2021-08-05T22:55:55Z
----------------------------------------------------------------

(done)

@review-notebook-app

review-notebook-app Bot commented Aug 4, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

cartal commented on 2021-08-04T15:50:38Z
----------------------------------------------------------------

This is a beautiful and clear explanation of what is going on. I would just add a reference fo the method for more details.


jlause commented on 2021-08-04T16:09:41Z
----------------------------------------------------------------

Ok, will do!

jlause commented on 2021-08-05T22:56:24Z
----------------------------------------------------------------

(done)

@review-notebook-app

review-notebook-app Bot commented Aug 4, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

cartal commented on 2021-08-04T15:50:39Z
----------------------------------------------------------------

As a general rule, I personally split the processing cells and the plotting cells so they are separated. It helps me focus on what is going on and keep my notebook clean.

Regarding colours, Red and Blue are fine, but also consider Gold and Blue or Purple and Green.

I would move the genes for markers_scanpy somewhere else, right now it is not clear why they are there. Obvious to analyst, less obvious to biologist navigating the workflow.


jlause commented on 2021-08-04T16:09:07Z
----------------------------------------------------------------

Good points, thank you!

I will split/reorganize the cell a little and add an explanation why the markers are needed/where they come from etc

Is there a default scanpy tutorial color scheme? Then I'd be happy to use that of course :)

jlause commented on 2021-08-05T22:57:35Z
----------------------------------------------------------------

Did the splitting and moved/explained the marker list above.

Left the colors as they are for now, but let me know if there is a favorite scanpy color scheme!

giovp commented on 2021-08-06T11:23:23Z
----------------------------------------------------------------

I think it looks great!

jlause commented on 2021-08-06T21:41:24Z
----------------------------------------------------------------

ok, then I'll leave it like this for now

@review-notebook-app

review-notebook-app Bot commented Aug 4, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

cartal commented on 2021-08-04T15:50:40Z
----------------------------------------------------------------

Ok, so DEGs from small populations will produce larger residuals. Define small population. What if I don't have small population in my data? Should I still use this method or go back to standard scanpy?

_This is why it makes sense to use them as basis for downstream processing._ - Not from this explanation.

Also, can we do this with UMAP as well?


jlause commented on 2021-08-04T16:05:58Z
----------------------------------------------------------------

Thank you for your feedback, I will try to clarify those points!

jlause commented on 2021-08-05T22:59:11Z
----------------------------------------------------------------

Done - let me know of you find it clearer now :)

@review-notebook-app

review-notebook-app Bot commented Aug 4, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

cartal commented on 2021-08-04T15:50:41Z
----------------------------------------------------------------

Very nice!

One question: could you add an example of how many cells do you mean by large or small?


jlause commented on 2021-08-04T16:04:22Z
----------------------------------------------------------------

Sure, I can e.g. add an example configuration how we processed a 2-million cell dataset with this method -- but the optimal settings for any will depend strongly on the amount of RAM available.

jlause commented on 2021-08-05T22:57:52Z
----------------------------------------------------------------

done

jlause commented Aug 4, 2021

Copy link
Copy Markdown
Contributor Author

Sure, I can e.g. add an example configuration how we processed a 2-million cell dataset with this method -- but the optimal settings for any will depend strongly on the amount of RAM available.


View entire conversation on ReviewNB

jlause commented Aug 4, 2021

Copy link
Copy Markdown
Contributor Author

Thank you for your feedback, I will try to clarify those points!


View entire conversation on ReviewNB

jlause commented Aug 4, 2021

Copy link
Copy Markdown
Contributor Author

Good points, thank you!

I will split/reorganize the cell a little and add an explanation why the markers are needed/where they come from etc

Is there a default scanpy tutorial color scheme? Then I'd be happy to use that of course :)


View entire conversation on ReviewNB

jlause commented Aug 4, 2021

Copy link
Copy Markdown
Contributor Author

Ok, will do!


View entire conversation on ReviewNB

jlause commented Aug 4, 2021

Copy link
Copy Markdown
Contributor Author

Ok, I can add something like that tomorrow!


View entire conversation on ReviewNB

jlause commented Aug 5, 2021

Copy link
Copy Markdown
Contributor Author

(done)


View entire conversation on ReviewNB

1 similar comment

jlause commented Aug 5, 2021

Copy link
Copy Markdown
Contributor Author

(done)


View entire conversation on ReviewNB

jlause commented Aug 5, 2021

Copy link
Copy Markdown
Contributor Author

Did the splitting and moved/explained the marker list above.

Left the colors as they are for now, but let me know if there is a favorite scanpy color scheme!


View entire conversation on ReviewNB

jlause commented Aug 5, 2021

Copy link
Copy Markdown
Contributor Author

done


View entire conversation on ReviewNB

jlause commented Aug 5, 2021

Copy link
Copy Markdown
Contributor Author

Done - let me know of you find it clearer now :)


View entire conversation on ReviewNB

@jlause

jlause commented Aug 5, 2021

Copy link
Copy Markdown
Contributor Author

Hey @cartal and @giovp,

thanks for the feedback and formatting help, I just pushed a revised version - let me know what you think, I can do further improvements next week!

Best, Jan.

giovp commented Aug 6, 2021

Copy link
Copy Markdown
Member

I think it looks great!


View entire conversation on ReviewNB

@review-notebook-app

review-notebook-app Bot commented Aug 6, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

lazappi commented on 2021-08-06T14:53:37Z
----------------------------------------------------------------

Nice intro, small typo in "archieved" -> "achieved"


jlause commented on 2021-08-06T19:59:00Z
----------------------------------------------------------------

thx! fixed :)

@review-notebook-app

review-notebook-app Bot commented Aug 6, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

lazappi commented on 2021-08-06T14:53:38Z
----------------------------------------------------------------

Typo "Preperations" -> "Preparations"


jlause commented on 2021-08-06T19:59:05Z
----------------------------------------------------------------

fixed!

@review-notebook-app

review-notebook-app Bot commented Aug 6, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

lazappi commented on 2021-08-06T14:53:39Z
----------------------------------------------------------------

Is this used in the tutorial? If not I would probably leave it out.


jlause commented on 2021-08-06T19:07:45Z
----------------------------------------------------------------

Yes, we use sc.tl.leiden(adata) in the end

@review-notebook-app

review-notebook-app Bot commented Aug 6, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

lazappi commented on 2021-08-06T14:53:39Z
----------------------------------------------------------------

Is there a way to include the code without it being run other than commenting it? I feel this might be confusing for users who are probably copy-pasting from the web. Maybe just describe how to get the data in text or maybe there is a Scanpy function that could be used?


jlause commented on 2021-08-06T19:14:01Z
----------------------------------------------------------------

I pretty much copied the approach from one of the existing tutorials: https://scanpy-tutorials.readthedocs.io/en/latest/pbmc3k.html

so I thought it might be ok like this. But you are right: For the 3k data there actually is a function that does the job: https://scanpy.readthedocs.io/en/stable/generated/scanpy.datasets.pbmc3k.html. for the 10k dataset, we would need to create a similar function for the 10k dataset.. happy to do that, but I'll leave that up to the scanpy team to decide :)

@review-notebook-app

review-notebook-app Bot commented Aug 6, 2021 •

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

lazappi commented on 2021-08-06T14:53:40Z
----------------------------------------------------------------

I would probably move this to straight after importing packages.


jlause commented on 2021-08-06T19:59:19Z
----------------------------------------------------------------

ok! done

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

Ok, I added short intro sentences to all cells - I think it was a good idea because it added some more motivation/context to some of the details

Regarding caching: I have not checked all tutorials, but in https://scanpy-tutorials.readthedocs.io/en/latest/pbmc3k.html caching is used as well


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

ok, fixed!


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

ok!


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

ok, changed accordingly!


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

I added a comment & explainer when the layer is created!


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

Right, I use those as a habit but it might be distracting here. removed and now using defaults!


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

good point, looping is not necessary here at all, fixed!


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

Yes, sure - I struggled to do it cleanly within the loop so I switched back to just modifying the two adata objects in parallel here


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

(I think this also makes it much more readable :) )


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

I agree, such a function makes a lot of sense to have (for any gene selection method, actually). Are you suggesting to add it as a scanpy core plotting function? Maybe you as the scanpy team should decide if we need to have it now, or add it at a later point and then change the tutorial again..?


View entire conversation on ReviewNB

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

ok, then I'll leave it like this for now


View entire conversation on ReviewNB

@jlause

jlause commented Aug 6, 2021

Copy link
Copy Markdown
Contributor Author

@jlause I just went through and made a bunch of comments. Sorry if it's a bit overwhelming but most of them are minor things. There are probably some other minor things in the text but not worth making 100 comments for.

Overall I think this is awesome, particularly the explanation of how the method works 🎉! Thanks for taking the time to contribute the function and the documentation.

Thanks a lot for the feedback @lazappi, that was very helpful! I made another improved revision including your suggestions which I will push in a moment. You also raised some issues that might require a joint decision from the scanpy team @giovp @cartal @lazappi @ivirshup:

  • how should tutorial data be loaded (commented-out wget code, scanpy.dataset function, just instructions. also: cached or not?). I tried to stick to the 3kPBMC example tutorial here, but will happily adapt if you want it changed
  • should the plot I made for inspecting the gene selection become a scanpy function, offering a diagnostic plot to the user? Worth adding it to Normalization and gene selection by analytical Pearson residuals  scanpy#1715 ? Now or in a later release?

Let me know what you think :)

@jlause

jlause commented Aug 10, 2021

Copy link
Copy Markdown
Contributor Author

PS: I added a brief mention of the wrapper functions (recipe_pearson_residuals() and normalize_pearson_residuals_pca()) in both intro and main part

@giovp

giovp commented Mar 9, 2022 •

Copy link
Copy Markdown
Member

@jlause I decided to also put this paper in references https://genomebiology.biomedcentral.com/articles/10.1186/s13059-021-02584-9

  • how should tutorial data be loaded (commented-out wget code, scanpy.dataset function, just instructions. also: cached or not?). I tried to stick to the 3kPBMC example tutorial here, but will happily adapt if you want it changed

At this point, I think this is fine although although a bit suboptimal. We have a pbmc3k datasets in Scanpy sc.datasets.pbmc3k() but you'd like to use both chemistry versions? what about only one?
@ivirshup ideas?

it would be very useful indeed but I think if you are still willing we can postpone it to another PR.

@giovp
giovp requested review from giovp and removed request for giovp March 9, 2022 20:39
@jlause

jlause commented Mar 11, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback!

@jlause I decided to also put this paper in references https://genomebiology.biomedcentral.com/articles/10.1186/s13059-021-02584-9

Yes that makes sense! I slightly edited the reference section again to have all references in the same format as the references in the scanpy docs (Authors, Title, Journal_with_Link).

  • how should tutorial data be loaded (commented-out wget code, scanpy.dataset function, just instructions. also: cached or not?). I tried to stick to the 3kPBMC example tutorial here, but will happily adapt if you want it changed

At this point, I think this is fine although although a bit suboptimal. We have a pbmc3k datasets in Scanpy sc.datasets.pbmc3k() but you'd like to use both chemistry versions? what about only one? @ivirshup ideas?

I think it would be nice to keep both in. If I'd need to choose, I'd prefer to keep the newer chemistry, because I think people would like to see a new method demonstrated on that. I could also write a loading function similar to the sc.datasets.pbmc3k() one if you wanted to. But at the moment, the same logic is used in the pbmc3k.ipynb tutorial, so maybe its fine as it is?! I leave that decision to you and can help implementing whichever way you choose

it would be very useful indeed but I think if you are still willing we can postpone it to another PR.

Okay, if you want to I can setup a PR for that next week and then we can see when there is time to merge it :)

@giovp

giovp commented Mar 11, 2022

Copy link
Copy Markdown
Member

Yes that makes sense! I slightly edited the reference section again to have all references in the same format as the references in the scanpy docs (Authors, Title, Journal_with_Link).

thank you!

I think it would be nice to keep both in. If I'd need to choose, I'd prefer to keep the newer chemistry, because I think people would like to see a new method demonstrated on that. I could also write a loading function similar to the sc.datasets.pbmc3k() one if you wanted to. But at the moment, the same logic is used in the pbmc3k.ipynb tutorial, so maybe its fine as it is?! I leave that decision to you and can help implementing whichever way you choose

makes sense, let's wait as datasets in general needs refactoring and also another host (pbmc3k in hosted by alex somwhere and makes CI fails sometime)

Okay, if you want to I can setup a PR for that next week and then we can see when there is time to merge it :)

that'd be great, not sure if we can fit it in for this release already but it'd be useful to have

so I assume this is ready to merge then @jlause ?

@jlause

jlause commented Mar 12, 2022

Copy link
Copy Markdown
Contributor Author

Okay, if you want to I can setup a PR for that next week and then we can see when there is time to merge it :)

that'd be great, not sure if we can fit it in for this release already but it'd be useful to have

okay sounds good!

so I assume this is ready to merge then @jlause ?

from my side yes! thanks a lot once more :)

@giovp
giovp merged commit eb9ff0e into scverse:master Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants