def analysis(saveto_h5, max_num_dataset=10): """ A bad way to organize a sequence of analysis """ # h5 files to read, tables, and paths to tables are encoded inside the analysis # ideally they would be refactored into a configuration file polar_h5 = tables.openFile('GA4_mon_polar_analysis.h5', mode='a') nonpolar_h5 = tables.openFile('GA4_mon_nonpolar_analysis.h5', mode='a') # analyze and aggregate all data for each iso and store each in a separate table for system in ["mon"]: for iso in ["scyllo", "chiro"]: # clear the results analysis_results = [] for i in range(0, max_num_dataset): table_path = '/%(system)s/%(iso)s%(i)d' % vars() print "analyzing", table_path polar_table = myh5.getTable(polar_h5, table_path) nonpolar_table = myh5.getTable(nonpolar_h5, table_path) if polar_table != None and nonpolar_table != None: polar_array = utils.convert_to_numpy(polar_table) nonpolar_array = utils.convert_to_numpy(nonpolar_table) s = stoichiometry(polar_array[0:5001, 1:], nonpolar_array[0:5001,1:]) analysis_results.append(s) myh5.save(saveto_h5, numpy.vstack(analysis_results), "/mon_analysis/stoichiometry_%(iso)s" % vars())
def mon(offset=0, max_num_dataset=10): """This is computes the intersection of polar and nonpolar binding of inositol""" polar_h5 = tables.openFile('GA4_mon_polar_analysis.h5', mode='a') nonpolar_h5 = tables.openFile('GA4_mon_nonpolar_analysis.h5', mode='a') # print >>f, "#table_name polar nonpolar p_and_np polar_fraction nonpolar_fraction p_and_np_fraction total_inositols bound unbound K" for system in ["mon"]: for iso in ["scyllo", "chiro"]: data = [] errorlist = [] for i in range(0, max_num_dataset): table_path = '/%(system)s/%(iso)s%(i)d' % vars() print "analyzing",table_path polar_table = myh5.getTable(polar_h5, table_path) nonpolar_table = myh5.getTable(nonpolar_h5, table_path) if polar_table != None and nonpolar_table != None: polar_array = utils.convert_to_numpy(polar_table) nonpolar_array = utils.convert_to_numpy(nonpolar_table) print "computing intersection ..." polar, nonpolar, p_and_np, total_inositol = intersect(polar_array[0:5001,1:], nonpolar_array[0:5001,1:]) print "computing binding constant ..." bound,unbound = binding(polar_array[offset:5001, 1:], nonpolar_array[offset:5001, 1:]) # errorlist.append(binding_error(polar_array[offset:5001, 1:], nonpolar_array[offset:5001, 1:], block_size=1000)) total = float(polar + nonpolar + p_and_np) # print >>f, table_path, polar, nonpolar, p_and_np, polar/total, nonpolar/total, p_and_np/total, total_inositol, bound, unbound, unbound/float(bound)*125 data.append(numpy.array([polar, nonpolar, p_and_np, total, total_inositol, bound, unbound])) else: print "table not found" data = numpy.vstack(data) # numpy.savetxt('%(iso)s_data.txt' % vars(), data, fmt='%-0.3f') data_sum = numpy.sum(data, axis=0) # nasty output heading = ["polar", "nonpolar", "p_and_np", "total", "total_inositol", "nbound", "nunbound"] d = dict(zip(heading, data_sum)) f = open('%(iso)s_data_aggregation.txt' % vars(), 'w') for key in sorted(d.keys()): print >>f, key, d[key] f.close() #compute error blocklist = block_average(data) numpy.savetxt('%(iso)s_blocks.txt' % vars(), blocklist, fmt='%.3f')
def disordered(): """This is computes the intersection of polar and nonpolar binding of inositol""" polar_h5 = tables.openFile('GA4_disordered_polar_analysis.h5', mode='a') nonpolar_h5 = tables.openFile('GA4_disordered_nonpolar_analysis.h5', mode='a') f = open('data.txt', 'w') print >>f, "#table_name polar nonpolar p_and_np polar_fraction nonpolar_fraction p_and_np_fraction total_inositols nframes bound unbound Kd" for system in ["ap1f", "oct"]: for iso in ["scyllo", "chiro"]: for i in range(0,6): table_path = '/%(system)s/%(iso)s%(i)d' % vars() polar_table = myh5.getTable(polar_h5, table_path) nonpolar_table = myh5.getTable(nonpolar_h5, table_path) if polar_table != None and nonpolar_table != None: # Note need to specify float64, since now pytables is all 32 bit polar_array = utils.convert_to_numpy(polar_table, dtype=numpy.float64) nonpolar_array = utils.convert_to_numpy(nonpolar_table, dtype=numpy.float64) # need to exclude first column of nonpolar data because its time polar,nonpolar,p_and_np, total_inositol = intersect(polar_array, nonpolar_array[:,1:]) bound,unbound = binding(polar_array, nonpolar_array[:,1:]) total = float(polar + nonpolar + p_and_np) print >>f, table_path, polar, nonpolar, p_and_np, polar/total, nonpolar/total, p_and_np/total, total_inositol, total_inositol/2, bound, unbound, unbound/float(bound)*123