Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AMIBIO
VARNA-api
Commits
57480deb
Commit
57480deb
authored
Dec 05, 2020
by
htyao
Browse files
Doc for annotation
parent
f1c4f4ca
Changes
4
Hide whitespace changes
Inline
Side-by-side
docs/annotation.md
0 → 100644
View file @
57480deb
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
[
VARNA.add_annotation
](
varna.md#varnaapi.VARNA.add_annotation
)
.
Four annotation types allowed in VARNA are represented by four objects below.
::: varnaapi
selection:
members: ["BaseAnnotation", "LoopAnnotation", "HelixAnnotation", "StaticAnnotation"]
docs/varnaapi.md
View file @
57480deb
::: varnaapi
selection:
filters: ["!^VARNA", "!^_", "__init__"]
filters: ["!^VARNA", "!^_", "__init__"
, "!Annotation"
]
mkdocs.yml
View file @
57480deb
...
...
@@ -8,6 +8,7 @@ theme:
nav
:
-
Overview
:
index.md
-
API
:
varnaapi.md
-
Annotation
:
annotation.md
-
VARNA
:
varna.md
plugins
:
...
...
@@ -19,6 +20,8 @@ plugins:
filters
:
-
"
!^_"
-
"
^__init__$"
rendering
:
show_root_toc_entry
:
False
watch
:
-
varnaapi.py
...
...
varnaapi.py
View file @
57480deb
...
...
@@ -129,11 +129,13 @@ class BasesStyle:
class
_Annotation
:
"""Basic Annotation
"""
def
__init__
(
self
,
text
,
type
,
color
=
"#000000"
,
size
=
10
):
self
.
text
=
text
self
.
type
=
type
self
.
color
=
color
self
.
size
=
size
self
.
size
=
size
#: int: font size
def
asdict
(
self
):
return
{
'text'
:
self
.
text
,
'type'
:
self
.
type
,
'color'
:
self
.
color
,
...
...
@@ -160,22 +162,49 @@ class _ObjectAnnotation(_Annotation):
class
BaseAnnotation
(
_ObjectAnnotation
):
def
__init__
(
self
,
text
,
anchor
,
color
=
"#000000"
,
size
=
10
):
def
__init__
(
self
,
text
:
str
,
anchor
:
int
,
color
=
"#000000"
,
size
=
10
):
"""Annoation on a base.
Args:
text: Annotation caption
anchor: Index of base to annotate
color (Hex): Annotation color
size (int): Font size
"""
super
().
__init__
(
text
,
'B'
,
color
,
size
)
class
LoopAnnotation
(
_ObjectAnnotation
):
"""Same as [BaseAnnotation][varnaapi.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
=
10
):
super
().
__init__
(
text
,
'L'
,
anchor
,
color
,
size
)
class
HelixAnnotation
(
_ObjectAnnotation
):
"""Same as [BaseAnnotation][varnaapi.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
=
10
):
super
().
__init__
(
text
,
'H'
,
anchor
,
color
,
size
)
class
StaticAnnotation
(
_Annotation
):
def
__init__
(
self
,
text
,
x
,
y
,
color
=
"#000000"
,
size
=
10
):
"""Annotation on a specified position in VARNA drawing.
Unlike [BaseAnnotation][varnaapi.BaseAnnotation], argument `anchor` is omitted.
However, arguments `x` and `y` are needed to specify annotation position.
__Note:__ 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")
"""
super
().
__init__
(
text
,
'P'
,
color
,
size
)
self
.
x
=
x
self
.
y
=
y
...
...
@@ -489,7 +518,10 @@ class VARNA:
self
.
bases_styles
[
style
]
=
self
.
bases_styles
.
get
(
style
,
set
()).
union
({
i
+
1
for
i
in
bases
})
def
add_annotation
(
self
,
annotation
):
def
add_annotation
(
self
,
annotation
:
_Annotation
):
"""Add an annotation.
Argument should be a valid [Annotation](/annotation/) object
"""
# Assert is annotation
if
not
isinstance
(
annotation
,
_Annotation
):
raise
Exception
(
"Should be a valid annotation object"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment