Classes to view sequences.
The viewer can display sequences and annotations, as in the following:
> "Unnamed" (550bp)
----------------GFP----------------
|<START
---- -----------RFP-----------
0 CCCAGGACTAGCGACTTTCCGTAACGCGACCTAACACCGGCCGTTCCTTCGAGCCAGGCAAATGTTACGTCACTTCCTTAGATTT
GGGTCCTGATCGCTGAAAGGCATTGCGCTGGATTGTGGCCGGCAAGGAAGCTCGGTCCGTTTACAATGCAGTGAAGGAATCTAAA
------GFP------
-----------------------------------------RFP-----------------------------------------
85 TGAACAGCGCCGTACCCCGATATGATATTTAGATATATAGCAGTTACACTTGGGGTTGCTATGGACTTAGATCTGCTGTATGTTT
ACTTGTCGCGGCATGGGGCTATACTATAAATCTATATATCGTCAATGTGAACCCCAACGATACCTGAATCTAGACGACATACAAA
-----------------------------------------RFP-----------------------------------------
170 TCTTACCTTCCGCATCAGGGGACAATTCGCCAGTAGAATTCAGTTTGTGCGTGAGAACATAAGATTGAATCCCACGCAGGCACAA
AGAATGGAAGGCGTAGTCCCCTGTTAAGCGGTCATCTTAAGTCAAACACGCACTCTTGTATTCTAACTTAGGGTGCGTCCGTGTT
---------------------RFP----------------------
255 GCAGGGCGGGCAGACTCTATAGGTCCTAAGACCCTGAGACTGCGTCCTCAAGATACAGGTTAACAATCCCCGTATGGAGCCGTTC
CGTCCCGCCCGTCTGAGATATCCAGGATTCTGGGACTCTGACGCAGGAGTTCTATGTCCAATTGTTAGGGGCATACCTCGGCAAG
340 TTAGCATGACCCGACAGGTGGGCTTGGCTCGCGTAAGTTGAGTGTTGCAGATACCTGCTGCTGCGCGGTCTAGGGGGAATCGCCG
AATCGTACTGGGCTGTCCACCCGAACCGAGCGCATTCAACTCACAACGTCTATGGACGACGACGCGCCAGATCCCCCTTAGCGGC
425 ATTTTGACGTAGGATCGGTAATGGGCAGTAAACCCGCAACTATTTTCAGCACCAGATGCAAGTTTCCCTAGAAAGCGTCATGGTT
TAAAACTGCATCCTAGCCATTACCCGTCATTTGGGCGTTGATAAAAGTCGTGGTCTACGTTCAAAGGGATCTTTCGCAGTACCAA
510 TGCAATCTCCTTAGGTCACAGCAAACATAGCAGCCCCTGT
ACGTTAGAGGAATCCAGTGTCGTTTGTATCGTCGGGGACA
Functions
|
Break an interable into chunks of size at most ‘n’ |
|
Indent lines |
|
Prepend lines with a label |
|
Converts a string to lines of length <= width |
Classes
|
SequenceViewer constructor |
|
|
|
A row in a |
|
A class that views longs sets of sequences. |
|
Class for managing string columns |
Flags for annotation directions |
jdna.viewer.
FASTAItem
(sequence)[source]¶Bases: jdna.viewer.SequenceViewer
SequenceViewer constructor
sequences (list) – list of sequences to view
sequence_labels (list) – optional labels to apply to sequence. Include the ‘{index}’ to enumerate the base pairs.
foreground_colors (list) – optional list base pair foreground colors (hex or common name) to apply to each sequence. If a string is provided, color will be applied to all sequences. If provided with “RANDOM”, a random color will be assigned to each sequence.
background_colors (list) – optional list base pair background colors (hex or common name) to apply to each sequence. Usage is analogous to foreground_colors parameter.
indent (int) – spacing before start of string and start of base pairs
width (string) – width of the view window for the sequences (e.g. width=100 would mean rows of at most len 100 characters
spacer (string) – string to apply inbetween rows (default is newline)
name (basestring) – optional name for this viewer, to be displayed in the header
window (tuple) – tuple of the start and end points of the viewing window
description (basestring) – optional description for this viewer
metadata (dict) – optional metadata to display in the header
_annotate_rows
(rows)¶Annotate the rows using the viewer’s annotations
annotate
(start, end, label=None, fill=None, color=None, background=None, top=True)¶Annotates this viewer object starting from ‘start’ to ‘end’ inclusively.
start (int) – inclusive start
end (int) – inclusive end
label (basestring | StringColumn) – optional label to apply to the annotation
fill (string) – the fill character to use to (e.g. ‘<’, ‘>’, ‘^’) to fill in whitespace
color (string) – the foreground color to apply to the annotation (hex or common name)
background (string) – the foreground color to apply to the annotation (hex or common name)
None
None
header
¶Return the formatted header and metadata
set_window
(start, end)¶Sets the inclusive viewing window
jdna.viewer.
SequenceRow
(lines, labels, indent, start, end, line_colors=None, line_backgrounds=None)[source]¶Bases: object
A row in a SequenceViewer
instance. Can be comprised of multiple sequences (i.e. lines)
and can be annotated with ‘features’.
SequenceRow constructor
lines (list) – list of lines to display. Lengths of all lines must all be equivalent.
labels (list) – list of labels to apply to each line
indent (string) – indent to apply to the lines
start (int) – start bp of this row
end (int) – end bp of this row
absolute_annotate
(start, end, fill, label, color=None, background=None, top=True)[source]¶Applyt annotation to this row using absolute start and ends for THIS row.
start (int) – inclusive start
end (int) – inclusive end
fill (basestring) – what to fill whitespace with
label (basestring) – annotation label
None
None
annotate
(start, end, fill, label='', color=None, background=None, top=True, wrap=False)[source]¶Annotate the sequence row. If ‘start’ or ‘end’ is beyond, the expected start or end for this row, the annotation will automatically be truncated.
start (int) – inclusive start
end (int) – inclusive end
fill – what to fill whitespace with
label (basestring) – optional label to apply to the annotation
in_bounds
(x)[source]¶Checks if the index ‘x’ is in between row start and end (inclusive)
x (int) – index
if in bounds
bool
make_annotation
(label, span, fill='*', color=None, background=None)[source]¶Make an annotation with ‘label’ spanning inclusive base pairs indices ‘span’
label (basestring) – annotation label
span (tuple) – the start and end (inclusive) of the annotation
fill (basestring) – what to fill whitespace with
jdna.viewer.
SequenceViewer
(sequences, sequence_labels=None, apply_indices=[0], foreground_colors=None, background_colors=None, indent=10, width=85, spacer='n', header_spacer='n', name='Unnamed', window=(0, None), description='', metadata=None)[source]¶Bases: object
A class that views longs sets of sequences.
SequenceViewer constructor
sequences (list) – list of sequences to view
sequence_labels (list) – optional labels to apply to sequence. Include the ‘{index}’ to enumerate the base pairs.
foreground_colors (list) – optional list base pair foreground colors (hex or common name) to apply to each sequence. If a string is provided, color will be applied to all sequences. If provided with “RANDOM”, a random color will be assigned to each sequence.
background_colors (list) – optional list base pair background colors (hex or common name) to apply to each sequence. Usage is analogous to foreground_colors parameter.
indent (int) – spacing before start of string and start of base pairs
width (string) – width of the view window for the sequences (e.g. width=100 would mean rows of at most len 100 characters
spacer (string) – string to apply inbetween rows (default is newline)
name (basestring) – optional name for this viewer, to be displayed in the header
window (tuple) – tuple of the start and end points of the viewing window
description (basestring) – optional description for this viewer
metadata (dict) – optional metadata to display in the header
annotate
(start, end, label=None, fill=None, color=None, background=None, top=True)[source]¶Annotates this viewer object starting from ‘start’ to ‘end’ inclusively.
start (int) – inclusive start
end (int) – inclusive end
label (basestring | StringColumn) – optional label to apply to the annotation
fill (string) – the fill character to use to (e.g. ‘<’, ‘>’, ‘^’) to fill in whitespace
color (string) – the foreground color to apply to the annotation (hex or common name)
background (string) – the foreground color to apply to the annotation (hex or common name)
None
None
header
¶Return the formatted header and metadata
jdna.viewer.
StringColumn
(strings=None, color=None, background=None, fill=None)[source]¶Bases: object
Class for managing string columns
StringColumn constructor.
strings (list) – list of strings
condense
(rows)[source]¶Condense a list of StringColumn
into the minimum number of StringColumns comprising of columns stripped
of white space. Briefly, this is similar to the following procedure:
input = [
'label ',
' label2 ',
' label3 '
]
# >> CONDENSE
output = [
'label label2 ',
' label3 '
]
rows –
jdna.viewer.
prepend_lines
(lines, label_iterable, indent, fill=' ', align='<')[source]¶Prepend lines with a label
lines (list) – lines to prepend
indent (int) – number of spaces between start of label and start of line
fill (what to fill the spaces) – default ‘ ‘
align (string) – either left “<”, center “^” or right “>”
new prepended lines
list