Browse Source

sfs plotting

tforest 1 year ago
parent
commit
ecc6fd23fc
1 changed files with 10 additions and 4 deletions
  1. 10 4
      sfs_tools.py

+ 10 - 4
sfs_tools.py View File

208
         #     else:
208
         #     else:
209
         #         sfs_val.append(ksi)
209
         #         sfs_val.append(ksi)
210
         if transformed:
210
         if transformed:
211
+            ylab = r'$ \phi_i $'
211
             if folded:
212
             if folded:
212
                 val = ((k*(2*n - k)) / (2*n))*(ksi)
213
                 val = ((k*(2*n - k)) / (2*n))*(ksi)
213
             else:
214
             else:
215
         else:
216
         else:
216
             val = ksi
217
             val = ksi
217
         sfs_val.append(val)
218
         sfs_val.append(val)
219
+
220
+        if not transformed and not normalized:
221
+            ylab = r'$ \eta_i $'
218
             
222
             
219
     #terminal case, same for folded or unfolded
223
     #terminal case, same for folded or unfolded
220
     if transformed:
224
     if transformed:
223
         last_bin = list(sfs.values())[n-1]
227
         last_bin = list(sfs.values())[n-1]
224
     sfs_val[-1] = last_bin
228
     sfs_val[-1] = last_bin
225
     if normalized:
229
     if normalized:
226
-        ylab = "Fraction of SNPs"
230
+        #ylab = "Fraction of SNPs "
231
+        ylab = r'$ \phi_i $'
227
         sum_val = sum(sfs_val)
232
         sum_val = sum(sfs_val)
228
         for k, sfs_bin in enumerate(sfs_val):
233
         for k, sfs_bin in enumerate(sfs_val):
229
             sfs_val[k] = sfs_bin / sum_val
234
             sfs_val[k] = sfs_bin / sum_val
235
+        
230
         #print(sum(sfs_val))
236
         #print(sum(sfs_val))
231
     #build the plot
237
     #build the plot
232
-    title = title+" (n="+str(len(sfs_val)+1)+") [folded="+str(folded)+"]"+" [transformed="+str(transformed)+"]"
238
+    title = title+" (n="+str(len(sfs_val))+") [folded="+str(folded)+"]"+" [transformed="+str(transformed)+"]"
233
     print("SFS =", sfs)
239
     print("SFS =", sfs)
234
     if folded:
240
     if folded:
235
         xlab = "Minor allele frequency"
241
         xlab = "Minor allele frequency"
236
     if transformed:
242
     if transformed:
237
-        print("Transformed SFS ( n =",len(sfs_val)+1, ") :", sfs_val)
238
-        plt.axhline(y=1/n, color='r', linestyle='-')
243
+        print("Transformed SFS ( n =",len(sfs_val), ") :", sfs_val)
244
+        #plt.axhline(y=1/n, color='r', linestyle='-')
239
     else:
245
     else:
240
         if normalized:
246
         if normalized:
241
             # then plot a theoritical distribution as 1/i
247
             # then plot a theoritical distribution as 1/i