Biopython: The quickest way to biuld and visualize tree with python
Align your Sequence
Set your arguments
|
Import libraries
|
Pre-align
|
clustalw2 -infile=Base.fa -outfile=assignment2.fasta -output=fasta
Trimming the gap
Gap from the head and tail could have huge effects on the result of the tree. So, we should avoid the side effects from the gaps because of the length-difference.
Here, we just counting the gaps from the head and tail of each sequences and retain the largest number. On the other hand, the numbers’ of gap extension were printed out so you can customize your own.
|
Gap head list: [115, 115, 86, 86, 86, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 91, 170, 70, 115, 117, 0, 115, 115, 192] Gap head tail: [13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, 0, 12] Gap head: 192 Gap head: 13 Slice of alignment from position 192 to 13 Alignment with 28 rows and 167 columns
Build the tree
|
, XP_009431258.3 | | , XP_005584739.1 | | |,| NP_001036203.1 ||| ||| XP_011717782.1 || |, XP_011852471.1 || || NP_001277233.1 || ,| XP_025230146.1 || |, AAU95547.1 || || XP_011803362.1 || || XP_010378328.1 | | , XP_033039886.1 |,| |||__ XP_037851661.1 ||| |||________ XP_026309478.1 || || ___ XP_011926036.1 ||,| ||||_____ XP_017738318.1 ||| | | _______________ XP_024205865.1 | |_________| | |_______________ XP_024205864.1 | | | |_________________________________________ NP_175517.1 | | XP_008962016.1 | | XP_030866972.1 | | XP_009250187.1 | | XP_004041225.1 | | XP_004041226.1 | | XP_002827755.1 | | XP_002827754.1 _| , sp|P01241|SOMA_HUMAN | | XP_002827756.1 | | XP_024090242.1
Visualizing it with ggtree
Reference: ggplot2 extensions; 2016
|
|

How to use
The quickest way:
- input file:
sample.fasta - output file prefix:
result - tree type:
UPGMA
|
results:
- result.fasta: original aligned file (with gaps)
- result_gap.fa: Trimmed file (with gaps)
- result_scliced.Trimmed file (without gaps)
- result_gap.phb: Tree file
- result_gap.phb.png: Tree visualizing with ggtree
Biopython: The quickest way to biuld and visualize tree with python
https://karobben.github.io/2021/10/22/Bioinfor/biopython-seq2tree/









