***** Object of Class vcfR *****
45 samples
26 CHROMs
2,274 variants
Object size: 4.2 Mb
7.873 percent missing data
***** ***** *****
Code
#remove invariant SNPsvsub<-min_mac(vsub, 1)
1.14% of SNPs fell below a minor allele count of 1 and were removed from the VCF
Code
vsub
***** Object of Class vcfR *****
45 samples
26 CHROMs
2,248 variants
Object size: 4.2 Mb
7.858 percent missing data
***** ***** *****
Code
#subset sampling file and fix pop IDssamps<-samps[samps$sample_ID %in%colnames(vsub@gt),]samps[16,5]<-"SoCal"samps[17,5]<-"SoCal"samps[18,5]<-"SoCal"#reorder sample file to match vcfsamps<-samps[match(colnames(vsub@gt)[-1],samps$sample_ID),]#convert vcfr to genogen<-vcfR2genlight(vsub)#assign popspop(gen)<-samps$Subspecies#calc FSTx<-stamppFst(gen)#reassignm<-x$Fsts#fill in upper triangle of matrixm[upper.tri(m)] <-t(m)[upper.tri(m)]#melt for plottingheat <- reshape::melt(m)
Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
the caller; using TRUE
Warning in type.convert.default(X[[i]], ...): 'as.is' should be specified by
the caller; using TRUE
0.3 plot
Code
#reorder factors for plottingplot.order<-c("tresmariae","oratrix (west)","oratrix (east)","belizensis","SoCal","unknown")heat$X1<-factor(heat$X1, levels=plot.order)heat$X2<-factor(heat$X2, levels=plot.order)#plot with labelsggplot(data = heat, aes(x=X1, y=X2, fill=value)) +geom_tile(color ="black", size=.5)+geom_text(data=heat,aes(label=round(value, 2)), size=2.25)+theme_minimal()+scale_fill_gradient2(low ="white", high ="darkgrey", space ="Lab", name="Fst") +theme(axis.text.x =element_text(angle =45, hjust =1),axis.text.y =element_text(angle =45, hjust =1))
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
Warning: Removed 6 rows containing missing values or values outside the scale range
(`geom_text()`).
Code
#ggsave(file="~/Desktop/YHPA.fst.pdf", units="in",width=4,height=3) #saves g
Source Code
---title: "YHPA.pairwise.FST"format: html: code-fold: show code-tools: truetoc: truetoc-title: Document Contentsnumber-sections: trueembed-resources: true---### load R packages; read in vcf and sample sheet```{r}#| output: falselibrary(vcfR)library(ggplot2)library(SNPfiltR)library(StAMPP)library(adegenet)v<-read.vcfR("~/Downloads/yhpa_final_filtered.vcf.gz")samps<-read.csv("~/Downloads/Table1.for.manuscript.csv")```### remove single auropalliata sample and then calculate FST between groups```{r}#remove samplevsub<-v[,colnames(v@gt) !="ao_LSUMZ_39731"]vsub#remove invariant SNPsvsub<-min_mac(vsub, 1)vsub#subset sampling file and fix pop IDssamps<-samps[samps$sample_ID %in%colnames(vsub@gt),]samps[16,5]<-"SoCal"samps[17,5]<-"SoCal"samps[18,5]<-"SoCal"#reorder sample file to match vcfsamps<-samps[match(colnames(vsub@gt)[-1],samps$sample_ID),]#convert vcfr to genogen<-vcfR2genlight(vsub)#assign popspop(gen)<-samps$Subspecies#calc FSTx<-stamppFst(gen)#reassignm<-x$Fsts#fill in upper triangle of matrixm[upper.tri(m)] <-t(m)[upper.tri(m)]#melt for plottingheat <- reshape::melt(m)```### plot```{r}#reorder factors for plottingplot.order<-c("tresmariae","oratrix (west)","oratrix (east)","belizensis","SoCal","unknown")heat$X1<-factor(heat$X1, levels=plot.order)heat$X2<-factor(heat$X2, levels=plot.order)#plot with labelsggplot(data = heat, aes(x=X1, y=X2, fill=value)) +geom_tile(color ="black", size=.5)+geom_text(data=heat,aes(label=round(value, 2)), size=2.25)+theme_minimal()+scale_fill_gradient2(low ="white", high ="darkgrey", space ="Lab", name="Fst") +theme(axis.text.x =element_text(angle =45, hjust =1),axis.text.y =element_text(angle =45, hjust =1))#ggsave(file="~/Desktop/YHPA.fst.pdf", units="in",width=4,height=3) #saves g```