def __init__(self, WORK_DIR): #ch.create_config(open(CONFIG_FNAME,'w')) #Collect config file entries: #self.config_dict = ch.read_config(CONFIG_FNAME) #print(self.config_dict) #self.work_dir = self.ConfigParam['workdir'] #self.work_dir='workspace' self.work_dir = WORK_DIR # Look for workspace, and if none exists create one: #if not os.path.exists(self.work_dir): # os.makedirs(self.work_dir) # Create work space # Collect user arguments into a dictionary: self.parsed_dict = ap.parse_args() #self.user_seed=int(self.parsed_dict['user_seed']) cfg_fname = self.parsed_dict['cfg_fname'] if (not cfg_fname): cfg_fname = CONFIG_FNAME cfg_path = os.path.dirname(cfg_fname) if (not cfg_path or cfg_path == "."): cfg_path = self.work_dir self.cfg_fname = cfg_path + '/' + basename(cfg_fname) #self.cfg_fname=self.work_dir+'/'+cfg_fname #self.config_dict = ch.read_config(CONFIG_FNAME) self.config_dict = ch.read_config(self.cfg_fname) #self.cfg_fname=self.work_dir+'/'+basename(cfg_fname) #Update the internal SEED, if user supplies this: if ((int(self.parsed_dict['SEED'])) != (int(self.config_dict['SEED']))): self.config_dict['SEED'] = self.parsed_dict['SEED'] #update the config_dict with USER_SEED from commandline: if ((int(self.parsed_dict['user_seed'])) != (int(self.config_dict['USER_SEED']))): self.config_dict['USER_SEED'] = self.parsed_dict['user_seed'] #Get .tpo filename: tpo_fname = self.parsed_dict['tpo_fname'] #tpo_path=os.path.dirname(self.parsed_dict['tpo_fname']) # #fn_prefix=(basename(tpo_fname)).strip().\ # split(self.config_dict['TOPOLOGY_FNAME_EXTENSION'])[0] fn_prefix=tpo_fname.strip().\ split(self.config_dict['TOPOLOGY_FNAME_EXTENSION'])[0] # Get .tpo filename with absolute path: #if (not tpo_path or tpo_path=="."): # tpo_path=self.work_dir #self.tpo_fname=tpo_path+'/'+basename(tpo_fname) self.tpo_fname = self.work_dir + '/' + tpo_fname # Get .prs filename with path: prs_fname = self.parsed_dict['prs_fname'] # if .prs file is not supplied, create file name for it: if not prs_fname: self.prs_fname=self.work_dir+'/'+\ fn_prefix+\ self.config_dict['PARAMETER_RANGE_FNAME_EXTENSION'] else: #otherwise, append working directory with it: self.prs_fname = self.work_dir + '/' + prs_fname # Get .exp filename with path: self.exp_fname = self.work_dir + '/' + self.parsed_dict['exp_fname'] # Get .params filename with path: self.params_input_fname = self.work_dir + '/' + self.parsed_dict[ 'params_input_fname'] # threshold test results self.edge_stat_fname = self.work_dir + '/' + self.parsed_dict[ 'outfile'] + '.edge.stat.txt' # Create other output filenames based on .tpo file name prefix: self.cfg_fname=self.work_dir+fn_prefix+\ self.config_dict['CONFIG_FNAME_EXTENSION'] self.params_fname=self.work_dir+'/'+\ fn_prefix+\ self.config_dict['PARAMETER_FNAME_EXTENSION'] self.LCtrace_fname=self.work_dir+'/'+\ fn_prefix+\ LIMIT_CYLCE_FNAME_SUFFIX self.prs_fname_bak=self.work_dir+'/'+\ fn_prefix+\ self.config_dict[\ 'PARAMETER_RANGE_FNAME_EXTENSION']+".bak" #input file name to read stable activations: self.fname_states_act = self.work_dir + '/' + fn_prefix + ".states.txt" #output files for C: #to write stable states: self.fname_states = self.work_dir + '/' + fn_prefix + ".states.exp.txt" self.fname_limitcycles = self.work_dir + '/' + fn_prefix + ".limitcycles.exp.txt" self.fname_summary = self.work_dir + '/' + fn_prefix + ".summary.txt" #create dictionary for file names to be used in C simulation: self.fname_dict_simu = OrderedDict() self.fname_dict_simu['FNAME_STATES'] = self.fname_states self.fname_dict_simu['FNAME_LIMITCYCLES'] = self.fname_limitcycles self.fname_dict_simu['FNAME_SUMMARY'] = self.fname_summary #file names for parameter ranges:MPR, DNR, TSH, HCO, and FCH: self.fname_dict_nodeprs = OrderedDict() self.fname_dict_nodeprs[ 'mpr'] = self.work_dir + '/' + fn_prefix + ".mpr.prs" self.fname_dict_nodeprs[ 'dnr'] = self.work_dir + '/' + fn_prefix + ".dnr.prs" self.fname_dict_edgeprs = OrderedDict() self.fname_dict_edgeprs[ 'tsh'] = self.work_dir + '/' + fn_prefix + ".tsh.prs" self.fname_dict_edgeprs[ 'hco'] = self.work_dir + '/' + fn_prefix + ".hco.prs" self.fname_dict_edgeprs[ 'fch'] = self.work_dir + '/' + fn_prefix + ".fch.prs" #output file names for parameters:MPR, DNR, TSH, HCO, and FCH: self.fname_dict_nodeparams = OrderedDict() self.fname_dict_nodeparams[ 'mpr'] = self.work_dir + '/' + fn_prefix + ".mpr.exp.txt" self.fname_dict_nodeparams[ 'dnr'] = self.work_dir + '/' + fn_prefix + ".dnr.exp.txt" self.fname_dict_edgeparams = OrderedDict() self.fname_dict_edgeparams[ 'tsh'] = self.work_dir + '/' + fn_prefix + ".tsh.exp.txt" self.fname_dict_edgeparams[ 'hco'] = self.work_dir + '/' + fn_prefix + ".hco.exp.txt" self.fname_dict_edgeparams[ 'fch'] = self.work_dir + '/' + fn_prefix + ".fch.exp.txt" #node_dict - gene/node names: self.node_dict = OrderedDict() #edge_dict - gene/node names: self.edge_dict = OrderedDict() #source_dict - maps target to source(s): self.source_dict = defaultdict(lambda: defaultdict(list)) #self.source_dict=defaultdict(lambda: OrderedDict()) #target_dict - maps source to target(s): self.target_dict = defaultdict(lambda: defaultdict(list)) #self.target_dict=defaultdict(lambda: OrderedDict()) #master_dict - maps each equation to a unique index: #Key:index #Value:(source,target,regulation type,TSH,HLC,FCH) #self.master_dict=defaultdict(list) #self.master_dict=defaultdict(tuple) self.master_dict = OrderedDict() #special data structures for C-interface: #node_id_dict - maps each gene/node to a unique id: self.node_id_dict = OrderedDict() #edge_id_dict - maps each equation to a unique id: self.edge_id_dict = OrderedDict() #edge_source_dict - maps each edge index to its source id: self.edge_source_dict = OrderedDict() #edge_target_dict - maps each edge index to its target id: self.edge_target_dict = OrderedDict() #edge_type_dict - maps each edge index to its type id: self.edge_type_dict = OrderedDict() return None
def main(): import ctypes clib = ctypes.cdll.LoadLibrary('./analyzer_clib.so') model_to_inspect = 2 parsed_dict = ap.parse_args() print("here:") print("tpo file name: ", parsed_dict['fname_tpo']) print("EXP file name: ", parsed_dict['fname_exp']) print("TSH file name: ", parsed_dict['fname_params']) tpo_fname = parsed_dict['fname_tpo'] tpo_path = os.path.dirname(parsed_dict['fname_tpo']) print(tpo_path) #fn_prefix=(basename(tpo_fname)).strip().\ # split(self.config_dict['TOPOLOGY_FNAME_EXTENSION'])[0] # Get .tpo filename with absolute path: print(CUR_DIR) if (not tpo_path or tpo_path == "."): tpo_path = CUR_DIR tpo_fname = tpo_path + '/' + tpo_fname tmp_fname = parsed_dict['fname_exp'] exp_fname = CUR_DIR + '/' + parsed_dict['fname_exp'] params_fname = CUR_DIR + '/' + parsed_dict['fname_params'] CONFIG_FNAME = CUR_DIR + '/' + 'racipe.cfg' config_dict = ch.read_config(CONFIG_FNAME) build_network(tpo_fname, config_dict) sys.exit(0) #tpo_fname=self.parsed_dict['tpo_fname'] #create an instance of Network class: network = nm.Network(CUR_DIR) #load network topology and parameter ranges: network.build_network() #obtain racipe config: config_dict = network.get_config_dict() SEED = int(config_dict['SEED']) user_seed = int(config_dict['USER_SEED']) #set the seed for model generation: clib.set_seed(ctypes.c_int(SEED * 2), ctypes.c_int(user_seed)) ma.inspect_model(network, model_to_inspect) sys.exit(0) SEED = int(config_dict['SEED']) user_seed = int(config_dict['USER_SEED']) clib = ctypes.cdll.LoadLibrary('./simulation_clib.so') clib.randu.argtypes = (ctypes.c_double, ctypes.c_double) clib.randu.restype = ctypes.c_double #clib.set_seed(ctypes.c_int(SEED)) #set seed for estimation of parameter ranges: clib.set_seed(ctypes.c_int(SEED), ctypes.c_int(user_seed)) mode = network.process_network() #generate models: if (mode == 'A' or mode == 'P'): print('Generating models ...') #set seed for generating models: #clib.set_seed(ctypes.c_int(SEED*2)) clib.set_seed(ctypes.c_int(SEED * 2), ctypes.c_int(user_seed)) #mg.generate_models_usingPython(network) mg.generate_models_usingC(network) return None