text: user3829: I need some help with forgi library for visualisation of RNA secondary structure.
  I have an RNA sequence and dot-bracket notation of the secondary structure and I would like to plot 2D graph like that you can find here.
  The input file is a .fx file, or a fasta file where the sequence is single-line and the third line is the dot-bracket notation of the RNA structure.
  >1y26
  CGCUUCAUAUAAUCCUAAUGAUAUGGUUUGGGAGUUUCUACCAAGAGCCUUAAACUCUUGAUUAUGAAGUG
  ((((((((((..(((((((.......)))))))......).((((((.......))))))..)))))))))
  
  
  If there any other possibilities to plot it in real-time (for instance, in jupyter notebook avoiding any crossing external scripts), I will be very thankful to learn them!
  
  user15654: I wrote a function to do that a while ago, maybe it helps. It only works with dot-bracket notation, and it turns it into ordered pairs which then you can easily plot.
  import pandas as pd
  import seaborn as sns
  
  
  def dot_bracket_to_pairs(ss_string):
      '''
      Takes dot and bracket string, returns dataframe
      with paired bases.
      If any invalid characters are in the structure, it
      will interpret them as dots, as it only reads parentheses.
      '''
      index_list = []
      pairs = {}
  
      for index, char in enumerate(ss_string):
          if char == '(':
              index_list.append(index)
          if char == ')':
              try:
                  # pair to last item in the list in dictionary
                  pairs[index_list.pop()] = index
              except IndexError:
                  print(f'Invalid structure, found extra \')\' in position {index}')
  
      if len(index_list) != 0:
          for item in index_list:
              print(f'Invalid structure, found extra in \'(\' in position {item}')
  
      df_pairs = pd.DataFrame(pairs.items(), columns=['Y', 'X'])
  
      return df_pairs
  
  db_string = '((((((((((..(((((((.......)))))))......).((((((.......))))))..)))))))))'
  df = dot_bracket_to_pairs(db_string)
  
  sns.scatterplot(data=df, x="X", y="Y")
  
  
  user3848: One way simply is to use VARNA, here is a link ... https://varna.lri.fr. This is well known for its power to view secondary structure (e.g. its in Jalview). It is generally considered the best viewer app for secondary structure.
  However, the solution by @nquinoneso whilst simple, is preferable. The output is here:
  
  The y-axis is the 3' and the x-axis is the 5', the dots represent hairpins. Whilst its simple, the power of this approach is the automation by direct access to the (pandas) dataframe.
  I do recommend upvoting the post.
  Complex secondary structure would not work because it will confuse the 5' stems with the immediate 3' stems which don't hybridise and  a more advanced solution using nucleotide code would be needed. Thats the bit for further development, using the index both for the dot-bracket and the nucleotide sequence to confirm the hairpin. VARNA does perform this calculation (because it identifies canonical mutations)... but you can't access the underlying array/dataframe which is certainly a limitation.
  
original_text: 3829: <p>I need some help with forgi library for visualisation of RNA secondary structure.</p>
  
  <p>I have an RNA sequence and dot-bracket notation of the secondary structure and I would like to plot 2D graph like that you can find <a href="https://viennarna.github.io/forgi/graph_tutorial.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The input file is a <code>.fx</code> file, or a fasta file where the sequence is single-line and the third line is the <a href="http://eternawiki.org/wiki/index.php5/Dot-Bracket_Notation" rel="nofollow noreferrer">dot-bracket notation</a> of the RNA structure.</p>
  
  <pre><code>&gt;1y26
  CGCUUCAUAUAAUCCUAAUGAUAUGGUUUGGGAGUUUCUACCAAGAGCCUUAAACUCUUGAUUAUGAAGUG
  ((((((((((..(((((((.......)))))))......).((((((.......))))))..)))))))))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/OlrLz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OlrLz.png" alt="enter image description here"></a></p>
  
  <p>If there any other possibilities to plot it in real-time (for instance, in jupyter notebook avoiding any crossing external scripts), I will be very thankful to learn them!</p>
   15654: <p>I wrote a function to do that a while ago, maybe it helps. It only works with dot-bracket notation, and it turns it into ordered pairs which then you can easily plot.</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import seaborn as sns
  
  
  def dot_bracket_to_pairs(ss_string):
      '''
      Takes dot and bracket string, returns dataframe
      with paired bases.
      If any invalid characters are in the structure, it
      will interpret them as dots, as it only reads parentheses.
      '''
      index_list = []
      pairs = {}
  
      for index, char in enumerate(ss_string):
          if char == '(':
              index_list.append(index)
          if char == ')':
              try:
                  # pair to last item in the list in dictionary
                  pairs[index_list.pop()] = index
              except IndexError:
                  print(f'Invalid structure, found extra \')\' in position {index}')
  
      if len(index_list) != 0:
          for item in index_list:
              print(f'Invalid structure, found extra in \'(\' in position {item}')
  
      df_pairs = pd.DataFrame(pairs.items(), columns=['Y', 'X'])
  
      return df_pairs
  
  db_string = '((((((((((..(((((((.......)))))))......).((((((.......))))))..)))))))))'
  df = dot_bracket_to_pairs(db_string)
  
  sns.scatterplot(data=df, x=&quot;X&quot;, y=&quot;Y&quot;)
  </code></pre>
   3848: <p>One way simply is to use VARNA, here is a link ... <a href="https://varna.lri.fr" rel="nofollow noreferrer">https://varna.lri.fr</a>. This is well known for its power to view secondary structure (e.g. its in Jalview). It is generally considered the best viewer app for secondary structure.</p>
  <p>However, the solution by @nquinoneso whilst simple, is preferable. The output is here:</p>
  <p><a href="https://i.stack.imgur.com/MC2ii.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MC2ii.png" alt="enter image description here" /></a></p>
  <p>The y-axis is the 3' and the x-axis is the 5', the dots represent hairpins. Whilst its simple, the power of this approach is the automation by direct access to the (pandas) dataframe.</p>
  <p><em>I do recommend upvoting the post.</em></p>
  <p>Complex secondary structure would not work because it will confuse the 5' stems with the immediate 3' stems which don't hybridise and  a more advanced solution using nucleotide code would be needed. Thats the bit for further development, using the index both for the dot-bracket and the nucleotide sequence to confirm the hairpin. VARNA does perform this calculation (because it identifies canonical mutations)... but you can't access the underlying array/dataframe which is certainly a limitation.</p>
  