Exemplo n.º 1
0
def plot_singlet_one_section(data, section):

    #This assumes protein data is in row above buffer data

    fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(12, 12))

    axes = axes.ravel()

    ALPHABET = string.ascii_uppercase

    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

    for i in range(0,15,2):
        protein_row = ALPHABET[i]
        buffer_row = ALPHABET[i+1]

        part1_data_protein = platereader.select_data(data, section, protein_row)
        part1_data_buffer = platereader.select_data(data, section, buffer_row)

        reorder_protein = reorder2list(part1_data_protein,well)
        reorder_buffer = reorder2list(part1_data_buffer,well)

        axes[i/2].semilogx()
        axes[i/2].plot(Lstated,reorder_protein,Lstated,reorder_buffer)
        axes[i/2].set_title('%s,%s' %(protein_row,buffer_row))

    fig.suptitle('%s' %section)
Exemplo n.º 2
0
def plot_singlet_one_section(data, section):

    #This assumes protein data is in row above buffer data

    fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(12, 12))

    axes = axes.ravel()

    ALPHABET = string.ascii_uppercase

    well = dict()
    for j in string.ascii_uppercase:
        for i in range(1, 25):
            well['%s' % j + '%s' % i] = i

    for i in range(0, 15, 2):
        protein_row = ALPHABET[i]
        buffer_row = ALPHABET[i + 1]

        try:
            part1_data_protein = platereader.select_data(
                data, section, protein_row)
            part1_data_buffer = platereader.select_data(
                data, section, buffer_row)

            reorder_protein = reorder2list(part1_data_protein, well)
            reorder_buffer = reorder2list(part1_data_buffer, well)

        except Exception as e:
            print('***no %s%s data*** : exception is %s' %
                  (protein_row, buffer_row, str(e)))
            continue

        axes[int(i / 2)].set_prop_cycle('color', ['black', 'red'])

        if i / 2 == 1:
            axes[int(i / 2)].plot(reorder_protein,
                                  marker='o',
                                  linestyle='None',
                                  label='protein+ligand')
            axes[int(i / 2)].plot(reorder_buffer,
                                  marker='o',
                                  linestyle='None',
                                  label='buffer+ligand')
            axes[int(i / 2)].legend(frameon=True)

        axes[int(i / 2)].plot(reorder_protein, marker='o', linestyle='None')
        axes[int(i / 2)].plot(reorder_buffer, marker='o', linestyle='None')
        axes[int(i / 2)].set_xticklabels(range(-4, 25, 5))
        axes[int(i / 2)].set_xlabel('Column Index',
                                    horizontalalignment='right',
                                    position=(1, 1),
                                    fontsize=8)
        axes[int(i / 2)].set_ylabel('Fluorescence')
        axes[int(i / 2)].set_title('%s,%s' % (protein_row, buffer_row))

    fig.suptitle('%s' % section)
Exemplo n.º 3
0
def plot_singlet_one_section(data, section):

    #This assumes protein data is in row above buffer data

    fig, axes = plt.subplots(nrows=3, ncols=3, figsize=(12, 12))

    axes = axes.ravel()

    ALPHABET = string.ascii_uppercase

    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

    for i in range(0, 15, 2):
        protein_row = ALPHABET[i]
        buffer_row = ALPHABET[i + 1]

        part1_data_protein = platereader.select_data(data, section,
                                                     protein_row)
        part1_data_buffer = platereader.select_data(data, section, buffer_row)

        reorder_protein = reorder2list(part1_data_protein, well)
        reorder_buffer = reorder2list(part1_data_buffer, well)

        axes[i / 2].semilogx()
        axes[i / 2].plot(Lstated, reorder_protein, Lstated, reorder_buffer)
        axes[i / 2].set_title('%s,%s' % (protein_row, buffer_row))

    fig.suptitle('%s' % section)
Exemplo n.º 4
0
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]
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
# 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
Exemplo n.º 7
0
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]