2.5D module drawing with hack mode
This notebook presents the usage of VARNA API hack mode to draw RNA 2.5D module with non-standard VARNA version (commit a463cfe).
import varnaapi
dbn = "..((......)).."
v = varnaapi.Structure(structure=dbn)
v.show()
['java', '-cp', './VARNAv3-93.jar', 'fr.orsay.lri.varna.applications.VARNAcmd', '-sequenceDBN', '', '-structureDBN', '..((......))..', '-o', '/tmp/tmpw3x76tym.png']
Output file: /tmp/tmpw3x76tym.png
Assume that the hairpin loop (4,11) above is a 2.D module containing a non-canonical basepair (5,9) with type cSH
.
Let's try to draw it using add_aux_BP
function.
v = varnaapi.Structure(structure=dbn)
v.add_aux_BP(5,9, edge5="s", edge3="h", color='green')
v.show()
['java', '-cp', './VARNAv3-93.jar', 'fr.orsay.lri.varna.applications.VARNAcmd', '-sequenceDBN', '', '-structureDBN', '..((......))..', '-o', '/tmp/tmp8ilw7aoz.png', '-auxBPs', '(5,9):edge5=s,edge3=h,color=#008000']
Output file: /tmp/tmp8ilw7aoz.png
As we can see, the drawing is different than we would expect, the non-canonical basepair breaks the hairpin loop into two loops. This is because the standard VARNA (v3.93) will try to complete the secondary structure by adding as many non-crossing basepairs as possible from the auxiliary list. The non-standard VARNA version from commit a463cfe allows us to keep bases in the original positions while adding the auxiliary basepairs with option keep
. However, the keep
option cannot pass the syntax check in normal mode.
v = varnaapi.Structure(structure=dbn)
v.add_aux_BP(5,9, edge5="s", edge3="h", color='green', keep=True)
v.show()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[4], line 2 1 v = varnaapi.Structure(structure=dbn) ----> 2 v.add_aux_BP(5,9, edge5="s", edge3="h", color='green', keep=True) 3 v.show() File ~/miniconda3/envs/varnaapi/lib/python3.9/site-packages/varnaapi/models.py:113, in BasicDraw.add_aux_BP(self, i, j, edge5, edge3, stericity, color, thickness, **kwargs) 100 """Add an additional base pair `(i,j)`, possibly defining and using custom style 101 102 Args: (...) 109 thickness: Base-pair thickness 110 """ 111 assert_valid_interval(self.length, i, j) --> 113 self.aux_BPs.append((i, j, _BPStyle(edge5=edge5, edge3=edge3, stericity=stericity, color=color, thickness=thickness, **kwargs))) File ~/miniconda3/envs/varnaapi/lib/python3.9/site-packages/varnaapi/param.py:360, in _BPStyle.__init__(self, **kwargs) 358 raise TypeError('Value of {} should be one of {}'.format(key, BP_CHOICES[key])) 359 else: --> 360 raise TypeError('{} is not a valid keyword'.format(key)) 361 self.values = res TypeError: keep is not a valid keyword
In order to use the non-standard version, VARNA API requires to turn on the hack mode, which will turn off most of the checks and allow us to pass additional options
varnaapi.enable_hack()
Then, we set the path to the hacked version and draw the structure again
varnaapi.set_VARNA('VARNA-module.jar')
v = varnaapi.Structure(structure=dbn)
v.add_aux_BP(5,9, edge5="s", edge3="h", color='green', keep=True)
v.show()
['java', '-cp', 'VARNA-module.jar', 'fr.orsay.lri.varna.applications.VARNAcmd', '-sequenceDBN', '', '-structureDBN', '..((......))..', '-o', '/tmp/tmp6gvy016s.png', '-auxBPs', '(5,9):edge5=s,edge3=h,color=#008000,keep=True']
Output file: /tmp/tmp6gvy016s.png
We can also set the command line option -keepAuxBPs
to True
if we want to keep all basepairs in auxiliary list as non-canonical.
v = varnaapi.Structure(structure=dbn)
v.add_aux_BP(5, 9, edge5="s", edge3="h", color='green')
v.add_aux_BP(6, 8, edge5="wc", edge3="h", color='red')
v.update(keepAuxBPs=True)
v.show()
['java', '-cp', 'VARNA-module.jar', 'fr.orsay.lri.varna.applications.VARNAcmd', '-sequenceDBN', '', '-structureDBN', '..((......))..', '-o', '/tmp/tmpd1u867zl.png', '-keepAuxBPs', 'True', '-auxBPs', '(5,9):edge5=s,edge3=h,color=#008000;(6,8):edge3=h,color=#ff0000']
Output file: /tmp/tmpd1u867zl.png