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

Introduce a groupby attribute for correlation computation #731

Merged
merged 4 commits into from
Jul 15, 2024

Conversation

Marius1311
Copy link
Collaborator

This introduces a groupby parameter for mapping_problem.correlate() to evaluate Pearson/Spearmann correlation over groups of cells. I've also adapted tests slightly to cover this case.

@Marius1311 Marius1311 requested a review from giovp July 9, 2024 13:52
@Marius1311 Marius1311 mentioned this pull request Jul 9, 2024
Copy link
Member

@giovp giovp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! Test also looks good. Minor comments. Thanks for the PR!

@@ -396,7 +396,9 @@ def correlate( # type: ignore[misc]
self: SpatialMappingMixinProtocol[K, B],
var_names: Optional[Sequence[str]] = None,
corr_method: Literal["pearson", "spearman"] = "pearson",
) -> Mapping[Tuple[K, K], pd.Series]:
device: Optional[Device_t] = None,
groupby: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about calling it groups? My understanding is that this is used to compute correlation between groups, see lines 457, 458. I think groups is more fitting and to some extent mirrors the usage of the argument in other scverse packages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually prefer groupby - you still get a vector of the same length, i.e. length n_genes. The difference to before it that when you compute correlation, you only take into account the cells in the current group. In other words, you now get one such vector (containing correlations) per problem and per group.

I tried to follow scanpy here a bit, see e.g. the violin plotting function, which uses grouopby in a similar fashion. https://scanpy.readthedocs.io/en/stable/generated/scanpy.pl.violin.html

On the other hand, in scanpy's scatter plot function, they use a groups attribute to restrict visualization to certain groups, which is not really what we are doing here: https://scanpy.readthedocs.io/en/stable/generated/scanpy.pl.scatter.html

src/moscot/problems/space/_mixins.py Outdated Show resolved Hide resolved
src/moscot/problems/space/_mixins.py Outdated Show resolved Hide resolved
src/moscot/problems/space/_mixins.py Outdated Show resolved Hide resolved
@giovp giovp requested a review from selmanozleyen July 10, 2024 07:04
@Marius1311
Copy link
Collaborator Author

Thanks for the review @giovp, incorporated all your suggestions, except for the groupby -> groups change, see comment above.

Copy link
Collaborator

@selmanozleyen selmanozleyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@Marius1311
Copy link
Collaborator Author

Great, thanks @selmanozleyen @giovp, merging this.

@Marius1311 Marius1311 merged commit e87b1a9 into theislab:main Jul 15, 2024
4 of 8 checks passed
@Marius1311 Marius1311 deleted the feat/spatial_mixins branch July 15, 2024 11:34
@selmanozleyen
Copy link
Collaborator

@giovp I think the problem with linting is here for sure. I thought maybe it's a link checking error because of connection but it fails only after this branch (I rerun the checks on older PR's)

@giovp
Copy link
Member

giovp commented Jul 23, 2024

yeah I think the problem is something in the docs of the correlate method, not a linkcheck

@selmanozleyen
Copy link
Collaborator

It's from the warning. Since the -W flag is set it gives error when warning is issued. I removed the flag and it works locally https://www.sphinx-doc.org/en/master/man/sphinx-build.html

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

Successfully merging this pull request may close these issues.

None yet

3 participants