Bio.Phyloの使い方

研究会での論文読みにてTalevich, Eric, et al. "Bio. Phylo: a unified toolkit for processing, analyzing and visualizing phylogenetic trees in Biopython." BMC bioinformatics 13.1 (2012): 1.を読んだので，そのメモをば．

# Biopython とは
Bioinformatics用に開発されたPythonのライブラリ．[Biopython Tutorial and Cookbook](http://biopython.org/DIST/docs/tutorial/Tutorial.html) でその使い方が説明されている．

```
pip install biopython
```

# Bio.Phylo

Bio.Phyloは系統樹の作成ができる．

論文中ではurllib2を使用しているがpython3ではurlopenはurllibに統合されている．

```python
# coding: utf-8

from Bio import Phylo
from urllib.request import urlopen

handle = urlopen("http://www.phyloxml.org/examples/apaf.xml")

tree = Phylo.read(handle, "phyloxml")

handle.close()

Phylo.draw(tree)
```

![figure_1.png](https://qiita-image-store.s3.amazonaws.com/0/133375/bacfeea2-3293-9ee2-dcf4-fd6ac03b8078.png)


```python
# coding: utf-8

from Bio import Phylo
from urllib.request import urlopen

handle = urlopen("http://www.phyloxml.org/examples/apaf.xml")

tree = Phylo.read(handle, "phyloxml")

handle.close()

tree.root_at_midpoint()
tree.ladderize(reverse=True)

vertebrata = tree.common_ancestor("Apaf-1_HUMAN", "15_TETNG")

vertebrata.color = "fuchsia"
vertebrata.width = 3
tree.root.color = "gray"

Phylo.draw(tree)
```

![figure_2.png](https://qiita-image-store.s3.amazonaws.com/0/133375/5828e46f-a39c-db2e-8d37-34f3f556bd64.png)

draw()の代わりにdraw_ascii()を用いると系統樹をアスキーアートとして出力してくれる．

```
                                   _ 22_MOUSE
                                  |
                                 _| Apaf-1_HUMAN
                                | |
                               ,| | 12_CANFA
                               ||
                              _||___ 11_CHICK
                             | |
                             | |___________ 16_XENLA
                      _______|
                     |       |       , 14_FUGRU
                     |       |     __|
                     |       |____|  |__ 15_TETNG
                _____|            |
               |     |            |____ 17_BRARE
               |     |
               |     |    ______ 1_BRAFL
               |     | __|
         ______|     ||  |_________ 18_NEMVE
        |      |      |
        |      |      |____________ 23_STRPU
        |      |
       _|      |          _________ 26_STRPU
      | |      |_________|
      | |                |________ 25_STRPU
      | |
      | |                                    ___ CED4_CAEEL
      | |___________________________________|
  ____|                                     |_ 31_CAEBR
 |    |
 |    |                                ___ 28_DROPS
 |    |          _____________________|
 |    |   ______|                     |____ Dark_DROME
 |    |  |      |
 |    |__|      |_______________________ 29_AEDAE
 |       |
 |       |__________________________ 30_TRICA
 |
 |                                                           _ 34_BRAFL
 |                                 _________________________|
_|                           _____|                         |_ 35_BRAFL
 |                          |     |
 |                        __|     |_______________ 8_BRAFL
 |                       |  |
 |                       |  |        ___________________ 20_NEMVE
 |         ______________|  |_______|
 |        |              |          |__________________________ 21_NEMVE
 |        |              |
 |     ___|              |______________________________ 9_BRAFL
 |    |   |
 |    |   |                _____________ 3_BRAFL
 |    |   |          _____|
 |    |   |_________|     |_________________ 2_BRAFL
 |____|             |
      |             |_______________ 19_NEMVE
      |
      |                                     _____ 37_BRAFL
      |            ________________________|
      |___________|                        |____ 36_BRAFL
                  |
                  |______________________ 33_BRAFL
```

# 参考文献
Talevich, Eric, et al. "Bio. Phylo: a unified toolkit for processing, analyzing and visualizing phylogenetic trees in Biopython." BMC bioinformatics 13.1 (2012): 1.