Skip to content

Commit

Permalink
DOC: Add Python example equivalent to RNAfold -p --MEA
Browse files Browse the repository at this point in the history
  • Loading branch information
RaumZeit committed Aug 9, 2019
1 parent 78f3e13 commit d097eb6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/refman.include/examples_python.dox
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Boltzmann Sampling (a.k.a. Probabilistic Backtracing)
-----------------------------------------------------
@include boltzmann_sampling.py

@anchor examples_python_MEA

RNAfold -p --MEA equivalent
-----------------------------------------------------
@include RNAfold_MEA.py

@anchor examples_python_soft_constraints

Fun with Soft Constraints
Expand Down
3 changes: 2 additions & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ examples_python = \
Python/helloworld_nondefault.py \
Python/maximum_matching.py \
Python/oo_example1.py \
Python/subopt.py
Python/subopt.py \
Python/RNAfold_MEA.py

data_files = \
files/alignment_clustal.aln \
Expand Down
37 changes: 37 additions & 0 deletions examples/Python/RNAfold_MEA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/python
#

import RNA

seq = "AUUUCCACUAGAGAAGGUCUAGAGUGUUUGUCGUUUGUCAGAAGUCCCUAUUCCAGGUACGAACACGGUGGAUAUGUUCGACGACAGGAUCGGCGCACUA"

# create fold_compound data structure (required for all subsequently applied algorithms)
fc = RNA.fold_compound(seq)

# compute MFE and MFE structure
(mfe_struct, mfe) = fc.mfe()

# rescale Boltzmann factors for partition function computation
fc.exp_params_rescale(mfe)

# compute partition function
(pp, pf) = fc.pf()

# compute centroid structure
(centroid_struct, dist) = fc.centroid()

# compute free energy of centroid structure
centroid_en = fc.eval_structure(centroid_struct)

# compute MEA structure
(MEA_struct, MEA) = fc.MEA()

# compute free energy of MEA structure
MEA_en = fc.eval_structure(MEA_struct)

# print everything like RNAfold -p --MEA
print("%s\n%s (%6.2f)" % (seq, mfe_struct, mfe))
print("%s [%6.2f]" % (pp, pf))
print("%s {%6.2f d=%.2f}" % (centroid_struct, centroid_en, dist))
print("%s {%6.2f MEA=%.2f}" % (MEA_struct, MEA_en, MEA))
print(" frequency of mfe structure in ensemble %g; ensemble diversity %-6.2f" % (fc.pr_structure(mfe_struct), fc.mean_bp_distance()))

0 comments on commit d097eb6

Please sign in to comment.