mudata 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mudata-0.2.2 → mudata-0.2.4}/PKG-INFO +41 -7
- {mudata-0.2.2 → mudata-0.2.4}/README.md +34 -1
- {mudata-0.2.2 → mudata-0.2.4}/mudata/__init__.py +1 -1
- {mudata-0.2.2 → mudata-0.2.4}/mudata/_core/io.py +4 -18
- {mudata-0.2.2 → mudata-0.2.4}/mudata/_core/mudata.py +80 -32
- {mudata-0.2.2 → mudata-0.2.4}/mudata/_core/repr.py +32 -12
- {mudata-0.2.2 → mudata-0.2.4}/mudata/_core/utils.py +16 -0
- {mudata-0.2.2 → mudata-0.2.4}/pyproject.toml +7 -6
- {mudata-0.2.2 → mudata-0.2.4}/mudata/_core/__init__.py +0 -0
- {mudata-0.2.2 → mudata-0.2.4}/mudata/_core/config.py +0 -0
- {mudata-0.2.2 → mudata-0.2.4}/mudata/_core/file_backing.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mudata
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Multimodal omics analysis framework
|
|
5
5
|
Home-page: https://github.com/scverse/mudata
|
|
6
6
|
Author: Danila Bredikhin
|
|
7
7
|
Author-email: danila.bredikhin@embl.de
|
|
8
|
-
Requires-Python: >= 3.
|
|
8
|
+
Requires-Python: >= 3.9
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: License :: OSI Approved :: BSD License
|
|
@@ -16,13 +16,14 @@ Classifier: Intended Audience :: Science/Research
|
|
|
16
16
|
Requires-Dist: numpy
|
|
17
17
|
Requires-Dist: pandas
|
|
18
18
|
Requires-Dist: h5py
|
|
19
|
-
Requires-Dist: anndata >= 0.8
|
|
20
|
-
Requires-Dist: sphinx
|
|
21
|
-
Requires-Dist: sphinx-book-theme
|
|
22
|
-
Requires-Dist: pydata-sphinx-theme
|
|
19
|
+
Requires-Dist: anndata >= 0.10.8
|
|
20
|
+
Requires-Dist: sphinx ; extra == "docs"
|
|
21
|
+
Requires-Dist: sphinx-book-theme ; extra == "docs"
|
|
22
|
+
Requires-Dist: pydata-sphinx-theme ; extra == "docs"
|
|
23
23
|
Requires-Dist: readthedocs-sphinx-search ; extra == "docs"
|
|
24
24
|
Requires-Dist: nbsphinx ; extra == "docs"
|
|
25
25
|
Requires-Dist: sphinx_automodapi ; extra == "docs"
|
|
26
|
+
Requires-Dist: recommonmark ; extra == "docs"
|
|
26
27
|
Requires-Dist: zarr ; extra == "test"
|
|
27
28
|
Project-URL: Documentation, https://muon.readthedocs.io/en/latest/
|
|
28
29
|
Provides-Extra: docs
|
|
@@ -32,10 +33,13 @@ Provides-Extra: test
|
|
|
32
33
|
|
|
33
34
|
[](http://mudata.readthedocs.io/)
|
|
34
35
|
[](https://pypi.org/project/mudata)
|
|
36
|
+
[](https://numfocus.org)
|
|
35
37
|
|
|
36
38
|
# MuData – multimodal data
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
[Documentation](https://mudata.readthedocs.io/) | [Publication](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-021-02577-8)
|
|
41
|
+
|
|
42
|
+
For using `MuData` in multimodal omics applications see [`muon`](https://github.com/scverse/muon).
|
|
39
43
|
|
|
40
44
|
## Data structure
|
|
41
45
|
|
|
@@ -108,4 +112,34 @@ adata = md.read("pbmc_10k.h5mu/rna")
|
|
|
108
112
|
md.write("pbmc_10k.h5mu/rna", adata)
|
|
109
113
|
```
|
|
110
114
|
|
|
115
|
+
## Citation
|
|
116
|
+
|
|
117
|
+
If you use `mudata` in your work, please cite the publication as follows:
|
|
118
|
+
|
|
119
|
+
> **MUON: multimodal omics analysis framework**
|
|
120
|
+
>
|
|
121
|
+
> Danila Bredikhin, Ilia Kats, Oliver Stegle
|
|
122
|
+
>
|
|
123
|
+
> _Genome Biology_ 2022 Feb 01. doi: [10.1186/s13059-021-02577-8](https://doi.org/10.1186/s13059-021-02577-8).
|
|
124
|
+
|
|
125
|
+
You can cite the scverse publication as follows:
|
|
126
|
+
|
|
127
|
+
> **The scverse project provides a computational ecosystem for single-cell omics data analysis**
|
|
128
|
+
>
|
|
129
|
+
> Isaac Virshup, Danila Bredikhin, Lukas Heumos, Giovanni Palla, Gregor Sturm, Adam Gayoso, Ilia Kats, Mikaela Koutrouli, Scverse Community, Bonnie Berger, Dana Pe’er, Aviv Regev, Sarah A. Teichmann, Francesca Finotello, F. Alexander Wolf, Nir Yosef, Oliver Stegle & Fabian J. Theis
|
|
130
|
+
>
|
|
131
|
+
> _Nat Biotechnol._ 2023 Apr 10. doi: [10.1038/s41587-023-01733-8](https://doi.org/10.1038/s41587-023-01733-8).
|
|
132
|
+
|
|
133
|
+
[//]: # "numfocus-fiscal-sponsor-attribution"
|
|
134
|
+
|
|
135
|
+
MuData is part of the scverse project ([website](https://scverse.org), [governance](https://scverse.org/about/roles)) and is fiscally sponsored by [NumFOCUS](https://numfocus.org/).
|
|
136
|
+
Please consider making a tax-deductible [donation](https://numfocus.org/donate-to-scverse) to help the project pay for developer time, professional services, travel, workshops, and a variety of other needs.
|
|
137
|
+
|
|
138
|
+
<a href="https://numfocus.org/project/scverse">
|
|
139
|
+
<img
|
|
140
|
+
src="https://raw.githubusercontent.com/numfocus/templates/master/images/numfocus-logo.png"
|
|
141
|
+
width="200"
|
|
142
|
+
>
|
|
143
|
+
</a>
|
|
144
|
+
|
|
111
145
|
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://mudata.readthedocs.io/)
|
|
4
4
|
[](https://pypi.org/project/mudata)
|
|
5
|
+
[](https://numfocus.org)
|
|
5
6
|
|
|
6
7
|
# MuData – multimodal data
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
[Documentation](https://mudata.readthedocs.io/) | [Publication](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-021-02577-8)
|
|
10
|
+
|
|
11
|
+
For using `MuData` in multimodal omics applications see [`muon`](https://github.com/scverse/muon).
|
|
9
12
|
|
|
10
13
|
## Data structure
|
|
11
14
|
|
|
@@ -78,3 +81,33 @@ adata = md.read("pbmc_10k.h5mu/rna")
|
|
|
78
81
|
md.write("pbmc_10k.h5mu/rna", adata)
|
|
79
82
|
```
|
|
80
83
|
|
|
84
|
+
## Citation
|
|
85
|
+
|
|
86
|
+
If you use `mudata` in your work, please cite the publication as follows:
|
|
87
|
+
|
|
88
|
+
> **MUON: multimodal omics analysis framework**
|
|
89
|
+
>
|
|
90
|
+
> Danila Bredikhin, Ilia Kats, Oliver Stegle
|
|
91
|
+
>
|
|
92
|
+
> _Genome Biology_ 2022 Feb 01. doi: [10.1186/s13059-021-02577-8](https://doi.org/10.1186/s13059-021-02577-8).
|
|
93
|
+
|
|
94
|
+
You can cite the scverse publication as follows:
|
|
95
|
+
|
|
96
|
+
> **The scverse project provides a computational ecosystem for single-cell omics data analysis**
|
|
97
|
+
>
|
|
98
|
+
> Isaac Virshup, Danila Bredikhin, Lukas Heumos, Giovanni Palla, Gregor Sturm, Adam Gayoso, Ilia Kats, Mikaela Koutrouli, Scverse Community, Bonnie Berger, Dana Pe’er, Aviv Regev, Sarah A. Teichmann, Francesca Finotello, F. Alexander Wolf, Nir Yosef, Oliver Stegle & Fabian J. Theis
|
|
99
|
+
>
|
|
100
|
+
> _Nat Biotechnol._ 2023 Apr 10. doi: [10.1038/s41587-023-01733-8](https://doi.org/10.1038/s41587-023-01733-8).
|
|
101
|
+
|
|
102
|
+
[//]: # "numfocus-fiscal-sponsor-attribution"
|
|
103
|
+
|
|
104
|
+
MuData is part of the scverse project ([website](https://scverse.org), [governance](https://scverse.org/about/roles)) and is fiscally sponsored by [NumFOCUS](https://numfocus.org/).
|
|
105
|
+
Please consider making a tax-deductible [donation](https://numfocus.org/donate-to-scverse) to help the project pay for developer time, professional services, travel, workshops, and a variety of other needs.
|
|
106
|
+
|
|
107
|
+
<a href="https://numfocus.org/project/scverse">
|
|
108
|
+
<img
|
|
109
|
+
src="https://raw.githubusercontent.com/numfocus/templates/master/images/numfocus-logo.png"
|
|
110
|
+
width="200"
|
|
111
|
+
>
|
|
112
|
+
</a>
|
|
113
|
+
|
|
@@ -65,7 +65,7 @@ def _write_h5mu(file: h5py.File, mdata: MuData, write_data=True, **kwargs):
|
|
|
65
65
|
if adata.raw is not None:
|
|
66
66
|
adata.strings_to_categoricals(adata.raw.var)
|
|
67
67
|
|
|
68
|
-
if write_data:
|
|
68
|
+
if write_data or not adata.isbacked:
|
|
69
69
|
write_elem(group, "X", adata.X, dataset_kwargs=kwargs)
|
|
70
70
|
if adata.raw is not None:
|
|
71
71
|
write_elem(group, "raw", adata.raw)
|
|
@@ -158,7 +158,7 @@ def write_zarr(
|
|
|
158
158
|
if adata.raw is not None:
|
|
159
159
|
adata.strings_to_categoricals(adata.raw.var)
|
|
160
160
|
|
|
161
|
-
if write_data:
|
|
161
|
+
if write_data or not adata.isbacked:
|
|
162
162
|
if chunks is not None and not isinstance(adata.X, sparse.spmatrix):
|
|
163
163
|
write_elem(group, "X", adata.X, dataset_kwargs=dict(chunks=chunks, **kwargs))
|
|
164
164
|
else:
|
|
@@ -306,7 +306,7 @@ def write(filename: PathLike, data: Union[MuData, AnnData]):
|
|
|
306
306
|
else:
|
|
307
307
|
assert isinstance(data, AnnData), "Only MuData and AnnData objects are accepted"
|
|
308
308
|
|
|
309
|
-
m = re.search("^(.+)
|
|
309
|
+
m = re.search("^(.+)\\.(h5mu)[/]?([^/]*)[/]?(.*)$", str(filename))
|
|
310
310
|
if m is not None:
|
|
311
311
|
m = m.groups()
|
|
312
312
|
else:
|
|
@@ -458,13 +458,6 @@ def _read_zarr_mod(g: zarr.Group, manager: MuDataFileManager = None, backed: boo
|
|
|
458
458
|
d[k] = read_dataframe(g[k])
|
|
459
459
|
elif k == "X":
|
|
460
460
|
X = g["X"]
|
|
461
|
-
if isinstance(X, zarr.Group):
|
|
462
|
-
dtype = X["data"].dtype
|
|
463
|
-
elif hasattr(X, "dtype"):
|
|
464
|
-
dtype = X.dtype
|
|
465
|
-
else:
|
|
466
|
-
raise ValueError()
|
|
467
|
-
d["dtype"] = dtype
|
|
468
461
|
if not backed:
|
|
469
462
|
d["X"] = read_elem(X)
|
|
470
463
|
elif k != "raw":
|
|
@@ -499,13 +492,6 @@ def _read_h5mu_mod(
|
|
|
499
492
|
d[k] = read_dataframe(g[k])
|
|
500
493
|
elif k == "X":
|
|
501
494
|
X = g["X"]
|
|
502
|
-
if isinstance(X, h5py.Group):
|
|
503
|
-
dtype = X["data"].dtype
|
|
504
|
-
elif hasattr(X, "dtype"):
|
|
505
|
-
dtype = X.dtype
|
|
506
|
-
else:
|
|
507
|
-
raise ValueError()
|
|
508
|
-
d["dtype"] = dtype
|
|
509
495
|
if not backed:
|
|
510
496
|
d["X"] = read_elem(X)
|
|
511
497
|
elif k != "raw":
|
|
@@ -582,7 +568,7 @@ def read(filename: PathLike, **kwargs) -> Union[MuData, AnnData]:
|
|
|
582
568
|
"""
|
|
583
569
|
import re
|
|
584
570
|
|
|
585
|
-
m = re.search("^(.+)
|
|
571
|
+
m = re.search("^(.+)\\.(h5mu)[/]?([^/]*)[/]?(.*)$", str(filename))
|
|
586
572
|
if m is not None:
|
|
587
573
|
m = m.groups()
|
|
588
574
|
else:
|
|
@@ -28,7 +28,7 @@ from anndata._core.aligned_mapping import (
|
|
|
28
28
|
from anndata._core.views import DataFrameView
|
|
29
29
|
|
|
30
30
|
from .file_backing import MuDataFileManager
|
|
31
|
-
from .utils import _make_index_unique, _restore_index
|
|
31
|
+
from .utils import _make_index_unique, _restore_index, _maybe_coerce_to_boolean
|
|
32
32
|
|
|
33
33
|
from .repr import *
|
|
34
34
|
from .config import OPTIONS
|
|
@@ -190,11 +190,35 @@ class MuData:
|
|
|
190
190
|
cobsidx, cvaridx = mudata_ref.obsmap[m][obsidx], mudata_ref.varmap[m][varidx]
|
|
191
191
|
cobsidx, cvaridx = cobsidx[cobsidx > 0] - 1, cvaridx[cvaridx > 0] - 1
|
|
192
192
|
if len(cobsidx) > 0 and len(cvaridx) > 0:
|
|
193
|
-
if
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
if np.all(np.diff(cobsidx) == 1):
|
|
194
|
+
if a.is_view:
|
|
195
|
+
if (
|
|
196
|
+
isinstance(a, MuData)
|
|
197
|
+
and len(cobsidx) == a._mudata_ref.n_obs
|
|
198
|
+
or isinstance(a, AnnData)
|
|
199
|
+
and len(cobsidx) == a._adata_ref.n_obs
|
|
200
|
+
):
|
|
201
|
+
cobsidx = slice(None)
|
|
202
|
+
elif len(cobsidx) == a.n_obs:
|
|
203
|
+
cobsidx = slice(None)
|
|
204
|
+
if np.all(np.diff(cvaridx) == 1):
|
|
205
|
+
if a.is_view:
|
|
206
|
+
if (
|
|
207
|
+
isinstance(a, MuData)
|
|
208
|
+
and len(cvaridx) == a._mudata_ref.n_vars
|
|
209
|
+
or isinstance(a, AnnData)
|
|
210
|
+
and len(cvaridx) == a._adata_ref.n_vars
|
|
211
|
+
):
|
|
212
|
+
cvaridx = slice(None)
|
|
213
|
+
elif len(cvaridx) == a.n_vars:
|
|
214
|
+
cvaridx = slice(None)
|
|
215
|
+
if a.is_view:
|
|
216
|
+
if isinstance(a, MuData):
|
|
217
|
+
self.mod[m] = a._mudata_ref[cobsidx, cvaridx]
|
|
218
|
+
else:
|
|
219
|
+
self.mod[m] = a._adata_ref[cobsidx, cvaridx]
|
|
220
|
+
else:
|
|
221
|
+
self.mod[m] = a[cobsidx, cvaridx]
|
|
198
222
|
|
|
199
223
|
self._obs = DataFrameView(mudata_ref.obs.iloc[obsidx, :], view_args=(self, "obs"))
|
|
200
224
|
self._obsm = mudata_ref.obsm._view(self, (obsidx,))
|
|
@@ -206,17 +230,18 @@ class MuData:
|
|
|
206
230
|
for attr, idx in (("obs", obsidx), ("var", varidx)):
|
|
207
231
|
posmap = {}
|
|
208
232
|
for mod, mapping in getattr(mudata_ref, attr + "map").items():
|
|
209
|
-
|
|
210
|
-
nz = newmap > 0
|
|
211
|
-
newmap[nz] = np.nonzero(nz)[0] + np.uint(1)
|
|
212
|
-
posmap[mod] = newmap
|
|
233
|
+
posmap[mod] = mapping[idx].copy()
|
|
213
234
|
setattr(self, "_" + attr + "map", posmap)
|
|
214
235
|
|
|
215
236
|
self.is_view = True
|
|
216
237
|
self.file = mudata_ref.file
|
|
217
|
-
self._mudata_ref = mudata_ref
|
|
218
238
|
self._axis = mudata_ref._axis
|
|
219
239
|
|
|
240
|
+
if mudata_ref.is_view:
|
|
241
|
+
self._mudata_ref = mudata_ref._mudata_ref
|
|
242
|
+
else:
|
|
243
|
+
self._mudata_ref = mudata_ref
|
|
244
|
+
|
|
220
245
|
def _init_as_actual(self, data: "MuData"):
|
|
221
246
|
self._init_common()
|
|
222
247
|
self.mod = data.mod
|
|
@@ -247,7 +272,14 @@ class MuData:
|
|
|
247
272
|
axis: Literal[0, 1] = 0,
|
|
248
273
|
):
|
|
249
274
|
return cls(
|
|
250
|
-
data={
|
|
275
|
+
data={
|
|
276
|
+
k: (
|
|
277
|
+
v
|
|
278
|
+
if isinstance(v, AnnData) or isinstance(v, MuData)
|
|
279
|
+
else MuData(**v) if "mod" in v else AnnData(**v)
|
|
280
|
+
)
|
|
281
|
+
for k, v in mod.items()
|
|
282
|
+
},
|
|
251
283
|
obs=obs,
|
|
252
284
|
var=var,
|
|
253
285
|
uns=uns,
|
|
@@ -281,7 +313,7 @@ class MuData:
|
|
|
281
313
|
for j, mod_j in enumerate(self.mod):
|
|
282
314
|
if j != i:
|
|
283
315
|
if any(
|
|
284
|
-
np.
|
|
316
|
+
np.isin(
|
|
285
317
|
mod_i_dup_attrs, getattr(self.mod[mod_j], attr + "_names").values
|
|
286
318
|
)
|
|
287
319
|
):
|
|
@@ -541,7 +573,10 @@ class MuData:
|
|
|
541
573
|
sort=False,
|
|
542
574
|
)
|
|
543
575
|
data_common = pd.concat(
|
|
544
|
-
[
|
|
576
|
+
[
|
|
577
|
+
_maybe_coerce_to_boolean(getattr(a, attr)[columns_common])
|
|
578
|
+
for m, a in self.mod.items()
|
|
579
|
+
],
|
|
545
580
|
join="outer",
|
|
546
581
|
axis=0,
|
|
547
582
|
sort=False,
|
|
@@ -571,10 +606,9 @@ class MuData:
|
|
|
571
606
|
# use 0 as special value for missing
|
|
572
607
|
# we could use a pandas.array, which has missing values support, but then we get an Exception upon hdf5 write
|
|
573
608
|
# also, this is compatible to Muon.jl
|
|
574
|
-
col = data_mod
|
|
575
|
-
col.replace(np.
|
|
576
|
-
|
|
577
|
-
data_mod.loc[:, colname] = col
|
|
609
|
+
col = data_mod[colname] + 1
|
|
610
|
+
col.replace(np.nan, 0, inplace=True)
|
|
611
|
+
data_mod[colname] = col.astype(np.uint32)
|
|
578
612
|
|
|
579
613
|
if len(data_global.columns) > 0:
|
|
580
614
|
# TODO: if there were intersecting attrnames between modalities,
|
|
@@ -588,11 +622,13 @@ class MuData:
|
|
|
588
622
|
else:
|
|
589
623
|
if join_common:
|
|
590
624
|
dfs = [
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
625
|
+
_maybe_coerce_to_boolean(
|
|
626
|
+
_make_index_unique(
|
|
627
|
+
getattr(a, attr)
|
|
628
|
+
.drop(columns_common, axis=1)
|
|
629
|
+
.assign(**{rowcol: np.arange(getattr(a, attr).shape[0])})
|
|
630
|
+
.add_prefix(m + ":")
|
|
631
|
+
)
|
|
596
632
|
)
|
|
597
633
|
for m, a in self.mod.items()
|
|
598
634
|
]
|
|
@@ -607,7 +643,9 @@ class MuData:
|
|
|
607
643
|
|
|
608
644
|
data_common = pd.concat(
|
|
609
645
|
[
|
|
610
|
-
|
|
646
|
+
_maybe_coerce_to_boolean(
|
|
647
|
+
_make_index_unique(getattr(a, attr)[columns_common])
|
|
648
|
+
)
|
|
611
649
|
for m, a in self.mod.items()
|
|
612
650
|
],
|
|
613
651
|
join="outer",
|
|
@@ -665,7 +703,7 @@ class MuData:
|
|
|
665
703
|
# we could use a pandas.array, which has missing values support, but then we get an Exception upon hdf5 write
|
|
666
704
|
# also, this is compatible to Muon.jl
|
|
667
705
|
col = data_mod.loc[:, colname] + 1
|
|
668
|
-
col.replace(np.
|
|
706
|
+
col.replace(np.nan, 0, inplace=True)
|
|
669
707
|
col = col.astype(np.uint32)
|
|
670
708
|
data_mod.loc[:, colname] = col
|
|
671
709
|
data_mod.set_index(colname, append=True, inplace=True)
|
|
@@ -1195,7 +1233,8 @@ class MuData:
|
|
|
1195
1233
|
|
|
1196
1234
|
write_zarr(store, self, **kwargs)
|
|
1197
1235
|
|
|
1198
|
-
def _gen_repr(self, n_obs, n_vars, extensive: bool = False) -> str:
|
|
1236
|
+
def _gen_repr(self, n_obs, n_vars, extensive: bool = False, nest_level: int = 0) -> str:
|
|
1237
|
+
indent = " " * nest_level
|
|
1199
1238
|
backed_at = f" backed at {str(self.filename)!r}" if self.isbacked else ""
|
|
1200
1239
|
view_of = "View of " if self.is_view else ""
|
|
1201
1240
|
descr = f"{view_of}MuData object with n_obs × n_vars = {n_obs} × {n_vars}{backed_at}"
|
|
@@ -1221,10 +1260,16 @@ class MuData:
|
|
|
1221
1260
|
)
|
|
1222
1261
|
)
|
|
1223
1262
|
if any(global_keys):
|
|
1224
|
-
descr += f"\n {attr}:\t{str([keys[i] for i in range(len(keys)) if global_keys[i]])[1:-1]}"
|
|
1225
|
-
descr += f"\n {len(self.mod)} modalit{'y' if len(self.mod) == 1 else 'ies'}"
|
|
1263
|
+
descr += f"\n{indent} {attr}:\t{str([keys[i] for i in range(len(keys)) if global_keys[i]])[1:-1]}"
|
|
1264
|
+
descr += f"\n{indent} {len(self.mod)} modalit{'y' if len(self.mod) == 1 else 'ies'}"
|
|
1226
1265
|
for k, v in self.mod.items():
|
|
1227
|
-
|
|
1266
|
+
mod_indent = " " * (nest_level + 1)
|
|
1267
|
+
if isinstance(v, MuData):
|
|
1268
|
+
descr += f"\n{mod_indent}{k}:\t" + v._gen_repr(
|
|
1269
|
+
n_obs, n_vars, extensive, nest_level + 1
|
|
1270
|
+
)
|
|
1271
|
+
continue
|
|
1272
|
+
descr += f"\n{mod_indent}{k}:\t{v.n_obs} x {v.n_vars}"
|
|
1228
1273
|
for attr in [
|
|
1229
1274
|
"obs",
|
|
1230
1275
|
"var",
|
|
@@ -1235,9 +1280,12 @@ class MuData:
|
|
|
1235
1280
|
"obsp",
|
|
1236
1281
|
"varp",
|
|
1237
1282
|
]:
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1283
|
+
try:
|
|
1284
|
+
keys = getattr(v, attr).keys()
|
|
1285
|
+
if len(keys) > 0:
|
|
1286
|
+
descr += f"\n{mod_indent} {attr}:\t{str(list(keys))[1:-1]}"
|
|
1287
|
+
except AttributeError:
|
|
1288
|
+
pass
|
|
1241
1289
|
return descr
|
|
1242
1290
|
|
|
1243
1291
|
def __repr__(self) -> str:
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#
|
|
4
4
|
|
|
5
5
|
from typing import Tuple, Iterable
|
|
6
|
-
from numbers import Integral, Real, Complex
|
|
6
|
+
from numbers import Number, Integral, Real, Complex
|
|
7
7
|
from warnings import warn
|
|
8
8
|
import numpy as np
|
|
9
9
|
import pandas as pd
|
|
@@ -38,26 +38,44 @@ def format_values(x):
|
|
|
38
38
|
elif isinstance(x, str):
|
|
39
39
|
s += x
|
|
40
40
|
else:
|
|
41
|
+
if not len(x):
|
|
42
|
+
return s
|
|
41
43
|
x = x[: min(100, len(x))]
|
|
44
|
+
testval = None
|
|
42
45
|
if hasattr(x, "shape"):
|
|
43
46
|
if isinstance(x, np.ndarray):
|
|
44
|
-
x = x.
|
|
47
|
+
x = x.reshape(-1)
|
|
45
48
|
elif isinstance(x, pd.Series):
|
|
46
49
|
x = x.to_numpy()
|
|
47
50
|
else:
|
|
48
51
|
warn(f"got unknown array type {type(x)}, don't know how handle it.")
|
|
49
52
|
return type(x)
|
|
50
|
-
|
|
53
|
+
if x.dtype == object:
|
|
54
|
+
try:
|
|
55
|
+
testval = next(
|
|
56
|
+
filter(
|
|
57
|
+
lambda y: ~np.isnan(y) if isinstance(y, Number) else x is not None,
|
|
58
|
+
x,
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
except StopIteration:
|
|
62
|
+
pass
|
|
63
|
+
if testval is None:
|
|
64
|
+
testval = x[0]
|
|
65
|
+
if (
|
|
66
|
+
isinstance(testval, Integral)
|
|
67
|
+
or isinstance(testval, np.bool_)
|
|
68
|
+
or isinstance(testval, bool)
|
|
69
|
+
):
|
|
51
70
|
s += ",".join([f"{i}" for i in x])
|
|
52
|
-
elif isinstance(
|
|
71
|
+
elif isinstance(testval, Real):
|
|
53
72
|
s += ",".join([f"{i:.2f}" for i in x])
|
|
54
|
-
elif isinstance(
|
|
73
|
+
elif isinstance(testval, Complex):
|
|
55
74
|
warn("got complex number, don't know how to handle it")
|
|
56
|
-
elif isinstance(
|
|
75
|
+
elif isinstance(testval, Iterable):
|
|
57
76
|
s += ",".join(map(format_values, x))
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
s = s[:-1]
|
|
77
|
+
lastidx = max(50, s.find(","))
|
|
78
|
+
s = s[:lastidx]
|
|
61
79
|
s += "..."
|
|
62
80
|
return s
|
|
63
81
|
|
|
@@ -129,9 +147,11 @@ def details_block_table(data, attr, name, expand=0, dims=True, square=False):
|
|
|
129
147
|
attr_key,
|
|
130
148
|
obj[attr_key].dtype if hasattr(obj[attr_key], "dtype") else "",
|
|
131
149
|
*maybe_module_class(obj[attr_key]),
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
150
|
+
(
|
|
151
|
+
f"{obj[attr_key].shape[1]} columns"
|
|
152
|
+
if len(obj[attr_key].shape) > 1 and dims
|
|
153
|
+
else ""
|
|
154
|
+
),
|
|
135
155
|
)
|
|
136
156
|
for attr_key in obj.keys()
|
|
137
157
|
]
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
from collections import Counter
|
|
2
|
+
from typing import TypeVar
|
|
2
3
|
import pandas as pd
|
|
3
4
|
import numpy as np
|
|
4
5
|
from anndata.utils import make_index_unique
|
|
5
6
|
|
|
7
|
+
T = TypeVar("T", pd.Series, pd.DataFrame)
|
|
8
|
+
|
|
6
9
|
|
|
7
10
|
def _make_index_unique(df: pd.DataFrame) -> pd.DataFrame:
|
|
8
11
|
dup_idx = np.zeros((df.shape[0],), dtype=np.uint8)
|
|
@@ -19,3 +22,16 @@ def _make_index_unique(df: pd.DataFrame) -> pd.DataFrame:
|
|
|
19
22
|
|
|
20
23
|
def _restore_index(df: pd.DataFrame) -> pd.DataFrame:
|
|
21
24
|
return df.reset_index(level=-1, drop=True)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _maybe_coerce_to_boolean(df: T) -> T:
|
|
28
|
+
if isinstance(df, pd.Series):
|
|
29
|
+
if df.dtype == bool:
|
|
30
|
+
return df.astype("boolean")
|
|
31
|
+
return df
|
|
32
|
+
|
|
33
|
+
for col in df.columns:
|
|
34
|
+
if df[col].dtype == bool:
|
|
35
|
+
df = df.assign(**{col: df[col].astype("boolean")})
|
|
36
|
+
|
|
37
|
+
return df
|
|
@@ -16,22 +16,23 @@ classifiers = [
|
|
|
16
16
|
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
17
17
|
"Intended Audience :: Science/Research"
|
|
18
18
|
]
|
|
19
|
-
requires-python = ">= 3.
|
|
19
|
+
requires-python = ">= 3.9"
|
|
20
20
|
requires = [
|
|
21
21
|
"numpy",
|
|
22
22
|
"pandas",
|
|
23
23
|
"h5py",
|
|
24
|
-
"anndata >= 0.8",
|
|
24
|
+
"anndata >= 0.10.8",
|
|
25
25
|
]
|
|
26
26
|
|
|
27
27
|
[tool.flit.metadata.requires-extra]
|
|
28
28
|
docs = [
|
|
29
|
-
"sphinx
|
|
30
|
-
"sphinx-book-theme
|
|
31
|
-
"pydata-sphinx-theme
|
|
29
|
+
"sphinx",
|
|
30
|
+
"sphinx-book-theme",
|
|
31
|
+
"pydata-sphinx-theme",
|
|
32
32
|
"readthedocs-sphinx-search",
|
|
33
33
|
"nbsphinx",
|
|
34
|
-
"sphinx_automodapi"
|
|
34
|
+
"sphinx_automodapi",
|
|
35
|
+
"recommonmark"
|
|
35
36
|
]
|
|
36
37
|
test = [
|
|
37
38
|
"zarr"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|