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

adding _annotation_mapping in AnalysisMixin #585

Merged
merged 85 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
e6651fd
_celltype_mapping draft
Jul 19, 2023
68c1a01
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 19, 2023
cdc3bc5
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Jul 19, 2023
c1acb13
exposing celltype_mapping in SpatialMapping and SpatialAlignment
Jul 20, 2023
4324afa
fix ruff ?
Jul 20, 2023
2567c0b
fix conflict
Jul 20, 2023
abcb8fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 20, 2023
c89236f
fixes for mypy and ruff
Jul 20, 2023
8a9138d
renamin, adding function to protocol
Jul 20, 2023
4539312
ruff fix?
Jul 21, 2023
d8f7714
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 21, 2023
954956c
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Jul 26, 2023
4944db6
adding cell_transition_kwargs
Jul 31, 2023
c2a2466
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
268e2c5
Merge branch 'main' into add/celltype_mapping
Jul 31, 2023
d10f82f
ruff and mypy fix ?
Jul 31, 2023
6bb5e20
Merge branch 'main' into add/celltype_mapping
Aug 12, 2023
e63eda8
Merge branch 'main' into add/celltype_mapping
Aug 23, 2023
17d48b0
anno_mapping changes
Sep 15, 2023
051270b
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Sep 27, 2023
6e8442e
Merge branch 'add/celltype_mapping' of https://github.com/theislab/mo…
Sep 27, 2023
86ed240
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Oct 10, 2023
c770d1d
Merge branch 'main' into add/celltype_mapping
giovp Oct 10, 2023
956d7c6
Merge branch 'add/celltype_mapping' of https://github.com/theislab/mo…
Oct 19, 2023
713e8e0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2023
b2a97c2
removed source and target groups
Oct 19, 2023
e81a681
merge
Oct 19, 2023
b44ec15
Merge branch 'main' into add/celltype_mapping
Oct 19, 2023
4f5a2b0
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Oct 20, 2023
f53b8be
Merge branch 'main' into add/celltype_mapping
giovp Oct 24, 2023
189d468
key_added logic
Nov 2, 2023
47b8ec5
key_added logic
Nov 2, 2023
d434bfa
Merge branch 'add/celltype_mapping' of https://github.com/theislab/mo…
Nov 2, 2023
7ac7e26
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2023
02109f0
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Nov 16, 2023
5f5bf26
anno_map progress
Nov 30, 2023
77605cf
Merge branch 'add/celltype_mapping' of https://github.com/theislab/mo…
Nov 30, 2023
94c43b2
Merge branch 'main' into add/celltype_mapping
Nov 30, 2023
f7accd4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 30, 2023
7478927
Merge branch 'add/celltype_mapping' of https://github.com/theislab/mo…
Nov 30, 2023
c408f37
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Dec 1, 2023
69c3e76
mp fix, ap and tp added
Dec 7, 2023
878a79e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 7, 2023
2366a32
make sum for temporal problem work
giovp Dec 11, 2023
5bd6696
fix max for temporal
giovp Dec 11, 2023
5b3d508
before merge
Dec 11, 2023
4651972
Merge branch 'main' into add/celltype_mapping
giovp Dec 11, 2023
09a3920
merge tp fix and added in cross_modality
Dec 12, 2023
415c40a
Merge branch 'add/celltype_mapping' of https://github.com/theislab/mo…
Dec 12, 2023
338e75a
passing batch key ap
Dec 12, 2023
5a6d538
cleaned arguments, forward in mp
Dec 14, 2023
da8eac1
fix for cross_modality and general label handling in max
Dec 19, 2023
10a79fe
handling annottion labels
Dec 19, 2023
d3f435b
update
giovp Dec 19, 2023
3a37762
update
giovp Dec 19, 2023
72e545d
update
giovp Dec 19, 2023
284c83d
update
Dec 20, 2023
fc7aba0
update
giovp Dec 20, 2023
e26266d
shorter returns
Dec 26, 2023
96dd1d5
fix for temporal cell_transition
Jan 7, 2024
039ce1e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 7, 2024
4c694ee
gt for annotation tests
Jan 9, 2024
d6968f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2024
112af8e
only passing tests
Jan 10, 2024
f370bc1
Merge branch 'add/celltype_mapping' of https://github.com/theislab/mo…
Jan 10, 2024
e0efc2e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2024
c055c8e
Merge branch 'main' into add/celltype_mapping
ArinaDanilina Jan 10, 2024
01637c8
ruff type annotation
Jan 10, 2024
2d9b73e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2024
6a5ad0b
Revert "ruff type annotation"
Jan 10, 2024
1cb646d
revert
Jan 10, 2024
93b2e8d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2024
4d3c8db
fully passing tests
Jan 17, 2024
e2b9c5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
e1608b0
some mypy fixes
Jan 18, 2024
ab89a42
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
57c2649
ruff typing
Jan 18, 2024
2b8aa48
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
1586794
docstrings
Jan 18, 2024
e13ef40
lint docstrings
Jan 18, 2024
a775e70
unexpose scale_by_marginals and edits
Jan 19, 2024
93b561f
Update src/moscot/problems/cross_modality/_mixins.py
ArinaDanilina Jan 19, 2024
8fb3776
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 19, 2024
557139d
returns -> Returns
Jan 19, 2024
0cd1ae5
returns -> Returns
Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/moscot/base/problems/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,47 @@ def _cell_transition_online(
forward=forward,
)

