Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 8c76aa88 authored by htyao's avatar htyao
Browse files

Some documentation

parent 0845c5b7
......@@ -81,6 +81,9 @@ def bp_to_struct(bps):
return ss
def parse_vienna(ss):
Parse secondary structure in dot-bracket notation
stacks = {c:[] for c in PARENTHESES_OPENING}
res = [-1 for i in range(len(ss))]
for i,c in enumerate(ss):
......@@ -92,7 +95,11 @@ def parse_vienna(ss):
return res
class VARNA:
"""VARNA object
def __init__(self, seq=None, structure=None):
self.length = -1
self.structure = []
self.sequence = ""
......@@ -126,11 +133,20 @@ class VARNA:
# Now we know the length, let's extend the sequence and structure if necessary
self.sequence += " "*(self.length-len(self.sequence))
self.structure += [-1]*(self.length-len(self.structure))
if self.dbn is not None:
self.dbn += "."*(self.length-len(self.structure))
def add_aux_BP(self, i, j, edge5='wc', edge3='wc', stericity='cis', color='#0000FF', thickness=1.0):
def add_aux_BP(self, i:int, j:int, edge5:str='wc', edge3:str='wc', stericity:str='cis', color:str='#0000FF', thickness:float=1.0):
"""Add an additional base pair `(i,j)`, possibly defining and using custom style
i: 5' position of base pair
j: 3' position of base pair
edge5: Edge 5' used for interaction in non-canonical base-pairs, as defined by the Leontis/Westhof classification of base-pairs. Admissible values are __wc__ (Watson/Crick edge), __h__ (Hoogsteen edge) and __s__ (Sugar edge).
edge3: Edge 3' used for interaction in non-canonical base-pairs. Admissible values are __wc__, __h__ and __s__.
stericity: Orientation of the strands. Admissible values are __cis__ and __trans__
color: Base-pair color in Hex color codes
thickness: Base-pair thickness
assert_valid_interval(self.length, i, j)
if edge5 not in ['wc', 's', 'h']:
raise Exception("edge5 should be one of wc, s, and h")
......@@ -143,7 +159,18 @@ class VARNA:
self.aux_BPs.append((i+1, j+1, color, thickness, edge5, edge3, stericity))
def add_highlight_region(self, i, j, fill="#9999FF", radius=15.0, outline="#3333FF"):
def add_highlight_region(self, i:int, j:int, radius:float=15.0, fill:str="#9999FF", outline:str="#3333FF"):
"""Highlights a region by drawing a polygon of predefined radius,
fill color and outline color around it.
A region consists in an interval from base `i` to base `j`.
i: 5'-end of the highlight
j: 3'-end of the highlight
radius: Thickness of the highlight
fill: The color used to fill the highlight
outline: The color used to draw the line around the highlight
assert_valid_interval(self.length, i, j)
fill = assert_hex_color(fill)
outline = assert_hex_color(outline)
......@@ -152,18 +179,48 @@ class VARNA:
self.highlight_regions.append((i+1, j+1, radius, fill, outline))
def set_algorithm(self, algo):
if algo not in ['line', 'circular', 'radiate', 'naview']:
"""Set algorithm other than __naview__ to draw secondary structure.
Supported options are __line__, __circular__, __radiate__ and __naview__.
if algo not in ['line', ' circular', 'radiate', 'naview']:
raise Exception("Sould be one of line, circular, radiate or naview")
self.params['algorithm'] = algo
def set_title(self, title, color='#808080', size=10):
def set_title(self, title:str, color:str='#808080', size:int=10):
"""Set title displayed at the bottom of the panel with color and font size
self.title = (title, color, size)
def set_zoom_level(self, level):
def set_zoom_level(self, level:float):
"""Defines the level of zoom and zoom increment used to display the RNA within this panel"""
self.param['zoom'] = level
def set_default_color(self, **kwargs):
"""Set default color used for different objects in the panel.
**kwargs: See below for the list of allowed keywords.
Value of a keyword is the default color, in Hex color codes, used for the related object.
| Name | Object in panel |
| backbone | phosphate-sugar backbone (aka skeleton) of the RNA |
| background | background color used within the panel |
| baseInner | inner base color |
| baseName | nucleotide name |
| baseNum | base numbers |
| baseOutline | outer base color |
| bp | base-pair |
| nsBasesColor | non-standard bases (Anything but `A`, `C`, `G` or `U`) |
>>> set_default_color({'backbone': '#000000', 'bp':'#FFFF00'})
for key, value in kwargs.items():
if key not in DEFAULT_COLOR_LIST:
raise Exception("{} is not a valid keyword".format(key))
......@@ -171,6 +228,31 @@ class VARNA:
self.default_color = kwargs
def toggle_options(self, **kwargs):
"""Enable or disable options of drawing
**kwargs: See below for detailed option lists.
Value of keyword is either `True` or `False`
Default value is set while [VARNA] object is created.
| Name | Option | Default |
| autoHelices | Annotates each and every helix in the RNA with a unique `Hn` label | False |
| autoInteriorLoops | Annotates each and every interior loop of the RNA with a unique `In` label | False |
| autoTerminalLoops | Annotates each and every terminal loop of the RNA with a unique `Tn` label | False |
| drawBackbone | Backbone drawing | True |
| drawBases | Displays the outline of a nucleotide base | True |
| drawNC | Displays non-canonical base-pairs | True |
| drawTertiary | Display of `non-planar` base-pairs, _i.e._ pseudoknots [^1] | False |
| fillBases | Fill bases | True |
| flat | In `radiate` drawing mode, redraws the whole structure, aligning to a baseline the base featured on the exterior loops (aka "dangling ends") | False |
[^1]: Since there is no canonical definition of pseudoknotted portions, a maximal planar subset is extracted from the input structure, defined to be the planar portion, and used as a scaffold for the drawing algorithms.
for key, value in kwargs.items():
if key not in OPTIONS:
raise Exception("{} is not a valid keyword".format(key))
......@@ -214,13 +296,31 @@ class VARNA:
return "".join(res)
def set_border(self, border):
def set_border(self, border:str):
"""Sets the width and height of the panel border, _i.e._ the gap
between the panel boundaries and those of the surface used to draw the RNA.
Parameter `border` is in format `"wxh"` where `w` and `h` are width and height separated by `x`.
>>> set_border("20x30")
match =
if not match:
raise Exception("border should be the format nxm where n and m are numbers")
self.params['border'] = "\"{}\"".format(border)
def set_bp_style(self, style):
def set_bp_style(self, style:str):
"""Set default style for base-pairs rendering, chosen among:
| Label | Description |
| none | Base-pairs are not drawn, but can be implicitly seen from "ladders", _i.e_ helix structures |
| line | A simple line is used to draw any base-pair, regardless of its type |
| rnaviz | A small square is drawn at equal distance of the two partners |
| lw | Both canonical and non-canonical base-pairs are rendered according to the Leontis/Westhof nomenclature |
__Note:__ `lw` is set by default
if style not in ['none', 'line', 'rnaviz', 'lw']:
raise Exception('Should be one of none, line, rnaviz or lw')
self.params['bpStyle'] = style
......@@ -237,6 +337,9 @@ class VARNA:
self.bases_styles[style] = self.bases_styles.get(style, set()).union({i+1 for i in bases})
def _gen_command(self):
Return command to run VARNA
cmd = "java -cp {} fr.orsay.lri.varna.applications.VARNAcmd".format(VARNA_PATH)
cmd += " -sequenceDBN \"{}\" -structureDBN \"{}\" -o {}".format(self.sequence, self.format_structure(), self.output)
......@@ -277,6 +380,9 @@ class VARNA:
return cmd
def savefig(self, output):
Call VARNA to draw and store the paint in output
self.output = output
cmd = self._gen_command()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment