Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Created June 27, 2016 09:49
Show Gist options
  • Save Swarchal/8290668440608c0e6f06d35357161ecf to your computer and use it in GitHub Desktop.
Save Swarchal/8290668440608c0e6f06d35357161ecf to your computer and use it in GitHub Desktop.
#! /bin/env python
def write_batch_scripts(template, placeholder, batch_file):
"""
converts a template qub submission script and a batch output file produced
by cellprofiler to multiple consecutively numbered submission scripts
arguments:
----------
template -- template submission script for qsub
placehoder -- placeholder string within the template file. This will be
substituted with the cellprofiler command
batch_file -- file produced by cellprofiler --get-batch-commands
"""
tmp = open(template).read()
inputs = open(batch_file).readlines()
for i, cmd in enumerate(inputs):
out = tmp.replace(placeholder, cmd)
outfile = open("out_{}".format(i), "w")
outfile.write(out)
if __name__ == "__main__":
write_batch_scripts(template="test_cp_batch_run.sh",
placeholder="PLACEHOLDER",
batch_file="batch_out.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment