Scorer
Compare RNA 3D structures using circular statistics on torsion angles.
This module implements a scoring pipeline that computes signed (MCD) and unsigned (MCQ) circular differences between backbone torsion angles of a target and model RNA structure, then derives a composite similarity score in [0, 1].
Terminology
MCD (Mean Circular Deviation): Signed angular difference, range [-pi, pi]. MCQ (Mean Circular Quality): Unsigned (absolute) angular difference, range [0, pi].
bootstrap_ci(data, statistic_fn, n_bootstrap, alpha=0.05)
Compute a bootstrap confidence interval for a circular statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Input data (list of floats). |
required | |
statistic_fn
|
Callable that takes a list and returns a scalar. |
required | |
n_bootstrap
|
Number of bootstrap resamples. |
required | |
alpha
|
Significance level (default 0.05 for 95% CI). |
0.05
|
Returns:
| Type | Description |
|---|---|
|
Tuple of (lower_bound, upper_bound) for the confidence interval. |
Source code in src/rnapolis/scorer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
circular_mad(data, median)
Compute the circular median absolute deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Angular values in radians. |
required | |
median
|
Circular median in radians. |
required |
Returns:
| Type | Description |
|---|---|
|
The median of absolute wrapped deviations from |
Source code in src/rnapolis/scorer.py
165 166 167 168 169 170 171 172 173 174 175 176 177 | |
compute_mcd_mcq(target, model)
Compute signed (MCD) and unsigned (MCQ) angular differences between two structures.
For each residue matched by chain, number, and name, wraps the angular difference of each backbone torsion angle into [-pi, pi] (MCD) and takes its absolute value (MCQ).
If a residue at position i in the target does not match the same position in the model, a lookup by residue identity is used as a fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
DataFrame of torsion angles for the reference structure. |
required | |
model
|
DataFrame of torsion angles for the model structure. |
required |
Returns:
| Type | Description |
|---|---|
|
Tuple of (signed_diffs, unsigned_diffs) where each is a list of |
|
|
floats in radians. |
Source code in src/rnapolis/scorer.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
compute_score(metrics)
Compute a composite similarity score from circular statistics.
Combines three weighted sub-scores:
- Fit: How close the mean and median MCQ are to zero.
- Concentration: How tightly the MCQ distribution is concentrated.
- Uniformity: How concentrated the MCD distribution is around zero, indicating lack of systematic bias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
Dictionary containing at minimum the keys |
required |
Returns:
| Type | Description |
|---|---|
|
Similarity score in [0, 1], where 1.0 means identical structures. |
Source code in src/rnapolis/scorer.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
evaluate_similarity(target_path, model_path, n_bootstrap=10000, visualize_on=False, output_dir='.')
Evaluate the similarity between two RNA structures.
Parses both structures, computes torsion angle differences, derives circular statistics with bootstrap confidence intervals, and returns a results dictionary including a composite score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_path
|
Path to the reference structure ( |
required | |
model_path
|
Path to the model structure ( |
required | |
n_bootstrap
|
Number of bootstrap resamples for confidence intervals. |
10000
|
|
visualize_on
|
If |
False
|
|
output_dir
|
Directory for output files (plots, CSV). |
'.'
|
Returns:
| Type | Description |
|---|---|
|
Dictionary of circular statistics and a |
|
|
composite similarity score in [0, 1]. |
Source code in src/rnapolis/scorer.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
main()
CLI entry point for RNA structure scoring.
Source code in src/rnapolis/scorer.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
monte_carlo_mad_test(data, observed_mad, use_full_circle, n_simulations)
Test concentration by comparing observed MAD to random circular samples.
Generates n_simulations random samples from a uniform circular
distribution and counts how often their MAD is at most as small as
the observed_mad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Original angular data (used only for its length). |
required | |
observed_mad
|
The observed circular MAD to compare against. |
required | |
use_full_circle
|
If |
required | |
n_simulations
|
Number of Monte Carlo iterations. |
required |
Returns:
| Type | Description |
|---|---|
|
Proportion of random samples with MAD <= |
Source code in src/rnapolis/scorer.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
parse_file(filepath)
Parse an RNA structure file in PDB or mmCIF format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path to the input file. Must have a |
required |
Returns:
| Type | Description |
|---|---|
|
Parsed atom data as a DataFrame. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not |
Source code in src/rnapolis/scorer.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
save_csv(result_file_path, data)
Write rows of data to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_file_path
|
Path to the output CSV file. |
required | |
data
|
List of rows, where each row is a list of values. |
required |
Source code in src/rnapolis/scorer.py
77 78 79 80 81 82 83 84 85 86 | |
visualize(d, outfile)
Save a polar plot of angular data to an SVG file.
Plots the circular distribution of angle differences using an adaptive configuration: for highly concentrated data (resultant length > 0.9) the density layer is disabled to avoid an uninformative spike, and the rose diagram uses finer bins.
Input angles are wrapped to [0, 2pi) before plotting so that signed differences (which may be negative) do not confuse the density estimator or scatter positioning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Array of angular values in radians. |
required | |
outfile
|
Output path for the polar plot (typically |
required |
Source code in src/rnapolis/scorer.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |