예제 #1
0
def test(OD_data, temp_data, vials, elapsed_time, exp_name):
    control = np.power(2, range(0, 32))
    flow_rate = np.array([
        1.01, 1.05, 1.06, 1.03, 1.05, 1.04, 1.07, 1.1, 1.03, 1.07, 1.02, 1,
        0.99, 1.04, 1.05, 1
    ])  #ml/sec
    volume = 30  #mL
    lower_thresh = np.array([
        0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
        9999, 9999, 9999, 9999
    ])
    upper_thresh = np.array([
        0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 9999, 9999,
        9999, 9999
    ])
    time_out = 20
    pump_wait = 7
    #wait between pumps (min)
    for x in vials:
        if OD_data[x] > upper_thresh[x]:
            time_in = -(np.log(lower_thresh[x] / upper_thresh[x]) *
                        volume) / flow_rate[x]
            MESSAGE = "%s,0,%d," % ("{0:b}".format(control[x] +
                                                   control[x + 16]), time_in)
            eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                         pump_wait * 60, exp_name, time_in,
                                         'n')
            MESSAGE = "%s,0,%d," % ("{0:b}".format(control[x + 16]), time_out)
            eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                         pump_wait * 60, exp_name, time_out,
                                         'y')
예제 #2
0
def update_Graphs():
    elapsed_time = round((time.time() - start_time), 0)
    if OD_data == 'empty':
        send_alert()
    else:

        print "Efflux ON for overflow check"
        MESSAGE = "111111110000000000000000,0,20,"
        eVOLVER_module.fluid_command(MESSAGE, 0, elapsed_time, 1, exp_name, 1,
                                     'n')
        MESSAGE = "11111111000000000000000000000000,0,20,"
        eVOLVER_module.fluid_command(MESSAGE, 0, elapsed_time, 1, exp_name, 1,
                                     'n')

        print "Increasing stir rate to prevent biofilm"
        global graph_exp
        #        eVOLVER_module.graph_data(vials, exp_name, 'OD')
        #        eVOLVER_module.graph_data(vials, exp_name, 'temp')
        eVOLVER_module.calc_growth_rate(vials, exp_name, elapsed_time, .3)
        MESSAGE = "20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,"
        #        MESSAGE = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
        eVOLVER_module.stir_rate(MESSAGE)
        print "Fast stirring!!!"
        time.sleep(40)
        MESSAGE = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
        eVOLVER_module.stir_rate(MESSAGE)
        time.sleep(10)
        MESSAGE = "12,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,"
        eVOLVER_module.stir_rate(MESSAGE)
        print "Normal stirring"
        time.sleep(20)
        graph_exp = root.after(60000 * 60, update_Graphs)
        print "Clean cycle completed!"
