I am trying to generate a phylogenetic tree using this code
#!/bin/python3
import re
from PIL import Image
from PyQt5.QtGui import QImage
import sys
import ete3
from ete3 import Tree
from ete3.treeview import NodeStyle
from ete3 import TreeStyle
def get_tree_dist():
'''
Read in the data and draw the tree with branch lengths
'''
# Read in the data
alignment_file = "MK.fasta"
with open("MK.fasta", "r") as f:
fasta_content = f.read()
# Create the Tree object
t = Tree("MK.fasta.treefile")
# Create a TreeStyle object
ts = TreeStyle()
ts.show_leaf_name = True
ts.show_branch_length = True
ts.show_branch_support = True
ts.scale = 150
# set the DPI value
dpi = 100
# Draw the tree
t.render("MK_tree.png", w=1000, h=800, units="px", tree_style=ts, dpi=int(dpi))
# Resize the image
img = Image.open("MK_tree.png")
img = img.resize((int(img.width * 300 / dpi), int(img.height * 300 / dpi)))
img.save("MK_tree.png", dpi=(300, 300))
# Change the DPI of the image
ii = QImage()
ii.load("MK_tree.png")
ii.setDotsPerMeterX(int(dpi / 0.0254)) # Convert inches to meters
ii.setDotsPerMeterY(int(dpi / 0.0254)) # Convert inches to meters
ii.save("MK_tree.png")
if __name__ == '__main__':
get_tree_dist()
But when I run it I got this message:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-xxx' Traceback (most recent call last): File "/mnt/d/tree3.py", line 47, in get_tree_dist()
File "/mnt/d/tree3.py", line 33, in get_tree_dist t.render("rbcL_tree.png", w=1000, h=800, units="px", tree_style=ts, dpi=int(dpi))
File "/home/xxx/.local/lib/python3.10/site-packages/ete3/coretype/tree.py", line 1392, in render return drawer.render_tree(self, file_name, w=w, h=h,
File "/home/xxx/.local/lib/python3.10/site-packages/ete3/treeview/drawer.py", line 113, in render_tree x_scale, y_scale = save(scene, imgName, w=w, h=h, units=units, dpi=dpi)
File "/home/xxx/.local/lib/python3.10/site-packages/ete3/treeview/main.py", line 754, in save ii.setDotsPerMeterX(dpi / 0.0254) # Convert inches to meters
TypeError: setDotsPerMeterX(self, a0: int): argument 1 has unexpected type 'float'
I do not know what else to do. Someone could help me please.