def to_Peppercorn(*args, **kargs): """Converts DNAObjects objects to Peppercorn objects. The following objects will be recognized in the key list and converted: - domains - complexes - reactions Other supplied objects are ignored. The output is in the form of a dictionary mapping the keys 'domains', 'complexes', and 'reactions' to a list of tuples of the form (object, converted_object). This may be iterated through directly or converted into a dict for object lookup. """ ## Clear previously created Peppercorn objects from memory ## to prevent duplication errors. enumobj.clear_memory() ## Extract all objects to be converted reactions = set(kargs.get('reactions', [])) complexes = set( sum([list(r.reactants + r.products) for r in reactions], []) + kargs.get('complexes', [])) domains = set( [d for c in complexes for d_list in c.base_domains() for d in d_list] + sum([d.base_domains() for d in kargs.get('domains', [])], [])) ## Convert domains, strands, complexes, and reactions enum_domains = {} for d in set(sum([d.base_domains() for d in domains], [])): enum_domains[d] = to_Peppercorn_domain(d) enum_complexes = {} for complex in set(complexes): enum_complexes[complex] = to_Peppercorn_complex(complex, enum_domains) enum_reactions = {} for reaction in set(reactions): enum_reactions[reaction] = to_Peppercorn_reaction( reaction, enum_complexes) ## Return in a dict results = dict() results['domains'] = enum_domains.items() results['complexes'] = enum_complexes.items() results['reactions'] = enum_reactions.items() return results
def tearDown(self): clear_memory()
def tearDown(self): objects.clear_memory()
def main(): logdata = True if not os.path.exists('tmp'): raise SystemExit('Please make a directory called "tmp" to store temorary results') fig = plt.figure() ax1 = fig.add_subplot(111) mycolors = list('bgrcmyk') mymarker = list('o*^.vph+D') (mc,mm) = (0,0) allresults = [] for data in paperdata: results = [] for e, pilstring in enumerate(map(data['piltemplate'], data['pilparams'])): clear_memory() tmpname = 'tmp/'+data['name'] + '_' + str(e) print tmpname enumOBJ, crn = peppercorn(pilstring, name=tmpname, **data['pepperargs']) if 'rates' in data: if len(enumOBJ.condensed_reactions) == 1: rxn = enumOBJ.condensed_reactions[0] er = data['exp_results'][e] results.append([er, rxn.rate]) else : if 'reactants' in data['rates']: for rxn in enumOBJ.condensed_reactions: if sorted([rs.name for rs in rxn.reactants]) == sorted(data['rates']['reactants']): er = data['exp_results'][e] results.append([er, rxn.rate]) break else: raise NotImplementedError('multiple condensed reactions') if 'simulation' in data: for i, command in enumerate(data['simulation']): nxy = simulate_crn(crn, tmpname, command) rep = data['reporter'] (et, ec) = data['exp_results'][e+i] time = get_simulated_time(nxy, rep, ec) #print e+i, rep, et, ec, time results.append([et, time]) #assert len(results) == len(data['exp_results']) xs = [] ys = [] for e, (x,y) in enumerate(results): if x is None or y is None: print 'WARNING: Skipping data points {}'.format(e) continue if logdata: xs.append(log(x,10)) ys.append(log(y,10)) else: xs.append(x) ys.append(y) print xs print ys ax1.scatter(xs, ys, color=mycolors[mc], marker=mymarker[mm], label=data['name']) mc += 1 if mc >= mcmax[mm]: mc = 0 mm += 1 plt.title('Peppercorn vs. experiment'); if logdata: ax1.set_xlabel('Experimental system speed [$\log_{10}(s)$]', fontsize=16) ax1.set_ylabel('Simulated system speed [$\log_{10}(s)$]', fontsize=16) (mi,ma)=(0, 6) (mi,ma)=(-3, 7) #plt.xlim(mi, ma) #plt.ylim(mi, ma) plt.plot([mi, ma], [mi, ma], color='black') else: ax1.set_xlabel('Experimental system speed [s]', fontsize=16) ax1.set_ylabel('Simulated system speed [s]', fontsize=16) (mi,ma) = (-10, 600) plt.xlim(mi, ma) plt.ylim(mi, ma) plt.plot([mi, ma], [mi, ma], color='black') lgd = plt.legend(bbox_to_anchor=(1.40, 1.0), loc='upper right', borderaxespad=0.) #plt.legend(loc='lower right'); #plt.legend(loc='lower right'); #pfile = 'zhang2009_condensed_log.png' #plt.savefig(pfile, bbox_extra_artists=(lgd,), bbox_inches='tight') plt.savefig('test.pdf', bbox_extra_artists=(lgd,), bbox_inches='tight') return