A short Python wrapper for Vienna tools
Project description
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!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vienna-0.8.0.tar.gz.
File metadata
- Download URL: vienna-0.8.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
001374b4ade2df1da08698c05b62a1e81b58d1d2338a4326c278f60b7371e0bb
|
|
| MD5 |
906f87e6040184c3db3c745b433a75a7
|
|
| BLAKE2b-256 |
1783ef3549d2728312db29f272f78db97bca80f3d9a7e45e39926cad71e7f4d0
|
File details
Details for the file vienna-0.8.0-py3-none-any.whl.
File metadata
- Download URL: vienna-0.8.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05055b3d9a07462f2c3a8319af108298df82e918014ce4707380574a6a7c9bc3
|
|
| MD5 |
a82791409b4b8976700e52accd020f72
|
|
| BLAKE2b-256 |
3a33934b652b3b5d233d1ce7043eb31f3d656ec6a3b5175a09651841d0a183a9
|