ViennaRNA / ViennaRNA

The ViennaRNA Package
Other
305 stars 78 forks source link

[Bug]: Google Colab with Vienna Python API, notebook crashes when running fc.centroid() #249

Open Tiurii opened 2 months ago

Tiurii commented 2 months ago

Contact Details

vhverhagen@outlook.com

What happened?

I want to calculate the dot-bracket notation for centroid configuration of single stranded RNA, length typically 60nt.

I did some calculations on the website which runs fine. Now I'm trying to run a batch with Python Jupyter Notebook in Google Colab. Importing Vienna RNA library is smooth.

Calculating mfe works. (see script below). When I run centroid() the notebook crashes. Can this work at all?

In reading documentation on centroid a pointer-argument should be passed which I do not know how to provide in Python.

I would like to read your comments on this. Thanks in advance.

Vincent

import RNA

The RNA sequence

seq = "AGGCGGGGGGCGGUGGCUCACGCCUGUAAUCCCAGCACU"

create new fold_compound object

fc = RNA.fold_compound(seq)

compute minimum free energy (mfe) and corresponding structure

(ss, mfe) = fc.mfe()

s = fc.centroid()

Google Colab with Python 3.10.12

Version

2.6.x (Default)

Which operating system are you using?

No response

Does the problem occur with one of our executable program or the C-library?

No response

Relevant log output

No response

Code of Conduct

RaumZeit commented 2 months ago

Hi, you need to compute the partition function and base pair probabilities before constructing the centroid structure, i.e you need to run

fc.pf()

first!

Also, to be on the safe side for longer input sequences, you should rescale the Boltzmann factors for the partition function computations to avoid over-/underflows. So a working example to compute the centroid structure may look like this:

(ss, mfe) = fc.mfe()
fc.exp_params_rescale(mfe)
(pp, dG) = fc.pf()
s = fc.centroid()

P.S.: I note that the fc.centroid() method should not crash the calling environment, but there are no checks implemented so far to ensure that base pair probabilities have been already computed. I put this into our issues list for future releases, hopefully we'll have some proper checks for that in the future...

Tiurii commented 2 months ago

Your suggestions are appreciated, very helpful, thanks!