ete icon indicating copy to clipboard operation
ete copied to clipboard

PyQt-related bug causing Tree.render() to fail

Open realmichaelhoffert opened this issue 3 years ago • 3 comments

I'm rendering a tree in ete3 (v3.1.2):

from ete3 import Tree
import os
os.environ['QT_QPA_PLATFORM']='offscreen'

test_tree = Tree('test_file.nw')

test_tree.render('tree.png')

And getting an error:

File ~/miniconda3/envs/periodic_phyla/lib/python3.10/site-packages/ete3-3.1.2-py3.7.egg/ete3/treeview/main.py:752, in save(scene, imgName, w, h, dpi, take_region, units)
    750 else:
    751     targetRect = QRectF(0, 0, w, h)
--> 752     ii= QImage(w, h, QImage.Format_ARGB32)
    753     ii.fill(QColor(Qt.white).rgb())
    754     ii.setDotsPerMeterX(dpi / 0.0254) # Convert inches to meters

TypeError: arguments did not match any overloaded call:
  QImage(): too many arguments
  QImage(QSize, QImage.Format): argument 1 has unexpected type 'float'
  QImage(int, int, QImage.Format): argument 1 has unexpected type 'float'
  QImage(bytes, int, int, QImage.Format): argument 1 has unexpected type 'float'
  QImage(sip.voidptr, int, int, QImage.Format): argument 1 has unexpected type 'float'
  QImage(bytes, int, int, int, QImage.Format): argument 1 has unexpected type 'float'
  QImage(sip.voidptr, int, int, int, QImage.Format): argument 1 has unexpected type 'float'
  QImage(List[str]): argument 1 has unexpected type 'float'
  QImage(str, format: str = None): argument 1 has unexpected type 'float'
  QImage(QImage): argument 1 has unexpected type 'float'
  QImage(Any): too many arguments

Following the suggestion in #616 , I provide ints to h and w, but get a related error, which I think is caused by the failure to cast the result of dpi / 0.0254 as an int.

test_tree.render('tree.png', h=200, w=200)
---------------------------------------------------------------------------
File ~/miniconda3/envs/periodic_phyla/lib/python3.10/site-packages/ete3-3.1.2-py3.7.egg/ete3/treeview/main.py:754, in save(scene, imgName, w, h, dpi, take_region, units)
    752 ii= QImage(w, h, QImage.Format_ARGB32)
    753 ii.fill(QColor(Qt.white).rgb())
--> 754 ii.setDotsPerMeterX(dpi / 0.0254) # Convert inches to meters
    755 ii.setDotsPerMeterY(dpi / 0.0254)
    756 pp = QPainter(ii)

TypeError: setDotsPerMeterX(self, int): argument 1 has unexpected type 'float'

The PyQt version I am using is 5.12.9. I think this problem is related to the incompatibility introduced in pyqt v5.12 mentioned here. I was able to fix this problem by switching to a conda environment with the same version of ete3 (v3.1.2) but different versions of pyqt / qt (5.9.7).

There might be a quick solution if the line PyQt5.sip.enableoverflowchecking(False) is added to treeview/qt.py, but I haven't been able to test this myself. Attached are the specs for the environment where this issue occurred, the specs of the environment where rendering worked, my newick tree file (as txt). The code to test for this error is above.

broken_environment_spec.txt functional_environment_spec.txt test_file.txt

realmichaelhoffert avatar Jun 08 '22 20:06 realmichaelhoffert

I am having the same error on the same ete3 version.

albertaillet avatar Nov 24 '22 09:11 albertaillet

Second this. Adding PyQt5.sip.enableoverflowchecking(False) to treeview/qt.py and treeview/main.py did not fix the problem. Got the following error:

File ~/scratch-midway3/miniconda3/envs/zeqian/lib/python3.11/site-packages/ete3/treeview/main.py:571, in _FaceAreas.setattr(self, attr, val) 569 if attr not in FACE_POSITIONS: 570 raise AttributeError("Face area [%s] not in %s" %(attr, FACE_POSITIONS) ) --> 571 return super(_FaceAreas, self).setattr(attr, val)

TypeError: super(type, obj): obj must be an instance or subtype of type

zeqianli avatar Dec 21 '22 17:12 zeqianli

Came across this same issue, applying the changes in https://github.com/etetoolkit/ete/pull/617 fixed it for me.

lovelaced avatar Jan 03 '23 20:01 lovelaced