cap-anndata 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- cap_anndata/__init__.py +10 -10
- cap_anndata/backed_df.py +81 -69
- cap_anndata/backed_dict.py +34 -34
- cap_anndata/cap_anndata.py +625 -600
- cap_anndata/reader.py +57 -57
- {cap_anndata-0.3.0.dist-info → cap_anndata-0.4.0.dist-info}/LICENSE +28 -28
- {cap_anndata-0.3.0.dist-info → cap_anndata-0.4.0.dist-info}/METADATA +67 -54
- cap_anndata-0.4.0.dist-info/RECORD +10 -0
- {cap_anndata-0.3.0.dist-info → cap_anndata-0.4.0.dist-info}/WHEEL +1 -1
- cap_anndata-0.3.0.dist-info/RECORD +0 -10
- {cap_anndata-0.3.0.dist-info → cap_anndata-0.4.0.dist-info}/top_level.txt +0 -0
cap_anndata/reader.py
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
import logging
|
2
|
-
import h5py
|
3
|
-
import warnings
|
4
|
-
|
5
|
-
from cap_anndata import CapAnnData
|
6
|
-
|
7
|
-
|
8
|
-
logger = logging.getLogger(__name__)
|
9
|
-
|
10
|
-
|
11
|
-
def read_h5ad(file_path: str, edit: bool = False):
|
12
|
-
"""
|
13
|
-
This is the main read method for CapAnnData.
|
14
|
-
Must be used in 'with' context.
|
15
|
-
"""
|
16
|
-
mode = "r+" if edit else "r"
|
17
|
-
logger.debug(f"Read file {file_path} mode={mode} in context...")
|
18
|
-
|
19
|
-
try:
|
20
|
-
file = h5py.File(file_path, mode)
|
21
|
-
cap_adata = CapAnnData(file)
|
22
|
-
logger.debug(f"Successfully read anndata file path {file_path}")
|
23
|
-
return cap_adata
|
24
|
-
|
25
|
-
except Exception as error:
|
26
|
-
logger.error(
|
27
|
-
f"Error during read anndata file at path: {file_path}, error = {error}!"
|
28
|
-
)
|
29
|
-
raise error
|
30
|
-
|
31
|
-
|
32
|
-
def deprecated(message):
|
33
|
-
def deprecated_decorator(func):
|
34
|
-
def deprecated_func(*args, **kwargs):
|
35
|
-
warnings.warn(
|
36
|
-
"{} is a deprecated function. {}".format(func.__name__, message),
|
37
|
-
category=DeprecationWarning,
|
38
|
-
stacklevel=2,
|
39
|
-
)
|
40
|
-
warnings.simplefilter("default", DeprecationWarning)
|
41
|
-
return func(*args, **kwargs)
|
42
|
-
|
43
|
-
return deprecated_func
|
44
|
-
|
45
|
-
return deprecated_decorator
|
46
|
-
|
47
|
-
|
48
|
-
# TODO: remove deprecated function
|
49
|
-
@deprecated(
|
50
|
-
"It will be removed in the next version of package. Please replace it with `read_h5ad`."
|
51
|
-
)
|
52
|
-
def read_directly(file_path: str, edit: bool = False) -> CapAnnData:
|
53
|
-
"""
|
54
|
-
Must be used only in specific cases.
|
55
|
-
User is responsible to close the h5py file when the work with CapAnnData instance done.
|
56
|
-
"""
|
57
|
-
return read_h5ad(file_path, edit)
|
1
|
+
import logging
|
2
|
+
import h5py
|
3
|
+
import warnings
|
4
|
+
|
5
|
+
from cap_anndata import CapAnnData
|
6
|
+
|
7
|
+
|
8
|
+
logger = logging.getLogger(__name__)
|
9
|
+
|
10
|
+
|
11
|
+
def read_h5ad(file_path: str, edit: bool = False):
|
12
|
+
"""
|
13
|
+
This is the main read method for CapAnnData.
|
14
|
+
Must be used in 'with' context.
|
15
|
+
"""
|
16
|
+
mode = "r+" if edit else "r"
|
17
|
+
logger.debug(f"Read file {file_path} mode={mode} in context...")
|
18
|
+
|
19
|
+
try:
|
20
|
+
file = h5py.File(file_path, mode)
|
21
|
+
cap_adata = CapAnnData(file)
|
22
|
+
logger.debug(f"Successfully read anndata file path {file_path}")
|
23
|
+
return cap_adata
|
24
|
+
|
25
|
+
except Exception as error:
|
26
|
+
logger.error(
|
27
|
+
f"Error during read anndata file at path: {file_path}, error = {error}!"
|
28
|
+
)
|
29
|
+
raise error
|
30
|
+
|
31
|
+
|
32
|
+
def deprecated(message):
|
33
|
+
def deprecated_decorator(func):
|
34
|
+
def deprecated_func(*args, **kwargs):
|
35
|
+
warnings.warn(
|
36
|
+
"{} is a deprecated function. {}".format(func.__name__, message),
|
37
|
+
category=DeprecationWarning,
|
38
|
+
stacklevel=2,
|
39
|
+
)
|
40
|
+
warnings.simplefilter("default", DeprecationWarning)
|
41
|
+
return func(*args, **kwargs)
|
42
|
+
|
43
|
+
return deprecated_func
|
44
|
+
|
45
|
+
return deprecated_decorator
|
46
|
+
|
47
|
+
|
48
|
+
# TODO: remove deprecated function
|
49
|
+
@deprecated(
|
50
|
+
"It will be removed in the next version of package. Please replace it with `read_h5ad`."
|
51
|
+
)
|
52
|
+
def read_directly(file_path: str, edit: bool = False) -> CapAnnData:
|
53
|
+
"""
|
54
|
+
Must be used only in specific cases.
|
55
|
+
User is responsible to close the h5py file when the work with CapAnnData instance done.
|
56
|
+
"""
|
57
|
+
return read_h5ad(file_path, edit)
|
@@ -1,28 +1,28 @@
|
|
1
|
-
BSD 3-Clause License
|
2
|
-
|
3
|
-
Copyright (c) 2024, R. Mukhin, A. Isaev, Cell-Annotation Platform
|
4
|
-
|
5
|
-
Redistribution and use in source and binary forms, with or without
|
6
|
-
modification, are permitted provided that the following conditions are met:
|
7
|
-
|
8
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
9
|
-
list of conditions and the following disclaimer.
|
10
|
-
|
11
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
-
this list of conditions and the following disclaimer in the documentation
|
13
|
-
and/or other materials provided with the distribution.
|
14
|
-
|
15
|
-
3. Neither the name of the copyright holder nor the names of its
|
16
|
-
contributors may be used to endorse or promote products derived from
|
17
|
-
this software without specific prior written permission.
|
18
|
-
|
19
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2024, R. Mukhin, A. Isaev, Cell-Annotation Platform
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
13
|
+
and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
16
|
+
contributors may be used to endorse or promote products derived from
|
17
|
+
this software without specific prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -1,54 +1,67 @@
|
|
1
|
-
Metadata-Version: 2.
|
2
|
-
Name: cap_anndata
|
3
|
-
Version: 0.
|
4
|
-
Summary: Partial read/write of AnnData (h5ad) files for low-memory operations with large datasets.
|
5
|
-
Home-page: https://github.com/cellannotation/cap-anndata
|
6
|
-
Author: R. Mukhin, A. Isaev
|
7
|
-
Author-email: roman@ebookapplications.com
|
8
|
-
Project-URL: Bug Tracker, https://github.com/cellannotation/cap-anndata/issues
|
9
|
-
|
10
|
-
|
11
|
-
Classifier:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Requires-Dist:
|
18
|
-
|
19
|
-
Requires-Dist:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: cap_anndata
|
3
|
+
Version: 0.4.0
|
4
|
+
Summary: Partial read/write of AnnData (h5ad) files for low-memory operations with large datasets.
|
5
|
+
Home-page: https://github.com/cellannotation/cap-anndata
|
6
|
+
Author: R. Mukhin, A. Isaev
|
7
|
+
Author-email: roman@ebookapplications.com
|
8
|
+
Project-URL: Bug Tracker, https://github.com/cellannotation/cap-anndata/issues
|
9
|
+
Project-URL: Changelog, https://github.com/cellannotation/cap-anndata/blob/main/CHANGELOG.md
|
10
|
+
Project-URL: Documentation, https://github.com/cellannotation/cap-anndata/blob/main/HOWTO.md
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
13
|
+
Classifier: Operating System :: OS Independent
|
14
|
+
Requires-Python: >=3.9
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
License-File: LICENSE
|
17
|
+
Requires-Dist: numpy>=1.23.5
|
18
|
+
Requires-Dist: pandas>=2.2.0
|
19
|
+
Requires-Dist: anndata>=0.10.0
|
20
|
+
Provides-Extra: dev
|
21
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
22
|
+
Requires-Dist: setuptools~=69.1.1; extra == "dev"
|
23
|
+
Dynamic: author
|
24
|
+
Dynamic: author-email
|
25
|
+
Dynamic: classifier
|
26
|
+
Dynamic: description
|
27
|
+
Dynamic: description-content-type
|
28
|
+
Dynamic: home-page
|
29
|
+
Dynamic: project-url
|
30
|
+
Dynamic: provides-extra
|
31
|
+
Dynamic: requires-dist
|
32
|
+
Dynamic: requires-python
|
33
|
+
Dynamic: summary
|
34
|
+
|
35
|
+
# CAP-AnnData: Partial I/O for AnnData (.h5ad) Files
|
36
|
+
|
37
|
+
## Overview
|
38
|
+
CAP-AnnData offering functionalities for selective reading and writing of [AnnData](https://pypi.org/project/anndata/)
|
39
|
+
file fields without the need for loading entire dataset (or even entire field) into memory.
|
40
|
+
For example, it allows to read and modify the single `obs` column taking nothing into memory except the column itself.
|
41
|
+
Package eager to replicate the original AnnData API as much as possible,
|
42
|
+
while providing additional features for efficient data manipulation for heavy datasets.
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
Install CAP-AnnData via pip:
|
46
|
+
|
47
|
+
```commandline
|
48
|
+
pip install -U cap-anndata
|
49
|
+
```
|
50
|
+
|
51
|
+
## Basic Example
|
52
|
+
|
53
|
+
The example below displayes how to read a single `obs` column, create new obs column and propagate it to the `.h5ad` file.
|
54
|
+
```python
|
55
|
+
from cap_anndata import read_h5ad
|
56
|
+
|
57
|
+
file_path = "your_data.h5ad"
|
58
|
+
with read_h5ad(file_path=file_path, edit=True) as cap_adata:
|
59
|
+
print(cap_adata.obs_keys()) # ['a', 'b', 'c']
|
60
|
+
print(cap_adata.obs) # Empty DataFrame
|
61
|
+
cap_adata.read_obs(columns=['a'])
|
62
|
+
print(cap_adata.obs.columns) # ['a']
|
63
|
+
cap_adata.obs['new_col'] = cap_adata.obs['a']
|
64
|
+
cap_adata.overwrite(fields=['obs'])
|
65
|
+
```
|
66
|
+
|
67
|
+
More example can be found in the [How-TO](https://github.com/cellannotation/cap-anndata/blob/main/HOWTO.md) file.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
cap_anndata/__init__.py,sha256=WRAQEDsWTvLbJWVUA5FmKCVrD2GN4oRd5I3c8jc9ajo,197
|
2
|
+
cap_anndata/backed_df.py,sha256=2OVomvTY51V05sYwEXg-4JYBgd9iJCA2-Lt7nEAL1Ug,3255
|
3
|
+
cap_anndata/backed_dict.py,sha256=Hb1SjnKuQ13mBUitQ5sL3kmcQ1j3GgB19r3yXkC0oIo,1019
|
4
|
+
cap_anndata/cap_anndata.py,sha256=-Lp6wxPncVcl_TaECnE6uHTfD9j_Ow_rScvpAWKK_fs,21081
|
5
|
+
cap_anndata/reader.py,sha256=UpZBCjaS4-K2w_9m6IuYetO9LwmEEJ5KvAw9aAoMRno,1609
|
6
|
+
cap_anndata-0.4.0.dist-info/LICENSE,sha256=XXTH6JikkxH7Gqy9VEj4crSizuwxzv04ROzkQ-ZS6o4,1532
|
7
|
+
cap_anndata-0.4.0.dist-info/METADATA,sha256=IXvItMAdXH-CunN3fNlyHPNFmxfoF9dOrU58tl17eLQ,2539
|
8
|
+
cap_anndata-0.4.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
9
|
+
cap_anndata-0.4.0.dist-info/top_level.txt,sha256=GKi_Uk4LUhXwWBfFCTIyJvEoJqFREt_4uH4CWgeLsg4,12
|
10
|
+
cap_anndata-0.4.0.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
cap_anndata/__init__.py,sha256=m-iyYXl6oIgczQMXr_rqhoObblRAs37YYxMoWidm7i4,207
|
2
|
-
cap_anndata/backed_df.py,sha256=06wZwEjszFQ8lkvy6-GgD_SD14idu9857RtlfMQiBjE,2691
|
3
|
-
cap_anndata/backed_dict.py,sha256=jPJl7RxPxV7s5ywD23ZxkInWPrgValyKHmlKZplDuTE,1053
|
4
|
-
cap_anndata/cap_anndata.py,sha256=RDozLa-RZoNq_-CWNbrEoLbrNfaD8GkIU8vmAkxFuoQ,21197
|
5
|
-
cap_anndata/reader.py,sha256=yiY8kButhg5TDc_OcXNOZkJv5Bbdht3XOzswjgDogdQ,1666
|
6
|
-
cap_anndata-0.3.0.dist-info/LICENSE,sha256=JAV0w7TBl6wQe9iFcCKjAWgpurym0f-Q0B75zm2PrKw,1560
|
7
|
-
cap_anndata-0.3.0.dist-info/METADATA,sha256=Fj4jPwlPbFr_u-e8-cW2KX5H0bUyhiZ5wcNACGrwK9w,2172
|
8
|
-
cap_anndata-0.3.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
9
|
-
cap_anndata-0.3.0.dist-info/top_level.txt,sha256=GKi_Uk4LUhXwWBfFCTIyJvEoJqFREt_4uH4CWgeLsg4,12
|
10
|
-
cap_anndata-0.3.0.dist-info/RECORD,,
|
File without changes
|