예제 #3
0
파일: custom_script.py 프로젝트: zheins/dpu
def turbidostat(OD_data, temp_data, vials, elapsed_time):

    ##### USER DEFINED VARIABLES #####

    turbidostat_vials = vials  #vials is all 16, can set to different range (ex. [0,1,2,3]) to only trigger tstat on those vials
    stop_after_n_curves = np.inf  #set to np.inf to never stop, or integer value to stop diluting after certain number of growth curves

    lower_thresh = [0.2] * len(
        vials)  #to set all vials to the same value, creates 16-value list
    upper_thresh = [0.4] * len(
        vials)  #to set all vials to the same value, creates 16-value list

    #Alternatively, use 16 value list to set different thresholds, use 9999 for vials not being used
    #lower_thresh = [0.2, 0.2, 0.3, 0.3, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999]
    #upper_thresh = [0.4, 0.4, 0.4, 0.4, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999]

    ##### END OF USER DEFINED VARIABLES #####

    ##### Turbidostat Settings #####
    #Tunable settings for overflow protection, pump scheduling etc. Unlikely to change between expts

    time_out = 5  #(sec) additional amount of time to run efflux pump
    pump_wait = 3  # (min) minimum amount of time to wait between pump events

    ##### End of Turbidostat Settings #####

    control = np.power(2, range(0, 32))  #vial addresses
    save_path = os.path.dirname(os.path.realpath(__file__))  #save path
    flow_rate = eVOLVER_module.get_flow_rate()  #read from calibration file

    ##### Turbidostat Control Code Below #####

    for x in turbidostat_vials:  #main loop through each vial

        # Update turbidostat configuration files for each vial
        # initialize OD and find OD path

        file_name = "vial{0}_ODset.txt".format(x)
        ODset_path = os.path.join(save_path, EXP_NAME, 'ODset', file_name)
        data = np.genfromtxt(ODset_path, delimiter=',')
        ODset = data[len(data) - 1][1]
        ODsettime = data[len(data) - 1][0]
        num_curves = len(data) / 2

        file_name = "vial{0}_OD.txt".format(x)
        OD_path = os.path.join(save_path, EXP_NAME, 'OD', file_name)
        data = np.genfromtxt(OD_path, delimiter=',')
        average_OD = 0

        # Determine whether turbidostat dilutions are needed
        enough_ODdata = (
            len(data) > 7
        )  #logical, checks to see if enough data points (couple minutes) for sliding window
        collecting_more_curves = (
            num_curves <= (stop_after_n_curves + 2)
        )  #logical, checks to see if enough growth curves have happened

        if enough_ODdata:
            # Take median to avoid outlier
            od_values_from_file = []
            for n in range(1, 7):
                od_values_from_file.append(data[len(data) - n][1])
            average_OD = float(np.median(od_values_from_file))

            #if recently exceeded upper threshold, note end of growth curve in ODset, allow dilutions to occur and growthrate to be measured
            if (average_OD > upper_thresh[x]) and (ODset != lower_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("{0},{1}\n".format(elapsed_time,
                                                   lower_thresh[x]))
                text_file.close()
                ODset = lower_thresh[x]
                # calculate growth rate
                eVOLVER_module.calc_growth_rate(x, ODsettime, elapsed_time)

            #if have approx. reached lower threshold, note start of growth curve in ODset
            if (average_OD < (lower_thresh[x] +
                              (upper_thresh[x] - lower_thresh[x]) / 3)) and (
                                  ODset != upper_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("{0},{1}\n".format(elapsed_time,
                                                   upper_thresh[x]))
                text_file.close()
                ODset = upper_thresh[x]

            #if need to dilute to lower threshold, then calculate amount of time to pump
            if average_OD > ODset and collecting_more_curves:

                time_in = -(np.log(lower_thresh[x] / average_OD) *
                            VOLUME) / flow_rate[x]

                if time_in > 20:
                    time_in = 20

                time_in = round(time_in, 2)

                save_path = os.path.dirname(os.path.realpath(__file__))
                file_name = "vial{0}_pump_log.txt".format(x)
                file_path = os.path.join(save_path, EXP_NAME, 'pump_log',
                                         file_name)
                data = np.genfromtxt(file_path, delimiter=',')
                last_pump = data[len(data) - 1][0]
                if (
                    (elapsed_time - last_pump) * 60
                ) >= pump_wait:  # if sufficient time since last pump, send command to Arduino
                    MESSAGE = {
                        'pumps_binary': "{0:b}".format(control[x]),
                        'pump_time': time_in,
                        'efflux_pump_time': time_out,
                        'delay_interval': 0,
                        'times_to_repeat': 0,
                        'run_efflux': 1
                    }
                    eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                                 pump_wait * 60, time_in, 'y')
예제 #4
0
def test(OD_data, temp_data, vials, elapsed_time, exp_name):

    ##### USER DEFINED VARIABLES #####

    temp_input = 30  #degrees C, can be scalar or 16-value numpy array
    stir_input = 8  #try 8,10,12; can be scalar or 16-value numpy array

    lower_thresh = np.array([9999] * len(vials))
    upper_thresh = np.array([9999] * len(vials))
    # lower_thresh = np.array([0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2])
    # upper_thresh = np.array([0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4,0.4])

    ##### END OF USER DEFINED VARIABLES #####

    ##### Calibration Values:
    # Be sure to check that OD_cal.txt and temp_calibration.txt are up to date
    # Additional calibration values below, remain the same between experiments

    time_out = 15  #(sec) additional amount of time to run efflux pump
    pump_wait = 3  # (min) minimum amount of time to wait between pump events
    control = np.power(2, range(0, 32))  #vial addresses
    flow_rate = np.array([
        0.95, 1.1, 0.975, 0.85, 0.95, 1.05, 1.05, 1.05, 1.025, 1.125, 1.0, 1.0,
        1.05, 1.15, 1.1, 1.025
    ])  #ml/sec, paste from pump calibration
    volume = 30  #mL, determined by straw length

    save_path = os.path.dirname(os.path.realpath(__file__))  #save path

    ##### End of Calibration Values

    ##### Turbidostat Control Code Below #####

    for x in vials:  #main loop through each vial

        # Update temperature configuration files for each vial
        file_name = "vial{0}_tempconfig.txt".format(x)
        tempconfig_path = os.path.join(save_path, exp_name, 'temp_config',
                                       file_name)
        temp_config = np.genfromtxt(tempconfig_path, delimiter=',')

        if (
                len(temp_config) is 2
        ):  #set temp at the beginning of the experiment, can clone for subsequent temp changes
            if np.isscalar(temp_input):
                temp_val = temp_input
            else:
                temp_val = temp_input[x]

            text_file = open(tempconfig_path, "a+")
            text_file.write("{0},{1}\n".format(elapsed_time, temp_val))
            text_file.close()

        # Update turbidostat configuration files for each vial
        # initialize OD and find OD path

        file_name = "vial{0}_ODset.txt".format(x)
        ODset_path = os.path.join(save_path, exp_name, 'ODset', file_name)
        data = np.genfromtxt(ODset_path, delimiter=',')
        ODset = data[len(data) - 1][1]

        file_name = "vial{0}_OD.txt".format(x)
        OD_path = os.path.join(save_path, exp_name, 'OD', file_name)
        data = np.genfromtxt(OD_path, delimiter=',')
        average_OD = 0

        # Determine whether turbidostat dilutions are needed
        if len(data) > 7:
            # Take median to avoid outlier
            od_values_from_file = []
            for n in range(1, 7):
                od_values_from_file.append(data[len(data) - n][1])
            average_OD = float(np.median(od_values_from_file))

            if (average_OD > upper_thresh[x]) and (ODset != lower_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("{0},{1}\n".format(elapsed_time,
                                                   lower_thresh[x]))
                text_file.close()
                ODset = lower_thresh[x]

            if (average_OD < (lower_thresh[x] +
                              (upper_thresh[x] - lower_thresh[x]) / 2)) and (
                                  ODset != upper_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("{0},{1}\n".format(elapsed_time,
                                                   upper_thresh[x]))
                text_file.close()
                ODset = upper_thresh[x]

            if average_OD > ODset:

                time_in = -(np.log(lower_thresh[x] / average_OD) *
                            volume) / flow_rate[x]

                if time_in > 20:
                    time_in = 20

                save_path = os.path.dirname(os.path.realpath(__file__))
                file_name = "vial{0}_pump_log.txt".format(x)
                file_path = os.path.join(save_path, exp_name, 'pump_log',
                                         file_name)
                data = np.genfromtxt(file_path, delimiter=',')
                last_pump = data[len(data) - 1][0]
                if ((elapsed_time - last_pump) * 60) >= pump_wait:
                    MESSAGE = {
                        'pumps_binary': "{0:b}".format(control[x]),
                        'pump_time': time_in,
                        'efflux_pump_time': time_out,
                        'delay_interval': 0,
                        'times_to_repeat': 0,
                        'run_efflux': 1
                    }
                    eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                                 pump_wait * 60, exp_name,
                                                 time_in, 'y')
예제 #5
0
def test (OD_data, temp_data, vials, elapsed_time, exp_name):
    MESSAGE = "8,8,8,8,8,8,8,8,14,8,8,14,8,8,8,8,"
    eVOLVER_module.stir_rate(MESSAGE)
    
    control = np.power(2,range(0,32))
    flow_rate = np.array([1.11,1.11,1.1,1.08,1.1,1.12,1.04,1.1,1.13,1.12,0.93,1.1,1.1,1.17,1.07,1.1])#ml/sec
    volume =  30#mL

    lower_thresh = np.array([.17,.17,.17,.17,.17,.17,.17,.17,.17,.17,.17,.17,.17,.17,.17,.17])
    upper_thresh = np.array([.2,.2,.2,.2,.2,.2,.2,.2,.2,.2,.2,.2,.2,.2,.2,.2])

    heat_shockdelay = 5.5 #hours
    normal_temp = 30.0 #degrees C
    temp_mag = np.array([30,33,33,33,36,36,36,36,39,39,39,39,42,42,42,42])
    temp_period = np.array([9999,2,6,48,9999,2,6,48,9999,2,6,48,9999,2,6,48])

    #temp_mag = np.array([42,42,42,42,39,39,39,39,36,36,36,36,33,33,33,30])
    #temp_period = np.array([2,6,48,9999,2,6,48,9999,2,6,48,9999,2,6,48,9999])
    
    
    time_out =5
    pump_wait = 3; #wait between pumps (min)

    save_path = os.path.dirname(os.path.realpath(__file__))

    for x in vials:
        if elapsed_time > heat_shockdelay:
            tempconfig_path =  "%s/%s/temp_config/vial%d_tempconfig.txt" % (save_path,exp_name,x)
            temp_config = np.genfromtxt(tempconfig_path, delimiter=',')
            last_tempset = temp_config[len(temp_config)-1][0]

            if (len(temp_config) is 2):
                text_file = open(tempconfig_path,"a+")
                text_file.write("%f,%s\n" %  (elapsed_time, temp_mag[x]))
                text_file.close()

            if ((elapsed_time - last_tempset) > (float(temp_period[x])/2)):
                text_file = open(tempconfig_path,"a+")
                if (len(temp_config) % 2 == 0):
                    text_file.write("%f,%s\n" %  (elapsed_time, temp_mag[x]))
                else:
                    text_file.write("%f,%s\n" %  (elapsed_time, normal_temp))
                text_file.close()

        ODset_path =  "%s/%s/ODset/vial%d_ODset.txt" % (save_path,exp_name,x)
        data = np.genfromtxt(ODset_path, delimiter=',')
        ODset = data[len(data)-1][1]


        OD_path =  "%s/%s/OD/vial%d_OD.txt" % (save_path,exp_name,x)
        data = np.genfromtxt(OD_path, delimiter=',')
        average_OD = 0

        if len(data) > 15:
            for n in range(1,6):
                average_OD = average_OD + (data[len(data)-n][1]/5)


            if (average_OD > upper_thresh[x]) and (ODset != lower_thresh[x]):
                text_file = open(ODset_path,"a+")
                text_file.write("%f,%s\n" %  (elapsed_time, lower_thresh[x]))
                text_file.close()
                ODset = lower_thresh[x]

            if (average_OD < (lower_thresh[x] + 0.005)) and (ODset != upper_thresh[x]):
                text_file = open(ODset_path,"a+")
                text_file.write("%f,%s\n" %  (elapsed_time, upper_thresh[x]))
                text_file.close()
                ODset = upper_thresh[x]

            if average_OD > ODset:

                time_in = - (np.log(lower_thresh[x]/average_OD)*volume)/flow_rate[x]

                if time_in > 20:
                    time_in = 20


                MESSAGE = "%s,0,%d," % ("{0:b}".format(control[x]+control[x+16]) , time_in)
                eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait *60, exp_name, time_in, 'n')
                MESSAGE = "%s,0,%d," % ("{0:b}".format(control[x+16]) , time_out)
                #eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait *60, exp_name, time_out,'n')
                eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait *60, exp_name, time_out,'y')
