-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslimutil.py
More file actions
39 lines (33 loc) · 1.24 KB
/
Copy pathslimutil.py
File metadata and controls
39 lines (33 loc) · 1.24 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
# Author: Sam Champer
# Functions to run SLiM and to configure command line arguments for SLiM.
import subprocess
def run_slim(command_line_args):
"""
Runs SLiM using subprocess.
Args:
command_line_args: list; a list of command line arguments.
return: The entire SLiM output as a string.
"""
slim = subprocess.Popen(command_line_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
out, err = slim.communicate()
return out
def configure_slim_command_line(args_dict):
"""
Sets up a list of command line arguments for running SLiM.
Args:
args_dict: a dictionary arguments from arg parser.
Return
clargs: A formated list of the arguments.
"""
clargs = "slim "
# The filename of the source file must be the last argument:
source = args_dict.pop("src")
# Add each argument from arg parser to the command line arguemnts for SLiM:
for arg in args_dict:
if isinstance(args_dict[arg], bool):
clargs += f"-d {arg}={'T' if args_dict[arg] else 'F'} "
else:
clargs += f"-d {arg}={args_dict[arg]} "
# Add the source file, and return the string split into a list.
clargs += source
return clargs.split()