<jupyter_start><jupyter_text>Graphein RNA Graph Construction Tutorial[API Reference](https://graphein.ai/modules/graphein.rna.html)In this notebook we construct graphs of RNA secondary structures.The inputs we require are a sequence (optional) and a [dotbracket](https://www.tbi.univie.ac.at/RNA/ViennaRNA/doc/html/rna_structure_notations.html) specification of the secondary structure.The workflow we follow is similar to the other data modalities. The desired edge constructions are passed as a list of functions to the construction function.[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/a-r-j/graphein/blob/master/notebooks/rna_graph_tutorial.ipynb)![](https://www.biorxiv.org/content/biorxiv/early/2021/10/12/2020.07.15.204701/F4.large.jpg?width=800&height=600&carousel=1])<jupyter_code># Install Graphein if necessary
# !pip install graphein
import logging
logging.getLogger("matplotlib").setLevel(logging.WARNING)
logging.getLogger("graphein").setLevel(logging.WARNING)

from typing import List, Callable
import networkx as nx
from graphein.rna.graphs import construct_rna_graph
from graphein.rna.edges import (
    add_all_dotbracket_edges,
    add_pseudoknots,
    add_phosphodiester_bonds,
    add_base_pairing_interactions
)<jupyter_output><empty_output><jupyter_text>Construction with a DotbracketGraph construction is handled by the [`construct_rna_graph()`](https://graphein.ai/modules/graphein.rna.htmlgraphein.rna.graphs.construct_rna_graph) function.<jupyter_code>from graphein.rna.visualisation import plot_rna_graph
edge_funcs_1: List[Callable] = [
    add_base_pairing_interactions,
    add_phosphodiester_bonds,
    add_pseudoknots,
]
edge_funcs_2: List[Callable] = [add_all_dotbracket_edges]

g = construct_rna_graph(
    "......((((((......[[[))))))......]]]....",
    sequence=None,
    edge_construction_funcs=edge_funcs_1,
)
nx.draw(g)

plot_rna_graph(g, layout=nx.layout.spring_layout)<jupyter_output>WARNING:graphein.rna.visualisation:No sequence data found in graph. Skipping base type labelling.<jupyter_text>Construction with a dotbracket and sequence<jupyter_code>g = construct_rna_graph(
    sequence="CGUCUUAAACUCAUCACCGUGUGGAGCUGCGACCCUUCCCUAGAUUCGAAGACGAG",
    dotbracket="((((((...(((..(((...))))))...(((..((.....))..)))))))))..",
    edge_construction_funcs=edge_funcs_1,
)
plot_rna_graph(g, layout=nx.layout.spring_layout)
g = construct_rna_graph(
    sequence="CGUCUUAAACUCAUCACCGUGUGGAGCUGCGACCCUUCCCUAGAUUCGAAGACGAG",
    dotbracket="((((((...(((..(((...))))))...(((..((.....))..)))))))))..",
    edge_construction_funcs=edge_funcs_1,
)
plot_rna_graph(g, layout=nx.layout.circular_layout)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14897510980966325, 'fraction_numerical': 0.01281112737920937, 'mean_word_length': 6.043814432989691, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '136794', 'license': 'MIT', 'n_tokens_mistral': 1030, 'n_tokens_neox': 956, 'n_words': 144, 'path': 'notebooks/rna_graph_tutorial.ipynb', 'repo_name': 'avivko/graphein', 'size': '2732'}