def process_files_singlet(xml_files): so_many = len(xml_files) print("****This script is about to make png files for %s xml files. ****" % so_many) for file in xml_files: file_name = os.path.splitext(file)[0] data = platereader.read_icontrol_xml(file) print("****The xml file " + file + " has %s data sections:****" % len(data.keys())) print(data.keys()) for key in data.keys(): plot_singlet_one_section(data, key) #fig.tight_layout() #fig.suptitle("%s_%s" % (file_name,key), fontsize=18) plt.savefig('%s_%s.png' % (file_name, key)) print('Look at how pretty your data is: %s_%s.png' % (file_name, key)) return
def process_files_singlet(xml_files): so_many = len(xml_files) print("****This script is about to make png files for %s xml files. ****" % so_many) for file in xml_files: file_name = os.path.splitext(file)[0] data = platereader.read_icontrol_xml(file) print("****The xml file " + file + " has %s data sections:****" % len(data.keys())) print(data.keys()) for key in data.keys(): plot_singlet_one_section(data,key) #fig.tight_layout() #fig.suptitle("%s_%s" % (file_name,key), fontsize=18) plt.savefig('%s_%s.png' % (file_name,key)) print('Look at how pretty your data is: %s_%s.png' % (file_name,key)) return
container = Container(name="assay-plate", id=id, container_type=container_type) # # Assay Parameters # Lstated = [ Unit(x, "moles/liter") for x in [20.0e-6,9.15e-6,4.18e-6,1.91e-6,0.875e-6,0.4e-6,0.183e-6,0.0837e-6,0.0383e-6,0.0175e-6,0.008e-6,0] ] # gefitinib concentration Pstated = Unit(0.5e-6, "moles/liter") well_volume = Unit(100, "milliliter") receptor_name = 'Src' ligand_name = 'gefitinib' # Load data into well format. filename = "../ipynbs/data-analysis/binding-assay/data/Gef_WIP_SMH_SrcBos_Extend_013015_mdfx_20150220_18.xml" from assaytools import platereader data = platereader.read_icontrol_xml(filename) # Define wells for fluorescence assay (the verbose way; we'd provide convenience methods to format the plate) ncolumns = 12 well_group = WellGroup([]) for column in range(ncolumns): for row in ['A', 'B']: well_name = row + str(column+1) well = container.well(well_name) well.set_volume(well_volume) well.set_properties({'area' : well_area}) # Set concentrations of well components if row == 'A': well.set_properties({'concentrations' : {receptor_name : Pstated, ligand_name : Lstated[column]} }) well.set_properties({'concentration_uncertainties' : {receptor_name : 0.10 * Pstated, ligand_name : 0.08 * Lstated[column]} })
Lstated = [ Unit(x, "moles/liter") for x in [ 20.0e-6, 9.15e-6, 4.18e-6, 1.91e-6, 0.875e-6, 0.4e-6, 0.183e-6, 0.0837e-6, 0.0383e-6, 0.0175e-6, 0.008e-6, 0 ] ] # gefitinib concentration Pstated = Unit(0.5e-6, "moles/liter") well_volume = Unit(100, "milliliter") receptor_name = 'Src' ligand_name = 'gefitinib' # Load data into well format. filename = "../ipynbs/data-analysis/binding-assay/data/Gef_WIP_SMH_SrcBos_Extend_013015_mdfx_20150220_18.xml" from assaytools import platereader data = platereader.read_icontrol_xml(filename) # Define wells for fluorescence assay (the verbose way; we'd provide convenience methods to format the plate) ncolumns = 12 well_group = WellGroup([]) for column in range(ncolumns): for row in ['A', 'B']: well_name = row + str(column + 1) well = container.well(well_name) well.set_volume(well_volume) well.set_properties({'area': well_area}) # Set concentrations of well components if row == 'A': well.set_properties({ 'concentrations': {
def read_infinite(container, xml_filename, wavelengths_to_analyze=None, measurements_to_analyze=None): """ Read measurements from a Tecan Infinite reader XML file. Parameters ---------- wavelengths_to_analyze : list, optional, default=None If not None, only read measurements involving these wavelengths measurements_to_analyze : list, optional, default=None If not None, only read these kinds of measurements (e.g. 'absorbance', 'fluorescence bottom', 'fluorescence top') Measurements are stored in `well.properties['measurements']` under * `absorbance` : e.g. { '280:nanometers' : 0.425 } * `fluorescence` : e.g. { ('280:nanometers', '350:nanometers', 'top') : 15363 } TODO ---- * Eventually, we can read all components of the Infinite file directly here. """ # TODO: Replace read_icontrol_xml with direct processing of XML file from assaytools import platereader data = platereader.read_icontrol_xml(xml_filename) for well in container.all_wells(): well_name = well.humanize() # Attach plate reader data # TODO: Only process wells for which measurements are available if 'measurements' not in well.properties: well.properties['measurements'] = dict() measurements = well.properties['measurements'] for key in data: if key.startswith('Abs_'): # absorbance [prefix, wavelength] = key.split('_') wavelength = wavelength + ':nanometers' # Skip if requested if wavelengths_to_analyze and not (wavelength in wavelengths_to_analyze): continue if measurements_to_analyze and not ( 'absorbance' in measurements_to_analyze): continue # Store if 'absorbance' not in measurements: measurements['absorbance'] = dict() measurements['absorbance'][wavelength] = float( data[key][well_name]) elif (key.endswith('_TopRead') or key.endswith('_BottomRead')): # top fluorescence read [wavelength, suffix] = key.split('_') excitation_wavelength = wavelength + ':nanometers' emission_wavelength = '480:nanometers' # This is hard-coded in for now because this information is not available in the platereader.read_icontrol_xml results if key.endswith('_TopRead'): geometry = 'top' else: geometry = 'bottom' # Skip if requested if wavelengths_to_analyze and not ( (excitation_wavelength in wavelengths_to_analyze) and (emission_wavelength in wavelengths_to_analyze)): continue if measurements_to_analyze and not ( ('fluorescence %s' % geometry) in measurements_to_analyze): continue # Store if 'fluorescence' not in measurements: measurements['fluorescence'] = dict() measurements['fluorescence'][(excitation_wavelength, emission_wavelength, geometry)] = float( data[key][well_name])
def get_data_using_inputs(inputs): """ Parses your data according to inputs dictionary. Requires you have a 'file_set' in your inputs. Parameters ---------- inputs : dict Dictionary of input information """ complex_fluorescence = {} ligand_fluorescence = {} for protein in inputs['file_set'].keys(): #concatenate xmls into one dictionary with all ligand data my_file = [] sw_data = [] # Data just helps define our keys, which will be our data sections. # We are importing the first two files, because sometimes we have two files per # data collection, e.g. if we wanted a lot of types of reads # (there is a limited number of type of read on the infinite per script). data = platereader.read_icontrol_xml(inputs['file_set']['%s' % protein][0]) try: data.update( platereader.read_icontrol_xml(inputs['file_set']['%s' % protein][1])) except: pass if 'single_well' in inputs: for file in inputs['file_set']['%s' % protein]: my_file.append(file) data_to_append = {key: None for key in data} new_dict = platereader.read_icontrol_xml(file) data_to_append.update(new_dict) sw_data.append(data_to_append) #sw_data is a list of dataframes in the order of the list of files if inputs['protein_wells'][protein][0] not in range( 1, 25): #make sure not a two digit number if len(str(inputs['protein_wells'][protein] [0])) == 2 or 3: # is it e.g. 'A1' or 'A11' if len(inputs['protein_wells'][protein]) == len( inputs['ligand_order']): pass else: print( '***To define individual wells, you need to define the same number of wells as ligands.***' ) break for i in range(0, len(inputs['ligand_order'])): # i defines ligand for j, protein_well_ID in enumerate( inputs['protein_wells'][protein]): # j defines protein if str(protein_well_ID) in ALPHABET: #print('Your ligands are in a row (1,2,3,4, etc. are different ligands)!') protein_well = '%s%s' % (protein_well_ID, i) buffer_well = '%s%s' % ( inputs['buffer_wells'][protein][j], i) name = "%s-%s-%s%s" % (protein, inputs['ligand_order'][i], protein_well, buffer_well) elif len(str(protein_well_ID)) == 2 or 3: if inputs['protein_wells'][protein][0] in range( 1, 25): # make sure not a two digit number pass else: protein_well = protein_well_ID buffer_well = inputs['buffer_wells'][protein][j] name = "%s-%s-%s%s" % (protein, inputs['ligand_order'][j], protein_well, buffer_well) else: #print('Your ligands are in a column (A,B,C,D, etc. are different ligands)!') protein_well = '%s%s' % (ALPHABET[i], protein_well_ID) buffer_well = '%s%s' % ( ALPHABET[i], inputs['buffer_wells'][protein][j]) name = "%s-%s-%s%s" % (protein, inputs['ligand_order'][i], protein_well, buffer_well) #print(name) protein_data = [] buffer_data = [] for k in range( len(sw_data) ): # k should define ligand concentration if your list of files was ordered correctly # for spectra assays if 'wavelength' in inputs: protein_data.append( float( platereader.select_data( sw_data[k], inputs['section'], [protein_well], wavelength='%s' % inputs['wavelength'])[protein_well])) buffer_data.append( float( platereader.select_data( sw_data[k], inputs['section'], [buffer_well], wavelength='%s' % inputs['wavelength'])[buffer_well])) # for single wavelength assays else: protein_data.append( float( platereader.select_data( sw_data[k], inputs['section'], [protein_well])[protein_well])) buffer_data.append( float( platereader.select_data( sw_data[k], inputs['section'], [buffer_well])[buffer_well])) complex_fluorescence[name] = np.asarray(protein_data) ligand_fluorescence[name] = np.asarray(buffer_data) else: for file in inputs['file_set']['%s' % protein]: my_file.append(file) new_dict = platereader.read_icontrol_xml(file) for key in data: try: data[key].update(new_dict[key]) except: pass # Are there any experiments the user wants to skip analyzing? skipped_experiments = [] for i, ligand in enumerate(inputs['ligand_order']): if ligand == None: skipped_experiments.append(i * 2) else: continue skipped_rows = [] for i in skipped_experiments: skipped_rows.append(ALPHABET[i]) skipped_rows.append(ALPHABET[i + 1]) if len(skipped_rows) != 0: print("Skipping analysis of rows: ", skipped_rows) for i in range(0, len(inputs['ligand_order'] * 2), 2): if i in skipped_experiments: continue else: protein_row = ALPHABET[i] buffer_row = ALPHABET[i + 1] name = "%s-%s-%s%s" % (protein, inputs['ligand_order'][int( i / 2)], protein_row, buffer_row) # for spectra assays if 'wavelength' in inputs: complex_fluorescence_data = platereader.select_data( data, inputs['section'], protein_row, wavelength='%s' % inputs['wavelength']) ligand_fluorescence_data = platereader.select_data( data, inputs['section'], buffer_row, wavelength='%s' % inputs['wavelength']) # for single wavelength assays else: complex_fluorescence_data = platereader.select_data( data, inputs['section'], protein_row) ligand_fluorescence_data = platereader.select_data( data, inputs['section'], buffer_row) complex_fluorescence[name] = reorder2list( complex_fluorescence_data, well) ligand_fluorescence[name] = reorder2list( ligand_fluorescence_data, well) return [complex_fluorescence, ligand_fluorescence]
def read_infinite(container, xml_filename, wavelengths_to_analyze=None, measurements_to_analyze=None): """ Read measurements from a Tecan Infinite reader XML file. Parameters ---------- wavelengths_to_analyze : list, optional, default=None If not None, only read measurements involving these wavelengths measurements_to_analyze : list, optional, default=None If not None, only read these kinds of measurements (e.g. 'absorbance', 'fluorescence bottom', 'fluorescence top') Measurements are stored in `well.properties['measurements']` under * `absorbance` : e.g. { '280:nanometers' : 0.425 } * `fluorescence` : e.g. { ('280:nanometers', '350:nanometers', 'top') : 15363 } TODO ---- * Eventually, we can read all components of the Infinite file directly here. """ # TODO: Replace read_icontrol_xml with direct processing of XML file from assaytools import platereader data = platereader.read_icontrol_xml(xml_filename) for well in container.all_wells(): well_name = well.humanize() # Attach plate reader data # TODO: Only process wells for which measurements are available if 'measurements' not in well.properties: well.properties['measurements'] = dict() measurements = well.properties['measurements'] for key in data: if key.startswith('Abs_'): # absorbance [prefix, wavelength] = key.split('_') wavelength = wavelength + ':nanometers' # Skip if requested if wavelengths_to_analyze and not (wavelength in wavelengths_to_analyze): continue if measurements_to_analyze and not ('absorbance' in measurements_to_analyze): continue # Store if 'absorbance' not in measurements: measurements['absorbance'] = dict() measurements['absorbance'][wavelength] = float(data[key][well_name]) elif (key.endswith('_TopRead') or key.endswith('_BottomRead')): # top fluorescence read [wavelength, suffix] = key.split('_') excitation_wavelength = wavelength + ':nanometers' emission_wavelength = '480:nanometers' # This is hard-coded in for now because this information is not available in the platereader.read_icontrol_xml results if key.endswith('_TopRead'): geometry = 'top' else: geometry = 'bottom' # Skip if requested if wavelengths_to_analyze and not ((excitation_wavelength in wavelengths_to_analyze) and (emission_wavelength in wavelengths_to_analyze)): continue if measurements_to_analyze and not (('fluorescence %s' % geometry) in measurements_to_analyze): continue # Store if 'fluorescence' not in measurements: measurements['fluorescence'] = dict() measurements['fluorescence'][(excitation_wavelength, emission_wavelength, geometry)] = float(data[key] [well_name])
def quick_model(inputs): xml_files = glob("%s/*.xml" % inputs['xml_file_path']) print(xml_files) for my_file in xml_files: file_name = os.path.splitext(my_file)[0] print(file_name) data = platereader.read_icontrol_xml(my_file) for i in range(0,15,2): protein_row = ALPHABET[i] buffer_row = ALPHABET[i+1] name = "%s-%s%s"%(inputs['ligand_order'][i/2],protein_row,buffer_row) print(name) metadata = {} metadata = dict(inputs) try: part1_data_protein = platereader.select_data(data, inputs['section'], protein_row) part1_data_buffer = platereader.select_data(data, inputs['section'], buffer_row) except: continue reorder_protein = reorder2list(part1_data_protein,well) reorder_buffer = reorder2list(part1_data_buffer,well) #these need to be changed so they are TAKEN FROM INPUTS!!! # Uncertainties in protein and ligand concentrations. dPstated = 0.35 * inputs['Pstated'] # protein concentration uncertainty dLstated = 0.08 * inputs['Lstated'] # ligand concentraiton uncertainty (due to gravimetric preparation and HP D300 dispensing) from assaytools import pymcmodels pymc_model = pymcmodels.make_model(inputs['Pstated'], dPstated, inputs['Lstated'], dLstated, top_complex_fluorescence=reorder_protein, top_ligand_fluorescence=reorder_buffer, use_primary_inner_filter_correction=True, use_secondary_inner_filter_correction=True, assay_volume=inputs['assay_volume'], DG_prior='uniform') import datetime my_datetime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") my_datetime_filename = datetime.datetime.now().strftime("%Y-%m-%d %H%M") mcmc = pymcmodels.run_mcmc(pymc_model, db = 'pickle', dbname = '%s_mcmc-%s.pickle'%(name,my_datetime)) map = pymcmodels.map_fit(pymc_model) pymcmodels.show_summary(pymc_model, map, mcmc) DeltaG_map = map.DeltaG.value DeltaG = mcmc.DeltaG.trace().mean() dDeltaG = mcmc.DeltaG.trace().std() ## PLOT MODEL #from assaytools import plots #figure = plots.plot_measurements(Lstated, Pstated, pymc_model, mcmc=mcmc) #Code below inspired by import above, but didn't quite work to import it... plt.clf() plt.subplot(211) property_name = 'top_complex_fluorescence' complex = getattr(pymc_model, property_name) plt.semilogx(inputs['Lstated'], complex.value, 'ko',label='complex') property_name = 'top_ligand_fluorescence' ligand = getattr(pymc_model, property_name) plt.semilogx(inputs['Lstated'], ligand.value, 'ro',label='ligand') for top_complex_fluorescence_model in mcmc.top_complex_fluorescence_model.trace()[::10]: plt.semilogx(inputs['Lstated'], top_complex_fluorescence_model, 'k:') for top_ligand_fluorescence_model in mcmc.top_ligand_fluorescence_model.trace()[::10]: plt.semilogx(inputs['Lstated'], top_ligand_fluorescence_model, 'r:') plt.xlabel('$[L]_T$ (M)'); plt.ylabel('fluorescence units'); plt.legend(loc=0); ## PLOT TRACE plt.subplot(212) plt.hist(mcmc.DeltaG.trace(), 40, alpha=0.75, label="DeltaG = %.1f +- %.1f kT"%(DeltaG, dDeltaG)) plt.axvline(x=DeltaG,color='blue') plt.axvline(x=DeltaG_map,color='black',linestyle='dashed',label="MAP = %.1f"%DeltaG_map) plt.legend(loc=0) plt.xlabel('$\Delta G$ ($k_B T$)'); plt.ylabel('$P(\Delta G)$'); plt.xlim(-35,-10) plt.suptitle("%s: %s" % (name, my_datetime)) plt.tight_layout() fig1 = plt.gcf() fig1.savefig('delG_%s-%s.png'%(name, my_datetime_filename)) np.save('DeltaG_%s-%s.npy'%(name, my_datetime_filename),DeltaG) np.save('DeltaG_trace_%s-%s.npy'%(name, my_datetime_filename),mcmc.DeltaG.trace()) Kd = np.exp(mcmc.DeltaG.trace().mean()) dKd = np.exp(mcmc.DeltaG.trace()).std() if (Kd < 1e-12): Kd_summary = "%.1f nM +- %.1f fM" % (Kd/1e-15, dKd/1e-15) elif (Kd < 1e-9): Kd_summary = "%.1f pM +- %.1f pM" % (Kd/1e-12, dKd/1e-12) elif (Kd < 1e-6): Kd_summary = "%.1f nM +- %.1f nM" % (Kd/1e-9, dKd/1e-9) elif (Kd < 1e-3): Kd_summary = "%.1f uM +- %.1f uM" % (Kd/1e-6, dKd/1e-6) elif (Kd < 1): Kd_summary = "%.1f mM +- %.1f mM" % (Kd/1e-3, dKd/1e-3) else: Kd_summary = "%.3e M +- %.3e M" % (Kd, dKd) outputs = { 'raw_data_file' : my_file, 'name' : name, 'analysis' : 'pymcmodels', #right now this is hardcoded, BOOO 'outfiles' : '%s_mcmc-%s.pickle, delG_%s-%s.png,DeltaG_%s-%s.npy,DeltaG_trace_%s-%s.npy'%(name,my_datetime,name,my_datetime,name,my_datetime,name,my_datetime), 'DeltaG' : "DeltaG = %.1f +- %.1f kT, MAP estimate = %.1f" % (DeltaG, dDeltaG, DeltaG_map), 'Kd' : Kd_summary, 'datetime' : my_datetime } metadata.update(outputs) metadata['Pstated'] = metadata['Pstated'].tolist() metadata['Lstated'] = metadata['Lstated'].tolist() with open('%s-%s.json'%(name,my_datetime), 'w') as outfile: json.dump(metadata, outfile, sort_keys = True, indent = 4, ensure_ascii=False)
# This is a script version of DMSO-backfill.ipynb from assaytools import platereader import matplotlib.pyplot as plt import string import numpy as np part1 = "p38_singlet1_20160420_153238.xml" part2 = "p38_singlet2_20160420_154750.xml" part1_data = platereader.read_icontrol_xml(part1) part2_data = platereader.read_icontrol_xml(part2) part1_data_C = platereader.select_data(part1_data, '280_480_TOP_120', 'C') part1_data_D = platereader.select_data(part1_data, '280_480_TOP_120', 'D') part1_data_K = platereader.select_data(part1_data, '280_480_TOP_120', 'K') part1_data_L = platereader.select_data(part1_data, '280_480_TOP_120', 'L') well = dict() for j in string.ascii_uppercase: for i in range(1,25): well['%s' %j + '%s' %i] = i Lstated = np.array([20.0e-6,14.0e-6,9.82e-6,6.88e-6,4.82e-6,3.38e-6,2.37e-6,1.66e-6,1.16e-6,0.815e-6,0.571e-6,0.4e-6,0.28e-6,0.196e-6,0.138e-6,0.0964e-6,0.0676e-6,0.0474e-6,0.0320e-6,0.0240e-6,0.0160e-6,0.0120e-6,0.008e-6,0.00001e-6], np.float64) # ligand concentration, M # Stated concentrations of protein and ligand. Pstated = 0.5e-6 * np.ones([24],np.float64) # protein concentration, M # Assay configuration details import math assay_volume = 50e-6 # assay volume, L
def get_data_using_inputs(inputs): """ Parses your data according to inputs dictionary. Requires you have a 'file_set' in your inputs. Parameters ---------- inputs : dict Dictionary of input information """ complex_fluorescence = {} ligand_fluorescence = {} for protein in inputs['file_set'].keys(): #concatenate xmls into one dictionary with all ligand data my_file = [] # Data just helps define our keys, which will be our data sections. # We are importing the first two files, because sometimes we have two files per # data collection, e.g. if we wanted a lot of types of reads # (there is a limited number of type of read on the infinite per script). data = platereader.read_icontrol_xml(inputs['file_set']['%s' % protein][0]) try: data.update( platereader.read_icontrol_xml(inputs['file_set']['%s' % protein][1])) except: pass for file in inputs['file_set']['%s' % protein]: my_file.append(file) new_dict = platereader.read_icontrol_xml(file) for key in data: try: data[key].update(new_dict[key]) except: pass # Are there any experiments the user wants to skip analyzing? skipped_experiments = [] for i, ligand in enumerate(inputs['ligand_order']): if ligand == None: skipped_experiments.append(i * 2) else: continue skipped_rows = [] for i in skipped_experiments: skipped_rows.append(ALPHABET[i]) skipped_rows.append(ALPHABET[i + 1]) print("Skipping analysis of rows: ", skipped_rows) for i in range(0, len(inputs['ligand_order'] * 2), 2): if i in skipped_experiments: continue else: protein_row = ALPHABET[i] buffer_row = ALPHABET[i + 1] name = "%s-%s-%s%s" % (protein, inputs['ligand_order'][int( i / 2)], protein_row, buffer_row) # for spectra assays if 'wavelength' in inputs: complex_fluorescence_data = platereader.select_data( data, inputs['section'], protein_row, wavelength='%s' % inputs['wavelength']) ligand_fluorescence_data = platereader.select_data( data, inputs['section'], buffer_row, wavelength='%s' % inputs['wavelength']) # for single wavelength assays else: complex_fluorescence_data = platereader.select_data( data, inputs['section'], protein_row) ligand_fluorescence_data = platereader.select_data( data, inputs['section'], buffer_row) complex_fluorescence[name] = reorder2list( complex_fluorescence_data, well) ligand_fluorescence[name] = reorder2list( ligand_fluorescence_data, well) return [complex_fluorescence, ligand_fluorescence]