Skip to content

Commit bf4215d

Browse files
committed
Adds a check for the RANDOMIZE parameter in and disables it with a warning if it is activated. Fixes #74
1 parent bfe2828 commit bf4215d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

structure_threader/argparser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ def argument_sanity(arguments, parser):
271271
parser.error("-mv requires --params.")
272272
elif "-mv" in sys.argv:
273273
sanity.file_checker(os.path.abspath(arguments.params))
274+
elif "-st" in sys.argv and arguments.params is None:
275+
arguments.params = os.path.join(os.path.dirname(arguments.infile),
276+
"mainparams")
274277

275278
# Number of replicates
276279
arguments.replicates = range(1, arguments.replicates + 1)

structure_threader/wrappers/structure_wrapper.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,35 @@ def str_param_checker(arg):
4949
"""
5050
Handles the parameter files for STRUCTURE (or lack thereoff)
5151
"""
52+
def _disable_STRUCUTRE_RANDOMIZE(extraparams_file):
53+
"""
54+
Checks if the RANDOMIZE option is set in the `extraparams` file.
55+
If it is, disable it (set to `0`)
56+
"""
57+
infile = open(extraparams, "r")
58+
params = ""
59+
overwrite = False
60+
for lines in infile:
61+
try:
62+
if lines.split()[1] == "RANDOMIZE":
63+
if lines.split()[2] == "1":
64+
lines = lines.replace("1", "0")
65+
logging.warning("The RANDOMIZE option was activated in"
66+
" the `extraparams` file. "
67+
" *Structure_threader* has disabled it"
68+
" since it handles this functionality "
69+
"internallly (random seed setting).")
70+
overwrite = True
71+
except IndexError:
72+
pass
73+
params += lines
74+
infile.close()
75+
76+
if overwrite:
77+
outfile = open(extraparams, "w")
78+
outfile.write(params)
79+
outfile.close()
80+
5281
os.chdir(os.path.dirname(arg.infile))
5382
if arg.params is not None:
5483
mainparams = arg.params
@@ -60,6 +89,8 @@ def str_param_checker(arg):
6089
"that you fill one out.")
6190
touch = open(extraparams, 'w')
6291
touch.close()
92+
else:
93+
_disable_STRUCUTRE_RANDOMIZE(extraparams)
6394
arg.params = ["-m", mainparams, "-e", extraparams]
6495

6596

0 commit comments

Comments
 (0)