Modify the sfs plot

master
tforest 2023-07-13 15:29:27 +02:00
parent 2b5dc75f30
commit 20d66bf1cc
2 changed files with 13 additions and 1 deletions

View File

@ -1,2 +1,2 @@
from frst import sfs_tools, customgraphics, vcf_utils, sfs_tools, stats_sfs, dependences from frst import sfs_tools, customgraphics, vcf_utils, sfs_tools, stats_sfs, dependences, swp2

View File

@ -227,11 +227,23 @@ def barplot_sfs(sfs, xlab, ylab, folded=True, title = "Barplot", transformed =
sum_val = sum(sfs_val) sum_val = sum(sfs_val)
for k, sfs_bin in enumerate(sfs_val): for k, sfs_bin in enumerate(sfs_val):
sfs_val[k] = sfs_bin / sum_val sfs_val[k] = sfs_bin / sum_val
#print(sum(sfs_val))
#build the plot #build the plot
title = title+" (n="+str(len(sfs_val)+1)+") [folded="+str(folded)+"]"+" [transformed="+str(transformed)+"]" title = title+" (n="+str(len(sfs_val)+1)+") [folded="+str(folded)+"]"+" [transformed="+str(transformed)+"]"
print("SFS =", sfs) print("SFS =", sfs)
if folded:
xlab = "Minor allele frequency"
if transformed: if transformed:
print("Transformed SFS ( n =",len(sfs_val)+1, ") :", sfs_val) print("Transformed SFS ( n =",len(sfs_val)+1, ") :", sfs_val)
plt.axhline(y=1/n, color='r', linestyle='-')
else:
if normalized:
# then plot a theoritical distribution as 1/i
expected_y = [1/(2*x+1) for x in list(sfs.keys())]
print(sum(expected_y))
plt.plot([x for x in list(sfs.keys())], expected_y, color='r', linestyle='-')
#print(expected_y)
customgraphics.barplot(x = [x for x in list(sfs.keys())], y= sfs_val, xlab = xlab, ylab = ylab, title = title) customgraphics.barplot(x = [x for x in list(sfs.keys())], y= sfs_val, xlab = xlab, ylab = ylab, title = title)
plt.show() plt.show()