Write various forms of phylogenetic tree in Python using ETE Toolkit

(2017/2/22, OS X El Capitan)

Introduction

I was doing phylogenetic analysis and wanted to write a phylogenetic tree that integrated alignment information, so I introduced the ETE Toolkit. With the ETE Toolkit, you can use Python to create a phylogenetic tree that integrates alignment, domains, heatmaps, and more. This time, I would like to introduce a simple phylogenetic tree, a phylogenetic tree with alignment, and other useful functions. Currently, there is no comprehensive information other than the official website, so please let me know if you have any suggestions on how to use it.

Reference site

http://etetoolkit.org

Installation

You need to install the above two. The OS is available on Mac or Linux. The official website recommends installing the ETE Toolkit using anaconda, which is often used to build Python environments. Please install anaconda by referring to the following pages. http://qiita.com/y__sama/items/5b62d31cb7e6ed50f02c

After installing anaconda, create a virtual environment and put it in with conda. As a caveat, it seems that an installation error occurs in Python 3.5 or later, so it is better to build a virtual environment as Python 3.4 (as of February 23, 2017).

$conda install -c etetoolkit ete3 ete3_external_apps

Finally, check if it was installed correctly.

$ete3 version
$ete3 build check

According to the official website, you can also build from source. http://etetoolkit.org/download/

How to use

Simple phylogenetic tree

Prepare a neick format tree file (extension can be .txt).

phylotree.py


#!/usr/bin/env python
import sys
from ete3 import PhyloTree

t = PhyloTree(sys.argv[1]) #Specify the newic file as an argument.
t.render("motifs.png ", w=2000, dpi=500) #Export file specification. w is width, h is height, unit is unit(“px”: pixels, “mm”: millimeters, “in”: inches), Dpi can be specified

画像

Circular phylogenetic tree

You can make it a circular style by specifying "c" in TreeStyle (). Besides that, TreeStyle allows you to specify various things such as node color and shape (dots, thick lines, etc.). Please refer to the official website below. http://etetoolkit.org/docs/latest/reference/reference_treeview.html?highlight=treestyle#treestyle

phylotree_circular.py


#!/usr/bin/env python
import sys
from ete3 import Tree, PhyloTree, TreeStyle

t = PhyloTree(sys.argv[1])
circular_style = TreeStyle() #TreeStyle()You can specify the shape of the phylogenetic tree with
circular_style.mode = "c" #"c"Specify circular_Make it a style tree
circular_style.scale = 60 #You can specify the scale of the node
t.render("circular_tree_3.png ", w=800, dpi=200, tree_style=circular_style)  #Export. w is width, h is height, unit is unit(“px”: pixels, “mm”: millimeters, “in”: inches), Dpi can be specified

sample.png

Phylogenetic tree with alignment

In addition to the newick file, prepare a fasta file aligned with mafft etc. I referred to the following site for how to use mafft. http://qiita.com/MaedaTaro_Umiushi/items/2d05225677ded15b19a7 In addition to the regular phylogenetic tree script, you can easily combine and visualize the phylogenetic tree and alignment by using the link_to_alignment option.

phylotree_align


#!/usr/bin/env python
import sys
from ete3 import Tree, PhyloTree, SeqMotifFace, TreeStyle

t = PhyloTree(sys.argv[1]) #Specify newic file as an argument
t.link_to_alignment(sys.argv[2])   #Link the alignment file to the tree.
t.render("motifs_align.png ", w=2000, dpi=500) #Export. w is width, h is height, unit is unit(“px”: pixels, “mm”: millimeters, “in”: inches), Dpi can be specified

画像

Other features

You can get the list of genes used for the tree as follows.

gene_list.py


import sys
from ete3 import Tree

t = Tree(sys.argv[1]) #Load the tree
gene_list = t.get_leaf_names() #Acquisition of gene name(Leaf name)
print(gene_list)

At the end

On the "The Programmable Tree Drawing Engine" page of the ETE Toolkit official website (http://etetoolkit.org/docs/latest/tutorial/tutorial_drawing.html?highlight=heatmap), everything from heatmaps to adding image files Has been shown to be possible. I will add it when I understand how to use it in the future.

Recommended Posts

Write various forms of phylogenetic tree in Python using ETE Toolkit
(Bad) practice of using this in Python
Output tree structure of files in Python
Summary of various for statements in Python
Write python modules in fortran using f2py
Draw a tree in Python 3 using graphviz
Meaning of using DI framework in Python
Summary of Excel operations using OpenPyXL in Python
Basics of I / O screen using tkinter in python3
Old openssl causes problems in various parts of python
Write Python in MySQL
Read and write NFC tags in python using PaSoRi
Various processing of Python
Ssh connection memo using ProxyCommand of ssh_config in Python
I measured various methods of interprocess communication in multiprocessing of python3
A memo of writing a basic function in Python using recursion
Write beta distribution in Python
Write python in Rstudio (reticulate)
About various encodings of Python 3
Equivalence of objects in Python
python: Basics of using scikit-learn ①
Implementation of quicksort in Python
Translate using googletrans in Python
Using Python mode in Processing
I wrote the code to write the code of Brainf * ck in python
Various ways to create an array of numbers from 1 to 10 in Python.
Pixel manipulation of images in Python
Write a binary search in Python
GUI programming in Python using Appjar
Precautions when using pit in Python
Write JSON Schema in Python DSL
Write an HTTP / 2 server in Python
Division of timedelta in Python 2.7 series
Removal of haze using Python detailEnhanceFilter
Write AWS Lambda function in Python
MySQL-automatic escape of parameters in python
Write A * (A-star) algorithm in Python
Handling of JSON files in Python
Try using LevelDB in Python (plyvel)
Implementation of life game in Python
Waveform display of audio in Python
Compiler in Python: PL / 0 syntax tree
Summary of various operations in Tensorflow
Using global variables in python functions
Write selenium test code in python
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python
Let's see using input in python
Infinite product in Python (using functools)
Implementation of desktop notifications using Python
Edit videos in Python using MoviePy
Python implementation of non-recursive Segment Tree
Law of large numbers in python
Implementation of original sorting in Python
Algorithm (segment tree) in Python (practice)
Reversible scrambling of integers in Python
Handwriting recognition using KNN in Python
Write C unit tests in Python
Try using Leap Motion in Python
Depth-first search using stack in Python