Browse Source

Add the cc3d-runner script.

Add a wrapper script around CC3D’s own script runner to allow
parameterized simulation runs.
master
Damien Goutte-Gattat 2 years ago
parent
commit
c27d86d994
  1. 0
      incenp/bio/modelling/__init__.py
  2. 86
      incenp/bio/modelling/cc3d.py
  3. 3
      setup.py

0
incenp/bio/modelling/__init__.py

86
incenp/bio/modelling/cc3d.py

@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
# Incenp.Bioutils - Incenp.org's utilities for computational biology
# Copyright © 2020 Damien Goutte-Gattat
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Wrapper to run parameterized CC3D simulations."""
import argparse
from json import load, dump
from os import getenv, mkdir
from os.path import dirname, exists, join
from subprocess import run
from time import sleep
def main():
home_dir = getenv('HOME', default='.')
parser = argparse.ArgumentParser(description="run CC3D simulations")
parser.add_argument('-C', '--cc3d-home', default='/opt/cc3d',
help="path to CC3D install directory")
parser.add_argument('-o', '--output-dir', default='{}/cc3d-runs'.format(home_dir),
help="path to output directory")
parser.add_argument('-n', '--runs', default=10, type=int,
help="number of runs to perform")
parser.add_argument('-p', '--parameters', default='',
help="path to a parameters file")
parser.add_argument('simfile',
help="path to the simulation file")
args = parser.parse_args()
simdir = dirname(args.simfile)
paramfile = join(simdir, 'Simulation', 'parameters.json')
cc3dbin = join(args.cc3d_home, 'runScript.sh')
if not exists(args.simfile):
parser.error("simulation file {} not found".format(args.simfile))
if not exists(cc3dbin):
parser.error("CC3D script runner {} not found".format(cc3dbin))
command = [
cc3dbin,
'-i', args.simfile,
'--current-dir', simdir,
'-o', args.output_dir
]
if args.parameters:
with open(args.parameters, 'r') as f:
try:
parameters = load(f)
except Exception as e:
parser.error("cannot parse parameters file: {}".format(e))
else:
parameters = [{}]
try:
if not exists(args.output_dir):
mkdir(args.output_dir)
for parameter_set in parameters:
with open(paramfile, 'w') as f:
dump(parameter_set, f)
for i in range(args.run):
run(command)
sleep(2)
except Exception as e:
parser.error("cannot run simulation: {}".format(e))
if __name__ == '__main__':
main()

3
setup.py

@ -47,7 +47,8 @@ setup(
entry_points={
'console_scripts': [
'sequtil = incenp.bio.seq.sequtil:main',
'siresist = incenp.bio.seq.silencing:main'
'siresist = incenp.bio.seq.silencing:main',
'cc3d-runner = incenp.bio.modelling.cc3d:main'
]
}
)

Loading…
Cancel
Save