PythonでRNAlibを動かすときのメモ
RNAlibのdocumentなりhelpがあまりにも欠如しているのでちまちま調べていたことを軽くまとめる。
githubのissueを見ると割と勉強になることを学んだ。
温度の設定
import RNA print(RNA.__version__) #2.4.11 seq = RNA.random_string(20, "AUGC") md = RNA.md() print(md.temperature) #デフォルトで37.0 fc_37 = RNA.fold_compound(seq, md) md.temperature = 20 fc_20 = RNA.fold_compound(seq, md) md.temperature = 4 fc_4 = RNA.fold_compound(seq, md) print(fc_37.mfe()) print(fc_20.mfe()) print(fc_4.mfe())
制約条件下のfolding
制約条件の下でのfoldingの記載も見つけた。
constraint folding in python · Issue #31 · ViennaRNA/ViennaRNA · GitHub
constraint = ".......................xxxxxxx" #制約条件 sequence = RNA.random_string(len(constraint), "AUGC") #適当に生成 # create fold_compound object fc = RNA.fold_compound(sequence) # add hard constraints, specified by dot-bracket like string fc.hc_add_from_db(constraint) # compute partition function (prob, energy) = fc.pf() fc.hc_init() #初期化
duplexfoldの使い方について
fold_compoundを使うのが新しいRNAlibの使い方らしいが、duplexfoldみたいな古いもの未だに残っているらしい。
&を使ったstructureの出力が謎だったが、これを読んではっきり理解することが出来た。
Matching duplexfold structure to sequence · Issue #38 · ViennaRNA/ViennaRNA · GitHub
d = RNA.duplexfold('CGT', 'AAG') print(d.structure) d.energy print(d.i, d.j) #(.&.) #2 2
(.&.) の &の前後の番号を示しているらしい。なるほど。流石にdocumentに書け。
suboptの使い方
suboptの引数の数字deltaはx0.01 kcal/molの間にあるsuboptの構造を出力してくれる
a = RNA.fold_compound(sequence) solution = a.subopt(500) print "%d suboptimals" % len(solution) for s in solution: print "%s %6.2f" % (s.structure,s.energy)