예제 #6
0
def valving(mux_command,
            vial_num=0,
            media_type=[0],
            step_size=[5000],
            vials=range(0, 16),
            x=1,
            elapsed_time=99999,
            pump_wait=1,
            exp_name='mux_test1',
            time_in=1,
            wash=3,
            preflush=2000,
            logging='n'):

    ## translates mux_command (formatted as string) to valving scheme
    if mux_command == 'syringe':
        y = vial_num

        #preflush with air
        path = list(set(media[0]))
        bin_path = format(sum([binvals[i] for i in path]), '032b')
        MESSAGE = "%s,0,%d," % (bin_path, preflush)
        eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait * 60,
                                     exp_name, time_in, 'n')
        #print(MESSAGE)

        #draw media
        for z in range(0, len(media_type)):
            path = list(set(media[media_type[z]]))
            bin_path = format(sum([binvals[i] for i in path]), '032b')
            MESSAGE = "%s,0,%d," % (bin_path, step_size[z])
            eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                         pump_wait * 60, exp_name, time_in,
                                         'n')
        #print(MESSAGE)

        #dispense media
        path = list(set(demux[y] + influx + efflux + mux[y] + peri))
        bin_path = format(sum([binvals[i] for i in path]), '032b')
        MESSAGE = "%s,0,%d," % (bin_path, (-1 * sum(step_size) - preflush))
        eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait * 60,
                                     exp_name, time_in, 'n')
        #print(MESSAGE)

    if mux_command == 'precleaned_syringe':
        y = vial_num

        #preflush with air
        path = list(set(media[0]))
        bin_path = format(sum([binvals[i] for i in path]), '032b')
        MESSAGE = "%s,0,%d," % (bin_path, preflush)
        eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait * 60,
                                     exp_name, time_in, 'n')
        #print(MESSAGE)

        #draw wash
        path = list(set(media[7]))
        bin_path = format(sum([binvals[i] for i in path]), '032b')
        MESSAGE = "%s,0,%d," % (bin_path, sum(step_size))
        eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait * 60,
                                     exp_name, time_in, 'n')
        #print(MESSAGE)

        #dispense wash
        path = list(set(demux[y] + bridge + mux[y] + peri))
        bin_path = format(sum([binvals[i] for i in path]), '032b')
        MESSAGE = "%s,0,%d," % (bin_path, (-1 * sum(step_size) - preflush))
        eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait * 60,
                                     exp_name, time_in, 'n')
        #print(MESSAGE)

        #preflush again
        path = list(set(media[0]))
        bin_path = format(sum([binvals[i] for i in path]), '032b')
        MESSAGE = "%s,0,%d," % (bin_path, preflush)
        eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait * 60,
                                     exp_name, time_in, 'n')
        #print(MESSAGE)

        #draw media
        for z in range(0, len(media_type)):
            path = list(set(media[media_type[z]]))
            bin_path = format(sum([binvals[i] for i in path]), '032b')
            MESSAGE = "%s,0,%d," % (bin_path, step_size[z])
            eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                         pump_wait * 60, exp_name, time_in,
                                         'n')
        #print(MESSAGE)

        #dispense media
        path = list(set(demux[y] + influx + efflux + mux[y] + peri))
        bin_path = format(sum([binvals[i] for i in path]), '032b')
        MESSAGE = "%s,0,%d," % (bin_path, (-1 * sum(step_size) - preflush))
        eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait * 60,
                                     exp_name, time_in, 'n')
        #print(MESSAGE)

    if mux_command == 'flush':  #set vials in function call in order to not wash all lines, otherwise range(0,16)

        for y in vials:  #wash using peristaltic
            path = list(
                set(media[media_type[0]] + demux[y] + mux[y] + bridge + peri))
            bin_path = format(sum([binvals[i] for i in path]), '032b')
            MESSAGE = "%s,1,%d," % (bin_path, wash)
            eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                         pump_wait * 60, exp_name, time_in,
                                         'n')
            #print(MESSAGE)

    if mux_command == 'efflux':  #set vials in function call in order to not clear all efflux lines, otherwise range(0,16)
        for y in vials:
            path = list(set(mux[y] + efflux + peri))
            bin_path = format(sum([binvals[i] for i in path]), '032b')
            MESSAGE = "%s,1,%d," % (bin_path, wash)
            eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                         pump_wait * 60, exp_name, time_in,
                                         logging)
