protein-quest 0.5.1__tar.gz → 0.6.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.
Potentially problematic release.
This version of protein-quest might be problematic. Click here for more details.
- {protein_quest-0.5.1 → protein_quest-0.6.0}/PKG-INFO +12 -1
- {protein_quest-0.5.1 → protein_quest-0.6.0}/README.md +10 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/notebooks/pdbe.ipynb +12 -8
- {protein_quest-0.5.1 → protein_quest-0.6.0}/pyproject.toml +1 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/__version__.py +1 -1
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/alphafold/confidence.py +2 -2
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/alphafold/fetch.py +28 -19
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/cli.py +133 -68
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/filters.py +2 -5
- protein_quest-0.6.0/src/protein_quest/io.py +350 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/mcp_server.py +8 -5
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/ss.py +3 -7
- protein_quest-0.5.1/src/protein_quest/pdbe/io.py → protein_quest-0.6.0/src/protein_quest/structure.py +53 -126
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/utils.py +26 -2
- protein_quest-0.6.0/tests/alphafold/cassettes/test_fetch/test_fetch_many_gzipped.yaml +4789 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/alphafold/test_confidence.py +3 -2
- protein_quest-0.6.0/tests/alphafold/test_fetch.py +39 -0
- protein_quest-0.6.0/tests/conftest.py +18 -0
- protein_quest-0.6.0/tests/fixtures/2Y29.cif.gz +0 -0
- protein_quest-0.6.0/tests/test_io.py +230 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_mcp.py +3 -8
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_ss.py +2 -10
- protein_quest-0.6.0/tests/test_structure.py +89 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/uv.lock +29 -0
- protein_quest-0.5.1/tests/alphafold/test_fetch.py +0 -20
- protein_quest-0.5.1/tests/pdbe/fixtures/2y29.cif +0 -940
- protein_quest-0.5.1/tests/pdbe/test_io.py +0 -142
- {protein_quest-0.5.1 → protein_quest-0.6.0}/.github/workflows/ci.yml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/.github/workflows/pages.yml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/.github/workflows/pypi-publish.yml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/.gitignore +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/.vscode/extensions.json +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/CITATION.cff +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/CODE_OF_CONDUCT.md +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/CONTRIBUTING.md +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/LICENSE +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/CONTRIBUTING.md +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/index.md +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/notebooks/.gitignore +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/notebooks/alphafold.ipynb +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/notebooks/index.md +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/notebooks/uniprot.ipynb +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/docs/protein-quest-mcp.png +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/mkdocs.yml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/__init__.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/alphafold/__init__.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/alphafold/entry_summary.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/converter.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/emdb.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/go.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/parallel.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/pdbe/__init__.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/pdbe/fetch.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/py.typed +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/taxonomy.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/src/protein_quest/uniprot.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/alphafold/AF-A1YPR0-F1-model_v4.pdb +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/alphafold/cassettes/test_fetch/test_fetch_many.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/alphafold/test_entry_summary.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_emdb/test_fetch.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_go/test_search_gene_ontology_term.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_taxonomy/test_search_taxon.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_taxonomy/test_search_taxon_by_id.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_uniprot/test_search4af.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_uniprot/test_search4emdb.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_uniprot/test_search4interaction_partners.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_uniprot/test_search4macromolecular_complexes.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_uniprot/test_search4pdb.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/cassettes/test_uniprot/test_search4uniprot.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/fixtures/3JRS_B2A.cif.gz +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/pdbe/cassettes/test_fetch/test_fetch.yaml +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/pdbe/test_fetch.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_cli.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_converter.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_emdb.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_go.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_taxonomy.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_uniprot.py +0 -0
- {protein_quest-0.5.1 → protein_quest-0.6.0}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: protein_quest
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Search/retrieve/filter proteins and protein structures
|
|
5
5
|
Project-URL: Homepage, https://github.com/haddocking/protein-quest
|
|
6
6
|
Project-URL: Issues, https://github.com/haddocking/protein-quest/issues
|
|
@@ -17,6 +17,7 @@ Requires-Dist: cattrs[orjson]>=24.1.3
|
|
|
17
17
|
Requires-Dist: dask>=2025.5.1
|
|
18
18
|
Requires-Dist: distributed>=2025.5.1
|
|
19
19
|
Requires-Dist: gemmi>=0.7.3
|
|
20
|
+
Requires-Dist: mmcif>=0.92.0
|
|
20
21
|
Requires-Dist: platformdirs>=4.3.8
|
|
21
22
|
Requires-Dist: psutil>=7.0.0
|
|
22
23
|
Requires-Dist: rich-argparse>=1.7.1
|
|
@@ -71,6 +72,7 @@ graph TB;
|
|
|
71
72
|
fetchad -->|mmcif_files| confidencefilter{{Filter out low confidence}}
|
|
72
73
|
confidencefilter --> |mmcif_files| ssfilter{{Filter on secondary structure}}
|
|
73
74
|
residuefilter --> |mmcif_files| ssfilter
|
|
75
|
+
ssfilter -. mmcif_files .-> convert2cif([Convert to cif])
|
|
74
76
|
classDef dashedBorder stroke-dasharray: 5 5;
|
|
75
77
|
goterm:::dashedBorder
|
|
76
78
|
taxonomy:::dashedBorder
|
|
@@ -78,6 +80,7 @@ graph TB;
|
|
|
78
80
|
fetchemdb:::dashedBorder
|
|
79
81
|
searchintactionpartners:::dashedBorder
|
|
80
82
|
searchcomplexes:::dashedBorder
|
|
83
|
+
convert2cif:::dashedBorder
|
|
81
84
|
```
|
|
82
85
|
|
|
83
86
|
(Dotted nodes and edges are side-quests.)
|
|
@@ -242,6 +245,14 @@ query_protein,complex_id,complex_url,complex_title,members
|
|
|
242
245
|
Q05471,CPX-2122,https://www.ebi.ac.uk/complexportal/complex/CPX-2122,Swr1 chromatin remodelling complex,P31376;P35817;P38326;P53201;P53930;P60010;P80428;Q03388;Q03433;Q03940;Q05471;Q06707;Q12464;Q12509
|
|
243
246
|
```
|
|
244
247
|
|
|
248
|
+
### Convert structure files to .cif format
|
|
249
|
+
|
|
250
|
+
Some tools (for example [powerfit](https://github.com/haddocking/powerfit)) only work with `.cif` files and not `*.cif.gz` or `*.bcif` files.
|
|
251
|
+
|
|
252
|
+
```shell
|
|
253
|
+
protein-quest convert --output-dir ./filtered-cif ./filtered-ss
|
|
254
|
+
```
|
|
255
|
+
|
|
245
256
|
## Model Context Protocol (MCP) server
|
|
246
257
|
|
|
247
258
|
Protein quest can also help LLMs like Claude Sonnet 4 by providing a [set of tools](https://modelcontextprotocol.io/docs/learn/server-concepts#tools-ai-actions) for protein structures.
|
|
@@ -40,6 +40,7 @@ graph TB;
|
|
|
40
40
|
fetchad -->|mmcif_files| confidencefilter{{Filter out low confidence}}
|
|
41
41
|
confidencefilter --> |mmcif_files| ssfilter{{Filter on secondary structure}}
|
|
42
42
|
residuefilter --> |mmcif_files| ssfilter
|
|
43
|
+
ssfilter -. mmcif_files .-> convert2cif([Convert to cif])
|
|
43
44
|
classDef dashedBorder stroke-dasharray: 5 5;
|
|
44
45
|
goterm:::dashedBorder
|
|
45
46
|
taxonomy:::dashedBorder
|
|
@@ -47,6 +48,7 @@ graph TB;
|
|
|
47
48
|
fetchemdb:::dashedBorder
|
|
48
49
|
searchintactionpartners:::dashedBorder
|
|
49
50
|
searchcomplexes:::dashedBorder
|
|
51
|
+
convert2cif:::dashedBorder
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
(Dotted nodes and edges are side-quests.)
|
|
@@ -211,6 +213,14 @@ query_protein,complex_id,complex_url,complex_title,members
|
|
|
211
213
|
Q05471,CPX-2122,https://www.ebi.ac.uk/complexportal/complex/CPX-2122,Swr1 chromatin remodelling complex,P31376;P35817;P38326;P53201;P53930;P60010;P80428;Q03388;Q03433;Q03940;Q05471;Q06707;Q12464;Q12509
|
|
212
214
|
```
|
|
213
215
|
|
|
216
|
+
### Convert structure files to .cif format
|
|
217
|
+
|
|
218
|
+
Some tools (for example [powerfit](https://github.com/haddocking/powerfit)) only work with `.cif` files and not `*.cif.gz` or `*.bcif` files.
|
|
219
|
+
|
|
220
|
+
```shell
|
|
221
|
+
protein-quest convert --output-dir ./filtered-cif ./filtered-ss
|
|
222
|
+
```
|
|
223
|
+
|
|
214
224
|
## Model Context Protocol (MCP) server
|
|
215
225
|
|
|
216
226
|
Protein quest can also help LLMs like Claude Sonnet 4 by providing a [set of tools](https://modelcontextprotocol.io/docs/learn/server-concepts#tools-ai-actions) for protein structures.
|
|
@@ -111,12 +111,12 @@
|
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
113
|
"cell_type": "code",
|
|
114
|
-
"execution_count":
|
|
114
|
+
"execution_count": null,
|
|
115
115
|
"id": "52a42ec2",
|
|
116
116
|
"metadata": {},
|
|
117
117
|
"outputs": [],
|
|
118
118
|
"source": [
|
|
119
|
-
"from protein_quest.
|
|
119
|
+
"from protein_quest.structure import write_single_chain_structure_file"
|
|
120
120
|
]
|
|
121
121
|
},
|
|
122
122
|
{
|
|
@@ -139,7 +139,9 @@
|
|
|
139
139
|
"source": [
|
|
140
140
|
"# A8MT69\t4NDY\tB/D/H/L/M/N/U/V/W/X=8-81\n",
|
|
141
141
|
"# above is the identifier, chain and position info for the structure from https://www.uniprot.org/uniprotkb/A8MT69/entry#structure\n",
|
|
142
|
-
"output_4dny_file =
|
|
142
|
+
"output_4dny_file = write_single_chain_structure_file(\n",
|
|
143
|
+
" input_file=save_dir / \"4ndy.cif.gz\", chain2keep=\"B\", output_dir=save_dir\n",
|
|
144
|
+
")\n",
|
|
143
145
|
"output_4dny_file"
|
|
144
146
|
]
|
|
145
147
|
},
|
|
@@ -162,13 +164,15 @@
|
|
|
162
164
|
],
|
|
163
165
|
"source": [
|
|
164
166
|
"# A8MT69\t4DRA\tE/F/G/H=1-81\n",
|
|
165
|
-
"output_4dra_file =
|
|
167
|
+
"output_4dra_file = write_single_chain_structure_file(\n",
|
|
168
|
+
" input_file=save_dir / \"4dra.cif.gz\", chain2keep=\"E\", output_dir=save_dir\n",
|
|
169
|
+
")\n",
|
|
166
170
|
"output_4dra_file"
|
|
167
171
|
]
|
|
168
172
|
},
|
|
169
173
|
{
|
|
170
174
|
"cell_type": "code",
|
|
171
|
-
"execution_count":
|
|
175
|
+
"execution_count": null,
|
|
172
176
|
"id": "673d1274",
|
|
173
177
|
"metadata": {},
|
|
174
178
|
"outputs": [
|
|
@@ -184,7 +188,7 @@
|
|
|
184
188
|
}
|
|
185
189
|
],
|
|
186
190
|
"source": [
|
|
187
|
-
"output_1xwh_file =
|
|
191
|
+
"output_1xwh_file = write_single_chain_structure_file(\n",
|
|
188
192
|
" input_file=save_dir / \"1xwh.cif.gz\",\n",
|
|
189
193
|
" chain2keep=\"A\",\n",
|
|
190
194
|
" output_dir=save_dir,\n",
|
|
@@ -194,7 +198,7 @@
|
|
|
194
198
|
},
|
|
195
199
|
{
|
|
196
200
|
"cell_type": "code",
|
|
197
|
-
"execution_count":
|
|
201
|
+
"execution_count": null,
|
|
198
202
|
"id": "5f03eb2c",
|
|
199
203
|
"metadata": {},
|
|
200
204
|
"outputs": [
|
|
@@ -211,7 +215,7 @@
|
|
|
211
215
|
],
|
|
212
216
|
"source": [
|
|
213
217
|
"# O00268 │ 8WAS │ D/d=1-1085\n",
|
|
214
|
-
"output_8was_file =
|
|
218
|
+
"output_8was_file = write_single_chain_structure_file(\n",
|
|
215
219
|
" input_file=save_dir / \"8was.cif.gz\",\n",
|
|
216
220
|
" chain2keep=\"D\",\n",
|
|
217
221
|
" output_dir=save_dir,\n",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.
|
|
1
|
+
__version__ = "0.6.0"
|
|
2
2
|
"""The version of the package."""
|
|
@@ -8,7 +8,7 @@ from pathlib import Path
|
|
|
8
8
|
import gemmi
|
|
9
9
|
|
|
10
10
|
from protein_quest.converter import Percentage, PositiveInt, converter
|
|
11
|
-
from protein_quest.
|
|
11
|
+
from protein_quest.io import read_structure, write_structure
|
|
12
12
|
from protein_quest.ss import nr_of_residues_in_total
|
|
13
13
|
from protein_quest.utils import CopyMethod, copyfile
|
|
14
14
|
|
|
@@ -127,7 +127,7 @@ def filter_file_on_residues(
|
|
|
127
127
|
result with filtered_file property set to Path where filtered PDB file is saved.
|
|
128
128
|
or None if structure was filtered out.
|
|
129
129
|
"""
|
|
130
|
-
structure =
|
|
130
|
+
structure = read_structure(file)
|
|
131
131
|
residues = set(find_high_confidence_residues(structure, query.confidence))
|
|
132
132
|
count = len(residues)
|
|
133
133
|
if count < query.min_residues or count > query.max_residues:
|
|
@@ -125,15 +125,15 @@ async def fetch_summary(
|
|
|
125
125
|
fn: AsyncPath | None = None
|
|
126
126
|
if save_dir is not None:
|
|
127
127
|
fn = AsyncPath(save_dir / f"{qualifier}.json")
|
|
128
|
+
if await fn.exists():
|
|
129
|
+
logger.debug(f"File {fn} already exists. Skipping download from {url}.")
|
|
130
|
+
raw_data = await fn.read_bytes()
|
|
131
|
+
return converter.loads(raw_data, list[EntrySummary])
|
|
128
132
|
cached_file = await cacher.copy_from_cache(Path(fn))
|
|
129
133
|
if cached_file is not None:
|
|
130
134
|
logger.debug(f"Using cached file {cached_file} for summary of {qualifier}.")
|
|
131
135
|
raw_data = await AsyncPath(cached_file).read_bytes()
|
|
132
136
|
return converter.loads(raw_data, list[EntrySummary])
|
|
133
|
-
if await fn.exists():
|
|
134
|
-
logger.debug(f"File {fn} already exists. Skipping download from {url}.")
|
|
135
|
-
raw_data = await fn.read_bytes()
|
|
136
|
-
return converter.loads(raw_data, list[EntrySummary])
|
|
137
137
|
async with semaphore, session.get(url) as response:
|
|
138
138
|
response.raise_for_status()
|
|
139
139
|
raw_data = await response.content.read()
|
|
@@ -170,6 +170,7 @@ async def fetch_many_async(
|
|
|
170
170
|
what: set[DownloadableFormat],
|
|
171
171
|
max_parallel_downloads: int = 5,
|
|
172
172
|
cacher: Cacher | None = None,
|
|
173
|
+
gzip_files: bool = False,
|
|
173
174
|
) -> AsyncGenerator[AlphaFoldEntry]:
|
|
174
175
|
"""Asynchronously fetches summaries and files from
|
|
175
176
|
[AlphaFold Protein Structure Database](https://alphafold.ebi.ac.uk/).
|
|
@@ -180,6 +181,7 @@ async def fetch_many_async(
|
|
|
180
181
|
what: A set of formats to download.
|
|
181
182
|
max_parallel_downloads: The maximum number of parallel downloads.
|
|
182
183
|
cacher: A cacher to use for caching the fetched files. Only used if summary is in what set.
|
|
184
|
+
gzip_files: Whether to gzip the downloaded files.
|
|
183
185
|
|
|
184
186
|
Yields:
|
|
185
187
|
A dataclass containing the summary, pdb file, and pae file.
|
|
@@ -193,7 +195,7 @@ async def fetch_many_async(
|
|
|
193
195
|
)
|
|
194
196
|
]
|
|
195
197
|
|
|
196
|
-
files = files_to_download(what, summaries)
|
|
198
|
+
files = files_to_download(what, summaries, gzip_files)
|
|
197
199
|
|
|
198
200
|
await retrieve_files(
|
|
199
201
|
files,
|
|
@@ -201,36 +203,40 @@ async def fetch_many_async(
|
|
|
201
203
|
desc="Downloading AlphaFold files",
|
|
202
204
|
max_parallel_downloads=max_parallel_downloads,
|
|
203
205
|
cacher=cacher,
|
|
206
|
+
gzip_files=gzip_files,
|
|
204
207
|
)
|
|
208
|
+
gzext = ".gz" if gzip_files else ""
|
|
205
209
|
for summary in summaries:
|
|
206
210
|
yield AlphaFoldEntry(
|
|
207
211
|
uniprot_acc=summary.uniprotAccession,
|
|
208
212
|
summary=summary,
|
|
209
213
|
summary_file=save_dir / f"{summary.uniprotAccession}.json" if save_dir_for_summaries is not None else None,
|
|
210
|
-
bcif_file=save_dir / summary.bcifUrl.name if "bcif" in what else None,
|
|
211
|
-
cif_file=save_dir / summary.cifUrl.name if "cif" in what else None,
|
|
212
|
-
pdb_file=save_dir / summary.pdbUrl.name if "pdb" in what else None,
|
|
213
|
-
pae_image_file=save_dir / summary.paeImageUrl.name if "paeImage" in what else None,
|
|
214
|
-
pae_doc_file=save_dir / summary.paeDocUrl.name if "paeDoc" in what else None,
|
|
214
|
+
bcif_file=save_dir / (summary.bcifUrl.name + gzext) if "bcif" in what else None,
|
|
215
|
+
cif_file=save_dir / (summary.cifUrl.name + gzext) if "cif" in what else None,
|
|
216
|
+
pdb_file=save_dir / (summary.pdbUrl.name + gzext) if "pdb" in what else None,
|
|
217
|
+
pae_image_file=save_dir / (summary.paeImageUrl.name + gzext) if "paeImage" in what else None,
|
|
218
|
+
pae_doc_file=save_dir / (summary.paeDocUrl.name + gzext) if "paeDoc" in what else None,
|
|
215
219
|
am_annotations_file=(
|
|
216
|
-
save_dir / summary.amAnnotationsUrl.name
|
|
220
|
+
save_dir / (summary.amAnnotationsUrl.name + gzext)
|
|
217
221
|
if "amAnnotations" in what and summary.amAnnotationsUrl
|
|
218
222
|
else None
|
|
219
223
|
),
|
|
220
224
|
am_annotations_hg19_file=(
|
|
221
|
-
save_dir / summary.amAnnotationsHg19Url.name
|
|
225
|
+
save_dir / (summary.amAnnotationsHg19Url.name + gzext)
|
|
222
226
|
if "amAnnotationsHg19" in what and summary.amAnnotationsHg19Url
|
|
223
227
|
else None
|
|
224
228
|
),
|
|
225
229
|
am_annotations_hg38_file=(
|
|
226
|
-
save_dir / summary.amAnnotationsHg38Url.name
|
|
230
|
+
save_dir / (summary.amAnnotationsHg38Url.name + gzext)
|
|
227
231
|
if "amAnnotationsHg38" in what and summary.amAnnotationsHg38Url
|
|
228
232
|
else None
|
|
229
233
|
),
|
|
230
234
|
)
|
|
231
235
|
|
|
232
236
|
|
|
233
|
-
def files_to_download(
|
|
237
|
+
def files_to_download(
|
|
238
|
+
what: set[DownloadableFormat], summaries: Iterable[EntrySummary], gzip_files: bool
|
|
239
|
+
) -> set[tuple[URL, str]]:
|
|
234
240
|
if not (set(what) <= downloadable_formats):
|
|
235
241
|
msg = (
|
|
236
242
|
f"Invalid format(s) specified: {set(what) - downloadable_formats}. "
|
|
@@ -238,7 +244,7 @@ def files_to_download(what: set[DownloadableFormat], summaries: Iterable[EntrySu
|
|
|
238
244
|
)
|
|
239
245
|
raise ValueError(msg)
|
|
240
246
|
|
|
241
|
-
|
|
247
|
+
url_filename_pairs: set[tuple[URL, str]] = set()
|
|
242
248
|
for summary in summaries:
|
|
243
249
|
for fmt in what:
|
|
244
250
|
if fmt == "summary":
|
|
@@ -248,9 +254,10 @@ def files_to_download(what: set[DownloadableFormat], summaries: Iterable[EntrySu
|
|
|
248
254
|
if url is None:
|
|
249
255
|
logger.warning(f"Summary {summary.uniprotAccession} does not have a URL for format '{fmt}'. Skipping.")
|
|
250
256
|
continue
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
257
|
+
fn = url.name + (".gz" if gzip_files else "")
|
|
258
|
+
url_filename_pair = (url, fn)
|
|
259
|
+
url_filename_pairs.add(url_filename_pair)
|
|
260
|
+
return url_filename_pairs
|
|
254
261
|
|
|
255
262
|
|
|
256
263
|
def fetch_many(
|
|
@@ -259,6 +266,7 @@ def fetch_many(
|
|
|
259
266
|
what: set[DownloadableFormat],
|
|
260
267
|
max_parallel_downloads: int = 5,
|
|
261
268
|
cacher: Cacher | None = None,
|
|
269
|
+
gzip_files: bool = False,
|
|
262
270
|
) -> list[AlphaFoldEntry]:
|
|
263
271
|
"""Synchronously fetches summaries and pdb and pae files from AlphaFold Protein Structure Database.
|
|
264
272
|
|
|
@@ -268,6 +276,7 @@ def fetch_many(
|
|
|
268
276
|
what: A set of formats to download.
|
|
269
277
|
max_parallel_downloads: The maximum number of parallel downloads.
|
|
270
278
|
cacher: A cacher to use for caching the fetched files. Only used if summary is in what set.
|
|
279
|
+
gzip_files: Whether to gzip the downloaded files.
|
|
271
280
|
|
|
272
281
|
Returns:
|
|
273
282
|
A list of AlphaFoldEntry dataclasses containing the summary, pdb file, and pae file.
|
|
@@ -277,7 +286,7 @@ def fetch_many(
|
|
|
277
286
|
return [
|
|
278
287
|
entry
|
|
279
288
|
async for entry in fetch_many_async(
|
|
280
|
-
ids, save_dir, what, max_parallel_downloads=max_parallel_downloads, cacher=cacher
|
|
289
|
+
ids, save_dir, what, max_parallel_downloads=max_parallel_downloads, cacher=cacher, gzip_files=gzip_files
|
|
281
290
|
)
|
|
282
291
|
]
|
|
283
292
|
|
|
@@ -28,8 +28,13 @@ from protein_quest.converter import converter
|
|
|
28
28
|
from protein_quest.emdb import fetch as emdb_fetch
|
|
29
29
|
from protein_quest.filters import filter_files_on_chain, filter_files_on_residues
|
|
30
30
|
from protein_quest.go import Aspect, allowed_aspects, search_gene_ontology_term, write_go_terms_to_csv
|
|
31
|
+
from protein_quest.io import (
|
|
32
|
+
convert_to_cif_files,
|
|
33
|
+
glob_structure_files,
|
|
34
|
+
locate_structure_file,
|
|
35
|
+
valid_structure_file_extensions,
|
|
36
|
+
)
|
|
31
37
|
from protein_quest.pdbe import fetch as pdbe_fetch
|
|
32
|
-
from protein_quest.pdbe.io import glob_structure_files, locate_structure_file
|
|
33
38
|
from protein_quest.ss import SecondaryStructureFilterQuery, filter_files_on_secondary_structure
|
|
34
39
|
from protein_quest.taxonomy import SearchField, _write_taxonomy_csv, search_fields, search_taxon
|
|
35
40
|
from protein_quest.uniprot import (
|
|
@@ -297,6 +302,38 @@ def _add_search_complexes_parser(subparsers: argparse._SubParsersAction):
|
|
|
297
302
|
parser.add_argument("--timeout", type=int, default=1_800, help="Maximum seconds to wait for query to complete")
|
|
298
303
|
|
|
299
304
|
|
|
305
|
+
def _add_copy_method_arguments(parser):
|
|
306
|
+
parser.add_argument(
|
|
307
|
+
"--copy-method",
|
|
308
|
+
type=str,
|
|
309
|
+
choices=copy_methods,
|
|
310
|
+
default="hardlink",
|
|
311
|
+
help=dedent("""\
|
|
312
|
+
How to make target file be same file as source file.
|
|
313
|
+
By default uses hardlinks to save disk space.
|
|
314
|
+
Note that hardlinks only work within the same filesystem and are harder to track.
|
|
315
|
+
If you want to track cached files easily then use 'symlink'.
|
|
316
|
+
On Windows you need developer mode or admin privileges to create symlinks.
|
|
317
|
+
"""),
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _add_cacher_arguments(parser: argparse.ArgumentParser):
|
|
322
|
+
"""Add cacher arguments to parser."""
|
|
323
|
+
parser.add_argument(
|
|
324
|
+
"--no-cache",
|
|
325
|
+
action="store_true",
|
|
326
|
+
help="Disable caching of files to central location.",
|
|
327
|
+
)
|
|
328
|
+
parser.add_argument(
|
|
329
|
+
"--cache-dir",
|
|
330
|
+
type=Path,
|
|
331
|
+
default=user_cache_root_dir(),
|
|
332
|
+
help="Directory to use as cache for files.",
|
|
333
|
+
)
|
|
334
|
+
_add_copy_method_arguments(parser)
|
|
335
|
+
|
|
336
|
+
|
|
300
337
|
def _add_retrieve_pdbe_parser(subparsers: argparse._SubParsersAction):
|
|
301
338
|
"""Add retrieve pdbe subcommand parser."""
|
|
302
339
|
parser = subparsers.add_parser(
|
|
@@ -345,6 +382,11 @@ def _add_retrieve_alphafold_parser(subparsers: argparse._SubParsersAction):
|
|
|
345
382
|
help=dedent("""AlphaFold formats to retrieve. Can be specified multiple times.
|
|
346
383
|
Default is 'summary' and 'cif'."""),
|
|
347
384
|
)
|
|
385
|
+
parser.add_argument(
|
|
386
|
+
"--gzip-files",
|
|
387
|
+
action="store_true",
|
|
388
|
+
help="Whether to gzip the downloaded files. Excludes summary files, they are always uncompressed.",
|
|
389
|
+
)
|
|
348
390
|
parser.add_argument(
|
|
349
391
|
"--max-parallel-downloads",
|
|
350
392
|
type=int,
|
|
@@ -561,6 +603,33 @@ def _add_filter_subcommands(subparsers: argparse._SubParsersAction):
|
|
|
561
603
|
_add_filter_ss_parser(subsubparsers)
|
|
562
604
|
|
|
563
605
|
|
|
606
|
+
def _add_convert_subcommands(subparsers: argparse._SubParsersAction):
|
|
607
|
+
"""Add convert command."""
|
|
608
|
+
parser = subparsers.add_parser(
|
|
609
|
+
"convert", help="Convert structure files between formats", formatter_class=ArgumentDefaultsRichHelpFormatter
|
|
610
|
+
)
|
|
611
|
+
parser.add_argument(
|
|
612
|
+
"input_dir",
|
|
613
|
+
type=Path,
|
|
614
|
+
help=f"Directory with structure files. Supported extensions are {valid_structure_file_extensions}",
|
|
615
|
+
)
|
|
616
|
+
parser.add_argument(
|
|
617
|
+
"--output-dir",
|
|
618
|
+
type=Path,
|
|
619
|
+
help=dedent("""\
|
|
620
|
+
Directory to write converted structure files. If not given, files are written to `input_dir`.
|
|
621
|
+
"""),
|
|
622
|
+
)
|
|
623
|
+
parser.add_argument(
|
|
624
|
+
"--format",
|
|
625
|
+
type=str,
|
|
626
|
+
choices=("cif",),
|
|
627
|
+
default="cif",
|
|
628
|
+
help="Output format to convert to.",
|
|
629
|
+
)
|
|
630
|
+
_add_copy_method_arguments(parser)
|
|
631
|
+
|
|
632
|
+
|
|
564
633
|
def _add_mcp_command(subparsers: argparse._SubParsersAction):
|
|
565
634
|
"""Add MCP command."""
|
|
566
635
|
|
|
@@ -580,38 +649,6 @@ def _add_mcp_command(subparsers: argparse._SubParsersAction):
|
|
|
580
649
|
parser.add_argument("--port", default=8000, type=int, help="Port to bind the server to")
|
|
581
650
|
|
|
582
651
|
|
|
583
|
-
def _add_copy_method_arguments(parser):
|
|
584
|
-
parser.add_argument(
|
|
585
|
-
"--copy-method",
|
|
586
|
-
type=str,
|
|
587
|
-
choices=copy_methods,
|
|
588
|
-
default="hardlink",
|
|
589
|
-
help=dedent("""\
|
|
590
|
-
How to make target file be same file as source file.
|
|
591
|
-
By default uses hardlinks to save disk space.
|
|
592
|
-
Note that hardlinks only work within the same filesystem and are harder to track.
|
|
593
|
-
If you want to track cached files easily then use 'symlink'.
|
|
594
|
-
On Windows you need developer mode or admin privileges to create symlinks.
|
|
595
|
-
"""),
|
|
596
|
-
)
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
def _add_cacher_arguments(parser: argparse.ArgumentParser):
|
|
600
|
-
"""Add cacher arguments to parser."""
|
|
601
|
-
parser.add_argument(
|
|
602
|
-
"--no-cache",
|
|
603
|
-
action="store_true",
|
|
604
|
-
help="Disable caching of files to central location.",
|
|
605
|
-
)
|
|
606
|
-
parser.add_argument(
|
|
607
|
-
"--cache-dir",
|
|
608
|
-
type=Path,
|
|
609
|
-
default=user_cache_root_dir(),
|
|
610
|
-
help="Directory to use as cache for files.",
|
|
611
|
-
)
|
|
612
|
-
_add_copy_method_arguments(parser)
|
|
613
|
-
|
|
614
|
-
|
|
615
652
|
def make_parser() -> argparse.ArgumentParser:
|
|
616
653
|
parser = argparse.ArgumentParser(
|
|
617
654
|
description="Protein Quest CLI", prog="protein-quest", formatter_class=ArgumentDefaultsRichHelpFormatter
|
|
@@ -624,27 +661,12 @@ def make_parser() -> argparse.ArgumentParser:
|
|
|
624
661
|
_add_search_subcommands(subparsers)
|
|
625
662
|
_add_retrieve_subcommands(subparsers)
|
|
626
663
|
_add_filter_subcommands(subparsers)
|
|
664
|
+
_add_convert_subcommands(subparsers)
|
|
627
665
|
_add_mcp_command(subparsers)
|
|
628
666
|
|
|
629
667
|
return parser
|
|
630
668
|
|
|
631
669
|
|
|
632
|
-
def main():
|
|
633
|
-
"""Main entry point for the CLI."""
|
|
634
|
-
parser = make_parser()
|
|
635
|
-
args = parser.parse_args()
|
|
636
|
-
logging.basicConfig(level=args.log_level, handlers=[RichHandler(show_level=False)])
|
|
637
|
-
|
|
638
|
-
# Dispatch table to reduce complexity
|
|
639
|
-
cmd = args.command
|
|
640
|
-
sub = getattr(args, f"{cmd}_cmd", None)
|
|
641
|
-
handler = HANDLERS.get((cmd, sub))
|
|
642
|
-
if handler is None:
|
|
643
|
-
msg = f"Unknown command: {cmd} {sub}"
|
|
644
|
-
raise SystemExit(msg)
|
|
645
|
-
handler(args)
|
|
646
|
-
|
|
647
|
-
|
|
648
670
|
def _handle_search_uniprot(args):
|
|
649
671
|
taxon_id = args.taxon_id
|
|
650
672
|
reviewed = args.reviewed
|
|
@@ -798,6 +820,7 @@ def _handle_retrieve_alphafold(args):
|
|
|
798
820
|
alphafold_csv = args.alphafold_csv
|
|
799
821
|
max_parallel_downloads = args.max_parallel_downloads
|
|
800
822
|
cacher = _initialize_cacher(args)
|
|
823
|
+
gzip_files = args.gzip_files
|
|
801
824
|
|
|
802
825
|
if what_formats is None:
|
|
803
826
|
what_formats = {"summary", "cif"}
|
|
@@ -808,7 +831,12 @@ def _handle_retrieve_alphafold(args):
|
|
|
808
831
|
validated_what: set[DownloadableFormat] = structure(what_formats, set[DownloadableFormat])
|
|
809
832
|
rprint(f"Retrieving {len(af_ids)} AlphaFold entries with formats {validated_what}")
|
|
810
833
|
afs = af_fetch(
|
|
811
|
-
af_ids,
|
|
834
|
+
af_ids,
|
|
835
|
+
download_dir,
|
|
836
|
+
what=validated_what,
|
|
837
|
+
max_parallel_downloads=max_parallel_downloads,
|
|
838
|
+
cacher=cacher,
|
|
839
|
+
gzip_files=gzip_files,
|
|
812
840
|
)
|
|
813
841
|
total_nr_files = sum(af.nr_of_files() for af in afs)
|
|
814
842
|
rprint(f"Retrieved {total_nr_files} AlphaFold files and {len(afs)} summaries, written to {download_dir}")
|
|
@@ -1017,24 +1045,24 @@ def _handle_mcp(args):
|
|
|
1017
1045
|
mcp.run(transport=args.transport, host=args.host, port=args.port)
|
|
1018
1046
|
|
|
1019
1047
|
|
|
1020
|
-
|
|
1021
|
-
(
|
|
1022
|
-
(
|
|
1023
|
-
(
|
|
1024
|
-
|
|
1025
|
-
(
|
|
1026
|
-
("
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
}
|
|
1048
|
+
def _handle_convert(args):
|
|
1049
|
+
input_dir = structure(args.input_dir, Path)
|
|
1050
|
+
output_dir = input_dir if args.output_dir is None else structure(args.output_dir, Path)
|
|
1051
|
+
copy_method: CopyMethod = structure(args.copy_method, CopyMethod) # pyright: ignore[reportArgumentType]
|
|
1052
|
+
|
|
1053
|
+
input_files = sorted(glob_structure_files(input_dir))
|
|
1054
|
+
rprint(f"Converting {len(input_files)} files in {input_dir} directory to cif format.")
|
|
1055
|
+
for _ in tqdm(
|
|
1056
|
+
convert_to_cif_files(
|
|
1057
|
+
input_files,
|
|
1058
|
+
output_dir,
|
|
1059
|
+
copy_method=copy_method,
|
|
1060
|
+
),
|
|
1061
|
+
total=len(input_files),
|
|
1062
|
+
unit="file",
|
|
1063
|
+
):
|
|
1064
|
+
pass
|
|
1065
|
+
rprint(f"Converted {len(input_files)} files into {output_dir}.")
|
|
1038
1066
|
|
|
1039
1067
|
|
|
1040
1068
|
def _read_lines(file: TextIOWrapper) -> list[str]:
|
|
@@ -1118,3 +1146,40 @@ def _write_complexes_csv(complexes: list[ComplexPortalEntry], output_csv: TextIO
|
|
|
1118
1146
|
members_str,
|
|
1119
1147
|
]
|
|
1120
1148
|
)
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
HANDLERS: dict[tuple[str, str | None], Callable] = {
|
|
1152
|
+
("search", "uniprot"): _handle_search_uniprot,
|
|
1153
|
+
("search", "pdbe"): _handle_search_pdbe,
|
|
1154
|
+
("search", "alphafold"): _handle_search_alphafold,
|
|
1155
|
+
("search", "emdb"): _handle_search_emdb,
|
|
1156
|
+
("search", "go"): _handle_search_go,
|
|
1157
|
+
("search", "taxonomy"): _handle_search_taxonomy,
|
|
1158
|
+
("search", "interaction-partners"): _handle_search_interaction_partners,
|
|
1159
|
+
("search", "complexes"): _handle_search_complexes,
|
|
1160
|
+
("retrieve", "pdbe"): _handle_retrieve_pdbe,
|
|
1161
|
+
("retrieve", "alphafold"): _handle_retrieve_alphafold,
|
|
1162
|
+
("retrieve", "emdb"): _handle_retrieve_emdb,
|
|
1163
|
+
("filter", "confidence"): _handle_filter_confidence,
|
|
1164
|
+
("filter", "chain"): _handle_filter_chain,
|
|
1165
|
+
("filter", "residue"): _handle_filter_residue,
|
|
1166
|
+
("filter", "secondary-structure"): _handle_filter_ss,
|
|
1167
|
+
("mcp", None): _handle_mcp,
|
|
1168
|
+
("convert", None): _handle_convert,
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
def main():
|
|
1173
|
+
"""Main entry point for the CLI."""
|
|
1174
|
+
parser = make_parser()
|
|
1175
|
+
args = parser.parse_args()
|
|
1176
|
+
logging.basicConfig(level=args.log_level, handlers=[RichHandler(show_level=False)])
|
|
1177
|
+
|
|
1178
|
+
# Dispatch table to reduce complexity
|
|
1179
|
+
cmd = args.command
|
|
1180
|
+
sub = getattr(args, f"{cmd}_cmd", None)
|
|
1181
|
+
handler = HANDLERS.get((cmd, sub))
|
|
1182
|
+
if handler is None:
|
|
1183
|
+
msg = f"Unknown command: {cmd} {sub}"
|
|
1184
|
+
raise SystemExit(msg)
|
|
1185
|
+
handler(args)
|
|
@@ -11,10 +11,7 @@ from distributed.deploy.cluster import Cluster
|
|
|
11
11
|
from tqdm.auto import tqdm
|
|
12
12
|
|
|
13
13
|
from protein_quest.parallel import configure_dask_scheduler, dask_map_with_progress
|
|
14
|
-
from protein_quest.
|
|
15
|
-
nr_residues_in_chain,
|
|
16
|
-
write_single_chain_pdb_file,
|
|
17
|
-
)
|
|
14
|
+
from protein_quest.structure import nr_residues_in_chain, write_single_chain_structure_file
|
|
18
15
|
from protein_quest.utils import CopyMethod, copyfile
|
|
19
16
|
|
|
20
17
|
logger = logging.getLogger(__name__)
|
|
@@ -38,7 +35,7 @@ def filter_file_on_chain(
|
|
|
38
35
|
input_file, chain_id = file_and_chain
|
|
39
36
|
logger.debug("Filtering %s on chain %s", input_file, chain_id)
|
|
40
37
|
try:
|
|
41
|
-
output_file =
|
|
38
|
+
output_file = write_single_chain_structure_file(
|
|
42
39
|
input_file, chain_id, output_dir, out_chain=out_chain, copy_method=copy_method
|
|
43
40
|
)
|
|
44
41
|
return ChainFilterStatistics(
|