-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathase_simulator_w_error.py
43 lines (40 loc) · 1.25 KB
/
ase_simulator_w_error.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
import pandas as pd
import gzip
import sys
import numpy as np
from numpy.random import uniform
#simulate-ase.py <num-genes> <het-sites-per-gene> <read-depth> <theta>
N=int(sys.argv[1])
M=int(sys.argv[2])
D=int(sys.argv[3])
theta=float(sys.argv[4])
error=float(sys.argv[5]) # 0.1
outfile=sys.argv[6]
#theta=3
#D=10
#M=5
#N=10
if theta <= 0:
raise ValueError("theta should be positive")
with open(outfile,'w') as f:
#f.write('M')
for k in range(N):
# A=np.random.binomial(D, theta/(1+theta), size=M)
# AR = ["%d\t%d" % (A[i], D-A[i]) for i in range(len(A))]
switch_ind = False
index = []
AR = []
Current_Step = ["A","R"]
for i in range(M):
A= np.random.binomial(D, theta/(1+theta))
value = {"A":A,"R":D-A}
switch_ind = True if uniform() <= error else False
index.append(switch_ind)
if switch_ind == True:
Current_Step = [ Current_Step[1], Current_Step[0]]
AR.append("%d\t%d" % (value[Current_Step[0]], value[Current_Step[1]] ))
else:
AR.append("%d\t%d" % (value[Current_Step[0]], value[Current_Step[1]] ))
line = '%d\t%d\t%s\t%s\n' % (k+1,M, "\t".join(AR), theta)
#print(index)
f.write(line)