scigantic-cryoet 0.1.0__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.
- scigantic_cryoet-0.1.0/LICENSE +16 -0
- scigantic_cryoet-0.1.0/PKG-INFO +116 -0
- scigantic_cryoet-0.1.0/README.md +81 -0
- scigantic_cryoet-0.1.0/pyproject.toml +55 -0
- scigantic_cryoet-0.1.0/setup.cfg +4 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet/__init__.py +14 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet/_search.py +104 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet/catalog.py +220 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet/py.typed +0 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet.egg-info/PKG-INFO +116 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet.egg-info/SOURCES.txt +15 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet.egg-info/dependency_links.txt +1 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet.egg-info/requires.txt +11 -0
- scigantic_cryoet-0.1.0/src/scigantic_cryoet.egg-info/top_level.txt +1 -0
- scigantic_cryoet-0.1.0/tests/test_catalog.py +105 -0
- scigantic_cryoet-0.1.0/tests/test_client.py +51 -0
- scigantic_cryoet-0.1.0/tests/test_search.py +48 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT No Attribution
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Scigantic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
6
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
7
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
8
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
permit persons to whom the Software is furnished to do so.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
12
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
13
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
14
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
15
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
16
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scigantic-cryoet
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Search the CZ CryoET Data Portal from Python -- a catalog and search layer over ~370 public cryo-electron tomography datasets, none of which the portal itself indexes.
|
|
5
|
+
Author: Scigantic
|
|
6
|
+
License: MIT-0
|
|
7
|
+
Project-URL: Homepage, https://scigantic.com
|
|
8
|
+
Project-URL: Repository, https://github.com/Scigantic/scigantic-cryoet
|
|
9
|
+
Project-URL: Issues, https://github.com/Scigantic/scigantic-cryoet/issues
|
|
10
|
+
Project-URL: CryoET Data Portal, https://cryoetdataportal.czscience.com/
|
|
11
|
+
Keywords: cryo-et,cryo-em,cryoet-data-portal,structural-biology,tomography,microscopy
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT No Attribution License (MIT-0)
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: requests<3,>=2.28
|
|
26
|
+
Requires-Dist: pandas<4,>=1.5
|
|
27
|
+
Provides-Extra: viz
|
|
28
|
+
Requires-Dist: ipython; extra == "viz"
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
31
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
32
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
33
|
+
Requires-Dist: pandas-stubs; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
<h1 align="center">scigantic-cryoet</h1>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<a href="https://github.com/Scigantic/scigantic-cryoet/actions/workflows/ci.yml">
|
|
40
|
+
<img alt="CI" src="https://github.com/Scigantic/scigantic-cryoet/actions/workflows/ci.yml/badge.svg" /></a>
|
|
41
|
+
<a href="https://pypi.org/project/scigantic-cryoet/">
|
|
42
|
+
<img alt="PyPI" src="https://img.shields.io/pypi/v/scigantic-cryoet" /></a>
|
|
43
|
+
<a href="https://pypi.org/project/scigantic-cryoet/">
|
|
44
|
+
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/scigantic-cryoet" /></a>
|
|
45
|
+
<a href="https://github.com/Scigantic/scigantic-cryoet/blob/main/LICENSE">
|
|
46
|
+
<img alt="License" src="https://img.shields.io/github/license/Scigantic/scigantic-cryoet" /></a>
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
Search the [CZ CryoET Data Portal](https://cryoetdataportal.czscience.com/) from Python.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import scigantic_cryoet as cryoet
|
|
53
|
+
|
|
54
|
+
cat = cryoet.CryoetCatalog()
|
|
55
|
+
cat.search("Legionella", has_annotations=True)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```console
|
|
61
|
+
$ pip install scigantic-cryoet
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Why this exists
|
|
65
|
+
|
|
66
|
+
`s3://cryoet-data-portal-public` is public and anonymous, but its top level is nothing but numeric dataset ids. There is no search: finding "a tomogram of a ribosome in a mammalian neuron" otherwise means opening `dataset_metadata.json` by hand, once per dataset, across all ~370 of them. This package is a catalog and search layer on top of that bucket, the same move [`scigantic-empiar`](https://github.com/Scigantic/scigantic-empiar) and [`scigantic-emdb`](https://github.com/Scigantic/scigantic-emdb) made for their own archives.
|
|
67
|
+
|
|
68
|
+
It does not read tomogram pixel data or reimplement OME-Zarr access. The portal already ships a `thumbnail.gif`/`snapshot.gif` per dataset (unlike EMPIAR, which ships no previews at all), and the official [`cryoet-data-portal`](https://pypi.org/project/cryoet-data-portal/) client already reads the zarr volumes well. This package's job ends at "which dataset, and where."
|
|
69
|
+
|
|
70
|
+
## The catalog
|
|
71
|
+
|
|
72
|
+
`CryoetCatalog` loads a pre-built index so search/filter across every dataset is instant, no live reads. Measured against the full portal, 2026-09-02 (370/370 datasets, 0 failures, 129s to build):
|
|
73
|
+
|
|
74
|
+
| field | fill rate | scope |
|
|
75
|
+
|---|---:|---|
|
|
76
|
+
| title, description, organism, sample_type, disease, assay | 100% | every dataset |
|
|
77
|
+
| n_runs, authors, release/deposition dates | 100% | every dataset |
|
|
78
|
+
| organism (named), tissue, cell_type | 97% / 96% / 94% | every dataset |
|
|
79
|
+
| voxel_spacings, reconstruction_method, annotation_objects | 98% / 98% / 92% | **one run per dataset** |
|
|
80
|
+
| emdb_ids / empiar_ids present | 12% / 6.5% | cross-reference, when deposited |
|
|
81
|
+
|
|
82
|
+
**Read `catalog_meta` before trusting a fill rate.** Fields drawn from `dataset_metadata.json` (title, organism, sample_type, disease, assay, cross-references, ...) are COMPLETE — every dataset has one. Fields that live one level down at the run/tomogram level (`voxel_spacings`, `reconstruction_method`, `ctf_corrected`, `annotation_objects`, ...) describe **one run**, named in `sampled_run` — walking every run of every dataset is thousands of listings for detail that barely varies within a dataset. `catalog_meta` names exactly which fields are sampled, so this can't be missed the way an earlier internal EMPIAR catalog once advertised "all ~3,000 entries" while actually holding 12.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
cat = cryoet.CryoetCatalog()
|
|
86
|
+
cat.catalog_meta # {"catalog_entries": 370, "sampled_fields": [...], ...}
|
|
87
|
+
|
|
88
|
+
cat.search(organism="Homo sapiens", has_annotations=True, sort="runs")
|
|
89
|
+
cat.search(has_emdb=True, sort="runs") # datasets cross-referenced to EMDB, most runs first
|
|
90
|
+
cat.gallery(cat.search("spike")) # HTML gallery, portal thumbnails
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The index isn't published yet — `CryoetCatalog()` with no argument points at where the monorepo's onboarding batch job will land it. Until then, point it at a local file built with the catalog script:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
cat = cryoet.CryoetCatalog(url="/path/to/cryoet-catalog.json")
|
|
97
|
+
# or: export SCIGANTIC_CRYOET_CATALOG=/path/to/cryoet-catalog.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Live reads
|
|
101
|
+
|
|
102
|
+
`CryoetClient` hits the portal's bucket directly, for a dataset newer than whatever snapshot is loaded, or to double-check a stale field:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
client = cryoet.CryoetClient()
|
|
106
|
+
client.dataset_metadata(10000) # full dataset_metadata.json, live
|
|
107
|
+
client.runs(10000) # run directory names, COMPLETE (not sampled)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Data license
|
|
111
|
+
|
|
112
|
+
The portal describes its data as "publicly available" / "open access" (checked 2026-09-02, portal homepage and Terms of Use), but does not state a specific license designation (CC0, CC-BY, or otherwise) on either page. Check a dataset's own citation/attribution requirements — via `dataset_metadata.json`'s `authors`/`publications` fields, or the portal's own dataset page — before redistributing.
|
|
113
|
+
|
|
114
|
+
## What this doesn't do (yet)
|
|
115
|
+
|
|
116
|
+
No synonym/alias expansion in `search()` (a plain "GPCR" won't match "G protein-coupled receptor") — `scigantic-empiar`'s query expansion is the template once this has real query traffic to tune against. No walk of every run per dataset (see the fill-rate table above); if you need every run's metadata for a specific dataset of interest, use `CryoetClient.runs()` plus the official `cryoet-data-portal` client.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<h1 align="center">scigantic-cryoet</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/Scigantic/scigantic-cryoet/actions/workflows/ci.yml">
|
|
5
|
+
<img alt="CI" src="https://github.com/Scigantic/scigantic-cryoet/actions/workflows/ci.yml/badge.svg" /></a>
|
|
6
|
+
<a href="https://pypi.org/project/scigantic-cryoet/">
|
|
7
|
+
<img alt="PyPI" src="https://img.shields.io/pypi/v/scigantic-cryoet" /></a>
|
|
8
|
+
<a href="https://pypi.org/project/scigantic-cryoet/">
|
|
9
|
+
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/scigantic-cryoet" /></a>
|
|
10
|
+
<a href="https://github.com/Scigantic/scigantic-cryoet/blob/main/LICENSE">
|
|
11
|
+
<img alt="License" src="https://img.shields.io/github/license/Scigantic/scigantic-cryoet" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
Search the [CZ CryoET Data Portal](https://cryoetdataportal.czscience.com/) from Python.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import scigantic_cryoet as cryoet
|
|
18
|
+
|
|
19
|
+
cat = cryoet.CryoetCatalog()
|
|
20
|
+
cat.search("Legionella", has_annotations=True)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```console
|
|
26
|
+
$ pip install scigantic-cryoet
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Why this exists
|
|
30
|
+
|
|
31
|
+
`s3://cryoet-data-portal-public` is public and anonymous, but its top level is nothing but numeric dataset ids. There is no search: finding "a tomogram of a ribosome in a mammalian neuron" otherwise means opening `dataset_metadata.json` by hand, once per dataset, across all ~370 of them. This package is a catalog and search layer on top of that bucket, the same move [`scigantic-empiar`](https://github.com/Scigantic/scigantic-empiar) and [`scigantic-emdb`](https://github.com/Scigantic/scigantic-emdb) made for their own archives.
|
|
32
|
+
|
|
33
|
+
It does not read tomogram pixel data or reimplement OME-Zarr access. The portal already ships a `thumbnail.gif`/`snapshot.gif` per dataset (unlike EMPIAR, which ships no previews at all), and the official [`cryoet-data-portal`](https://pypi.org/project/cryoet-data-portal/) client already reads the zarr volumes well. This package's job ends at "which dataset, and where."
|
|
34
|
+
|
|
35
|
+
## The catalog
|
|
36
|
+
|
|
37
|
+
`CryoetCatalog` loads a pre-built index so search/filter across every dataset is instant, no live reads. Measured against the full portal, 2026-09-02 (370/370 datasets, 0 failures, 129s to build):
|
|
38
|
+
|
|
39
|
+
| field | fill rate | scope |
|
|
40
|
+
|---|---:|---|
|
|
41
|
+
| title, description, organism, sample_type, disease, assay | 100% | every dataset |
|
|
42
|
+
| n_runs, authors, release/deposition dates | 100% | every dataset |
|
|
43
|
+
| organism (named), tissue, cell_type | 97% / 96% / 94% | every dataset |
|
|
44
|
+
| voxel_spacings, reconstruction_method, annotation_objects | 98% / 98% / 92% | **one run per dataset** |
|
|
45
|
+
| emdb_ids / empiar_ids present | 12% / 6.5% | cross-reference, when deposited |
|
|
46
|
+
|
|
47
|
+
**Read `catalog_meta` before trusting a fill rate.** Fields drawn from `dataset_metadata.json` (title, organism, sample_type, disease, assay, cross-references, ...) are COMPLETE — every dataset has one. Fields that live one level down at the run/tomogram level (`voxel_spacings`, `reconstruction_method`, `ctf_corrected`, `annotation_objects`, ...) describe **one run**, named in `sampled_run` — walking every run of every dataset is thousands of listings for detail that barely varies within a dataset. `catalog_meta` names exactly which fields are sampled, so this can't be missed the way an earlier internal EMPIAR catalog once advertised "all ~3,000 entries" while actually holding 12.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
cat = cryoet.CryoetCatalog()
|
|
51
|
+
cat.catalog_meta # {"catalog_entries": 370, "sampled_fields": [...], ...}
|
|
52
|
+
|
|
53
|
+
cat.search(organism="Homo sapiens", has_annotations=True, sort="runs")
|
|
54
|
+
cat.search(has_emdb=True, sort="runs") # datasets cross-referenced to EMDB, most runs first
|
|
55
|
+
cat.gallery(cat.search("spike")) # HTML gallery, portal thumbnails
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The index isn't published yet — `CryoetCatalog()` with no argument points at where the monorepo's onboarding batch job will land it. Until then, point it at a local file built with the catalog script:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
cat = cryoet.CryoetCatalog(url="/path/to/cryoet-catalog.json")
|
|
62
|
+
# or: export SCIGANTIC_CRYOET_CATALOG=/path/to/cryoet-catalog.json
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Live reads
|
|
66
|
+
|
|
67
|
+
`CryoetClient` hits the portal's bucket directly, for a dataset newer than whatever snapshot is loaded, or to double-check a stale field:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
client = cryoet.CryoetClient()
|
|
71
|
+
client.dataset_metadata(10000) # full dataset_metadata.json, live
|
|
72
|
+
client.runs(10000) # run directory names, COMPLETE (not sampled)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Data license
|
|
76
|
+
|
|
77
|
+
The portal describes its data as "publicly available" / "open access" (checked 2026-09-02, portal homepage and Terms of Use), but does not state a specific license designation (CC0, CC-BY, or otherwise) on either page. Check a dataset's own citation/attribution requirements — via `dataset_metadata.json`'s `authors`/`publications` fields, or the portal's own dataset page — before redistributing.
|
|
78
|
+
|
|
79
|
+
## What this doesn't do (yet)
|
|
80
|
+
|
|
81
|
+
No synonym/alias expansion in `search()` (a plain "GPCR" won't match "G protein-coupled receptor") — `scigantic-empiar`'s query expansion is the template once this has real query traffic to tune against. No walk of every run per dataset (see the fill-rate table above); if you need every run's metadata for a specific dataset of interest, use `CryoetClient.runs()` plus the official `cryoet-data-portal` client.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scigantic-cryoet"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Search the CZ CryoET Data Portal from Python -- a catalog and search layer over ~370 public cryo-electron tomography datasets, none of which the portal itself indexes."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT-0" }
|
|
12
|
+
authors = [{ name = "Scigantic" }]
|
|
13
|
+
keywords = ["cryo-et", "cryo-em", "cryoet-data-portal", "structural-biology", "tomography", "microscopy"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"License :: OSI Approved :: MIT No Attribution License (MIT-0)",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
dependencies = [
|
|
28
|
+
# Upper bounds checked live against each package's current PyPI major
|
|
29
|
+
# (requests 2.x, pandas 2.x as of 2026-09) on 2026-09-02; defensive
|
|
30
|
+
# ceilings, not a response to a known break in either's next major.
|
|
31
|
+
"requests>=2.28,<3",
|
|
32
|
+
"pandas>=1.5,<4",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
viz = ["ipython"]
|
|
37
|
+
dev = ["pytest>=7", "mypy>=1.10", "types-requests", "pandas-stubs"]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://scigantic.com"
|
|
41
|
+
Repository = "https://github.com/Scigantic/scigantic-cryoet"
|
|
42
|
+
Issues = "https://github.com/Scigantic/scigantic-cryoet/issues"
|
|
43
|
+
"CryoET Data Portal" = "https://cryoetdataportal.czscience.com/"
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.packages.find]
|
|
46
|
+
where = ["src"]
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.package-data]
|
|
49
|
+
scigantic_cryoet = ["py.typed"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
testpaths = ["tests"]
|
|
53
|
+
|
|
54
|
+
[tool.mypy]
|
|
55
|
+
strict = true
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""scigantic_cryoet -- search the CZ CryoET Data Portal from Python.
|
|
2
|
+
|
|
3
|
+
>>> import scigantic_cryoet as cryoet
|
|
4
|
+
>>> cat = cryoet.CryoetCatalog()
|
|
5
|
+
>>> cat.search("neuron", organism="Homo sapiens").head()
|
|
6
|
+
|
|
7
|
+
See CryoetCatalog for the searchable index and CryoetClient for live
|
|
8
|
+
per-dataset reads straight from the portal's public bucket.
|
|
9
|
+
"""
|
|
10
|
+
from .catalog import CryoetCatalog, CryoetClient
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|
|
13
|
+
|
|
14
|
+
__all__ = ["CryoetCatalog", "CryoetClient", "__version__"]
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Free-text scoring over a catalog record.
|
|
2
|
+
|
|
3
|
+
Deliberately simple for v0.1: case-insensitive token overlap across the
|
|
4
|
+
fields a structural biologist actually searches on, no synonym expansion.
|
|
5
|
+
scigantic-empiar's `expand_query`/`match_score` (alias tables for "GPCR",
|
|
6
|
+
"cryoET", etc.) is the natural next step once this catalog has real query
|
|
7
|
+
traffic to tune against -- guessing synonyms ahead of usage risks the same
|
|
8
|
+
trap the search team has hit before: an untested expansion can silently
|
|
9
|
+
hurt ranking as easily as help it.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
TEXT_FIELDS = (
|
|
16
|
+
"title", "description", "organism", "sample_type", "disease",
|
|
17
|
+
"assay", "tissue", "cell_type", "cell_strain", "cell_component",
|
|
18
|
+
"reconstruction_method",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _tokens(s: str) -> set[str]:
|
|
23
|
+
return {t for t in "".join(c if c.isalnum() else " " for c in s.lower()).split() if t}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def expand_query(query: Any) -> set[str]:
|
|
27
|
+
return _tokens(str(query)) if query else set()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _record_text(record: dict[str, Any]) -> str:
|
|
31
|
+
parts = []
|
|
32
|
+
for f in TEXT_FIELDS:
|
|
33
|
+
v = record.get(f)
|
|
34
|
+
if v:
|
|
35
|
+
parts.append(str(v))
|
|
36
|
+
authors = record.get("authors") or []
|
|
37
|
+
parts.extend(str(a) for a in authors)
|
|
38
|
+
return " ".join(parts)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def match_score(record: dict[str, Any], terms: set[str], primary: str | None = None) -> float:
|
|
42
|
+
"""Fraction of query terms present as a SUBSTRING of some token, +1 bonus
|
|
43
|
+
if the literal phrase matches the title.
|
|
44
|
+
|
|
45
|
+
Substring, not exact token equality: "neuron" has to match "Neuronal
|
|
46
|
+
synapse tomography" (the everyday case of a plain word-form mismatch,
|
|
47
|
+
not literal token identity), and a catalog record with no query
|
|
48
|
+
expansion yet (see the module docstring) needs whatever help substring
|
|
49
|
+
matching can give it.
|
|
50
|
+
"""
|
|
51
|
+
if not terms:
|
|
52
|
+
return 1.0
|
|
53
|
+
text = _record_text(record).lower()
|
|
54
|
+
text_tokens = _tokens(text)
|
|
55
|
+
hits = sum(1 for t in terms if any(t in tok for tok in text_tokens))
|
|
56
|
+
if hits == 0:
|
|
57
|
+
return 0.0
|
|
58
|
+
score = hits / len(terms)
|
|
59
|
+
if primary and primary in str(record.get("title") or "").lower():
|
|
60
|
+
score += 1.0
|
|
61
|
+
return score
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def passes_filters(record: dict[str, Any], *, organism: str | None = None,
|
|
65
|
+
disease: str | None = None, sample_type: str | None = None,
|
|
66
|
+
tissue: str | None = None, cell_type: str | None = None,
|
|
67
|
+
assay: str | None = None, reconstruction_method: str | None = None,
|
|
68
|
+
has_annotations: bool | None = None, has_emdb: bool | None = None,
|
|
69
|
+
has_empiar: bool | None = None,
|
|
70
|
+
ctf_corrected: bool | None = None) -> bool:
|
|
71
|
+
def _contains(field: str, needle: str | None) -> bool:
|
|
72
|
+
if needle is None:
|
|
73
|
+
return True
|
|
74
|
+
v = record.get(field)
|
|
75
|
+
return bool(v) and str(needle).lower() in str(v).lower()
|
|
76
|
+
|
|
77
|
+
if not _contains("organism", organism):
|
|
78
|
+
return False
|
|
79
|
+
if not _contains("disease", disease):
|
|
80
|
+
return False
|
|
81
|
+
if not _contains("sample_type", sample_type):
|
|
82
|
+
return False
|
|
83
|
+
if not _contains("tissue", tissue):
|
|
84
|
+
return False
|
|
85
|
+
if not _contains("cell_type", cell_type):
|
|
86
|
+
return False
|
|
87
|
+
if not _contains("assay", assay):
|
|
88
|
+
return False
|
|
89
|
+
if not _contains("reconstruction_method", reconstruction_method):
|
|
90
|
+
return False
|
|
91
|
+
if has_annotations is not None:
|
|
92
|
+
n = record.get("n_annotations") or 0
|
|
93
|
+
if bool(n) != bool(has_annotations):
|
|
94
|
+
return False
|
|
95
|
+
if has_emdb is not None:
|
|
96
|
+
if bool(record.get("emdb_ids")) != bool(has_emdb):
|
|
97
|
+
return False
|
|
98
|
+
if has_empiar is not None:
|
|
99
|
+
if bool(record.get("empiar_ids")) != bool(has_empiar):
|
|
100
|
+
return False
|
|
101
|
+
if ctf_corrected is not None:
|
|
102
|
+
if record.get("ctf_corrected") != ctf_corrected:
|
|
103
|
+
return False
|
|
104
|
+
return True
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""catalog.py -- the searchable index, and a live per-dataset metadata client.
|
|
2
|
+
|
|
3
|
+
The CZ CryoET Data Portal (`s3://cryoet-data-portal-public`, anonymous,
|
|
4
|
+
~370 datasets as of 2026-09) has no search of its own: a bucket whose top
|
|
5
|
+
level is nothing but numeric dataset ids. `CryoetCatalog` loads a pre-built
|
|
6
|
+
index (one JSON file, produced by the monorepo's `cryoet_build_catalog.py`
|
|
7
|
+
batch job) so filtering across every dataset is instant, no live reads.
|
|
8
|
+
`CryoetClient` is the complementary live path, for the current state of one
|
|
9
|
+
dataset the snapshot might not have, or a dataset newer than the index.
|
|
10
|
+
|
|
11
|
+
This package does not read tomogram pixel data. The portal already ships
|
|
12
|
+
`thumbnail.gif`/`snapshot.gif` per dataset (unlike EMPIAR, which ships no
|
|
13
|
+
previews at all -- see scigantic-empiar), and the official `cryoet-data-portal`
|
|
14
|
+
client already reads the OME-Zarr volumes well. Reinventing either here would
|
|
15
|
+
just be a second, divergent copy of something that already works.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import urllib.parse
|
|
22
|
+
import xml.etree.ElementTree as ET
|
|
23
|
+
from typing import Any, cast
|
|
24
|
+
|
|
25
|
+
import pandas as pd
|
|
26
|
+
import requests
|
|
27
|
+
|
|
28
|
+
from ._search import expand_query, match_score, passes_filters
|
|
29
|
+
|
|
30
|
+
__all__ = ["CryoetCatalog", "CryoetClient"]
|
|
31
|
+
|
|
32
|
+
BUCKET = "cryoet-data-portal-public"
|
|
33
|
+
ENDPOINT = f"https://{BUCKET}.s3.amazonaws.com"
|
|
34
|
+
|
|
35
|
+
# Not live yet: this points at where the monorepo's onboarding batch job will
|
|
36
|
+
# publish the built index, same rollout order scigantic-empiar and
|
|
37
|
+
# scigantic-emdb followed (library ships, then the catalog lands). Until then
|
|
38
|
+
# CryoetCatalog.load() 404s -- point SCIGANTIC_CRYOET_CATALOG at a local
|
|
39
|
+
# `cryoet_build_catalog.py --out` file to develop against real data meanwhile.
|
|
40
|
+
CATALOG_URL = os.environ.get(
|
|
41
|
+
"SCIGANTIC_CRYOET_CATALOG",
|
|
42
|
+
"https://scigantic-cryoet-catalog.s3.amazonaws.com/catalog.json",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
_UA = {"User-Agent": "Scigantic-cryoet/0.1 (+https://scigantic.com; mailto:support@scigantic.com)"}
|
|
46
|
+
_session = requests.Session()
|
|
47
|
+
_session.headers.update(_UA)
|
|
48
|
+
|
|
49
|
+
_S3_NS = "{http://s3.amazonaws.com/doc/2006-03-01/}"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class CryoetClient:
|
|
53
|
+
"""Live per-dataset metadata, straight from the portal's own bucket.
|
|
54
|
+
|
|
55
|
+
Anonymous S3 REST, no boto3, no credentials -- the same shape as the
|
|
56
|
+
monorepo's onboarding script. Useful for a dataset newer than whatever
|
|
57
|
+
catalog snapshot is loaded, or to double-check a stale field.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def dataset_metadata(self, dataset_id: int | str) -> dict[str, Any]:
|
|
61
|
+
r = _session.get(f"{ENDPOINT}/{dataset_id}/dataset_metadata.json", timeout=30)
|
|
62
|
+
if r.status_code == 404:
|
|
63
|
+
raise FileNotFoundError(f"no dataset_metadata.json for dataset {dataset_id}")
|
|
64
|
+
r.raise_for_status()
|
|
65
|
+
result: dict[str, Any] = r.json()
|
|
66
|
+
return result
|
|
67
|
+
|
|
68
|
+
def runs(self, dataset_id: int | str) -> list[str]:
|
|
69
|
+
"""Run directory names under a dataset (COMPLETE, one delimiter listing)."""
|
|
70
|
+
q = {"list-type": "2", "prefix": f"{dataset_id}/", "delimiter": "/"}
|
|
71
|
+
r = _session.get(f"{ENDPOINT}/?{urllib.parse.urlencode(q)}", timeout=30)
|
|
72
|
+
r.raise_for_status()
|
|
73
|
+
root = ET.fromstring(r.content)
|
|
74
|
+
names = [
|
|
75
|
+
cp.text.rstrip("/").split("/")[-1]
|
|
76
|
+
for cp in root.findall(f"{_S3_NS}CommonPrefixes/{_S3_NS}Prefix") if cp.text
|
|
77
|
+
]
|
|
78
|
+
return [n for n in names if n != "Images"]
|
|
79
|
+
|
|
80
|
+
def thumbnail_url(self, dataset_id: int | str) -> str:
|
|
81
|
+
return f"{ENDPOINT}/{dataset_id}/Images/thumbnail.gif"
|
|
82
|
+
|
|
83
|
+
def snapshot_url(self, dataset_id: int | str) -> str:
|
|
84
|
+
return f"{ENDPOINT}/{dataset_id}/Images/snapshot.gif"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class CryoetCatalog:
|
|
88
|
+
"""Searchable catalog across every CryoET Data Portal dataset.
|
|
89
|
+
|
|
90
|
+
Field semantics vary by how the index was built -- see the `catalog_meta`
|
|
91
|
+
property before trusting a fill rate. `title`/`description`/`organism`/
|
|
92
|
+
`sample_type`/`disease`/`assay`/`n_runs` etc. are COMPLETE (sourced from
|
|
93
|
+
each dataset's own `dataset_metadata.json`, which every dataset has).
|
|
94
|
+
`voxel_spacings`/`tomogram_size`/`reconstruction_method`/`ctf_corrected`/
|
|
95
|
+
`annotation_objects` etc. describe ONE run per dataset (`sampled_run`),
|
|
96
|
+
not every run -- walking every run of every dataset is thousands of
|
|
97
|
+
listings for detail that barely varies within a dataset. A dataset with
|
|
98
|
+
heterogeneous runs will be under-reported on these fields specifically.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
def __init__(self, url: str = CATALOG_URL) -> None:
|
|
102
|
+
self.url = url
|
|
103
|
+
self._df: pd.DataFrame | None = None
|
|
104
|
+
self._meta: dict[str, Any] | None = None
|
|
105
|
+
|
|
106
|
+
def load(self) -> pd.DataFrame:
|
|
107
|
+
if self._df is not None:
|
|
108
|
+
return self._df
|
|
109
|
+
if self.url.startswith("http://") or self.url.startswith("https://"):
|
|
110
|
+
r = _session.get(self.url, timeout=30)
|
|
111
|
+
r.raise_for_status()
|
|
112
|
+
payload = r.json()
|
|
113
|
+
else:
|
|
114
|
+
with open(self.url) as fh:
|
|
115
|
+
payload = json.load(fh)
|
|
116
|
+
# Raise on an unexpected shape instead of degrading to an empty (but
|
|
117
|
+
# still queryable) catalog -- the exact failure mode EmpiarCatalog.load()
|
|
118
|
+
# was fixed to stop making, after it once fell back to a bare listing
|
|
119
|
+
# on any exception and kept answering queries as if nothing were wrong.
|
|
120
|
+
if not isinstance(payload, dict) or "entries" not in payload:
|
|
121
|
+
got = sorted(payload.keys()) if isinstance(payload, dict) else type(payload).__name__
|
|
122
|
+
raise ValueError(
|
|
123
|
+
f"catalog at {self.url!r} has no 'entries' key (got: {got}); "
|
|
124
|
+
"this reader expects the {meta, entries} shape cryoet_build_catalog.py writes"
|
|
125
|
+
)
|
|
126
|
+
self._meta = payload.get("meta", {})
|
|
127
|
+
self._df = pd.DataFrame(payload["entries"])
|
|
128
|
+
return self._df
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def catalog_meta(self) -> dict[str, Any]:
|
|
132
|
+
"""Build-time metadata: dataset/run counts, the complete-vs-sampled
|
|
133
|
+
field split, and the sentinel-normalisation counts. Read this before
|
|
134
|
+
quoting a fill rate from the catalog."""
|
|
135
|
+
if self._meta is None:
|
|
136
|
+
self.load()
|
|
137
|
+
return self._meta or {}
|
|
138
|
+
|
|
139
|
+
def search(self, query: str | None = None, *, organism: str | None = None,
|
|
140
|
+
disease: str | None = None, sample_type: str | None = None,
|
|
141
|
+
tissue: str | None = None, cell_type: str | None = None,
|
|
142
|
+
assay: str | None = None, reconstruction_method: str | None = None,
|
|
143
|
+
has_annotations: bool | None = None, has_emdb: bool | None = None,
|
|
144
|
+
has_empiar: bool | None = None, ctf_corrected: bool | None = None,
|
|
145
|
+
limit: int | None = 50, sort: str = "relevance") -> pd.DataFrame:
|
|
146
|
+
"""Find datasets by scientific content, not just id.
|
|
147
|
+
|
|
148
|
+
query free text, matched across title/description/
|
|
149
|
+
organism/sample_type/disease/assay/tissue/
|
|
150
|
+
cell_type/authors.
|
|
151
|
+
organism/disease/... substring filters against the COMPLETE fields.
|
|
152
|
+
has_annotations require (or exclude, False) at least one
|
|
153
|
+
annotation on the sampled run.
|
|
154
|
+
has_emdb/has_empiar require (or exclude) a cross-reference.
|
|
155
|
+
ctf_corrected True/False -- sampled-run field, see catalog_meta.
|
|
156
|
+
sort "relevance" (default), "runs", or "id".
|
|
157
|
+
|
|
158
|
+
Returns a DataFrame.
|
|
159
|
+
"""
|
|
160
|
+
df = self.load().copy()
|
|
161
|
+
if df.empty:
|
|
162
|
+
return df
|
|
163
|
+
records = cast("list[dict[str, Any]]", df.to_dict("records"))
|
|
164
|
+
terms = expand_query(query)
|
|
165
|
+
primary = str(query or "").strip().lower() or None
|
|
166
|
+
hits = [
|
|
167
|
+
r for r in records
|
|
168
|
+
if (not terms or match_score(r, terms, primary) > 0)
|
|
169
|
+
and passes_filters(
|
|
170
|
+
r, organism=organism, disease=disease, sample_type=sample_type,
|
|
171
|
+
tissue=tissue, cell_type=cell_type, assay=assay,
|
|
172
|
+
reconstruction_method=reconstruction_method,
|
|
173
|
+
has_annotations=has_annotations, has_emdb=has_emdb,
|
|
174
|
+
has_empiar=has_empiar, ctf_corrected=ctf_corrected)
|
|
175
|
+
]
|
|
176
|
+
if sort == "relevance" and terms:
|
|
177
|
+
hits.sort(key=lambda r: -match_score(r, terms, primary))
|
|
178
|
+
elif sort == "runs":
|
|
179
|
+
hits.sort(key=lambda r: -(r.get("n_runs") or 0))
|
|
180
|
+
elif sort == "id":
|
|
181
|
+
hits.sort(key=lambda r: (r.get("id") is None, r.get("id") or 0))
|
|
182
|
+
|
|
183
|
+
out = pd.DataFrame(hits[:limit] if limit else hits)
|
|
184
|
+
if out.empty:
|
|
185
|
+
return out
|
|
186
|
+
preferred = ["id", "title", "organism", "sample_type", "disease", "n_runs",
|
|
187
|
+
"reconstruction_method", "voxel_spacings", "emdb_ids", "empiar_ids",
|
|
188
|
+
"thumbnail_url"]
|
|
189
|
+
cols = [c for c in preferred if c in out.columns]
|
|
190
|
+
return out[cols + [c for c in out.columns if c not in cols]]
|
|
191
|
+
|
|
192
|
+
def gallery(self, df: pd.DataFrame | None = None, cols: int = 4) -> Any:
|
|
193
|
+
"""HTML gallery using the portal's own thumbnail.gif per dataset."""
|
|
194
|
+
from IPython.display import HTML
|
|
195
|
+
import html as _html
|
|
196
|
+
df = self.load() if df is None else df
|
|
197
|
+
cells = []
|
|
198
|
+
for _, r in df.iterrows():
|
|
199
|
+
def g(key: str, default: Any = "") -> Any:
|
|
200
|
+
v = r.get(key, default)
|
|
201
|
+
return default if v is None or v != v else v
|
|
202
|
+
|
|
203
|
+
did, thumb = g("id"), g("thumbnail_url")
|
|
204
|
+
if thumb:
|
|
205
|
+
art = (f'<img src="{_html.escape(str(thumb))}" title="dataset thumbnail"'
|
|
206
|
+
' style="width:100%;border-radius:6px;background:#111">')
|
|
207
|
+
else:
|
|
208
|
+
art = ('<div style="height:120px;border-radius:6px;background:#f2f2f2;'
|
|
209
|
+
'display:flex;align-items:center;justify-content:center;color:#aaa;'
|
|
210
|
+
'font:10px sans-serif">no thumbnail</div>')
|
|
211
|
+
label = str(g("title"))
|
|
212
|
+
bits = [str(x) for x in (g("organism"), g("sample_type")) if x]
|
|
213
|
+
if g("n_runs"):
|
|
214
|
+
bits.append(f"{g('n_runs')} run(s)")
|
|
215
|
+
cells.append(
|
|
216
|
+
f'<div style="width:{100 // cols - 2}%;display:inline-block;vertical-align:top;'
|
|
217
|
+
f'margin:1%;font:11px sans-serif">{art}'
|
|
218
|
+
f'<b>CryoET-{_html.escape(str(did))}</b><br>{_html.escape(label[:70])}'
|
|
219
|
+
f'<br><span style="color:#888">{" · ".join(bits)}</span></div>')
|
|
220
|
+
return HTML("<div>" + "".join(cells) + "</div>") # type: ignore[no-untyped-call]
|
|
File without changes
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scigantic-cryoet
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Search the CZ CryoET Data Portal from Python -- a catalog and search layer over ~370 public cryo-electron tomography datasets, none of which the portal itself indexes.
|
|
5
|
+
Author: Scigantic
|
|
6
|
+
License: MIT-0
|
|
7
|
+
Project-URL: Homepage, https://scigantic.com
|
|
8
|
+
Project-URL: Repository, https://github.com/Scigantic/scigantic-cryoet
|
|
9
|
+
Project-URL: Issues, https://github.com/Scigantic/scigantic-cryoet/issues
|
|
10
|
+
Project-URL: CryoET Data Portal, https://cryoetdataportal.czscience.com/
|
|
11
|
+
Keywords: cryo-et,cryo-em,cryoet-data-portal,structural-biology,tomography,microscopy
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT No Attribution License (MIT-0)
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: requests<3,>=2.28
|
|
26
|
+
Requires-Dist: pandas<4,>=1.5
|
|
27
|
+
Provides-Extra: viz
|
|
28
|
+
Requires-Dist: ipython; extra == "viz"
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
31
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
32
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
33
|
+
Requires-Dist: pandas-stubs; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
<h1 align="center">scigantic-cryoet</h1>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<a href="https://github.com/Scigantic/scigantic-cryoet/actions/workflows/ci.yml">
|
|
40
|
+
<img alt="CI" src="https://github.com/Scigantic/scigantic-cryoet/actions/workflows/ci.yml/badge.svg" /></a>
|
|
41
|
+
<a href="https://pypi.org/project/scigantic-cryoet/">
|
|
42
|
+
<img alt="PyPI" src="https://img.shields.io/pypi/v/scigantic-cryoet" /></a>
|
|
43
|
+
<a href="https://pypi.org/project/scigantic-cryoet/">
|
|
44
|
+
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/scigantic-cryoet" /></a>
|
|
45
|
+
<a href="https://github.com/Scigantic/scigantic-cryoet/blob/main/LICENSE">
|
|
46
|
+
<img alt="License" src="https://img.shields.io/github/license/Scigantic/scigantic-cryoet" /></a>
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
Search the [CZ CryoET Data Portal](https://cryoetdataportal.czscience.com/) from Python.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import scigantic_cryoet as cryoet
|
|
53
|
+
|
|
54
|
+
cat = cryoet.CryoetCatalog()
|
|
55
|
+
cat.search("Legionella", has_annotations=True)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```console
|
|
61
|
+
$ pip install scigantic-cryoet
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Why this exists
|
|
65
|
+
|
|
66
|
+
`s3://cryoet-data-portal-public` is public and anonymous, but its top level is nothing but numeric dataset ids. There is no search: finding "a tomogram of a ribosome in a mammalian neuron" otherwise means opening `dataset_metadata.json` by hand, once per dataset, across all ~370 of them. This package is a catalog and search layer on top of that bucket, the same move [`scigantic-empiar`](https://github.com/Scigantic/scigantic-empiar) and [`scigantic-emdb`](https://github.com/Scigantic/scigantic-emdb) made for their own archives.
|
|
67
|
+
|
|
68
|
+
It does not read tomogram pixel data or reimplement OME-Zarr access. The portal already ships a `thumbnail.gif`/`snapshot.gif` per dataset (unlike EMPIAR, which ships no previews at all), and the official [`cryoet-data-portal`](https://pypi.org/project/cryoet-data-portal/) client already reads the zarr volumes well. This package's job ends at "which dataset, and where."
|
|
69
|
+
|
|
70
|
+
## The catalog
|
|
71
|
+
|
|
72
|
+
`CryoetCatalog` loads a pre-built index so search/filter across every dataset is instant, no live reads. Measured against the full portal, 2026-09-02 (370/370 datasets, 0 failures, 129s to build):
|
|
73
|
+
|
|
74
|
+
| field | fill rate | scope |
|
|
75
|
+
|---|---:|---|
|
|
76
|
+
| title, description, organism, sample_type, disease, assay | 100% | every dataset |
|
|
77
|
+
| n_runs, authors, release/deposition dates | 100% | every dataset |
|
|
78
|
+
| organism (named), tissue, cell_type | 97% / 96% / 94% | every dataset |
|
|
79
|
+
| voxel_spacings, reconstruction_method, annotation_objects | 98% / 98% / 92% | **one run per dataset** |
|
|
80
|
+
| emdb_ids / empiar_ids present | 12% / 6.5% | cross-reference, when deposited |
|
|
81
|
+
|
|
82
|
+
**Read `catalog_meta` before trusting a fill rate.** Fields drawn from `dataset_metadata.json` (title, organism, sample_type, disease, assay, cross-references, ...) are COMPLETE — every dataset has one. Fields that live one level down at the run/tomogram level (`voxel_spacings`, `reconstruction_method`, `ctf_corrected`, `annotation_objects`, ...) describe **one run**, named in `sampled_run` — walking every run of every dataset is thousands of listings for detail that barely varies within a dataset. `catalog_meta` names exactly which fields are sampled, so this can't be missed the way an earlier internal EMPIAR catalog once advertised "all ~3,000 entries" while actually holding 12.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
cat = cryoet.CryoetCatalog()
|
|
86
|
+
cat.catalog_meta # {"catalog_entries": 370, "sampled_fields": [...], ...}
|
|
87
|
+
|
|
88
|
+
cat.search(organism="Homo sapiens", has_annotations=True, sort="runs")
|
|
89
|
+
cat.search(has_emdb=True, sort="runs") # datasets cross-referenced to EMDB, most runs first
|
|
90
|
+
cat.gallery(cat.search("spike")) # HTML gallery, portal thumbnails
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The index isn't published yet — `CryoetCatalog()` with no argument points at where the monorepo's onboarding batch job will land it. Until then, point it at a local file built with the catalog script:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
cat = cryoet.CryoetCatalog(url="/path/to/cryoet-catalog.json")
|
|
97
|
+
# or: export SCIGANTIC_CRYOET_CATALOG=/path/to/cryoet-catalog.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Live reads
|
|
101
|
+
|
|
102
|
+
`CryoetClient` hits the portal's bucket directly, for a dataset newer than whatever snapshot is loaded, or to double-check a stale field:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
client = cryoet.CryoetClient()
|
|
106
|
+
client.dataset_metadata(10000) # full dataset_metadata.json, live
|
|
107
|
+
client.runs(10000) # run directory names, COMPLETE (not sampled)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Data license
|
|
111
|
+
|
|
112
|
+
The portal describes its data as "publicly available" / "open access" (checked 2026-09-02, portal homepage and Terms of Use), but does not state a specific license designation (CC0, CC-BY, or otherwise) on either page. Check a dataset's own citation/attribution requirements — via `dataset_metadata.json`'s `authors`/`publications` fields, or the portal's own dataset page — before redistributing.
|
|
113
|
+
|
|
114
|
+
## What this doesn't do (yet)
|
|
115
|
+
|
|
116
|
+
No synonym/alias expansion in `search()` (a plain "GPCR" won't match "G protein-coupled receptor") — `scigantic-empiar`'s query expansion is the template once this has real query traffic to tune against. No walk of every run per dataset (see the fill-rate table above); if you need every run's metadata for a specific dataset of interest, use `CryoetClient.runs()` plus the official `cryoet-data-portal` client.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/scigantic_cryoet/__init__.py
|
|
5
|
+
src/scigantic_cryoet/_search.py
|
|
6
|
+
src/scigantic_cryoet/catalog.py
|
|
7
|
+
src/scigantic_cryoet/py.typed
|
|
8
|
+
src/scigantic_cryoet.egg-info/PKG-INFO
|
|
9
|
+
src/scigantic_cryoet.egg-info/SOURCES.txt
|
|
10
|
+
src/scigantic_cryoet.egg-info/dependency_links.txt
|
|
11
|
+
src/scigantic_cryoet.egg-info/requires.txt
|
|
12
|
+
src/scigantic_cryoet.egg-info/top_level.txt
|
|
13
|
+
tests/test_catalog.py
|
|
14
|
+
tests/test_client.py
|
|
15
|
+
tests/test_search.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
scigantic_cryoet
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""catalog.py -- CryoetCatalog (no network)."""
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import scigantic_cryoet as sc
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _catalog():
|
|
9
|
+
cat = sc.CryoetCatalog()
|
|
10
|
+
cat._df = pd.DataFrame([
|
|
11
|
+
{"id": 10000, "title": "Neuronal synapse tomography", "organism": "Homo sapiens",
|
|
12
|
+
"sample_type": "cell", "disease": None, "n_runs": 3, "emdb_ids": ["EMD-1234"],
|
|
13
|
+
"empiar_ids": [], "n_annotations": 2, "ctf_corrected": True},
|
|
14
|
+
{"id": 10301, "title": "SARS-CoV-2 spike in situ", "organism": "SARS-CoV-2",
|
|
15
|
+
"sample_type": "organelle", "disease": "COVID-19", "n_runs": 1, "emdb_ids": [],
|
|
16
|
+
"empiar_ids": ["11123"], "n_annotations": 0, "ctf_corrected": None},
|
|
17
|
+
{"id": 10450, "title": "Mitochondria in mouse neuron", "organism": "Mus musculus",
|
|
18
|
+
"sample_type": "organelle", "disease": None, "n_runs": 5, "emdb_ids": [],
|
|
19
|
+
"empiar_ids": [], "n_annotations": 4, "ctf_corrected": False},
|
|
20
|
+
])
|
|
21
|
+
cat._meta = {"catalog_entries": 3}
|
|
22
|
+
return cat
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_search_by_query_matches_title_and_organism():
|
|
26
|
+
hits = _catalog().search("neuron")
|
|
27
|
+
assert set(hits["id"]) == {10000, 10450}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_search_by_organism_filter():
|
|
31
|
+
hits = _catalog().search(organism="Mus musculus")
|
|
32
|
+
assert list(hits["id"]) == [10450]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_search_has_emdb():
|
|
36
|
+
hits = _catalog().search(has_emdb=True)
|
|
37
|
+
assert list(hits["id"]) == [10000]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_search_has_annotations_false():
|
|
41
|
+
hits = _catalog().search(has_annotations=False)
|
|
42
|
+
assert list(hits["id"]) == [10301]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_search_ctf_corrected():
|
|
46
|
+
hits = _catalog().search(ctf_corrected=False)
|
|
47
|
+
assert list(hits["id"]) == [10450]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_search_sort_runs():
|
|
51
|
+
hits = _catalog().search(sort="runs")
|
|
52
|
+
assert list(hits["id"]) == [10450, 10000, 10301]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_search_limit():
|
|
56
|
+
assert len(_catalog().search(limit=1)) == 1
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_search_no_query_returns_all():
|
|
60
|
+
assert len(_catalog().search()) == 3
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_catalog_meta_passthrough():
|
|
64
|
+
assert _catalog().catalog_meta == {"catalog_entries": 3}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_load_local_path(tmp_path):
|
|
68
|
+
import json
|
|
69
|
+
p = tmp_path / "catalog.json"
|
|
70
|
+
p.write_text(json.dumps({
|
|
71
|
+
"meta": {"catalog_entries": 1},
|
|
72
|
+
"entries": [{"id": 1, "title": "x"}],
|
|
73
|
+
}))
|
|
74
|
+
cat = sc.CryoetCatalog(url=str(p))
|
|
75
|
+
df = cat.load()
|
|
76
|
+
assert list(df["id"]) == [1]
|
|
77
|
+
assert cat.catalog_meta == {"catalog_entries": 1}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_load_raises_on_wrong_shape(tmp_path):
|
|
81
|
+
"""The exact bug this test guards against shipped in v0.1.0 development:
|
|
82
|
+
an earlier version of load() looked for a 'datasets' key that the real
|
|
83
|
+
builder (cryoet_build_catalog.py) never writes (it writes 'entries'),
|
|
84
|
+
and silently fell back to an empty-but-still-queryable catalog instead
|
|
85
|
+
of raising. Caught by smoke-testing against a real catalog file, not by
|
|
86
|
+
a unit test -- this test exists so it can't regress silently again."""
|
|
87
|
+
import json
|
|
88
|
+
p = tmp_path / "catalog.json"
|
|
89
|
+
p.write_text(json.dumps({"meta": {}, "datasets": [{"id": 1}]}))
|
|
90
|
+
with pytest.raises(ValueError, match="entries"):
|
|
91
|
+
sc.CryoetCatalog(url=str(p)).load()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_load_http_raises_on_failure(monkeypatch):
|
|
95
|
+
"""A failed fetch must raise, not silently return an empty/degraded
|
|
96
|
+
catalog -- the exact failure mode scigantic-empiar's load() was fixed
|
|
97
|
+
to stop making (see its own test_catalog_load_raises_instead_of_degrading)."""
|
|
98
|
+
import requests
|
|
99
|
+
|
|
100
|
+
def _boom(*a, **kw):
|
|
101
|
+
raise requests.exceptions.ConnectionError("unreachable")
|
|
102
|
+
|
|
103
|
+
monkeypatch.setattr(sc.catalog._session, "get", _boom)
|
|
104
|
+
with pytest.raises(requests.exceptions.ConnectionError):
|
|
105
|
+
sc.CryoetCatalog().load()
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""catalog.py -- CryoetClient (no network, monkeypatched requests.Session.get)."""
|
|
2
|
+
import scigantic_cryoet as sc
|
|
3
|
+
from scigantic_cryoet.catalog import CryoetClient
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class _FakeResponse:
|
|
7
|
+
def __init__(self, payload=None, status_code=200, content=b""):
|
|
8
|
+
self._payload = payload
|
|
9
|
+
self.status_code = status_code
|
|
10
|
+
self.content = content
|
|
11
|
+
|
|
12
|
+
def raise_for_status(self):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
def json(self):
|
|
16
|
+
return self._payload
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_dataset_metadata(monkeypatch):
|
|
20
|
+
fake = {"dataset_title": "Neuronal synapse tomography"}
|
|
21
|
+
monkeypatch.setattr(sc.catalog._session, "get", lambda *a, **kw: _FakeResponse(fake))
|
|
22
|
+
md = CryoetClient().dataset_metadata(10000)
|
|
23
|
+
assert md["dataset_title"] == "Neuronal synapse tomography"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_dataset_metadata_404(monkeypatch):
|
|
27
|
+
import pytest
|
|
28
|
+
monkeypatch.setattr(sc.catalog._session, "get",
|
|
29
|
+
lambda *a, **kw: _FakeResponse(status_code=404))
|
|
30
|
+
with pytest.raises(FileNotFoundError):
|
|
31
|
+
CryoetClient().dataset_metadata(999999)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_runs_parses_common_prefixes(monkeypatch):
|
|
35
|
+
xml = (
|
|
36
|
+
b'<?xml version="1.0" encoding="UTF-8"?>'
|
|
37
|
+
b'<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">'
|
|
38
|
+
b'<CommonPrefixes><Prefix>10000/Images/</Prefix></CommonPrefixes>'
|
|
39
|
+
b'<CommonPrefixes><Prefix>10000/TS_001/</Prefix></CommonPrefixes>'
|
|
40
|
+
b'<CommonPrefixes><Prefix>10000/TS_002/</Prefix></CommonPrefixes>'
|
|
41
|
+
b'</ListBucketResult>'
|
|
42
|
+
)
|
|
43
|
+
monkeypatch.setattr(sc.catalog._session, "get", lambda *a, **kw: _FakeResponse(content=xml))
|
|
44
|
+
runs = CryoetClient().runs(10000)
|
|
45
|
+
assert runs == ["TS_001", "TS_002"] # Images/ is not a run
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_thumbnail_and_snapshot_urls():
|
|
49
|
+
c = CryoetClient()
|
|
50
|
+
assert c.thumbnail_url(10000).endswith("10000/Images/thumbnail.gif")
|
|
51
|
+
assert c.snapshot_url(10000).endswith("10000/Images/snapshot.gif")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""_search.py -- scoring and filters, pure functions."""
|
|
2
|
+
from scigantic_cryoet._search import expand_query, match_score, passes_filters
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_expand_query_tokenizes():
|
|
6
|
+
assert expand_query("SARS-CoV-2 spike") == {"sars", "cov", "2", "spike"}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_expand_query_empty():
|
|
10
|
+
assert expand_query(None) == set()
|
|
11
|
+
assert expand_query("") == set()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_match_score_zero_when_no_overlap():
|
|
15
|
+
record = {"title": "Mitochondria in mouse neuron"}
|
|
16
|
+
assert match_score(record, {"spike", "sars"}) == 0.0
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_match_score_partial_overlap():
|
|
20
|
+
record = {"title": "Neuronal synapse tomography", "organism": "Homo sapiens"}
|
|
21
|
+
score = match_score(record, {"neuron", "spike"})
|
|
22
|
+
assert 0 < score < 1 # one of two terms hits
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_match_score_title_bonus():
|
|
26
|
+
record = {"title": "mitochondria study"}
|
|
27
|
+
terms = {"mitochondria", "study"}
|
|
28
|
+
with_bonus = match_score(record, terms, primary="mitochondria study")
|
|
29
|
+
without_bonus = match_score(record, terms, primary=None)
|
|
30
|
+
assert with_bonus > without_bonus
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_passes_filters_organism_substring():
|
|
34
|
+
record = {"organism": "Homo sapiens"}
|
|
35
|
+
assert passes_filters(record, organism="sapiens")
|
|
36
|
+
assert not passes_filters(record, organism="mouse")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_passes_filters_has_annotations():
|
|
40
|
+
assert passes_filters({"n_annotations": 3}, has_annotations=True)
|
|
41
|
+
assert not passes_filters({"n_annotations": 0}, has_annotations=True)
|
|
42
|
+
assert passes_filters({"n_annotations": 0}, has_annotations=False)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_passes_filters_ctf_corrected_tri_state():
|
|
46
|
+
assert passes_filters({"ctf_corrected": True}, ctf_corrected=True)
|
|
47
|
+
assert not passes_filters({"ctf_corrected": None}, ctf_corrected=True)
|
|
48
|
+
assert not passes_filters({"ctf_corrected": None}, ctf_corrected=False)
|