def _celltype_mapping(
self: AnalysisMixinProtocol[K, B],
mapping_mode: Literal["sum", "max"],
key: Optional[str],
source: K,
target: K,
source_groups: Str_Dict_t,
target_groups: Str_Dict_t,
forward: bool = False, # return value will be row-stochastic if forward=True, else column-stochastic
aggregation_mode: Literal["annotation", "cell"] = "annotation",
other_key: Optional[str] = None,
other_adata: Optional[str] = None,
batch_size: Optional[int] = None,
normalize: bool = True,
scale_by_marginals: bool = True,
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing return type

if mapping_mode == "sum":
return self._cell_transition_online(
Copy link
Collaborator

Choose a reason for hiding this comment

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

use _cell_transition.

key=key,
source=source,
target=target,
source_groups=source_groups,
target_groups=target_groups,
forward=forward,
aggregation_mode=aggregation_mode,
other_key=other_key,
other_adata=other_adata,
batch_size=batch_size,
normalize=normalize,
)
if mapping_mode == "max":
source_annotation_key, source_annotations, source_annotations_ordered = _validate_args_cell_transition(
self.adata, source_groups
)
target_annotation_key, target_annotations, target_annotations_ordered = _validate_args_cell_transition(
self.adata if other_adata is None else other_adata, target_groups
)
dummy = pd.get_dummies(source_annotations)
out = self.pull(dummy, scale_by_marginals=scale_by_marginals)
return pd.Categorical([dummy.columns[i] for i in np.array(out.argmax(1))])

ArinaDanilina marked this conversation as resolved.
Show resolved Hide resolved
def _sample_from_tmap(
self: AnalysisMixinProtocol[K, B],
source: K,
Expand Down
74 changes: 74 additions & 0 deletions src/moscot/problems/space/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def _cell_transition(
) -> pd.DataFrame:
...

def _celltype_mapping(
self: AnalysisMixinProtocol[K, B],
*args: Any,
**kwargs: Any,
) -> pd.DataFrame:
...


class SpatialMappingMixinProtocol(AnalysisMixinProtocol[K, B]):
"""Protocol class."""
Expand All @@ -82,6 +89,9 @@ def _filter_vars(
def _cell_transition(self: AnalysisMixinProtocol[K, B], *args: Any, **kwargs: Any) -> pd.DataFrame:
...

def _celltype_mapping(self: AnalysisMixinProtocol[K, B], *args: Any, **kwargs: Any) -> pd.DataFrame:
...


class SpatialAlignmentMixin(AnalysisMixin[K, B]):
"""Spatial alignment mixin class."""
Expand Down Expand Up @@ -273,6 +283,38 @@ def cell_transition( # type: ignore[misc]
key_added=key_added,
)

def celltype_mapping(
self: SpatialAlignmentMixinProtocol[K, B],
mapping_mode: Literal["sum", "max"],
key: Optional[str],
source: K,
target: K,
source_groups: Str_Dict_t,
target_groups: Str_Dict_t,
forward: bool = False, # return value will be row-stochastic if forward=True, else column-stochastic
aggregation_mode: Literal["annotation", "cell"] = "annotation",
other_key: Optional[str] = None,
other_adata: Optional[str] = None,
ArinaDanilina marked this conversation as resolved.
Show resolved Hide resolved
batch_size: Optional[int] = None,
normalize: bool = True,
scale_by_marginals: bool = True,
ArinaDanilina marked this conversation as resolved.
Show resolved Hide resolved
) -> pd.DataFrame:
ArinaDanilina marked this conversation as resolved.
Show resolved Hide resolved
return self._celltype_mapping(
mapping_mode=mapping_mode,
key=key,
source=source,
target=target,
source_groups=source_groups,
target_groups=target_groups,
forward=forward,
aggregation_mode=aggregation_mode,
other_key=other_key,
other_adata=other_adata,
ArinaDanilina marked this conversation as resolved.
Show resolved Hide resolved
batch_size=batch_size,
normalize=normalize,
scale_by_marginals=scale_by_marginals,
)

@property
def spatial_key(self) -> Optional[str]:
"""Spatial key in :attr:`~anndata.AnnData.obsm`."""
Expand Down Expand Up @@ -562,6 +604,38 @@ def cell_transition( # type: ignore[misc]
key_added=key_added,
)

def celltype_mapping(
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing docstrings.
also introduce a variable "cell_transition_kwargs".

Copy link
Collaborator

Choose a reason for hiding this comment

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

"cell_transition_kwargs" should be default types.MappingProxyType({}). Raise error if cell_transition_kwargs is not an empty dict although cell_transition is not used

self: SpatialMappingMixinProtocol[K, B],
mapping_mode: Literal["sum", "max"],
key: Optional[str],
source: K,
target: K,
source_groups: Str_Dict_t,
target_groups: Str_Dict_t,
forward: bool = False, # return value will be row-stochastic if forward=True, else column-stochastic
aggregation_mode: Literal["annotation", "cell"] = "annotation",
other_key: Optional[str] = None,
other_adata: Optional[str] = None,
batch_size: Optional[int] = None,
normalize: bool = True,
scale_by_marginals: bool = True,
) -> pd.DataFrame:
return self._celltype_mapping(
mapping_mode=mapping_mode,
key=key,
source=source,
target=target,
source_groups=source_groups,
target_groups=target_groups,
forward=forward,
aggregation_mode=aggregation_mode,
other_key=other_key,
other_adata=other_adata,
batch_size=batch_size,
normalize=normalize,
scale_by_marginals=scale_by_marginals,
)

@property
def batch_key(self) -> Optional[str]:
"""Batch key in :attr:`~anndata.AnnData.obs`."""
Expand Down
Loading