0
1

ETE Toolkitとは

ETE(Environment for Tree Exploration)は、系統樹の構築、分析、可視化をpythonで操作できる計算フレームワークです。これまで、ETEのバージョン3であるete3が使用されてきましたが、この環境構築は公式ページの方法に従っても上手くいきません(私の環境では)。最近はete4が新しく開発されているようなので、ete4の環境構築を試しました。

動作環境

  • Windows11 + WSL2
  • Ubuntu
  • python 3.9.19

環境構築フロー

  1. 仮想環境の準備
  2. パッケージのインストール

仮想環境の準備

私は普段anacondaを使っていましたが、ete4はpipで提供されています。condaとpipは併用したくないので、venvで系統樹解析用の環境を新しく用意することにしました。

Ubuntu
$ mkdir tree_analysis #系統樹解析を実施するディレクトリを用意
$ cd tree_analysis #系統樹解析を実施するディレクトリに移動
$ python -m venv venv #仮想環境を作成
$ source venv/bin/activate #仮想環境を起動
(venv)$

パッケージのインストール

パッケージは以下の二つをインストールします。

Ubuntu
(venv)$ pip install https://github.com/etetoolkit/ete/archive/ete4.zip
(venv)$ pip install pyqt6

動作確認

ete4の使用方法はこのドキュメントにまとまっています。試しに、このドキュメントに紹介されたプログラムの一つをtest.pyとして実行します(python test.py)。

test.py
from ete4 import Tree
from ete4.treeview import faces, AttrFace, TreeStyle, NodeStyle


def layout(node):
    if node.is_leaf:
        N = AttrFace('name', fsize=30)
        faces.add_face_to_node(N, node, 0, position='aligned')


def get_example_tree():
    # Set dashed blue lines in all leaves.
    nst1 = NodeStyle()
    nst1['bgcolor'] = 'LightSteelBlue'
    nst2 = NodeStyle()
    nst2['bgcolor'] = 'Moccasin'
    nst3 = NodeStyle()
    nst3['bgcolor'] = 'DarkSeaGreen'
    nst4 = NodeStyle()
    nst4['bgcolor'] = 'Khaki'

    t = Tree('((((a1,a2),a3), ((b1,b2),(b3,b4))), ((c1,c2),c3));')
    for n in t.traverse():
        n.dist = 0

    n1 = t.common_ancestor(['a1', 'a2', 'a3'])
    n1.set_style(nst1)
    n2 = t.common_ancestor(['b1', 'b2', 'b3', 'b4'])
    n2.set_style(nst2)
    n3 = t.common_ancestor(['c1', 'c2', 'c3'])
    n3.set_style(nst3)
    n4 = t.common_ancestor(['b3', 'b4'])
    n4.set_style(nst4)
    ts = TreeStyle()
    ts.layout_fn = layout
    ts.show_leaf_name = False

    ts.mode = 'c'
    ts.root_opening_factor = 1
    return t, ts


if __name__ == '__main__':
    t, ts = get_example_tree()
    t.show(tree_style=ts)
    # Or save it with:
    #   t.render('node_background.png', w=400, tree_style=ts)

以下のような出力が得られ、系統樹のレンダリングに成功しました。

ete4.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1