RNAlib-2.4.14
HelloWorld (Perl/Python)

Table of Contents

Perl5

Simple MFE prediction for a given sequence

use RNA;
# The RNA sequence
my $seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA";
# compute minimum free energy (MFE) and corresponding structure
my ($ss, $mfe) = RNA::fold($seq);
# print output
printf "%s\n%s [ %6.2f ]\n", $seq, $ss, $mfe;

Simple MFE prediction for a multiple sequence alignment

use RNA;
# The RNA sequence alignment
my @sequences = (
"CUGCCUCACAACGUUUGUGCCUCAGUUACCCGUAGAUGUAGUGAGGGU",
"CUGCCUCACAACAUUUGUGCCUCAGUUACUCAUAGAUGUAGUGAGGGU",
"---CUCGACACCACU---GCCUCGGUUACCCAUCGGUGCAGUGCGGGU"
);
# compute the consensus sequence
my $cons = RNA::consensus(\@sequences);
# predict Minmum Free Energy and corresponding secondary structure
my ($ss, $mfe) = RNA::alifold(\@sequences);
# print output
printf "%s\n%s [ %6.2f ]\n", $cons, $ss, $mfe;

Deviating from the Default Model

use RNA;
# The RNA sequence
my $seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA";
# create a new model details structure
my $md = new RNA::md();
# change temperature and dangle model
$md->{temperature} = 20.0; # 20 Deg Celcius
$md->{dangles} = 1; # Dangle Model 1
# create a fold compound
my $fc = new RNA::fold_compound($seq, $md);
# predict Minmum Free Energy and corresponding secondary structure
my ($ss, $mfe) = $fc->mfe();
# print sequence, structure and MFE
printf "%s\n%s [ %6.2f ]\n", $seq, $ss, $mfe;

Python

Simple MFE prediction for a given sequence

1 import RNA
2 
3 # The RNA sequence
4 seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA"
5 
6 # compute minimum free energy (MFE) and corresponding structure
7 (ss, mfe) = RNA.fold(seq)
8 
9 # print output
10 print "%s\n%s [ %6.2f ]" % (seq, ss, mfe)

Simple MFE prediction for a multiple sequence alignment

1 import RNA
2 
3 # The RNA sequence alignment
4 sequences = [
5  "CUGCCUCACAACGUUUGUGCCUCAGUUACCCGUAGAUGUAGUGAGGGU",
6  "CUGCCUCACAACAUUUGUGCCUCAGUUACUCAUAGAUGUAGUGAGGGU",
7  "---CUCGACACCACU---GCCUCGGUUACCCAUCGGUGCAGUGCGGGU"
8 ]
9 
10 # compute the consensus sequence
11 cons = RNA.consensus(sequences)
12 
13 # predict Minmum Free Energy and corresponding secondary structure
14 (ss, mfe) = RNA.alifold(sequences);
15 
16 # print output
17 print "%s\n%s [ %6.2f ]" % (cons, ss, mfe)

Deviating from the Default Model

1 import RNA
2 
3 # The RNA sequence
4 seq = "GAGUAGUGGAACCAGGCUAUGUUUGUGACUCGCAGACUAACA"
5 
6 # create a new model details structure
7 md = RNA.md()
8 
9 # change temperature and dangle model
10 md.temperature = 20.0 # 20 Deg Celcius
11 md.dangles = 1 # Dangle Model 1
12 
13 # create a fold compound
14 fc = RNA.fold_compound(seq, md)
15 
16 # predict Minmum Free Energy and corresponding secondary structure
17 (ss, mfe) = fc.mfe()
18 
19 # print sequence, structure and MFE
20 print "%s\n%s [ %6.2f ]\n" % (seq, ss, mfe)