-
Notifications
You must be signed in to change notification settings - Fork 9
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
Changes from 7 commits
e6651fd
68c1a01
cdc3bc5
c1acb13
4324afa
2567c0b
abcb8fc
c89236f
8a9138d
4539312
d8f7714
954956c
4944db6
c2a2466
268e2c5
d10f82f
6bb5e20
e63eda8
17d48b0
051270b
6e8442e
86ed240
c770d1d
956d7c6
713e8e0
b2a97c2
e81a681
b44ec15
4f5a2b0
f53b8be
189d468
47b8ec5
d434bfa
7ac7e26
02109f0
5f5bf26
77605cf
94c43b2
f7accd4
7478927
c408f37
69c3e76
878a79e
2366a32
5bd6696
5b3d508
4651972
09a3920
415c40a
338e75a
5a6d538
da8eac1
10a79fe
d3f435b
3a37762
72e545d
284c83d
fc7aba0
e26266d
96dd1d5
039ce1e
4c694ee
d6968f5
112af8e
f370bc1
e0efc2e
c055c8e
01637c8
2d9b73e
6a5ad0b
1cb646d
93b2e8d
4d3c8db
e2b9c5b
e1608b0
ab89a42
57c2649
2b8aa48
1586794
e13ef40
a775e70
93b561f
8fb3776
557139d
0cd1ae5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
): | ||
if mapping_mode == "sum": | ||
return self._cell_transition_online( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.""" | ||
|
@@ -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.""" | ||
|
@@ -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`.""" | ||
|
@@ -562,6 +604,38 @@ def cell_transition( # type: ignore[misc] | |
key_added=key_added, | ||
) | ||
|
||
def celltype_mapping( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing docstrings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "cell_transition_kwargs" should be default types.MappingProxyType({}). Raise error if |
||
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`.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing return type