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!"
Exemple #2
0
def test_chemostat(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 = 10  #try 8,10,12; see paper for rpm conversion, can be scalar or 16-value numpy array

    start_OD = 0  # ~OD600, set to 0 to start chemostate dilutions at any positive OD

    start_time1 = 0  #hours, set 0 to start immediately
    rate_config1 = np.array(
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    )  #UNITS of 1/hr, NOT mL/hr, so dilution rate ~ growth rate, set to 0 for unused vials.

    #start_timeN = XX #define as many as needed if successive rounds with different flow rates needed
    #rate_configN = XX #define as many as needed if successive rounds with different flow rates needed

    ##### 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

    control = np.power(2, range(0, 32))  #vial addresses
    flow_rate = np.array([
        1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
        1.1, 1.1
    ])  #ml/sec, paste from pump calibration
    volume = 25  #mL, determined by straw length
    bolus = 500  #uL, can be changed with great caution, 200uL is absolute minimum
    period_config = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                              0])  #initialize array
    save_path = os.path.dirname(os.path.realpath(__file__))  #save path

    bolus_in_s = flow_rate * (bolus / 1000)

    ##### End of Calibration Values

    ##### Chemostat 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 chemostat configuration files for each vial

        #initialize OD and find OD path
        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

        if len(
                data
        ) > 7:  #waits for seven OD measurements (couple minutes) for sliding window
            for n in range(1, 6):
                average_OD = average_OD + (
                    data[len(data) - n][1] / 5
                )  #calculates average OD over a small window

            # set chemostat config path and pull current state from file
            file_name = "vial{0}_chemoconfig.txt".format(x)
            chemoconfig_path = os.path.join(save_path, exp_name,
                                            'chemo_config', file_name)
            chemo_config = np.genfromtxt(chemoconfig_path, delimiter=',')
            last_chemoset = chemo_config[len(chemo_config) - 1][
                0]  #should t=0 initially, changes each time a new command is written to file
            last_chemophase = chemo_config[len(chemo_config) - 1][
                1]  #should be zero initially, changes each time a new command is written to file

            # once start time has passed and culture hits start OD, if no command has been written, write new chemostat command to file
            if ((elapsed_time > start_time1) & (average_OD > start_OD)):

                if (last_chemophase == 0):

                    # calculate the period (i.e. frequency of dilution events) based on user specified growth rate and bolus size
                    if rate_config1[x] > 0:
                        period_config[x] = (3600 * bolus) / (
                            (rate_config1[x]) * volume)
                        period_config[x] = (period_config[x]) * flow_rate[x] * (
                            25 / volume
                        )  #corrects for flow rates other than 1mL/sec and volumes other than 25mL
                        period_config[
                            x] = period_config[x] / 1000  # converts to s
                    else:  # if no dilutions needed, then just loops with no dilutions
                        period_config[x] = 0

                    print('Chemostat initiated in vial {0}'.format(x))
                    # writes command to chemo_config file, for storage
                    text_file = open(chemoconfig_path, "a+")
                    text_file.write("{0},1,{1}\n".format(
                        elapsed_time, period_config[x])
                                    )  #note that this sets chemophase to 1
                    text_file.close()

                ##### Sample code below for subsequent chemostat phases, be sure to update N in variable names etc.
                # if  ((last_chemophase == N-1) & (elapsed_time > start_timeN):

                #     # calculate the period (i.e. frequency of dilution events) based on user specified growth rate and bolus size
                #     if rate_configN[x] > 0:
                #         period_config[x] = (3600*bolus)/((rate_configN[x])*volume)
                #         period_config[x] = (period_config[x])*flow_rate[x]*(25/volume) #corrects for flow rates other than 1mL/sec and volumes other than 25mL

                #     else: # if no dilutions needed, then just loops with no dilutions
                #         period_config[x] = 0

                #     print 'Chemostat updated in vial %i' % (x)
                #     # writes command to chemo_config file, for storage
                #     text_file = open(chemoconfig_path,"a+")
                #     text_file.write("%f,N,%i\n" %  (elapsed_time,period_config[x])) #note that this sets chemophase to N, replace with integer value
                #     text_file.close()

        #end of main loop through vials

    #Update chemostat command after all vials are dealt with
    eVOLVER_module.update_chemo(
        vials, exp_name, bolus_in_s,
        control)  #uses values stored in chemo_config files

    #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)
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')
def test(OD_data, temp_data, vials, elapsed_time, exp_name):
    MESSAGE = "10,10,10,10,10,10,10,10,14,10,10,14,10,10,10,10,"
    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([.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, .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])

    time_out = 5
    pump_wait = 10
    #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 = 0
                #step_size = (((-1)*np.log(lower_thresh[x]/average_OD)*volume)+2.25)/(0.002)
                step_size = ((
                    (-1) * np.log(lower_thresh[x] / average_OD) * volume) +
                             3) / (0.002)

                if step_size > 5000:
                    step_size = 5000

                # send command to syringe pump
                pump(vial_num=x,
                     media_type=mixture[x],
                     step_size=[step_size / 2, step_size / 2],
                     logging='y',
                     x=x,
                     elapsed_time=elapsed_time,
                     pump_wait=pump_wait,
                     exp_name=exp_name,
                     time_in=time_in)
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')
Exemple #6
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')
Exemple #7
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)