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

Motif and Comparison mode to new format

parent 574425cd
......@@ -63,7 +63,7 @@ def _parse_vienna(ss):
return res
class VARNA(VarnaConfig):
def __init__(self, **kwargs):
def __init__(self, *args, **kwargs):
"""Classic VARNA drawing mode. Constructor from given RNA sequence or/and secondary structure.
If sequence and structure have different size, the larger one is used
and ` `s or `.`s will be added to sequence or structure to complement.
......@@ -81,7 +81,7 @@ class VARNA(VarnaConfig):
"""
super().__init__()
self._init_features()
self._read_input(**kwargs)
self._read_input(*args, **kwargs)
def _read_input(self, seq=None, structure=None):
self.length = -1
......@@ -294,19 +294,20 @@ class VARNA(VarnaConfig):
class Comparison(VARNA):
def __init__(self, seq1, structure1, seq2, structure2):
"""Drawing of two aligned RNAs.
Unlike classic [VARNA][varnaapi.VARNA] mode,
both sequences and structures __MUST__ be specified and have the same size.
Additionally, the merged secondary structures must currently be without any crossing
interactions (e.g. pseudoknots), and merging them should give a secondary structure.
Gap character is `.`.
Args:
seq1 (str): Sets the gapped nucleotide sequence for the first RNA sequence
structure1 (str): Sets the first secondary structure in Dot-Bracket Notation
seq2 (str): Sets the gapped nucleotide sequence for the second sequence
strcuture2 (str): Sets the second secondary structure in Doc-Bracket Notation
"""
"""Drawing of two aligned RNAs.
Unlike classic [VARNA][varnaapi.VARNA] mode,
both sequences and structures __MUST__ be specified and have the same size.
Additionally, the merged secondary structures must currently be without any crossing
interactions (e.g. pseudoknots), and merging them should give a secondary structure.
Gap character is `.`.
Args:
seq1 (str): Sets the gapped nucleotide sequence for the first RNA sequence
structure1 (str): Sets the first secondary structure in Dot-Bracket Notation
seq2 (str): Sets the gapped nucleotide sequence for the second sequence
strcuture2 (str): Sets the second secondary structure in Doc-Bracket Notation
"""
def _read_input(self, seq1, structure1, seq2, structure2):
if not (len(seq1) == len(structure1) == len(seq2) == len(structure2)):
raise Exception("All length should be equal")
self.seq1 = seq1
......@@ -314,51 +315,50 @@ class Comparison(VARNA):
self.seq2 = seq2
self.structure2 = structure2
self.length = len(seq1)
self._init_features()
def _gen_input_cmd(self):
return " -comparisonMode True -firstSequence \"{}\" -firstStructure \"{}\" -secondSequence \"{}\" -secondStructure \"{}\"".format(self.seq1, self.structure1, self.seq2, self.structure2)
return ["-comparisonMode", str(True), "-firstSequence", self.seq1, "-firstStructure", self.structure1, "-secondSequence", self.seq2, "-secondStructure", self.structure2]
def __repr__(self):
return repr((self.seq1, self.structure1, self.seq2, self.structure2))
class Motif(VARNA):
def __init__(self, motif, sequence=None):
"""Special class for motif drawing.
A motif is a rooted ordered tree, similar to a secondary structure,
but whose leaves may represent base paired positions, named open base
pairs or open paired leaves and denoted by `(*)`, and the root always
represents a closing base pair. A motif can also be seen as an union
of consecutive loops. The figure below represents `((*)(*)(((*)(*))))`.
Motif class inherits from [VARNA][varnaapi.VARNA] with some pre-set
parameters.
- rotation is set at `180`
- default base pair style is `simple`
- base number is hidden by setting default color to white
(default background color)
A dummy base pair is added after each open base pair and in front of
the root, as shown in the figure below.
Therefore, the index of bases is changed after creating the object.
For example, the index of first base of root is `1` instead of `0`.
The default bases style for root is
`BasesStyle(fill="#606060", outline="#FFFFFF",number="#FFFFFF")` and
`BasesStyle(fill="#DDDDDD", outline="#FFFFFF", number="#FFFFFF")` for
dummy bases. One can change them using
[set_root_bases_style][varnaapi.Motif.set_root_bases_style] and
[set_dummy_bases_style][varnaapi.Motif.set_dummy_bases_style].
"""Special class for motif drawing.
A motif is a rooted ordered tree, similar to a secondary structure,
but whose leaves may represent base paired positions, named open base
pairs or open paired leaves and denoted by `(*)`, and the root always
represents a closing base pair. A motif can also be seen as an union
of consecutive loops. The figure below represents `((*)(*)(((*)(*))))`.
Motif class inherits from [VARNA][varnaapi.VARNA] with some pre-set
parameters.
- rotation is set at `180`
- default base pair style is `simple`
- base number is hidden by setting default color to white
(default background color)
A dummy base pair is added after each open base pair and in front of
the root, as shown in the figure below.
Therefore, the index of bases is changed after creating the object.
For example, the index of first base of root is `1` instead of `0`.
The default bases style for root is
`BasesStyle(fill="#606060", outline="#FFFFFF",number="#FFFFFF")` and
`BasesStyle(fill="#DDDDDD", outline="#FFFFFF", number="#FFFFFF")` for
dummy bases. One can change them using
[set_root_bases_style][varnaapi.Motif.set_root_bases_style] and
[set_dummy_bases_style][varnaapi.Motif.set_dummy_bases_style].
Args:
motif (str): Motif in Dot-Bracket Notation.
`(*)` is used to represent open base pair.
sequence (str): Chain of characters for motif. Note that sequence
should exactly match with motif, _i.e._ Equal length and same
positions for all `*`.
Args:
motif (str): Motif in Dot-Bracket Notation.
`(*)` is used to represent open base pair.
sequence (str): Chain of characters for motif. Note that sequence
should exactly match with motif, _i.e._ Equal length and same
positions for all `*`.
"""
"""
def _read_input(self, motif, sequence=None):
seq = ""
struct = ""
extra_bps = []
......@@ -390,17 +390,14 @@ class Motif(VARNA):
extra_bps.append((0, self.length - 1))
self.extra_bps = extra_bps
self._init_features()
# Default Bases Styles
self.rootBasesStyle = BasesStyle(fill="#606060", outline="#FFFFFF",number="#FFFFFF")
self.dummyBasesStyle = BasesStyle(fill="#DDDDDD", outline="#FFFFFF", number="#FFFFFF")
self.rootBasesStyle = BasesStyle(fill="#606060", outline="#FFFFFF")
self.dummyBasesStyle = BasesStyle(fill="#DDDDDD", outline="#FFFFFF")
self.default_color['baseNum'] = "#FFFFFF"
self.params['bpStyle'] = 'simple'
self.params['rotation'] = 180
self.update(baseNum="#FFFFFF", bpStyle='simple', rotation=180)
def _gen_input_cmd(self):
return " -sequenceDBN \"{}\" -structureDBN \"{}\"".format(self.sequence, self.structure)
return ["-sequenceDBN", self.sequence, "-structureDBN", self.structure]
def set_dummy_bases_style(self, style):
"""Set style for dummy bases. Argument is a [BasesStyle][varnaapi.BasesStyle] object.
......@@ -420,7 +417,7 @@ class Motif(VARNA):
dummybps = []
for (i,j) in self.extra_bps:
dummybps += [i, j]
self.add_aux_BP(i=i, j=j, color="#DDDDDD", thickness=1)
self.add_aux_BP(i=i, j=j, color="#DDDDDD")
self.add_aux_BP(i=1, j=self.length-2, color="#000000", thickness=2)
self.add_bases_style(self.rootBasesStyle, [1, self.length-2])
......
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