From b520a0d51a72ededbc0ec6a77a349c3570ddc9d2 Mon Sep 17 00:00:00 2001 From: Starlitnightly Date: Fri, 26 Jul 2024 01:48:31 +0800 Subject: [PATCH] Fixed an error in `ov.utils.roe` when some expected frequencies are less than expected value. --- README.md | 2 +- omicverse/externel/spatrio/spatrio.py | 16 +++++++++++----- omicverse/utils/_roe.py | 3 +++ omicverse_guide/docs/Release_notes.md | 6 +++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 237a2bb7..55b93d31 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ If you use `omicverse` in your work, please cite the `omicverse` publication as > > Zeng, Z., Ma, Y., Hu, L. et al. > -> _Nature Communication_ 2024 Jul 17. doi: [10.1038/s41467-024-50194-3](https://doi.org/10.1038/s41467-024-50194-3). +> _Nature Communication_ 2024 Jul 16. doi: [10.1038/s41467-024-50194-3](https://doi.org/10.1038/s41467-024-50194-3). ## `8` [Other](#) diff --git a/omicverse/externel/spatrio/spatrio.py b/omicverse/externel/spatrio/spatrio.py index 4117d2b9..1634614e 100755 --- a/omicverse/externel/spatrio/spatrio.py +++ b/omicverse/externel/spatrio/spatrio.py @@ -26,7 +26,7 @@ def ot_alignment( norm: str = 'l2', backend = None, return_obj: bool = False, - verbose: bool = False, + verbose: bool = True, k: int = 10, graph_mode: str = "connectivity", aware_spatial: bool = True, @@ -541,8 +541,11 @@ def f(G): def df(G): return ot.gromov.gwggrad(constC, hC1, hC2, G) if log: - res, log = ot.gromov.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, log=True, numItermaxEmd=numItermaxEmd, **kwargs) - + if ot.__version__ < '0.9.0': + res, log = ot.gromov.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, log=True, numItermaxEmd=numItermaxEmd, **kwargs) + else: + res, log = ot.optim.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, log=True, numItermaxEmd=numItermaxEmd, **kwargs) + fgw_dist = log['loss'][-1] log['fgw_dist'] = fgw_dist @@ -550,5 +553,8 @@ def df(G): log['v'] = log['v'] return res, log else: - return ot.gromov.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, **kwargs) - + if ot.__version__ < '0.9.0': + return ot.gromov.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, **kwargs) + else: + return ot.optim.cg(p, q, (1 - alpha) * M, alpha, f, df, G0, armijo=armijo, C1=C1, C2=C2, constC=constC, **kwargs) + diff --git a/omicverse/utils/_roe.py b/omicverse/utils/_roe.py index 8154a104..5d38a3cd 100644 --- a/omicverse/utils/_roe.py +++ b/omicverse/utils/_roe.py @@ -55,6 +55,9 @@ def roe( f"Some expected frequencies are less than {expected_value_threshold}, it is suggested to use other statistical methods, such as Fisher's exact test") expected_data = pd.DataFrame(expected, index=num_cell.index, columns=num_cell.columns) adata.uns['expected_values'] = expected_data + roe = num_cell / expected_data + adata.uns['roe_results'] = roe + adata.uns['unsig_roe_results'] = roe else: print("P-value is greater than 0.05, there is no statistical significance") roe_ratio = num_cell / expected diff --git a/omicverse_guide/docs/Release_notes.md b/omicverse_guide/docs/Release_notes.md index a784daa8..5aa625ca 100644 --- a/omicverse_guide/docs/Release_notes.md +++ b/omicverse_guide/docs/Release_notes.md @@ -420,13 +420,17 @@ Support Raw Windows platform ### Pl Module - Fixed the 'celltyep_key' error of `ov.pl.cpdb_group_heatmap` #109 +- Fixed an error in `ov.utils.roe` when some expected frequencies are less than expected value. + +### Single Module +- Fixed the bug of `ov.single.cytotrace2` when adata.X is not sparse data. #115, #116 ### Bulk Module - Fixed an key error in `ov.bulk.Matrix_ID_mapping` - Added `enrichment_multi_concat` in `ov.bulk` to concat the result of enrichment. -### Bulk Module +### Bulk2Single Module - Added `adata.var_names_make_unique()` to avoid mat shape error if gene not unique. #100