예제 #7
0
import time
import pickle
import numpy as np
import numpy.matlib
import requests

import eVOLVER_module
import custom_script

x = 1  #why is this needed?
elapsed_time = 99999  #ensures fluidic commands not stopped by timing
pump_wait = 1  #ensures fluidic commands not stopped by timing
exp_name = 'mux_test1'  #match with main_eVOLVER.py
time_in = 1  #also not needed

eVOLVER_module.fluid_command('clear', x, elapsed_time, pump_wait * 60,
                             exp_name, time_in, 'n')
exp_continue = raw_input('Conduct pump test (y/n): ')
while exp_continue == 'y':
    custom_script.pump(3, [7], [5000], logging='n')
    print('Testing...')
    exp_continue = raw_input('Conduct test again(y/n): ')

exp_continue = raw_input('Conduct pump test with precleaning (y/n): ')
while exp_continue == 'y':
    custom_script.precleaned_pump(3, [7], [5000], logging='n')
    print('Testing...')
    exp_continue = raw_input('Conduct test again(y/n): ')

exp_continue = raw_input('Conduct wash (y/n): ')
while exp_continue == 'y':
    custom_script.valving('flush', vials=[3], media_type=[7])
예제 #8
0
def test (OD_data, temp_data, vials, elapsed_time, exp_name):
    MESSAGE = "15,15,15,15,15,15,15,15,15,15,15,15,15,15,12,15,"
    eVOLVER_module.stir_rate(MESSAGE)
        
    control = np.power(2,range(0,32))
    flow_rate = np.array([1.07,1,1.15,1.05,0.96,1.11,1.18,1.01,1.07,1.04,1.1,1.03,1.1,1.1,0.95,1.07])#ml/sec
    volume =  15 #mL

    lower_thresh = np.array([0.05, 0.05,9999999,0.1,0.05,9999999,0.1,9999999,0.15,0.05,0.1,0.15,0.2,0.05,0.1,0.15])
    upper_thresh = np.array([0.1,0.15,9999999,0.15,0.2,9999999,0.2,9999999,0.2,0.25,0.25,0.25,0.25,0.3,0.3,0.3])

    #lower_thresh = np.array([.05,.05,.05,.05,.05,.05,.05,.05,.05,.05,.05,.05,.05,.05,.05,.05])
    #upper_thresh = np.array([.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1])
    #lower_thresh = np.array([.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6,.6])
    #upper_thresh = np.array([.65,.65,.65,.65,.65,.65,.65,.65,.65,.65,.65,.65,.65,.65,.65,.65])
    time_out =5
    pump_wait = 2; #wait between pumps (min)

    save_path = os.path.dirname(os.path.realpath(__file__))

    for x in vials:

        ODset_path =  "%s/%s/ODset/vial%d_ODset.txt" % (save_path,exp_name,x)
        data = np.genfromtxt(ODset_path, delimiter=',')
        ODset = data[len(data)-1][1]


        OD_path =  "%s/%s/OD/vial%d_OD.txt" % (save_path,exp_name,x)
        data = np.genfromtxt(OD_path, delimiter=',')
        average_OD = 0

        if len(data) > 15:
            for n in range(1,6):
                average_OD = average_OD + (data[len(data)-n][1]/5)


            if (average_OD > upper_thresh[x]) and (ODset != lower_thresh[x]):
                text_file = open(ODset_path,"a+")
                text_file.write("%f,%s\n" %  (elapsed_time, lower_thresh[x]))
                text_file.close()
                ODset = lower_thresh[x]

            if (average_OD < (lower_thresh[x] + 0.005)) and (ODset != upper_thresh[x]):
                text_file = open(ODset_path,"a+")
                text_file.write("%f,%s\n" %  (elapsed_time, upper_thresh[x]))
                text_file.close()
                ODset = upper_thresh[x]

            if average_OD > ODset:

                time_in = - (np.log((lower_thresh[x]-0.005)/average_OD)*volume)/flow_rate[x]

                if time_in > 30:
                    time_in = 30


                MESSAGE = "%s,0,%d," % ("{0:b}".format(control[x]+control[x+16]) , time_in)
                eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait *60, exp_name, time_in, 'n')
                MESSAGE = "%s,0,%d," % ("{0:b}".format(control[x+16]) , time_out)
                #eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait *60, exp_name, time_out,'n')
                eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time, pump_wait *60, exp_name, time_out,'y')
