glyphs
Contains the Glyph class used to define the different type of glyphs that can be used to represent features, as well the basic plotting functions for GenomeBrowser
Glyph
Glyph (glyph_type:str='arrow', colors:tuple=('purple', 'orange'), alpha:float=0.8, show_name:bool=True, name_attr:str='gene', height:float=1)
A class used to define the different types of glyphs shown for different feature types.
Type | Default | Details | |
---|---|---|---|
glyph_type | str | arrow | type of the Glyph (arrow or box) |
colors | tuple | (‘purple’, ‘orange’) | can be a single color or a tuple of two colors, one for each strand |
alpha | float | 0.8 | transparency |
show_name | bool | True | |
name_attr | str | gene | default attribute to use as the name of the feature to be displayed |
height | float | 1 | height of the feature relative to other features (between 0 and 1) |
get_default_glyphs
get_default_glyphs (arrow_colors=('purple', 'orange'), box_colors=('grey',))
*Returns a dictionnary with:
- keys: feature types (str)
- values: a Glyph object*
'CDS'] default_glyphs[
Glyph object with attributes:
glyph_type: arrow
colors: ('purple', 'orange')
height: 1
alpha: 0.8
show_name: True
name_attr: gene
get_patch_coordinates
get_patch_coordinates (feature, glyphs_dict, feature_height=0.15, color_attribute=None)
= get_example_data_dir()
data_path = os.path.join(data_path, "MG1655_U00096.gff3")
gff_path =parse_gff(gff_path,
features=default_types,
feature_types="U00096.3")[0]
seq_id
apply(get_patch_coordinates, glyphs_dict=default_glyphs, axis=1) features.head().
0 (((190, 190, 190, 255, 190), (0.05, 0.2, 0.2, ...
1 (((337, 337, 2699, 2799, 2699), (0.05, 0.2, 0....
2 (((2801, 2801, 3633, 3733, 3633), (0.05, 0.2, ...
3 (((3734, 3734, 4920, 5020, 4920), (0.05, 0.2, ...
4 (((5234, 5234, 5430, 5530, 5430), (0.05, 0.2, ...
dtype: object
html_wordwrap
html_wordwrap (input_string:str, line_len=50, start=0)
"test","'UniProtKB/Swiss-Prot:P0AF03,NCBI_GP:AAC73120.1,ASAP:ABE-0000030,ECOCYC:EG11511,EcoGene:EG11511'") _format_attribute(
'<span style="color:DodgerBlue">test</span><span>: 'UniProtKB/Swiss-Prot:P0AF03,NCBI_GP:AAC73120<br>.1,ASAP:ABE-0000030,ECOCYC:EG11511,EcoGene:EG11511&<br>#x27;</span>'
get_tooltip
get_tooltip (feature, attributes, wrap=50)
apply(lambda row: get_tooltip(row, default_attributes),
features.=1)[0] axis
'<span style="color:FireBrick">CDS</span><br><span style="color:DodgerBlue">gene</span><span>: thrL</span><br><span style="color:DodgerBlue">locus_tag</span><span>: b0001</span><br><span style="color:DodgerBlue">product</span><span>: thr operon leader peptide</span>'
10] features.attributes[
OrderedDict([('ID', 'cds-AAC73120.1'),
('Parent', 'gene-b0009'),
('Dbxref',
'UniProtKB/Swiss-Prot:P0AF03,NCBI_GP:AAC73120.1,ASAP:ABE-0000030,ECOCYC:EG11511,EcoGene:EG11511'),
('Name', 'AAC73120.1'),
('gbkey', 'CDS'),
('gene', 'mog'),
('locus_tag', 'b0009'),
('orig_transcript_id', 'gnl|b0009|mrna.b0009'),
('product', 'molybdopterin adenylyltransferase'),
('protein_id', 'AAC73120.1'),
('transl_table', '11')])
get_feature_name
get_feature_name (row, glyphs_dict)
For each row of features DataFrame uses the Glyph object provided in the glyphs_dict to know which attribute to use as the name
apply(get_feature_name, glyphs_dict=default_glyphs, axis=1) features.head().
0 thrL
1 thrA
2 thrB
3 thrC
4 yaaX
dtype: object
#hide
=default_glyphs.copy()
gl"CDS"].name_attr="locus_tag"
gl[assert features.head().apply(get_feature_name, glyphs_dict=gl, axis=1)[0]=="b0001"
assert features.loc[features.type=="repeat_region"].head().apply(get_feature_name, glyphs_dict=default_glyphs, axis=1).values[0]==''
#hide
"rRNA"]=Glyph(glyph_type="box",
gl[="red",
colors=0.5,
height="locus_tag",
name_attr=True)
show_name
print(gl["rRNA"])
type=="rRNA"].head().apply(get_feature_name, glyphs_dict=gl, axis=1) features.loc[features.
Glyph object with attributes:
glyph_type: box
colors: ('red',)
height: 0.5
alpha: 0.8
show_name: True
name_attr: locus_tag
235 b0201
238 b0204
239 b0205
3061 b2588
3062 b2589
dtype: object
get_feature_patches
get_feature_patches (features:pandas.core.frame.DataFrame, left:int, right:int, glyphs_dict:dict, attributes:dict=defaultdict(<function <lambda> at 0x7f21ecf2c430>, {'CDS': ['gene', 'locus_tag', 'product']}), feature_height:float=0.15, label_vertical_offset:float=0.05, label_justify:str='center', color_attribute:str=None)
Type | Default | Details | |
---|---|---|---|
features | DataFrame | DataFrame of the features | |
left | int | left limit | |
right | int | right limit | |
glyphs_dict | dict | a dictionary of glyphs to use for each feature type | |
attributes | dict | defaultdict(<function |
dictionary with feature type as keys and a list of attributes to display when hovering as values |
feature_height | float | 0.15 | fraction of the annotation track height occupied by the features |
label_vertical_offset | float | 0.05 | |
label_justify | str | center | |
color_attribute | str | None | |
Returns | DataFrame |
=get_feature_patches(features,8000,12000, glyphs_dict=default_glyphs)
patches patches
names | xs | ys | xbox_min | color | alpha | pos | attributes | type | label_y | label_x | |
---|---|---|---|---|---|---|---|---|---|---|---|
9 | b0008 | (8238, 8238, 9091, 9191, 9091) | (0.05, 0.2, 0.2, 0.125, 0.05) | 8238 | purple | 0.8 | 8714.5 | <span style="color:FireBrick">CDS</span><br><s... | CDS | 0.25 | 8714.5 |
10 | b0009 | (9306, 9306, 9793, 9893, 9793) | (0.05, 0.2, 0.2, 0.125, 0.05) | 9306 | purple | 0.8 | 9599.5 | <span style="color:FireBrick">CDS</span><br><s... | CDS | 0.25 | 9599.5 |
11 | b0010 | (10494, 10494, 10028, 9928, 10028) | (0.05, 0.2, 0.2, 0.125, 0.05) | 10028 | orange | 0.8 | 10211.0 | <span style="color:FireBrick">CDS</span><br><s... | CDS | 0.25 | 10211.0 |
12 | b0011 | (11356, 11356, 10743, 10643, 10743) | (0.05, 0.2, 0.2, 0.125, 0.05) | 10743 | orange | 0.8 | 10999.5 | <span style="color:FireBrick">CDS</span><br><s... | CDS | 0.25 | 10999.5 |
13 | b0012 | (10830, 10830, 11215, 11315, 11215) | (0.05, 0.2, 0.2, 0.125, 0.05) | 10830 | purple | 0.8 | 11072.5 | <span style="color:FireBrick">CDS</span><br><s... | CDS | 0.25 | 11072.5 |
14 | b0013 | (11786, 11786, 11482, 11382, 11482) | (0.05, 0.2, 0.2, 0.125, 0.05) | 11482 | orange | 0.8 | 11584.0 | <span style="color:FireBrick">CDS</span><br><s... | CDS | 0.25 | 11584.0 |