Skip to content

Style classes for VARNA operations

Two helper class groups can be imported from python varnaapi.param for two VARNA operations, add_annotation and add_bases_style.

Annotation

An Annotation object represents a textual annotation added to a VARNA drawing. The object stores the text and other informtation needed. One can add Annotation to drawing using BasicDraw.add_annotation. Four annotation types allowed in VARNA are represented by four objects below.

BaseAnnotation

Bases: _Annotation

Annoation on a base.

Parameters:

Name Type Description Default
text str

Annotation caption

required
anchor int

Index of base to annotate

required
color color

Annotation color

'#000000'
size int

Font size

12
Source code in src/varnaapi/param.py
405
406
407
408
409
410
411
412
413
414
415
class BaseAnnotation(_Annotation):
    """Annoation on a base.

    Args:
        text: Annotation caption
        anchor: Index of base to annotate
        color (color): Annotation color
        size (int): Font size
    """
    def __init__(self, text:str, anchor:int, color="#000000", size=12, **kwargs):
        super().__init__(text, 'B', int(anchor), color, size, **kwargs)

HelixAnnotation

Bases: _Annotation

Same as BaseAnnotation but on an helix. Argument anchor can be index of any base in the helix of interest.

Source code in src/varnaapi/param.py
424
425
426
427
428
429
class HelixAnnotation(_Annotation):
    """Same as [BaseAnnotation][varnaapi.param.BaseAnnotation] but on an helix.
    Argument `anchor` can be index of any base in the helix of interest.
    """
    def __init__(self, text, anchor, color="#000000", size=12, **kwargs):
        super().__init__(text, 'H', int(anchor), color, size, **kwargs)

LoopAnnotation

Bases: _Annotation

Same as BaseAnnotation but on a loop. Argument anchor can be index of any base in the loop of interest.

Source code in src/varnaapi/param.py
417
418
419
420
421
422
class LoopAnnotation(_Annotation):
    """Same as [BaseAnnotation][varnaapi.param.BaseAnnotation] but on a loop.
    Argument `anchor` can be index of any base in the loop of interest.
    """
    def __init__(self, text, anchor, color="#000000", size=12, **kwargs):
        super().__init__(text, 'L', int(anchor), color, size,**kwargs)

StaticAnnotation

Bases: _Annotation

Annotation on a specified position in VARNA drawing. Unlike BaseAnnotation, argument anchor is omitted. However, arguments x and y are needed to specify annotation position.

Danger

It is unrecommended to use static annotation unless you know what you're doing

Parameters:

Name Type Description Default
x int

x-coordinate of position

required
y int

y-ccordinate of position

required

Examples:

>>> sa = StaticAnnotation("Hello World", 100, 150, color="#FF0000")
Source code in src/varnaapi/param.py
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
class StaticAnnotation(_Annotation):
    """Annotation on a specified position in VARNA drawing.
    Unlike [BaseAnnotation][varnaapi.param.BaseAnnotation], argument `anchor` is omitted.
    However, arguments `x` and `y` are needed to specify annotation position.

    Danger:
        It is unrecommended to use static annotation unless you know what you're doing

    Args:
        x (int): x-coordinate of position
        y (int): y-ccordinate of position

    Examples:
        >>> sa = StaticAnnotation("Hello World", 100, 150, color="#FF0000")
    """
    def __init__(self, text, x, y, color="#000000", size=12, **kwargs):
        super().__init__(text, 'P', (int(x), int(y)),  color, size, **kwargs)

BasesStyle

Bases: _DefaultObj

Defines a custom base-style, to be applied later to a set of bases. A BasesStyle style contains colors used for different components of a base. BasesStyle is constructed from given colors for different components.

Error

At least one argument should be given.

Parameters:

Name Type Description Default
fill color

color of inner part of base

None
outline color

color of outline of base

None
label color

base text (name) color

None
number color

base number color

None

Examples:

>>> style = BasesStyle(fill='#FF0000', outline='#00FF00')

See Also: BasicDraw.add_bases_style

Source code in src/varnaapi/param.py
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
class BasesStyle(_DefaultObj):
    """Defines a custom base-style, to be applied later to a set of bases.
    A BasesStyle style contains colors used for different components of a base.
    BasesStyle is constructed from given colors for different components.

    Error:
        At least one argument should be given.

    Args:
        fill (color): color of inner part of base
        outline (color): color of outline of base
        label (color): base text (name) color
        number (color): base number color

    Examples:
        >>> style = BasesStyle(fill='#FF0000', outline='#00FF00')

    __See Also:__ [BasicDraw.add_bases_style][varnaapi.BasicDraw.add_bases_style]
    """
    def __init__(self, fill=None, outline=None, label=None, number=None, **kwargs):
        super().__init__(fill=COLOR_DEFAULT['baseInner'], outline=COLOR_DEFAULT['baseOutline'], label=COLOR_DEFAULT['baseName'], number=COLOR_DEFAULT['baseNum'])
        if varnaapi.settings.CONFIG['hackmode']:
            self._update(fill=fill, outline=outline, label=label, number=number, **kwargs)
        else:
            self._update(fill=fill, outline=outline, label=label, number=number)

    def _update(self, **kwargs):
        """Update component _colors.
        Same rule as [\_\_init\_\_][varnaapi.param.BasesStyle.__init__]
        """
        # if fill is None and outline is None and label is None and number is None:
        #     raise Exception("At least one should not be None")
        for par, val in kwargs.items():
            if val is not None:
                self.values[par] = Color(val)

    def _to_cmd(self, **kwargs):
        """Custom command generator for BasesStyle.
        Function takes the default bases color set by user in kwargs
        """
        for par, val in kwargs.items():
            self.default[par] = val
        return ",".join(k+"="+v for k, v in self._get_diff().items() if v is not None)