Commit ae495500 authored by htyao's avatar htyao
Browse files

Introduce Chemical Probing

parent 862bc7b1
......@@ -394,6 +394,34 @@ class StaticAnnotation(_Annotation):
"""
super().__init__(text, 'P', (int(x), int(y)), color, size)
CHEM_DEFAULT = {'glyph': 'arrow', 'dir': 'in', 'intensity': 1, 'color': Color('#0000B2')}
CHEM_CHOICES = {'glyph': ['arrow', 'dot', 'pin', 'triangle'], 'dir': ['in', 'out']}
class _ChemProb(_DefaultObj):
def __init__(self, **kwargs):
super().__init__(**CHEM_DEFAULT)
for key, val in CHEM_CHOICES.items():
if key in kwargs:
try:
assert kwargs[key] in val
self.values[key] = kwargs[key]
except AssertionError:
raise TypeError('Value of {} should be one of {}'.format(key, val))
if 'color' in kwargs:
self.values['color'] = Color(kwargs['color'])
if 'intensity' in kwargs:
self.values['intensity'] = float(kwargs['intensity'])
def to_cmd(self):
return ','.join('{}={}'.format(k, v) for k, v in self._get_diff().items())
#################
# #
# Main #
# #
#################
class VarnaConfig:
"""Create default configuration for VARNA
......
......@@ -6,7 +6,7 @@ from colour import Color
import subprocess
from deprecated import deprecated
from param import VarnaConfig, BasesStyle, _Title, _Highlight, _Annotation, _BPStyle
from param import VarnaConfig, BasesStyle, _Title, _Highlight, _Annotation, _BPStyle, _ChemProb
__version__ = '0.1.0'
......@@ -73,6 +73,8 @@ class BasicDraw(VarnaConfig):
self._title = None
self.bases_styles = {}
self.annotations = []
self.chem_prob = []
self.length = 0
def add_aux_BP(self, i:int, j:int, **kwargs):
"""Add an additional base pair `(i,j)`, possibly defining and using custom style
......@@ -146,6 +148,13 @@ class BasicDraw(VarnaConfig):
raise Exception("Should be a valid annotation object")
self.annotations.append(annotation)
def add_chem_prob(self, i, **kwargs):
try:
assert i>=0 and i < self.length-1
except AssertionError:
raise Exception("Base should be in between 0 and {}".format(self.length-1))
self.chem_prob.append((int(i), _ChemProb(**kwargs)))
def _gen_command(self):
"""
Return command to run VARNA
......@@ -197,6 +206,17 @@ class BasicDraw(VarnaConfig):
if len(self.annotations) > 0:
cmd += ["-annotations", ';'.join([t.to_cmd() for t in self.annotations])]
# Chem Prob
if len(self.chem_prob) > 0:
res = []
for i, style in self.chem_prob:
s = "{}-{}".format(i, i+1)
setting = style.to_cmd()
if not setting == "":
s += ":" + setting
res.append(s)
cmd += ["-chemProb", ";".join(res)]
return cmd
def _gen_input_cmd(self):
......
Supports Markdown
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