-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathparseFreyjaBootstraps.py
executable file
·67 lines (48 loc) · 1.99 KB
/
parseFreyjaBootstraps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import sys
import pandas as pd
import numpy as np
from getDisplayName import *
if len(sys.argv) != 4:
raise Exception('Incorrect call to the script.')
# Data regarding the current sample passed by UNIX
freyjaOutputFile = sys.argv[1]
freyjaBootFile = sys.argv[2]
outfilename = sys.argv[3]
# Process the bootstrap result table generated by Freyja
freyja_boot = pd.read_table(freyjaBootFile, index_col=0, header=0, sep=',')
boot_names = [ getDisplayName(x) for x in list(freyja_boot) ]
percentiles = list(freyja_boot.index)
index25 = percentiles.index(0.25)
index50 = percentiles.index(0.50)
index75 = percentiles.index(0.75)
percentile25 = list(freyja_boot.iloc[index25])
percentile50 = list(freyja_boot.iloc[index50])
percentile75 = list(freyja_boot.iloc[index75])
# Import the freyja file
(lineages, abundances, freyja_names) = import_freyja_demix(freyjaOutputFile)
freyja_hits = []
for dname in set(freyja_names):
pct = 100 * sum([ y for (x,y) in zip(freyja_names, abundances) if x==dname ])
median = 100 * sum([ y for (x,y) in zip(boot_names, percentile50) if x==dname ])
spread = 100 * np.sqrt(sum([ (z-y)**2 for (x,y,z) in zip(boot_names, percentile25, percentile75) if x==dname ]))
freyja_hits.append( (dname, pct, median, spread) )
# Make a scatter plot, value vs. estimated spread
plt.rcParams.update({'font.size': 14})
for (dname, pct, median, spread) in freyja_hits:
color2plot = getColor(dname)
plt.plot(pct, median, 'o', color=color2plot, markersize=20)
plt.errorbar(pct, median, yerr=3*spread, color='k')
r = np.random.uniform(5,8)
phi = np.random.uniform(0,np.pi)
plt.text(pct+r*np.sin(phi), median+r*np.cos(phi), dname, color=color2plot)
plt.plot([0,100], [0,100], 'k--')
plt.axis('tight')
plt.xlim(0, 100)
plt.ylim(0, 100)
plt.xlabel('Freyja demix prediction')
plt.ylabel('Freyja boot median +/- 3 FWHM')
plt.title('Freyja bootstrapping (Experimental)')
plt.savefig(outfilename, dpi=300)
plt.close()