vienna
a short python wrapper for vienna tools (https://www.tbi.univie.ac.at/RNA/ViennaRNA/doc/html/install.html) Note I did not develop this software just built this short wrapper.
Installation
Using Conda (Recommended)
The easiest way to install is using conda with the provided environment file:
# Clone the repository
git clone https://github.com/jyesselm/vienna
cd vienna
# Create and activate the conda environment (includes ViennaRNA)
conda env create -f environment.yml
conda activate vienna
Using pip
Note: This is just a wrapper, so you must install ViennaRNA first.
Install ViennaRNA:
# Using conda (recommended)
conda install -c bioconda viennarna
# Or install from source: https://www.tbi.univie.ac.at/RNA/
Install the Python package:
# From PyPI
pip install vienna
# Or from source
git clone https://github.com/jyesselm/vienna
cd vienna
pip install .
Usage
Basic Folding
The simplest way to fold an RNA sequence:
import vienna
# Fold a simple RNA sequence
result = vienna.fold('GGGGAAAACCCC')
print(result)
# FoldResults(dot_bracket='((((....))))', mfe=-5.4, ens_defect=1.62)
# Access individual properties
print(f"Structure: {result.dot_bracket}")
print(f"Minimum Free Energy: {result.mfe} kcal/mol")
print(f"Ensemble Diversity: {result.ens_defect}")
Getting Just the Structure
If you only need the secondary structure:
structure = vienna.folded_structure('GGGGAAAACCCC')
print(structure) # '((((....))))'
Folding with Base Pair Probabilities
Calculate base pair probabilities for more detailed analysis:
result = vienna.fold('GGGGAAAACCCC', bp_probs=True)
print(f"Number of base pairs: {len(result.bp_probs)}")
# Access base pair probabilities
for bp in result.bp_probs:
i, j, prob = bp
if prob > 0.5: # Only show high-probability pairs
print(f"Base pair {i}-{j}: probability = {prob:.3f}")
Cofolding Two Sequences
Fold two RNA sequences together to predict their interaction:
# Separate sequences with '&'
result = vienna.cofold('GGGG&AAACCCC')
print(f"Combined structure: {result.dot_bracket}")
print(f"Combined energy: {result.mfe} kcal/mol")
Inverse Folding
Design sequences that fold into a specific structure:
# Target structure and sequence constraints
target_structure = "(((.(((....))).)))"
constraint = "NNNgNNNNNNNNNNaNNN" # N = any nucleotide, lowercase = specific
# Generate sequences
results = vienna.inverse_fold(target_structure, constraint, n_sol=10)
print(f"Found {len(results)} sequences:")
for seq_score in results:
print(f" {seq_score.seq} (score: {seq_score.score:.2f})")
Checking if Sequence Folds to Target Structure
Verify if a sequence folds into a desired structure:
sequence = 'GGGGAAAACCCC'
target = '((((....))))'
if vienna.does_sequence_fold_to(sequence, target):
print("Sequence folds to target structure!")
else:
print("Sequence does not fold to target structure")
Working with Longer Sequences
The library handles sequences of any length:
# Longer sequence
long_seq = 'GGGGAAAACCCC' * 10
result = vienna.fold(long_seq)
print(f"Structure length: {len(result.dot_bracket)}")
print(f"Energy: {result.mfe} kcal/mol")
Example: Analyzing a tRNA-like Sequence
# tRNA-like sequence
tRNA_seq = 'GGGGAUAUAGCUCAGUUGGUAGAGCGCUGCCUUUGCACGGCAGAUGUCAGAGGUUCGAUUCUCUGUUAUCCCC'
result = vienna.fold(tRNA_seq, bp_probs=True)
print(f"tRNA structure:\n{result.dot_bracket}")
print(f"Energy: {result.mfe} kcal/mol")
print(f"Ensemble diversity: {result.ens_defect}")
# Find highly probable base pairs
high_prob_pairs = [bp for bp in result.bp_probs if bp[2] > 0.9]
print(f"\nHighly probable base pairs (>90%): {len(high_prob_pairs)}")
Examples
See the notebooks/ directory for detailed Jupyter notebook examples demonstrating:
- Basic folding workflows
- Base pair probability analysis
- Sequence design with inverse folding
- Cofolding analysis
- And more!
Release files for vienna 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vienna-0.8.0.tar.gz | 10.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vienna-0.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / vienna-0.8.0.tar.gz
| Download URL | vienna-0.8.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
001374b4ade2df1da08698c05b62a1e81b58d1d2338a4326c278f60b7371e0bb
|
|
BLAKE2b-256 checksum How to use checksums |
1783ef3549d2728312db29f272f78db97bca80f3d9a7e45e39926cad71e7f4d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / vienna-0.8.0-py3-none-any.whl
| Download URL | vienna-0.8.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
05055b3d9a07462f2c3a8319af108298df82e918014ce4707380574a6a7c9bc3
|
|
BLAKE2b-256 checksum How to use checksums |
3a33934b652b3b5d233d1ce7043eb31f3d656ec6a3b5175a09651841d0a183a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|