-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-driver.py
More file actions
62 lines (48 loc) · 2.16 KB
/
Copy pathpython-driver.py
File metadata and controls
62 lines (48 loc) · 2.16 KB
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
from argparse import ArgumentParser
from slimutil import run_slim, configure_slim_command_line
# Make sure slimutil.py is also transferred to this cluster directory
def parse_slim(slim_string):
"""
Arguments:
1. slim_string = output printed to the SLiM console
Returns:
2. suppressed = True if the drive suppressed the population within 100 generations, False if not
"""
line_split = slim_string.split('\n')
suppressed = False
for line in line_split:
if line.startswith("SUPPRESSION"):
suppressed = True
return suppressed
def main():
"""
1. Configure using argparse.
2. Generate cl string and run SLiM.
3. Parse the output of SLiM.
4. Print the results.
"""
# Get args from arg parser:
parser = ArgumentParser()
parser.add_argument('-src', '--src', default="distant_site_pan_TA.slim", type=str,help="SLiM file to be run.")
parser.add_argument('-nreps', '--nreps', type=int, default=10,help="number of replicates")
parser.add_argument('-embryo_res', '--EMBRYO_RESISTANCE_RATE', default=0.1, type=float, help="embryo cut rate")
parser.add_argument('-germline_res', '--GERMLINE_RESISTANCE_RATE', type=float, default=1.0,help="germline cut rate")
args_dict = vars(parser.parse_args())
sim_reps = args_dict.pop("nreps")
embryo_resistance_rate = args_dict["EMBRYO_RESISTANCE_RATE"]
germline_resistance_rate = args_dict["GERMLINE_RESISTANCE_RATE"]
# Assemble the command line arguments to use for SLiM:
clargs = configure_slim_command_line(args_dict)
# I want to record the fraction of replicates where the drive suppresses the population
suppression_count = 0
for i in range(sim_reps):
slim_result = run_slim(clargs)i
suppressed = parse_slim(slim_result)
if suppressed:
suppression_count += 1
p_suppression = suppression_count/sim_reps
# output: embryo resistance rate, germline resistance rate, fraction of replicates where drive suppressed
csv_line = f"{embryo_resistance_rate},{germline_resistance_rate},{p_suppression}"
print(csv_line)
if __name__ == "__main__":
main()