API reference¶
monoseq
¶
monoseq
, a Python library for pretty-printing DNA and protein sequences
using a monospace font.
-
monoseq.
PlaintextFormat
¶ Plaintext output format.
-
monoseq.
AnsiFormat
¶ Plaintext output format with ANSI escape codes.
-
monoseq.
HtmlFormat
¶ HTML output format.
-
class
monoseq.
Format
[source]¶ Type of output formats for pretty-printed sequences.
Parameters: - annotations (list) – For each annotation level, a pair (left, right) of delimiters to use for enclosing a subsequence at that level.
- margin (tuple) – A pair (left, right) of delimiters to use for enclosing the margin (containing sequence positions).
The annotations field can have any number of items, any subsequent annotation levels will be ignored in pretty-printing sequences.
-
monoseq.
partition_range
(stop, annotations=None)[source]¶ Partition the range from 0 to stop based on annotations.
>>> partition_range(50, annotations=[[(0, 21), (30, 35)], ... [(15, 32), (40, 46)]]) [(0, 15, {0}), (15, 21, {0, 1}), (21, 30, {1}), (30, 32, {0, 1}), (32, 35, {0}), (35, 40, set()), (40, 46, {1}), (46, 50, set())]
Parameters: - stop (int) – End point (not included) of the range (similar to the stop
argument of the built-in
range()
function). - annotations (list) – For each annotation level, a list of (start, stop) pairs defining an annotated region.
Returns: Partitioning of the range as (start, stop, levels) tuples defining a region with a set of annotation levels.
Return type: list
All regions (start, stop) are defined as in slicing notation, so zero-based and stop is not included.
The annotations argument is a list of annotations. An annotation is a list of regions as (start, stop) tuples. The level of each annotation is its index in annotations.
Annotation regions can overlap (overlap within one level is ignored) and do not need to be sorted.
- stop (int) – End point (not included) of the range (similar to the stop
argument of the built-in
-
monoseq.
pprint_sequence
(sequence, annotations=None, block_length=10, blocks_per_line=6, format=Format(annotations=[], margin=('', '')))[source]¶ Pretty-print sequence for use with a monospace font.
>>> sequence = 'MIMANQPLWLDSEVEMNHYQQSHIKSKSPYFPEDKHICWIKIFKAFGT' * 4 >>> print pprint_sequence(sequence, format=PlaintextFormat) 1 MIMANQPLWL DSEVEMNHYQ QSHIKSKSPY FPEDKHICWI KIFKAFGTMI MANQPLWLDS 61 EVEMNHYQQS HIKSKSPYFP EDKHICWIKI FKAFGTMIMA NQPLWLDSEV EMNHYQQSHI 121 KSKSPYFPED KHICWIKIFK AFGTMIMANQ PLWLDSEVEM NHYQQSHIKS KSPYFPEDKH 181 ICWIKIFKAF GT
Parameters: - sequence (str or any sliceable yielding slices representable as strings.) – Sequence to pretty-print.
- annotations (list) – For each annotation level, a list of (start, stop) pairs defining an annotated region.
- block_length (int) – Length of space-separated blocks.
- blocks_per_line (int) – Number of blocks per line.
- format (
Format
) – Output format to use for pretty-printing. Some formats are pre-defined asHtmlFormat
,AnsiFormat
, andPlaintextFormat
.
Returns: Pretty-printed version of sequence.
Return type: str
All regions (start, stop) are defined as in slicing notation, so zero-based and stop is not included.
The annotations argument is a list of annotations. An annotation is a list of regions as (start, stop) tuples. The level of each annotation is its index in annotations.
Annotation regions can overlap (overlap within one level is ignored) and do not need to be sorted.
The number of annotation levels supported depends on format.
HtmlFormat
supports 10 levels,AnsiFormat
supports 3 levels and annotations are ignored completely withPlaintextFormat
.
monoseq.ipynb
¶
Convenience wrapper around monoseq
for use in the IPython Notebook.
-
monoseq.ipynb.
Seq
(sequence, annotations=None, block_length=10, blocks_per_line=6, style=DEFAULT_STYLE)[source]¶ Pretty-printed sequence object that’s displayed nicely in the IPython Notebook.
Parameters: style (str) – Custom CSS as a format string, where a selector for the top-level <pre>
element is substituted for {selector}. SeeDEFAULT_STYLE
for an example.For a description of the other arguments, see
monoseq.pprint_sequence()
.
-
monoseq.ipynb.
DEFAULT_STYLE
¶ Default CSS for styling in the IPython Notebook, suporting up to four levels of annotation. They are displayed as red, inverted, underlined, and bold.