Bernd and Luis,
Appreciate the reply, the generated sfs plots didn't show anything of interest, but I think I found a workaround for my data looking at the allele frequencies as histograms for the suspected ploidy pops. This is using the vcf file generated after realignment to a new genome to recover more SNPs than our normal SNP library. Don't think I can share the plot, but the histograms generally follow the distribution of ~0.5 for diploids, 0.33 / 0.66 for triploids, and 0.25 / 0.5 / 0.75 for tetraploids. Flow cytometry will have to be used for confirmation in my case.
vcf_data <- read.vcfR("final_biallelic_snps.vcf")
ad <-
extract.gt(vcf_data, element = 'AD')
colnames(ad)
matching_indices <- match(colnames(ad), metadata$id)
new_names <- metadata$genotype[matching_indices]
colnames(ad)[!
is.na(new_names)] <- new_names[!
is.na(new_names)]
#### Loop through the populations based on metadata column ####
pop_list <- unique(metadata$ploidy)
pop_list
pdf("Population_Allele_Balance.pdf", width = 8, height = 12)
par(mfrow = c(2, 1))
for (p in pop_list) {
# Get all individual IDs belonging to this population
pop_ids <- metadata$genotype[metadata$ploidy == p]
# Concatenate all AD data for all individuals in this pop
# This creates one massive pool of read counts for the population
pop_ad <- as.vector(unlist(ad[, pop_ids]))
# Calculate ratios for the entire population pool
# change >= 30 for read depth which helps reduce noisy plots
ratios_pop <- sapply(strsplit(pop_ad, ","), function(x) {
counts <- as.numeric(x)
total <- sum(counts)
if(!
is.na(total) && total >= 30) return(counts[2] / total) else return(NA)
})
ratios_pop <- ratios_pop[!
is.na(ratios_pop)]
# drops homozygous reference or alternate reads, only keeping heterozygous
ratios_het <- ratios_pop[ratios_pop > 0 & ratios_pop < 1]
# Plot
hist(ratios_het,
breaks = 100,
col = "darkorchid",
main = paste("Population:", p, "| Sites:", length(ratios_het)),
xlab = "Alternative Allele Ratio",
xlim = c(0, 1))
abline(v = c(0.25, 0.33, 0.5, 0.66, 0.75), col = "red", lty = 3)
}
dev.off()