RNApolis 0.4.11__tar.gz → 0.4.13__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {rnapolis-0.4.11/src/RNApolis.egg-info → rnapolis-0.4.13}/PKG-INFO +1 -1
- {rnapolis-0.4.11 → rnapolis-0.4.13}/setup.py +1 -1
- {rnapolis-0.4.11 → rnapolis-0.4.13/src/RNApolis.egg-info}/PKG-INFO +1 -1
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/RNApolis.egg-info/SOURCES.txt +1 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/molecule_filter.py +85 -29
- rnapolis-0.4.13/tests/test_molecule_filter.py +37 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/LICENSE +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/README.md +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/pyproject.toml +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/setup.cfg +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/RNApolis.egg-info/dependency_links.txt +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/RNApolis.egg-info/entry_points.txt +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/RNApolis.egg-info/requires.txt +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/RNApolis.egg-info/top_level.txt +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/annotator.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/clashfinder.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/common.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/metareader.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/motif_extractor.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/parser.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/rfam_folder.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/tertiary.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/transformer.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/src/rnapolis/util.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_annotator.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_bugfixes.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_common.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_metareader.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_parser.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_quadruplexes.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_rfam_folder.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_tertiary.py +0 -0
- {rnapolis-0.4.11 → rnapolis-0.4.13}/tests/test_transformer.py +0 -0
@@ -1,10 +1,11 @@
|
|
1
1
|
#! /usr/bin/env python
|
2
2
|
import argparse
|
3
3
|
import tempfile
|
4
|
-
from typing import List, Set, Tuple
|
4
|
+
from typing import Iterable, List, Set, Tuple
|
5
5
|
|
6
6
|
from mmcif.io.IoAdapterPy import IoAdapterPy
|
7
7
|
from mmcif.io.PdbxReader import DataCategory, DataContainer
|
8
|
+
|
8
9
|
from rnapolis.util import handle_input_file
|
9
10
|
|
10
11
|
# Source: https://mmcif.wwpdb.org/dictionaries/mmcif_pdbx_v50.dic/Items/_entity_poly.type.html
|
@@ -20,6 +21,7 @@ ENTITY_POLY_TYPES = [
|
|
20
21
|
]
|
21
22
|
|
22
23
|
CATEGORIES_WITH_ENTITY_ID = [
|
24
|
+
("entity", "id"),
|
23
25
|
("atom_site", "label_entity_id"),
|
24
26
|
("entity_keywords", "entity_id"),
|
25
27
|
("entity_name_com", "entity_id"),
|
@@ -153,38 +155,63 @@ def select_category_by_id(
|
|
153
155
|
return attributes, rows
|
154
156
|
|
155
157
|
|
156
|
-
def
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
158
|
+
def filter_by_poly_types(
|
159
|
+
file_content: str, entity_poly_types: Iterable[str] = ["polyribonucleotide"]
|
160
|
+
) -> str:
|
161
|
+
adapter = IoAdapterPy()
|
162
|
+
|
163
|
+
with tempfile.NamedTemporaryFile("rt+") as f:
|
164
|
+
f.write(file_content)
|
165
|
+
f.seek(0)
|
166
|
+
data = adapter.readFile(f.name)
|
167
|
+
|
168
|
+
entity_ids = select_ids(
|
169
|
+
data, "entity_poly", "type", "entity_id", set(entity_poly_types)
|
164
170
|
)
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
action="append",
|
169
|
-
default=[],
|
171
|
+
asym_ids = select_ids(data, "struct_asym", "entity_id", "id", entity_ids)
|
172
|
+
auth_asym_ids = select_ids(
|
173
|
+
data, "atom_site", "label_asym_id", "auth_asym_id", asym_ids
|
170
174
|
)
|
171
|
-
parser.add_argument("path", help="path to a PDBx/mmCIF file")
|
172
|
-
args = parser.parse_args()
|
173
175
|
|
174
|
-
file = handle_input_file(args.path)
|
175
|
-
adapter = IoAdapterPy()
|
176
|
-
data = adapter.readFile(file.name)
|
177
176
|
output = DataContainer("rnapolis")
|
178
177
|
|
179
|
-
|
180
|
-
|
181
|
-
asym_ids
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
asym_ids = select_ids(data, "struct_asym", "entity_id", "id", entity_ids)
|
178
|
+
for table, ids in (
|
179
|
+
(CATEGORIES_WITH_ENTITY_ID, entity_ids),
|
180
|
+
(CATEGORIES_WITH_ASYM_ID, asym_ids),
|
181
|
+
(CATEGORIES_WITH_AUTH_ASYM_ID, auth_asym_ids),
|
182
|
+
):
|
183
|
+
for category, field_name in table:
|
184
|
+
attributes, rows = select_category_by_id(data, category, field_name, ids)
|
187
185
|
|
186
|
+
if attributes and rows:
|
187
|
+
obj = DataCategory(category, attributes, rows)
|
188
|
+
output.append(obj)
|
189
|
+
|
190
|
+
with tempfile.NamedTemporaryFile("rt+") as tmp:
|
191
|
+
adapter.writeFile(tmp.name, [output])
|
192
|
+
tmp.seek(0)
|
193
|
+
return tmp.read()
|
194
|
+
|
195
|
+
|
196
|
+
def filter_by_chains(file_content: str, chains: Iterable[str]) -> str:
|
197
|
+
"""
|
198
|
+
Filter a PDBx/mmCIF file by chain IDs. The function returns a new PDBx/mmCIF file.
|
199
|
+
|
200
|
+
Warning! The new file might contain more chains than provided in the `chains` argument.
|
201
|
+
This is because the function filters by entity, so if you ask for chain "A",
|
202
|
+
which is part of entity 1 having chains "A", "B" and "C", then you will get all three chains.
|
203
|
+
"""
|
204
|
+
adapter = IoAdapterPy()
|
205
|
+
|
206
|
+
with tempfile.NamedTemporaryFile("rt+") as f:
|
207
|
+
f.write(file_content)
|
208
|
+
f.seek(0)
|
209
|
+
data = adapter.readFile(f.name)
|
210
|
+
|
211
|
+
output = DataContainer("rnapolis")
|
212
|
+
|
213
|
+
entity_ids = select_ids(data, "struct_asym", "id", "entity_id", set(chains))
|
214
|
+
asym_ids = set(chains)
|
188
215
|
auth_asym_ids = select_ids(
|
189
216
|
data, "atom_site", "label_asym_id", "auth_asym_id", asym_ids
|
190
217
|
)
|
@@ -201,9 +228,38 @@ def main():
|
|
201
228
|
obj = DataCategory(category, attributes, rows)
|
202
229
|
output.append(obj)
|
203
230
|
|
204
|
-
with tempfile.NamedTemporaryFile() as tmp:
|
231
|
+
with tempfile.NamedTemporaryFile("rt+") as tmp:
|
205
232
|
adapter.writeFile(tmp.name, [output])
|
206
|
-
|
233
|
+
tmp.seek(0)
|
234
|
+
return tmp.read()
|
235
|
+
|
236
|
+
|
237
|
+
def main():
|
238
|
+
parser = argparse.ArgumentParser()
|
239
|
+
parser.add_argument(
|
240
|
+
"--type",
|
241
|
+
help="a type of molecule to select, you can provide this argument multiple times (default: polyribonucleotide)",
|
242
|
+
action="append",
|
243
|
+
default=["polyribonucleotide"],
|
244
|
+
choices=ENTITY_POLY_TYPES,
|
245
|
+
)
|
246
|
+
parser.add_argument(
|
247
|
+
"--chain",
|
248
|
+
help="a chain ID (label_asym_id) to select, you can provide this argument multiple times (if provided, it overrides the --type argument)",
|
249
|
+
action="append",
|
250
|
+
default=[],
|
251
|
+
)
|
252
|
+
parser.add_argument("path", help="path to a PDBx/mmCIF file")
|
253
|
+
args = parser.parse_args()
|
254
|
+
|
255
|
+
file = handle_input_file(args.path)
|
256
|
+
|
257
|
+
if args.chain:
|
258
|
+
print(filter_by_chains(file.read(), args.chain))
|
259
|
+
elif args.type:
|
260
|
+
print(filter_by_poly_types(file.read(), args.type))
|
261
|
+
else:
|
262
|
+
parser.print_help()
|
207
263
|
|
208
264
|
|
209
265
|
if __name__ == "__main__":
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import re
|
2
|
+
import tempfile
|
3
|
+
|
4
|
+
from rnapolis.molecule_filter import filter_by_chains, filter_by_poly_types
|
5
|
+
from rnapolis.parser import parse_cif
|
6
|
+
|
7
|
+
|
8
|
+
def test_filter_by_poly_types():
|
9
|
+
with open("tests/1a9n.cif") as f:
|
10
|
+
content = f.read()
|
11
|
+
|
12
|
+
filtered = filter_by_poly_types(content, ["polyribonucleotide"])
|
13
|
+
assert re.search(r"^_entity.id", filtered, re.MULTILINE) is not None
|
14
|
+
|
15
|
+
with tempfile.NamedTemporaryFile("rt+") as f:
|
16
|
+
f.write(filtered)
|
17
|
+
f.seek(0)
|
18
|
+
atoms, _, _, _ = parse_cif(f)
|
19
|
+
|
20
|
+
chains = set([atom.label.chain for atom in atoms if atom.label])
|
21
|
+
assert chains == {"A", "B"}
|
22
|
+
|
23
|
+
|
24
|
+
def test_filter_by_chains():
|
25
|
+
with open("tests/1a9n.cif") as f:
|
26
|
+
content = f.read()
|
27
|
+
|
28
|
+
filtered = filter_by_chains(content, ["A", "C"])
|
29
|
+
assert re.search(r"^_entity.id", filtered, re.MULTILINE) is not None
|
30
|
+
|
31
|
+
with tempfile.NamedTemporaryFile("rt+") as f:
|
32
|
+
f.write(filtered)
|
33
|
+
f.seek(0)
|
34
|
+
atoms, _, _, _ = parse_cif(f)
|
35
|
+
|
36
|
+
chains = set([atom.label.chain for atom in atoms if atom.label])
|
37
|
+
assert chains >= {"A", "C"}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|