1.计算Tajima's D
通过vcftools对不同物种的Tajima'D进行滑窗计算:
vcftools --vcf str.vcf --out pop1.tajimaD --TajimaD 500000 --keep pop1.txt
vcftools --vcf str.vcf --out pop2.tajimaD --TajimaD 500000 --keep pop2.txt
#绘制Tajima D windows=500000kb
library(ggplot2)
2.在R中读取TajimaD文件
pop1_tajimaD<-read.table("vcftools/pop1.tajimaD.Tajima.D",header = T)
pop2_tajimaD<-read.table("vcftools/pop2.tajimaD.Tajima.D",header = T)
3.删除空值并将两个结果进行合并
pop1_tajimaD1<-na.omit(pop1_tajimaD)
pop2_tajimaD1<-na.omit(pop2_tajimaD)
pop1_tajimaD1$species <- "Species1"
pop2_tajimaD1$species <- "Species2"
merge <- rbind(pop1_tajimaD1,pop2_tajimaD1)
4.绘图
ggplot(sll,aes(x=species,y=TajimaD,color=species,fill=species))+
scale_y_continuous(breaks=-2:4)+
scale_color_manual(values = my_pal,guide="none")+
scale_fill_manual(values = my_pal,guide="none")+
stat_boxplot(geom = "errorbar",width=0.2,size=1)+
geom_boxplot(width=0.2,fill="white",size=1,outlier.shape = NA)+ #绘制箱线图
gghalves::geom_half_violin(aes(fill=species),alpha=0.5,size=1,side = "r",position = position_nudge(x = .15, y = 0))+ #绘制小提琴图
gghalves::geom_half_point(aes(fill=species),side = "l",range_scale = 0.3,alpha=0.5,size=1)+ #绘制点图
labs(x="Species",y="TajimaD")+ theme_bw()+
theme(legend.title = element_blank(),
legend.background = element_blank(),
#legend.key = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.position='right')