Skip to content

Commit

Permalink
ncbi_taxonomy_layouts.py: Do not force a download of taxid2color.json…
Browse files Browse the repository at this point in the history
… until needed.

Otherwise, just installing ete would download it, and it is not
necessary if we never use the ncbi layout.
  • Loading branch information
jordibc committed Oct 30, 2023
1 parent a9fe0f9 commit e8dda13
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions ete4/smartview/renderer/layouts/ncbi_taxonomy_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
__all__ = [ "LayoutLastCommonAncestor" ]


taxid2color_file = ETE_DATA_HOME + '/taxid2color.json'

if not os.path.exists(taxid2color_file):
url = ('https://github.com/etetoolkit/ete-data/raw/main'
'/layouts/taxid2color.json')
update_ete_data(taxid2color_file, url)

with open(taxid2color_file) as handle:
_taxid2color = json.load(handle)

def get_level(node, level=0):
if node.is_root:
return level
Expand All @@ -43,16 +33,24 @@ def __init__(self, name="Last common ancestor",
self.column = column

def get_color(self, node):
color = node.props.get('sci_name_color', None)
color = node.props.get('sci_name_color')
if color:
return color

taxid = node.props.get('taxid', None)
color = _taxid2color.get(str(taxid))
if color:
return color
# Make sure we have the big file with all the colors.
taxid2color_file = ETE_DATA_HOME + '/taxid2color.json'

if not os.path.exists(taxid2color_file):
url = ('https://github.com/etetoolkit/ete-data/raw/main'
'/layouts/taxid2color.json')
update_ete_data(taxid2color_file, url)

with open(taxid2color_file) as handle:
_taxid2color = json.load(handle)

return 'lightgray'
# Use it to colorize according to taxid.
taxid = node.props.get('taxid')
return _taxid2color.get(taxid, 'lightgray')


def set_node_style(self, node):
Expand Down

0 comments on commit e8dda13

Please sign in to comment.