etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
773 stars 216 forks source link

data type issues on staple_layouts from LayoutBarplot branch #660

Open dengzq1234 opened 1 year ago

dengzq1234 commented 1 year ago

I noticed the following lines which contains data type error in regards to properties fetching in https://github.com/etetoolkit/ete/blob/LayoutBarplot/ete4/smartview/renderer/layouts/staple_layouts.py

1) line 57

prop = node.props.get(p)
if type(prop) in [int, float]:
vals[metric][1] = min(minval, prop)
vals[metric][2] = max(maxval, prop)
elif prop is None or prop == "":
return
else:
uniqvals.add(prop)

prop will be string at the first place when fetch from the node, so I would suggest:

prop = node.props.get(p)
try:
    prop = float(prop) # prop by default is string 
    if type(prop) in [int, float]:
        vals[metric][1] = min(minval, prop)
        vals[metric][2] = max(maxval, prop)
    elif prop is None or prop == "":
        return
    else:
        uniqvals.add(prop)
except:
    pass

2) line 109 the same issue,

return node.props.get(self.size_prop, 0) / maxval * self.width

should be:

return float(node.props.get(self.size_prop, 0)) / maxval * self.width