|
@@ -20,6 +20,7 @@ Rectify SFS comp in parsed funct.
|
20
|
20
|
import gzip
|
21
|
21
|
import sys
|
22
|
22
|
import matplotlib.pyplot as plt
|
|
23
|
+from frst import customgraphics
|
23
|
24
|
|
24
|
25
|
def sfs_from_vcf(n, vcf_file, folded = True, diploid = True, phased = False, verbose = False,
|
25
|
26
|
strip = False, count_ext = False):
|
|
@@ -194,8 +195,9 @@ def sfs_from_parsed_vcf(n, vcf_dict, folded = True, diploid = True, phased = Fal
|
194
|
195
|
def barplot_sfs(sfs, xlab, ylab, folded=True, title = "Barplot", transformed = False):
|
195
|
196
|
sfs_val = []
|
196
|
197
|
n = len(sfs.values())
|
197
|
|
- for k in range(1, n):
|
198
|
|
- ksi = list(sfs.values())[k-1]
|
|
198
|
+ print("n =", n)
|
|
199
|
+ for k, ksi in sfs.items():
|
|
200
|
+ #ksi = list(sfs.values())[k-1]
|
199
|
201
|
# k+1 because k starts from 0
|
200
|
202
|
# if folded:
|
201
|
203
|
# # ?check if 2*n or not?
|
|
@@ -207,7 +209,8 @@ def barplot_sfs(sfs, xlab, ylab, folded=True, title = "Barplot", transformed =
|
207
|
209
|
# sfs_val.append(ksi)
|
208
|
210
|
if transformed:
|
209
|
211
|
if folded:
|
210
|
|
- sfs_val.append(ksi * k * (2*n - k))
|
|
212
|
+ #sfs_val.append(ksi * k * (2*n - k))
|
|
213
|
+ sfs_val.append(((k*(2*n - k)) / (2*n))*ksi)
|
211
|
214
|
else:
|
212
|
215
|
sfs_val.append(ksi * k)
|
213
|
216
|
else:
|
|
@@ -215,17 +218,15 @@ def barplot_sfs(sfs, xlab, ylab, folded=True, title = "Barplot", transformed =
|
215
|
218
|
|
216
|
219
|
#terminal case, same for folded or unfolded
|
217
|
220
|
if transformed:
|
218
|
|
- sfs_val.append(list(sfs.values())[n-1] * n)
|
|
221
|
+ sfs_val[-1] = list(sfs.values())[n-1] * n
|
219
|
222
|
else:
|
220
|
|
- sfs_val.append(list(sfs.values())[n-1])
|
|
223
|
+ sfs_val[-1] = list(sfs.values())[n-1]
|
221
|
224
|
#build the plot
|
222
|
225
|
title = title+" [folded="+str(folded)+"]"+" [transformed="+str(transformed)+"]"
|
223
|
|
- if ylab:
|
224
|
|
- plt.ylabel(ylab)
|
225
|
|
- if xlab:
|
226
|
|
- plt.xlabel(xlab)
|
227
|
|
- plt.title(title)
|
228
|
|
- plt.bar([i+1 for i in sfs.keys()], sfs_val)
|
|
226
|
+ print("SFS =", sfs)
|
|
227
|
+ if transformed:
|
|
228
|
+ print("Transformed SFS ( n =",len(sfs_val), ") :", sfs_val)
|
|
229
|
+ customgraphics.barplot(x = sfs.keys(), y= sfs_val, xlab = xlab, ylab = ylab, title = title)
|
229
|
230
|
plt.show()
|
230
|
231
|
|
231
|
232
|
if __name__ == "__main__":
|