By wuzhenzhen, 28 April, 2026

背景:基于非连锁的SNP文件(vcf文件)进行进化树的构建。

1 vcf转 phylip格式

进化树构建软件输入数据格式一般为 phylip或者 fasta格式,需要对 vcf文件进行格式转换。

(1)安装Tassel 5.0

# 官网:https://www.maizegenetics.net/tassel
(base) [root@3eb13a5fb4e6 software]:/home/software_own# wget https://tassel.bitbucket.io/installer/TASSEL_5_unix.sh # wget如果失败,可以手动下载
(base) [root@3eb13a5fb4e6 software]$bash TASSEL_5_unix.sh
# 安装位置
(base) [root@3eb13a5fb4e6 software]$cd /opt/TASSEL5

(2)对vcf文件进行sort

run_pipeline.pl -Xms1G -Xmx5G -SortGenotypeFilePlugin -inputFile ../../00.filter/all.LDfilter.vcf -outputFile all.LDfilter.sort.vcf -fileType VCF

(3)vcf文件转phylip格式

# vcf文件转phylip格式;其他常用format: Fasta, Hapmap, Plink, Phylip_Seq, Phylip_Inter, VCF
# 示例代码
run_pipeline.pl -Xms1G -Xmx5G -importGuess all.LDfilter.sort.vcf -ExportPlugin -saveAs sequences.phy -format Phylip_Inter

2 利用phylip 软件建nj树

(1)下载phylip软件

# 教程:https://blog.csdn.net/sheepyulu/article/details/137131425
(base) [root@3eb13a5fb4e6 software]$wget https://phylipweb.github.io/phylip/download/phylip-3.697.tar.gz
(base) [root@3eb13a5fb4e6 software]$tar -xvf phylip-3.697.tar.gz
(base) [root@3eb13a5fb4e6 src]$vim Makefile.unx
(base) [root@3eb13a5fb4e6 phylip-3.697]$cd ../exe

# 报错及解决
## 报错
(base) [root@3eb13a5fb4e6 src]$make -f Makefile.unx install
Building PHYLIP version 3.696
gcc  clique.o disc.o phylip.o -lm -o clique
/usr/bin/ld: disc.o:(.bss+0x0): multiple definition of `javarun'; clique.o:(.bss+0x0): first defined here
/usr/bin/ld: disc.o:(.bss+0x1): multiple definition of `firstplotblock'; clique.o:(.bss+0x1): first defined here
/usr/bin/ld: phylip.o:(.bss+0x0): multiple definition of `javarun'; clique.o:(.bss+0x0): first defined here
/usr/bin/ld: phylip.o:(.bss+0x1): multiple definition of `firstplotblock'; clique.o:(.bss+0x1): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile.unx:273: clique] Error 1
## 解决
### 添加 GCC 编译选项 -fcommon(快速修复,推荐);
### 编辑 PHYLIP 源码目录下的 Makefile.unx,找到 CFLAGS定义行(通常在文件开头)GCC 10+ 版本默认启用 -fno-common(禁止全局变量跨文件重复定义),而 PHYLIP 老代码未适配。通过添加 -fcommon选项可允许重复定义(链接时合并为一个),快速绕过问题。
(base) [root@3eb13a5fb4e6 src]$vim Makefile.unx 
### 修改 CFLAGS = -O -fcommon
(base) [root@3eb13a5fb4e6 src]$make -f Makefile.unx clean
(base) [root@3eb13a5fb4e6 src]$make -f Makefile.unx install

(2)使用 phylip软件使用 NJ方法构树

(1) 生成dnadist需要的配置文件
# phylip默认是交互运行的,因此需要写一个配置文件,放在后台运行
# 示例代码
$ echo -e "2genome_sequences.phy\nY" > dnadist.cfg

(2) 运行dnadist生成距离矩阵文件
# 示例代码:输出文件为outfile dnadist.log
dnadist < dnadist.cfg > dnadist.log

(3) 生成neighbor程序需要的配置文件
# 示例代码
mv outfile infile.dist
echo -e "infile.dist\nY" > neighbor.cfg

(4) 进行nj树构建
# 示例代码:输出文件为nj.log  outfile  outtree
neighbor < neighbor.cfg > nj.log

(5) 对结果格式进行整理
# 示例代码
less infile.dist | tr '\n' '|' | \sed 's/| / /g' | tr '|' '\n' \>infile.dist.table
less outtree | tr '\n' ' ' | \sed 's/ //g' > outtree.nwk