RNApolis 0.3.8__tar.gz → 0.3.10__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {RNApolis-0.3.8/src/RNApolis.egg-info → RNApolis-0.3.10}/PKG-INFO +1 -1
- {RNApolis-0.3.8 → RNApolis-0.3.10}/setup.py +1 -1
- {RNApolis-0.3.8 → RNApolis-0.3.10/src/RNApolis.egg-info}/PKG-INFO +1 -1
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/RNApolis.egg-info/SOURCES.txt +1 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/annotator.py +12 -8
- RNApolis-0.3.10/src/rnapolis/annotator_ml.py +278 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/parser.py +10 -2
- {RNApolis-0.3.8 → RNApolis-0.3.10}/LICENSE +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/README.md +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/pyproject.toml +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/setup.cfg +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/RNApolis.egg-info/dependency_links.txt +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/RNApolis.egg-info/entry_points.txt +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/RNApolis.egg-info/requires.txt +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/RNApolis.egg-info/top_level.txt +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/clashfinder.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/common.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/metareader.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/molecule_filter.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/motif_extractor.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/rfam_folder.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/tertiary.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/transformer.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/src/rnapolis/util.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_annotator.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_bugfixes.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_common.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_metareader.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_parser.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_quadruplexes.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_rfam_folder.py +0 -0
- {RNApolis-0.3.8 → RNApolis-0.3.10}/tests/test_tertiary.py +0 -0
@@ -175,7 +175,7 @@ def merge_and_clean_bph_br(
|
|
175
175
|
|
176
176
|
|
177
177
|
def find_pairs(
|
178
|
-
structure: Structure3D, model: int =
|
178
|
+
structure: Structure3D, model: Optional[int] = None
|
179
179
|
) -> Tuple[List[BasePair], List[BasePhosphate], List[BaseRibose]]:
|
180
180
|
# put all donors and acceptors into a KDTree
|
181
181
|
coordinates = []
|
@@ -183,7 +183,7 @@ def find_pairs(
|
|
183
183
|
coordinates_type_map: Dict[Tuple[float, float, float], str] = {}
|
184
184
|
coordinates_residue_map: Dict[Tuple[float, float, float], Residue3D] = {}
|
185
185
|
for residue in structure.residues:
|
186
|
-
if residue.model != model:
|
186
|
+
if model is not None and residue.model != model:
|
187
187
|
continue
|
188
188
|
acceptors = (
|
189
189
|
BASE_ACCEPTORS.get(residue.one_letter_name, [])
|
@@ -396,12 +396,14 @@ def find_pairs(
|
|
396
396
|
return base_pairs, base_phosphates, base_riboses
|
397
397
|
|
398
398
|
|
399
|
-
def find_stackings(
|
399
|
+
def find_stackings(
|
400
|
+
structure: Structure3D, model: Optional[int] = None
|
401
|
+
) -> List[Stacking]:
|
400
402
|
# put all nitrogen ring centers into a KDTree
|
401
403
|
coordinates = []
|
402
404
|
coordinates_residue_map: Dict[Tuple[float, float, float], Residue3D] = {}
|
403
405
|
for residue in structure.residues:
|
404
|
-
if residue.model != model:
|
406
|
+
if model is not None and residue.model != model:
|
405
407
|
continue
|
406
408
|
base_atoms = BASE_ATOMS.get(residue.one_letter_name, [])
|
407
409
|
xs, ys, zs = [], [], []
|
@@ -473,7 +475,7 @@ def find_stackings(structure: Structure3D, model: int = 1) -> List[Stacking]:
|
|
473
475
|
|
474
476
|
|
475
477
|
def extract_base_interactions(
|
476
|
-
tertiary_structure: Structure3D, model: int =
|
478
|
+
tertiary_structure: Structure3D, model: Optional[int] = None
|
477
479
|
) -> BaseInteractions:
|
478
480
|
base_pairs, base_phosphate, base_ribose = find_pairs(tertiary_structure, model)
|
479
481
|
stackings = find_stackings(tertiary_structure, model)
|
@@ -481,7 +483,9 @@ def extract_base_interactions(
|
|
481
483
|
|
482
484
|
|
483
485
|
def extract_secondary_structure(
|
484
|
-
tertiary_structure: Structure3D,
|
486
|
+
tertiary_structure: Structure3D,
|
487
|
+
model: Optional[int] = None,
|
488
|
+
find_gaps: bool = False,
|
485
489
|
) -> BaseInteractions:
|
486
490
|
base_interactions = extract_base_interactions(tertiary_structure, model)
|
487
491
|
mapping = Mapping2D3D(
|
@@ -597,8 +601,8 @@ def main():
|
|
597
601
|
args = parser.parse_args()
|
598
602
|
|
599
603
|
file = handle_input_file(args.input)
|
600
|
-
structure3d = read_3d_structure(file,
|
601
|
-
structure2d = extract_secondary_structure(structure3d,
|
604
|
+
structure3d = read_3d_structure(file, None)
|
605
|
+
structure2d = extract_secondary_structure(structure3d, None, args.find_gaps)
|
602
606
|
|
603
607
|
if args.csv:
|
604
608
|
write_csv(args.csv, structure2d)
|
@@ -0,0 +1,278 @@
|
|
1
|
+
#! /usr/bin/env python
|
2
|
+
import argparse
|
3
|
+
import csv
|
4
|
+
import logging
|
5
|
+
import math
|
6
|
+
import os
|
7
|
+
from collections import defaultdict
|
8
|
+
from typing import Dict, List, Optional, Tuple
|
9
|
+
|
10
|
+
import numpy
|
11
|
+
import numpy.typing
|
12
|
+
import orjson
|
13
|
+
from ordered_set import OrderedSet
|
14
|
+
from scipy.spatial import KDTree
|
15
|
+
|
16
|
+
from rnapolis.common import (
|
17
|
+
BaseInteractions,
|
18
|
+
BasePair,
|
19
|
+
BpSeq,
|
20
|
+
LeontisWesthof,
|
21
|
+
Residue,
|
22
|
+
Saenger,
|
23
|
+
Stacking,
|
24
|
+
Structure2D,
|
25
|
+
)
|
26
|
+
from rnapolis.parser import read_3d_structure
|
27
|
+
from rnapolis.tertiary import (
|
28
|
+
AVERAGE_OXYGEN_PHOSPHORUS_DISTANCE_COVALENT,
|
29
|
+
Atom,
|
30
|
+
Mapping2D3D,
|
31
|
+
Residue3D,
|
32
|
+
Structure3D,
|
33
|
+
torsion_angle,
|
34
|
+
)
|
35
|
+
from rnapolis.util import handle_input_file
|
36
|
+
|
37
|
+
C1P_MAX_DISTANCE = 10.0
|
38
|
+
|
39
|
+
logging.basicConfig(level=os.getenv("LOGLEVEL", "INFO").upper())
|
40
|
+
|
41
|
+
|
42
|
+
# TODO: implement this function
|
43
|
+
def is_base_pair(residue_i: Residue3D, residue_j: Residue3D) -> bool:
|
44
|
+
return False
|
45
|
+
|
46
|
+
|
47
|
+
# TODO: implement this function
|
48
|
+
def classify_lw(residue_i: Residue3D, residue_j: Residue3D) -> Optional[LeontisWesthof]:
|
49
|
+
return None
|
50
|
+
|
51
|
+
|
52
|
+
# TODO: implement this function
|
53
|
+
def classify_saenger(residue_i: Residue3D, residue_j: Residue3D) -> Optional[Saenger]:
|
54
|
+
return None
|
55
|
+
|
56
|
+
|
57
|
+
# TODO: implement this function
|
58
|
+
def is_stacking(residue_i: Residue3D, residue_j: Residue3D) -> bool:
|
59
|
+
return False
|
60
|
+
|
61
|
+
|
62
|
+
def find_candidates(
|
63
|
+
structure: Structure3D, model: Optional[int] = None
|
64
|
+
) -> List[Tuple[Residue3D, Residue3D]]:
|
65
|
+
residue_map = {}
|
66
|
+
coordinates = []
|
67
|
+
|
68
|
+
for residue in structure.residues:
|
69
|
+
if model is not None and residue.model != model:
|
70
|
+
continue
|
71
|
+
|
72
|
+
atom = residue.find_atom("C1'")
|
73
|
+
|
74
|
+
if atom is not None:
|
75
|
+
atom_xyz = (atom.x, atom.y, atom.z)
|
76
|
+
residue_map[atom_xyz] = residue
|
77
|
+
coordinates.append(atom_xyz)
|
78
|
+
|
79
|
+
kdtree = KDTree(coordinates)
|
80
|
+
candidates = []
|
81
|
+
|
82
|
+
for i, j in kdtree.query_pairs(C1P_MAX_DISTANCE):
|
83
|
+
residue_i = residue_map[coordinates[i]]
|
84
|
+
residue_j = residue_map[coordinates[j]]
|
85
|
+
candidates.append((residue_i, residue_j))
|
86
|
+
|
87
|
+
return candidates
|
88
|
+
|
89
|
+
|
90
|
+
def find_pairs(structure: Structure3D, model: Optional[int] = None) -> List[BasePair]:
|
91
|
+
base_pairs = []
|
92
|
+
|
93
|
+
for residue_i, residue_j in find_candidates(structure, model):
|
94
|
+
if is_base_pair(residue_i, residue_j):
|
95
|
+
lw = classify_lw(residue_i, residue_j)
|
96
|
+
saenger = classify_saenger(residue_i, residue_j)
|
97
|
+
base_pairs.append(
|
98
|
+
BasePair(
|
99
|
+
Residue(residue_i.label, residue_i.auth),
|
100
|
+
Residue(residue_j.label, residue_j.auth),
|
101
|
+
lw,
|
102
|
+
saenger,
|
103
|
+
)
|
104
|
+
)
|
105
|
+
|
106
|
+
return base_pairs
|
107
|
+
|
108
|
+
|
109
|
+
def find_stackings(
|
110
|
+
structure: Structure3D, model: Optional[int] = None
|
111
|
+
) -> List[Stacking]:
|
112
|
+
stackings = []
|
113
|
+
|
114
|
+
for residue_i, residue_j in find_candidates(structure, model):
|
115
|
+
if is_stacking(residue_i, residue_j):
|
116
|
+
stackings.append(
|
117
|
+
Stacking(
|
118
|
+
Residue(residue_i.label, residue_i.auth),
|
119
|
+
Residue(residue_j.label, residue_j.auth),
|
120
|
+
None,
|
121
|
+
)
|
122
|
+
)
|
123
|
+
|
124
|
+
return stackings
|
125
|
+
|
126
|
+
|
127
|
+
def extract_base_interactions(
|
128
|
+
tertiary_structure: Structure3D, model: Optional[int] = None
|
129
|
+
) -> BaseInteractions:
|
130
|
+
base_pairs = find_pairs(tertiary_structure, model)
|
131
|
+
stackings = find_stackings(tertiary_structure, model)
|
132
|
+
return BaseInteractions(base_pairs, stackings, [], [], [])
|
133
|
+
|
134
|
+
|
135
|
+
def extract_secondary_structure(
|
136
|
+
tertiary_structure: Structure3D,
|
137
|
+
model: Optional[int] = None,
|
138
|
+
find_gaps: bool = False,
|
139
|
+
) -> BaseInteractions:
|
140
|
+
base_interactions = extract_base_interactions(tertiary_structure, model)
|
141
|
+
mapping = Mapping2D3D(
|
142
|
+
tertiary_structure,
|
143
|
+
base_interactions.basePairs,
|
144
|
+
base_interactions.stackings,
|
145
|
+
find_gaps,
|
146
|
+
)
|
147
|
+
stems, single_strands, hairpins, loops = mapping.bpseq.elements
|
148
|
+
return Structure2D(
|
149
|
+
base_interactions,
|
150
|
+
str(mapping.bpseq),
|
151
|
+
mapping.dot_bracket,
|
152
|
+
mapping.extended_dot_bracket,
|
153
|
+
stems,
|
154
|
+
single_strands,
|
155
|
+
hairpins,
|
156
|
+
loops,
|
157
|
+
)
|
158
|
+
|
159
|
+
|
160
|
+
def write_json(path: str, structure2d: BaseInteractions):
|
161
|
+
with open(path, "wb") as f:
|
162
|
+
f.write(orjson.dumps(structure2d))
|
163
|
+
|
164
|
+
|
165
|
+
def write_csv(path: str, structure2d: Structure2D):
|
166
|
+
with open(path, "w") as f:
|
167
|
+
writer = csv.writer(f)
|
168
|
+
writer.writerow(["nt1", "nt2", "type", "classification-1", "classification-2"])
|
169
|
+
for base_pair in structure2d.baseInteractions.basePairs:
|
170
|
+
writer.writerow(
|
171
|
+
[
|
172
|
+
base_pair.nt1.full_name,
|
173
|
+
base_pair.nt2.full_name,
|
174
|
+
"base pair",
|
175
|
+
base_pair.lw.value,
|
176
|
+
(
|
177
|
+
base_pair.saenger.value or ""
|
178
|
+
if base_pair.saenger is not None
|
179
|
+
else ""
|
180
|
+
),
|
181
|
+
]
|
182
|
+
)
|
183
|
+
for stacking in structure2d.baseInteractions.stackings:
|
184
|
+
writer.writerow(
|
185
|
+
[
|
186
|
+
stacking.nt1.full_name,
|
187
|
+
stacking.nt2.full_name,
|
188
|
+
"stacking",
|
189
|
+
stacking.topology.value if stacking.topology is not None else "",
|
190
|
+
"",
|
191
|
+
]
|
192
|
+
)
|
193
|
+
for base_phosphate in structure2d.baseInteractions.basePhosphateInteractions:
|
194
|
+
writer.writerow(
|
195
|
+
[
|
196
|
+
base_phosphate.nt1.full_name,
|
197
|
+
base_phosphate.nt2.full_name,
|
198
|
+
"base-phosphate interaction",
|
199
|
+
base_phosphate.bph.value if base_phosphate.bph is not None else "",
|
200
|
+
"",
|
201
|
+
]
|
202
|
+
)
|
203
|
+
for base_ribose in structure2d.baseInteractions.basePhosphateInteractions:
|
204
|
+
writer.writerow(
|
205
|
+
[
|
206
|
+
base_ribose.nt1.full_name,
|
207
|
+
base_ribose.nt2.full_name,
|
208
|
+
"base-ribose interaction",
|
209
|
+
base_ribose.bph.value if base_ribose.bph is not None else "",
|
210
|
+
"",
|
211
|
+
]
|
212
|
+
)
|
213
|
+
for other in structure2d.baseInteractions.otherInteractions:
|
214
|
+
writer.writerow(
|
215
|
+
[
|
216
|
+
other.nt1.full_name,
|
217
|
+
other.nt2.full_name,
|
218
|
+
"other interaction",
|
219
|
+
"",
|
220
|
+
"",
|
221
|
+
]
|
222
|
+
)
|
223
|
+
|
224
|
+
|
225
|
+
def write_bpseq(path: str, bpseq: BpSeq):
|
226
|
+
with open(path, "w") as f:
|
227
|
+
f.write(str(bpseq))
|
228
|
+
|
229
|
+
|
230
|
+
def main():
|
231
|
+
parser = argparse.ArgumentParser()
|
232
|
+
parser.add_argument("input", help="Path to PDB or mmCIF file")
|
233
|
+
parser.add_argument("--bpseq", help="(optional) path to output BPSEQ file")
|
234
|
+
parser.add_argument("--csv", help="(optional) path to output CSV file")
|
235
|
+
parser.add_argument(
|
236
|
+
"--json",
|
237
|
+
help="(optional) path to output JSON file",
|
238
|
+
)
|
239
|
+
parser.add_argument(
|
240
|
+
"--extended",
|
241
|
+
action="store_true",
|
242
|
+
help="(optional) if set, the program will print extended secondary structure to the standard output",
|
243
|
+
)
|
244
|
+
parser.add_argument(
|
245
|
+
"--find-gaps",
|
246
|
+
action="store_true",
|
247
|
+
help="(optional) if set, the program will detect gaps and break the PDB chain into two or more strands; "
|
248
|
+
f"the gap is defined as O3'-P distance greater then {1.5 * AVERAGE_OXYGEN_PHOSPHORUS_DISTANCE_COVALENT}",
|
249
|
+
)
|
250
|
+
parser.add_argument("--dot", help="(optional) path to output DOT file")
|
251
|
+
args = parser.parse_args()
|
252
|
+
|
253
|
+
breakpoint()
|
254
|
+
|
255
|
+
file = handle_input_file(args.input)
|
256
|
+
structure3d = read_3d_structure(file, None)
|
257
|
+
structure2d = extract_secondary_structure(structure3d, None, args.find_gaps)
|
258
|
+
|
259
|
+
if args.csv:
|
260
|
+
write_csv(args.csv, structure2d)
|
261
|
+
|
262
|
+
if args.json:
|
263
|
+
write_json(args.json, structure2d)
|
264
|
+
|
265
|
+
if args.bpseq:
|
266
|
+
write_bpseq(args.bpseq, structure2d.bpseq)
|
267
|
+
|
268
|
+
if args.extended:
|
269
|
+
print(structure2d.extendedDotBracket)
|
270
|
+
else:
|
271
|
+
print(structure2d.dotBracket)
|
272
|
+
|
273
|
+
if args.dot:
|
274
|
+
print(BpSeq.from_string(structure2d.bpseq).graphviz)
|
275
|
+
|
276
|
+
|
277
|
+
if __name__ == "__main__":
|
278
|
+
main()
|
@@ -7,12 +7,20 @@ from rnapolis.tertiary import BASE_ATOMS, Atom, Residue3D, Structure3D
|
|
7
7
|
|
8
8
|
|
9
9
|
def read_3d_structure(
|
10
|
-
cif_or_pdb: IO[str], model: int =
|
10
|
+
cif_or_pdb: IO[str], model: Optional[int] = None, nucleic_acid_only: bool = False
|
11
11
|
) -> Structure3D:
|
12
12
|
atoms, modified, sequence = (
|
13
13
|
parse_cif(cif_or_pdb) if is_cif(cif_or_pdb) else parse_pdb(cif_or_pdb)
|
14
14
|
)
|
15
|
-
|
15
|
+
available_models = {atom.model: None for atom in atoms}
|
16
|
+
atoms_by_model = {
|
17
|
+
model: list(filter(lambda atom: atom.model == model, atoms))
|
18
|
+
for model in available_models
|
19
|
+
}
|
20
|
+
if model is not None and model in available_models:
|
21
|
+
atoms = atoms_by_model[model]
|
22
|
+
else:
|
23
|
+
atoms = atoms_by_model[list(available_models.keys())[0]]
|
16
24
|
return group_atoms(atoms, modified, sequence, nucleic_acid_only)
|
17
25
|
|
18
26
|
|
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
|