RNApolis 0.4.11__tar.gz → 0.4.12__tar.gz

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