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 1 commit
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
13 changes: 6 additions & 7 deletions src/moscot/base/problems/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def _cell_transition(
)
if aggregation_mode == "cell" and source_groups is None and target_groups is None:
raise ValueError("At least one of `source_groups` and `target_group` must be specified.")

_check_argument_compatibility_cell_transition(
source_annotation=source_groups,
target_annotation=target_groups,
Expand Down Expand Up @@ -208,13 +207,13 @@ def _cell_transition_online(
)
df_source = _get_df_cell_transition(
self.adata,
[source_annotation_key, target_annotation_key],
[source_annotation_key],
key,
source,
)
df_target = _get_df_cell_transition(
self.adata if other_adata is None else other_adata,
[source_annotation_key, target_annotation_key],
[target_annotation_key],
key if other_adata is None else other_key,
target,
ArinaDanilina marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down Expand Up @@ -323,7 +322,7 @@ def _annotation_mapping(
cell_transition_kwargs.setdefault("forward", forward)
if forward:
source_df = _get_df_cell_transition(
self.adata,
self.adata if other_adata is None else other_adata,
annotation_keys=[annotation_label],
filter_key=key,
filter_value=source,
Expand All @@ -332,9 +331,9 @@ def _annotation_mapping(
axis = 1 # columns
cell_transition_kwargs.setdefault("source_groups", None)
cell_transition_kwargs.setdefault("target_groups", annotation_label)
elif not forward:
else:
target_df = _get_df_cell_transition(
self.adata if other_adata is None else other_adata,
self.adata,
annotation_keys=[annotation_label],
filter_key=key,
filter_value=target,
Expand All @@ -346,7 +345,7 @@ def _annotation_mapping(
if mapping_mode == "sum":
out: pd.DataFrame = self._cell_transition(**cell_transition_kwargs)
return out.idxmax(axis=axis).to_frame(name=annotation_label)
elif mapping_mode == "max":
if mapping_mode == "max":
if forward:
out: ArrayLike = self[(source, target)].push(dummy, scale_by_marginals=scale_by_marginals)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/moscot/base/problems/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _check_argument_compatibility_cell_transition(
raise ValueError("Unable to infer distributions, missing `adata` and `key`.")
if forward and target_annotation is None:
raise ValueError("No target annotation provided.")
if not forward and source_annotation is None:
if aggregation_mode == "annotation" and (not forward and source_annotation is None):
raise ValueError("No source annotation provided.")
if (aggregation_mode == "annotation") and (source_annotation is None or target_annotation is None):
raise ValueError(
Expand Down
9 changes: 8 additions & 1 deletion src/moscot/problems/space/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,19 @@ def annotation_mapping(
scale_by_marginals: bool = True,
cell_transition_kwargs: Mapping[str, Any] = types.MappingProxyType({}),
) -> pd.DataFrame:
cell_transition_kwargs = dict(cell_transition_kwargs)
if forward:
cell_transition_kwargs.setdefault("source_groups", None)
cell_transition_kwargs.setdefault("target_groups", annotation_label)
else:
cell_transition_kwargs.setdefault("source_groups", None)
cell_transition_kwargs.setdefault("target_groups", annotation_label)
annotation = self._annotation_mapping(
ArinaDanilina marked this conversation as resolved.
Show resolved Hide resolved
mapping_mode=mapping_mode,
annotation_label=annotation_label,
source=source,
target=target,
forward=forward,
forward=not forward,
key=self.batch_key,
other_adata=self.adata_sc,
scale_by_marginals=scale_by_marginals,
Expand Down
Loading