def main(argv): if len(sys.argv) != 3: print "Usage: %s model_filename cm_filename" % __file__ return 1 model_filename = argv[1] cm_filename = argv[2] # Sanity checks on filename if not os.path.exists(model_filename): raise Exception("File '%s' doesn't exist" % model_filename) if not re.search(r'\.py$', model_filename): raise Exception("File '%s' is not a .py file" % model_filename) sys.path.insert(0, os.path.dirname(model_filename)) model_name = re.sub(r'\.py$', '', os.path.basename(model_filename)) # import it try: # FIXME if the model has the same name as some other "real" module # which we use, there will be trouble (use the imp package and import # as some safe name?) model_module = __import__(model_name) except StandardError as e: print "Error in model script:\n" raise # grab the 'model' variable from the module try: model = model_module.__dict__['model'] except KeyError: raise Exception("File '%s' isn't a model file" % model_filename) # Make the contact map kappa.contact_map(model, base_filename=cm_filename) return 0
def make_contact_map(pysb_model, model_id): """Generate a Kappa contact map.""" try: cm = kappa.contact_map(pysb_model) fname = 'model%d_cm' % model_id abs_path = os.path.abspath(os.getcwd()) full_path = os.path.join(abs_path, fname + '.png') cm.draw(full_path, prog='dot') except Exception: return None return full_path
lopez_modules.momp_monomers() Observable('aBax', Bax(state='A')) Observable('cSmac', Smac(state='C')) # The specific MOMP model to use lopez_modules.embedded(do_pore_transport=False) # Set Bid initial condition to be tBid model.update_initial_condition_pattern(Bid(state='U', bf=None), Bid(state='T', bf=None)) # Get rid of CytoC and Smac model.parameters['Smac_0'].value = 0 model.parameters['CytoC_0'].value = 0 # Put some Noxa at the membrane Initial(Noxa(state='M', bf=None), Parameter('mNoxa_0', 1)) Initial(Bad(state='M', bf=None), Parameter('mBad_0', 1)) # Generate the contact map output_dir = os.path.abspath(os.path.dirname(__file__)) contact_map(model, output_dir, 'fig5d') try: # Remove the extra output files we don't need os.unlink('fig5d.ka') os.unlink('fig5d_cm.jpg') except OSError: pass print() print("Generated fig5d_cm.dot in", output_dir)