예제 #9
0
def test(OD_data, temp_data, vials, elapsed_time, exp_name):

    ### Set Stir Rate
    #### Message Stir Rates
    MESSAGE = ""
    for x in vials:
        stir_rate_path = "%s/%s/stir_rate/vial%d_stir_rate.txt" % (save_path,
                                                                   exp_name, x)
        data = np.genfromtxt(stir_rate_path, delimiter=',')
        stir_set = data[len(data) - 1][1]
        MESSAGE += str(stir_set)
        MESSAGE += ","

    eVOLVER_module.stir_rate(MESSAGE)

    control = np.power(2, range(0, 32))
    #flow_rate = np.array([1.11,1.11,1.1,1.08,1.1,1.12,1.04,1.1,1.13,1.12,0.93,1.1,1.1,1.17,1.07,1.1])#ml/sec
    volume = 35  #mL

    #lower_thresh = np.array([.25,.25,.25,.25,.25,.25,.25,.25,.25,.25,.25,.25,.25,.25,.25,.25])
    #upper_thresh = np.array([.3,.3,.3,.3,.3,.3,.3,.3,.3,.3,.3,.3,.3,.3,.3,.3])

    lower_thresh = np.array([
        .25, .25, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999,
        9999, 9999, 9999, 9999
    ])
    upper_thresh = np.array([
        .3, .3, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999,
        9999, 9999, 9999, 9999
    ])

    time_out = 5
    pump_wait = 10
    #wait between pumps (min)

    save_path = os.path.dirname(os.path.realpath(__file__))

    drug_dose_start = 10  #hours
    vial2vial_timeThresh = 14  #hours

    #### Change media based on before or after drug dose
    if elapsed_time > drug_dose_start:
        media = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    else:
        media = np.array([1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

        #media 0- YPD
        #media 1- YPD + chx
        #media 2- YPD + keto
        #media 3- YPD + chx + keto
        #media 4- YPD + 20x chx
        #media 5- YPD + 20x keto
        #media 7- YPD + 20x keto + 20x chx

    ###### Make decision to dilute or not ################

    for x in vials:
        ODset_path = "%s/%s/ODset/vial%d_ODset.txt" % (save_path, exp_name, x)
        data = np.genfromtxt(ODset_path, delimiter=',')
        ODset = data[len(data) - 1][1]

        OD_path = "%s/%s/OD/vial%d_OD.txt" % (save_path, exp_name, x)
        data = np.genfromtxt(OD_path, delimiter=',')
        average_OD = 0

        if len(data) > 15:
            ## Averages last 5 data points
            for n in range(1, 6):
                average_OD = average_OD + (data[len(data) - n][1] / 5)

            ######### Set OD thresholds ########

            #### Set to lower target growth rate for dilutions
            if (average_OD > upper_thresh[x]) and (ODset != lower_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("%f,%s\n" % (elapsed_time, lower_thresh[x]))
                text_file.close()
                ODset = lower_thresh[x]

                ########## Measure and record growth rate when hits OD threshold###########
                growth_rate = measure_growthRate(x, save_path, exp_name)
                growth_rate_path = "%s/%s/growth_rate/vial%d_growth_rate.txt" % (
                    save_path, exp_name, x)
                text_file = open(growth_rate_path, "a+")
                text_file.write("%f,%s\n" % (elapsed_time, growth_rate))
                text_file.close()

            if (average_OD <
                (lower_thresh[x] + 0.005)) and (ODset != upper_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("%f,%s\n" % (elapsed_time, upper_thresh[x]))
                text_file.close()
                ODset = upper_thresh[x]

            ### Average last three growth rates ######
            growth_rate_path = "%s/%s/growth_rate/vial%d_growth_rate.txt" % (
                save_path, exp_name, x)
            rate_data = np.genfromtxt(growth_rate_path, delimiter=',')
            average_rate = 0
            num_averaged = 3
            if len(rate_data) > num_averaged:
                for n in range(1, num_averaged + 1):
                    average_rate = average_rate + (
                        rate_data[len(rate_data) - n][1] / num_averaged)

            ##### Make decision on growth rates #####
            if elapsed_time > vial2vial_timeThresh:
                rate_thresholds = np.array(
                    np.mat('0 99999; 1 99999; 0 99999; 1 99999')
                )  ## [vial_output, growth_rate threshold]
                next_vial_0 = np.array(np.mat('2 4; 5 7; 8 10; 11 13'))
                next_vail_1 = np.array(
                    np.mat('3 4; 6 7; 9 10; 12 13'))  ## ['vial_in1, vial_in2']
                for n in range(0, len(rate_thresholds)):
                    if x == rate_thresholds[n][
                            0]:  ## checks to see if correct vial output
                        if average_rate > rate_thresholds[n][
                                1]:  ## check to see what the rate threshold is

                            rate_thresh_path = "%s/%s/rate_thresh/vial%d_rate_thresh.txt" % (
                                save_path, exp_name, x)
                            data = np.genfromtxt(rate_thresh_path,
                                                 delimiter=',')
                            last_rate_thresh = data[len(data) - 1][1]

                            if rate_thresholds[n][1] > last_rate_thresh:

                                rate_thresh_path = "%s/%s/rate_thresh/vial%d_rate_thresh.txt" % (
                                    save_path, exp_name, x)
                                text_file = open(rate_thresh_path, "a+")
                                text_file.write(
                                    "%f,%s\n" %
                                    (elapsed_time, rate_thresholds[n][1]))
                                text_file.close()

                                ## media, vialOut, vialIn1, vialIn2
                                MESSAGE = "v2v_2x,%d,2000,0,%d,%d,%d,100,5,2000," % (
                                    media[0], 0, next_vial_0[n][0],
                                    next_vial_0[n][1])
                                eVOLVER_module.fluid_command(
                                    MESSAGE, 0, elapsed_time, pump_wait * 60,
                                    exp_name, time_out, 'y')

                                ODset_path = "%s/%s/ODset/vial%d_ODset.txt" % (
                                    save_path, exp_name, 0)
                                text_file = open(ODset_path, "a+")
                                text_file.write(
                                    "%f,%s\n" %
                                    (elapsed_time, upper_thresh[0]))
                                text_file.close()

                                ## media, vialOut, vialIn1, vialIn2
                                MESSAGE = "v2v_2x,%d,2000,0,%d,%d,%d,100,5,2000," % (
                                    media[1], 1, next_vial_1[n][0],
                                    next_vial_1[n][1])
                                eVOLVER_module.fluid_command(
                                    MESSAGE, 1, elapsed_time, pump_wait * 60,
                                    exp_name, time_out, 'y')

                                ODset_path = "%s/%s/ODset/vial%d_ODset.txt" % (
                                    save_path, exp_name, 1)
                                text_file = open(ODset_path, "a+")
                                text_file.write(
                                    "%f,%s\n" %
                                    (elapsed_time, upper_thresh[1]))
                                text_file.close()

            #### Make decision for stir rates if above a certain density then change stir rate
            stir_thresh = .8
            if average_OD > stir_thresh:

                stir_rate_path = "%s/%s/stir_rate/vial%d_stir_rate.txt" % (
                    save_path, exp_name, x)
                data = np.genfromtxt(stir_rate_path, delimiter=',')
                stir_set = data[len(data) - 1][1]

                if stir_set == 0:
                    stir_rate_path = "%s/%s/stir_rate/vial%d_stir_rate.txt" % (
                        save_path, exp_name, x)
                    text_file = open(stir_rate_path, "a+")
                    text_file.write("%f,%s\n" % (elapsed_time, 0))
                    text_file.close()

            if average_OD > ODset:
                time_in = 0
                step_size = ((
                    (-1) * np.log(lower_thresh[x] / average_OD) * volume) +
                             .1) / (.0009)

                if step_size < 1000:
                    step_size = 1000

                MESSAGE = "dilute,%d,%d,0,%d,3,5,0,0,0," % (media[x],
                                                            step_size, x)
                eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                             pump_wait * 60, exp_name,
                                             time_out, 'y')
예제 #10
0
def test(OD_data, temp_data, vials, elapsed_time, exp_name):

    ##### USER DEFINED VARIABLES #####

    temp_input = 25  #degrees C, can be scalar or 16-value numpy array
    stir_input = 11  #try 8,10,12; see paper for rpm conversion, can be scalar or 16-value numpy array

    # lower_thresh = np.array([0.2] * len(vials))
    lower_thresh = np.array([9999] * 16)
    upper_thresh = np.array([9999] * 16)

    ##### END OF USER DEFINED VARIABLES #####

    ##### Calibration Values:
    # Be sure to check that OD_cal.txt and temp_calibration.txt are up to date
    # Additional calibration values below, remain the same between experiments

    time_out = 5  #(sec) additional amount of time to run efflux pump
    pump_wait = 15  # (min) minimum amount of time to wait between pump events
    control = np.power(2, range(0, 32))  #vial addresses
    flow_rate = np.array([
        0.95, 1.1, 0.975, 0.85, 0.95, 1.05, 1.05, 1.05, 1.025, 1.125, 1.0, 1.0,
        1.05, 1.15, 1.1, 1.025
    ])  #ml/sec, paste from pump calibration
    volume = 25  #mL, determined by straw length

    save_path = os.path.dirname(os.path.realpath(__file__))  #save path

    ##### End of Calibration Values

    ##### Turbidostat Control Code Below #####

    for x in vials:  #main loop through each vial

        # Update temperature configuration files for each vial
        tempconfig_path = "{0}/{1}/temp_config/vial{2}_tempconfig.txt".format(
            save_path, exp_name, x)
        temp_config = np.genfromtxt(tempconfig_path, delimiter=',')

        if (
                len(temp_config) is 2
        ):  #set temp at the beginning of the experiment, can clone for subsequent temp changes
            if np.isscalar(temp_input):
                temp_val = temp_input
            else:
                temp_val = temp_input[x]

            text_file = open(tempconfig_path, "a+")
            text_file.write("{0},{1}\n".format(elapsed_time, temp_val))
            text_file.close()

        # Update turbidostat configuration files for each vial

        # initialize OD and find OD path

        ODset_path = "{0}/{1}/ODset/vial{2}_ODset.txt".format(
            save_path, exp_name, x)
        data = np.genfromtxt(ODset_path, delimiter=',')
        ODset = data[len(data) - 1][1]

        OD_path = "{0}/{1}/OD/vial{2}_OD.txt".format(save_path, exp_name, x)
        data = np.genfromtxt(OD_path, delimiter=',')
        average_OD = 0

        # Determine whether turbidostat dilutions are needed

        if len(data) > 7:
            for n in range(1, 6):
                average_OD = average_OD + (data[len(data) - n][1] / 5)

            if (average_OD > upper_thresh[x]) and (ODset != lower_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("{0},{1}\n".format(elapsed_time,
                                                   lower_thresh[x]))
                text_file.close()
                ODset = lower_thresh[x]

            if (average_OD < (lower_thresh[x] +
                              (upper_thresh[x] - lower_thresh[x]) / 2)) and (
                                  ODset != upper_thresh[x]):
                text_file = open(ODset_path, "a+")
                text_file.write("{0},{1}\n".format(elapsed_time,
                                                   upper_thresh[x]))
                text_file.close()
                ODset = upper_thresh[x]

            if average_OD > ODset:

                time_in = -(np.log(lower_thresh[x] / average_OD) *
                            volume) / flow_rate[x]

                if time_in > 20:
                    time_in = 20

                save_path = os.path.dirname(os.path.realpath(__file__))
                file_path = "{0}/{1}/pump_log/vial{2}_pump_log.txt".format(
                    save_path, exp_name, x)
                data = np.genfromtxt(file_path, delimiter=',')
                last_pump = data[len(data) - 1][0]
                if ((elapsed_time - last_pump) * 60) >= pump_wait:
                    MESSAGE = {
                        'pump_binary': "{0:b}".format(control[x]),
                        'pump_time': time_in,
                        'efflux_pump_time': time_out,
                        'delay_interval': 0,
                        'times_to_repeat': 0,
                        'run_efflux': 1
                    }
                    eVOLVER_module.fluid_command(MESSAGE, x, elapsed_time,
                                                 pump_wait * 60, exp_name,
                                                 time_in, 'y')

    #Update stir rate for all vials
    if np.isscalar(stir_input):
        STIR_MESSAGE = [stir_input] * 16
    else:
        stir_val = np.array2string(stir_input, separator=',')
        stir_val = stir_val.replace(' ', '')
        stir_val = stir_val.replace('[', '')
        stir_val = stir_val.replace(']', '')
        STIR_MESSAGE = list(map(int, stir_val.split(',')))

    eVOLVER_module.stir_rate(STIR_MESSAGE)