Skip to content

I can't visualize RNA with color #37

Description

@Shunsuke-1994

Hi! I love forgi very much!
I am trying to visualize RNA differently colored at each nucleotide using forgi.visual.fornac module.

And, i tried this following code. But if I opend the html file, RNA is not displayed......
I'm using forgi 2.0 and python 3.7 on macOS 10.14.4

import RNA 
import forgi
import forgi.visual.mplotlib as fvm
import forgi.visual.fornac as fvf
import forgi.graph.bulge_graph as fbg


rna = "GGGUUCGCCC"
ss, _ = RNA.fold(rna) #(((....)))

nucleotide_colors = {}
for i, n in enumerate(ss):
    if n == ".":
        nucleotide_colors[i] = (255,0,0)
    else:
        nucleotide_colors[i] = (0,255,0)

color_string = fvf.nucleotide_colors_to_fornac_color_string(nucleotide_colors)
html_txt = forgi.visual.fornac.create_fornac_page_for_structure(bg, color_string)

#'\n<!DOCTYPE html>\n<meta charset="utf-8">\n\nThis is an RNA container.\n<div id=\'rna_ss\'> </div>\nThis after the RNA container.\n\n    <link rel=\'stylesheet\' type=\'text/css\' href=\'https://raw.githubusercontent.com/pkerpedjiev/fornac/master/css/fornac.css\' />\n    <script type=\'text/javascript\' src=\'https://code.jquery.com/jquery-2.1.4.min.js\'></script>\n    <script type=\'text/javascript\' src=\'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js\'></script>\n    <script type=\'text/javascript\' src=\'https://rawgit.com/pkerpedjiev/fornac/master/js/fornac.js\'></script>\n\n    <script type=\'text/javascript\'>\n        var container = new fornac.FornaContainer("#rna_ss",\n            {\'applyForce\': true, \'allowPanningAndZooming\': true, "initialSize": [500,800], \'cssFileLocation\': "https://raw.githubusercontent.com/pkerpedjiev/fornac/master/css/fornac.css"});\n\n        var options = {\'structure\': \'(((....)))\',\n                        \'sequence\': \'NNNNNNNNNN\'};\n\n        colorStr = "0:rgb(0,255,0) 1:rgb(0,255,0) 2:rgb(0,255,0) 3:rgb(255,0,0) 4:rgb(255,0,0) 5:rgb(255,0,0) 6:rgb(255,0,0) 7:rgb(0,255,0) 8:rgb(0,255,0) 9:rgb(0,255,0) " \n\n        container.addRNA(options.structure, options);\n        cs = ColorScheme(colorStr);\n\n        container.addCustomColors(cs.colorsJson);\n        container.changeColorScheme(\'custom\'); \n    </script>\n'



with open("test_forgi_viz.txt", "w") as f:
    f.write(html_txt) 

!open test_forgi_viz.txt

Do you know what's wrong with this code? The html txt seems good, I think...
And, if you can visualize RNA colored at each nucleotide by matplotlib, please tell me how to do it.
I would appreciate if you will help me. Thank you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions