Example #1
0
def run(protocol: protocol_api.ProtocolContext):
    """
    Aliquoting mastermix;
    Adding samples from different labware.
    """
# =============================================================================

# LOADING LABWARE AND PIPETTES=================================================
# =============================================================================
    # Pipette tips
    if dispension_vol >= 19:
      ## When the mm volume to be dispensed >= 19, 200µL tips are          
      ## needed in addition to the 20µL tips.                              
        tips_200 = protocol.load_labware(
            'opentrons_96_filtertiprack_200ul', 
            4,                                  
            '200tips')                          
        tips_20_1 = protocol.load_labware(
            'opentrons_96_filtertiprack_20ul',  
            7,                                  
            '20tips_1')                                
        tips_20_2 = protocol.load_labware(
            'opentrons_96_filtertiprack_20ul',  
            10,                                 
            '20tips_2')                         
        tips_20 = [tips_20_1, tips_20_2]
    else:
      ## When the mm volume to be dispensed <=19, only 20µL are needed      
        tips_20_1 = protocol.load_labware(
            'opentrons_96_filtertiprack_20ul',  
            4,                                  
            '20tips_1')                           
        tips_20_2 = protocol.load_labware(
            'opentrons_96_filtertiprack_20ul',  
            7,                                  
            '20tips_2')                           
        tips_20_3 = protocol.load_labware(
            'opentrons_96_filtertiprack_20ul',  
            10,                                 
            '20tips_3')                             
        tips_20 = [tips_20_1, tips_20_2, tips_20_3]
    
    # Tube_racks & plates
    destination_plate = protocol.load_labware(
        'biorad_96_wellplate_200ul_pcr',        
        3,                                      
        'plate_96')   
    
    if mastermix_tube_type == 'tube_1.5mL':
        mastermix_tube = protocol.load_labware(
            'opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap',
            1,
            'mastermix_tube')
    
    if sample_tube_type == 'tube_1.5mL':
        sample_source_1 = protocol.load_labware(
            'opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap',
            2,
            'sample_source_1')
        sample_source_2 = protocol.load_labware(
            'opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap',
            5,
            'sample_source_2')
        sample_source_3 = protocol.load_labware(
            'opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap',
            8,
            'sample_source_3')
        sample_source_4 = protocol.load_labware(
            'opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap',
            11,
            'sample_source_4')
    if sample_tube_type == 'plate_96':
        sample_source_1 = protocol.load_labware(
            'biorad_96_wellplate_200ul_pcr',    
            2,                                  
            'sample_source_1')
        sample_source_2 = protocol.load_labware(
            'biorad_96_wellplate_200ul_pcr',    
            5,                                  
            'sample_source_2')
    
    if simulate: #Simulator
        if mastermix_tube_type == 'tube_5mL': 
            with open("labware/eppendorfscrewcap_15_tuberack_5000ul/"
                 "eppendorfscrewcap_15_tuberack_5000ul.json") as labware_file:
                      labware_def_5mL = json.load(labware_file)
            mastermix_tube = protocol.load_labware_from_definition( 
                labware_def_5mL,           
                1,                         
                'mastermix_tube')   
        if sample_tube_type == 'PCR_strip':
            with open("labware/pcrstrips_96_wellplate_200ul/"
                      "pcrstrips_96_wellplate_200ul.json") as labware_file:
                    labware_def_pcrstrips = json.load(labware_file)
            sample_source_1 = protocol.load_labware_from_definition( 
                labware_def_pcrstrips,     
                2,                         
                'sample_source_1')         
            sample_source_2 = protocol.load_labware_from_definition( 
                labware_def_pcrstrips, 
                5,                     
                'sample_source_2')    
            sample_source_3 = protocol.load_labware_from_definition( 
                labware_def_pcrstrips,
                8,                   
                'sample_source_3')    
            sample_source_4 = protocol.load_labware_from_definition( 
                labware_def_pcrstrips,
                11,                   
                'sample_source_4')     
    else: 
        if mastermix_tube_type == 'tube_5mL': 
            mastermix_tube = protocol.load_labware(
                'eppendorfscrewcap_15_tuberack_5000ul',
                1,                                     
                'mastermix_tube')  
        if sample_tube_type == 'PCR_strips':
            sample_source_1 = protocol.load_labware( 
                'pcrstrips_96_wellplate_200ul',        
                2,                                     
                'sample_source_1')                      
            sample_source_2 = protocol.load_labware_( 
                'pcrstrips_96_wellplate_200ul',    
                5,                                 
                'sample_source_2')                 
            sample_source_3 = protocol.load_labware( 
                'pcrstrips_96_wellplate_200ul',    
                8,                                
                'sample_source_3') 
            sample_source_4 = protocol.load_labware( 
                'pcrstrips_96_wellplate_200ul',    
                11,                                
                'sample_source_4') 
                
    # Pipettes
    if dispension_vol >= 19:
        p300 = protocol.load_instrument(
            'p300_single_gen2',             
            'right',                        
            tip_racks=[tips_200])           
    p20 = protocol.load_instrument(
        'p20_single_gen2',                  
        'left',                             
        tip_racks=tips_20)
# =============================================================================

# PREDIFINED VARIABLES=========================================================
# =============================================================================
    aspiration_vol = dispension_vol + (dispension_vol/100*2)
      ## The aspiration_vol is the volume (µL) that is aspirated from the   
      ## container.                                                         
    ##### Variables for volume tracking
    start_height = vt.cal_start_height(mastermix_tube_type, start_vol)
      ## Call start height calculation function from volume tracking module.
    current_height = start_height
      ## Set the current height to start height at the beginning of the     
      ## protocol.                                                          
    sample_mix_vol = sample_vol + 3
      ## primer_mix_vol = volume for pipetting up and down                  
# =============================================================================    

# SETTING LOCATIONS============================================================
# =============================================================================
    # Setting starting tip                                           
    if dispension_vol >= 19:
        ## If the mm volume to be dispendsed >= 19, assign p300 starting tip
        p300.starting_tip = tips_200.well(starting_tip_p200)
    p20.starting_tip = tips_20_1.well(starting_tip_p20)
    
    # Mastermix tube location
    MasterMix = mastermix_tube[mastermix_source]
    
    # Make a list of all possible wells in the destination plate
    destination_wells = []
    for well in destination_plate.wells():
        destination_wells.append(well)
    # Create a list of wells where samples should go
    sample_wells = destination_wells[:number_of_samples*replicates]
    
    #Create a list of wells where standard sample replicates should go
    slice_std_sample_wells = slice(
        (number_of_samples * replicates), (number_of_samples * replicates)+ number_of_std_samples)
    std_sample_wells = destination_wells[slice_std_sample_wells]
      ## Slice the list after the number of samples, and after the number
      ## of standard sample replicates to retrieve the wells in between
    
    # Create the list of wells where NTCs should go
    slice_NTC_wells = slice(
        (number_of_samples * replicates)+ number_of_std_samples,
        (number_of_samples * replicates)+ number_of_std_samples + number_of_NTCs)
    NTC_wells = destination_wells[slice_NTC_wells]
      ## Slice the list after the number of samples + the number of standard
      ## sample replicates, and after that + the number of NTCs to retrieve
      ## the wells in between (the last of the wells that need to be filled)
    
    # Create the list of wells where standerd series should go
    std_series_wells = [] 
    std_series_columns = (
        [destination_plate.columns_by_name()[column_name] for column_name in
         ['12', '11', '10']])
    std_series_columns = std_series_columns[:number_of_std_series]
    ## Reserve a column at the end of the plate for every std_series        
    ## Separate the columns into wells and append them to list              
    for column in std_series_columns:
        column = column[:length_std_series]
        ## cut off the columns after a certain std_series length            
        for well in column:
            std_series_wells.append(well)
    
    # Create a list with wells where mastermix should go
    MasterMixAliquots = (
        sample_wells + std_sample_wells + NTC_wells + std_series_wells)
    
    if redo:
        ## This is the part of the protocol that accesses the specific
        ## sample wells specified in the variables to set
        ## NOTE: this only works for 96wells plate, when you need to redo 
        ## samples with other labware you can rearrange the order of tubes
        sample_sources = []
        wells_sample_source_1 = (
            [sample_source_1.wells_by_name()[well_name] for well_name in
            samples_sample_source_1])
        for well in wells_sample_source_1:
            sample_sources.append(well)
        wells_sample_source_2 = (
            [sample_source_2.wells_by_name()[well_name] for well_name in
            samples_sample_source_2])
        for well in wells_sample_source_2:
            sample_sources.append(well)
        wells_sample_source_3 = (
            [sample_source_3.wells_by_name()[well_name] for well_name in
            samples_sample_source_3])
        for well in wells_sample_source_3:
            sample_sources.append(well)
        wells_sample_source_4 = (
            [sample_source_4.wells_by_name()[well_name] for well_name in
            samples_sample_source_4])
        for well in wells_sample_source_4:
            sample_sources.append(well)
        
    else: 
        ## This is the part of the protocol that access the sample wells in
        ## a normal PCR (where you don't need to access specific wells)
        sample_source_wells = []
        sample_source_wells_string = []
          ## The string list is needed to be able to start at another well
        if sample_tube_type == 'tube_1.5mL' or sample_tube_type == 'plate_96':
            if sample_racks >= 1:
                for well in sample_source_1.wells():
                    sample_source_wells.append(well)
                    sample_source_wells_string.append(str(well))
            if sample_racks >= 2:
                for well in sample_source_2.wells():
                    sample_source_wells.append(well)
                    sample_source_wells_string.append(str(well))
            if sample_racks >= 3:
                for well in sample_source_3.wells():
                    sample_source_wells.append(well)
                    sample_source_wells_string.append(str(well))
            if sample_racks >= 4:
                for well in sample_source_4.wells():
                    sample_source_wells.append(well)
                    sample_source_wells_string.append(str(well))

        if sample_tube_type == 'PCR_strip':
            sample_source_columns = (
                    ([sample_source_1.columns_by_name()[column_name] 
                      for column_name in sample_columns]))
            if sample_racks >= 2:
                sample_columns_2 = (
                    ([sample_source_2.columns_by_name()[column_name] 
                      for column_name in sample_columns]))
                for column in sample_columns_2:
                    sample_source_columns.append(column)
            if sample_racks >= 3:
                sample_columns_3 = (
                    ([sample_source_3.columns_by_name()[column_name] 
                      for column_name in sample_columns]))
                for column in sample_columns_3:
                    sample_source_columns.append(column)
            if sample_racks >= 4:
                sample_columns_4 = (
                    ([sample_source_4.columns_by_name()[column_name] 
                      for column_name in sample_columns]))
                for column in sample_columns_4:
                    sample_source_columns.append(column)
              ## Make a list of columns, this is a list of lists!   
            for column in sample_source_columns:
                for well in column:
                    sample_source_wells.append(well)
                    sample_source_wells_string.append(str(well))
              ## Separate the columns into wells and append them to list 

        ## Cut slice out off list of sample_sources, starting with the 
        ## indicated first sample and ending after the number_of_samples                        
        first_sample_index = sample_source_wells_string.index(
            first_sample + ' of sample_source_1 on 2')
          ## Determine the index of the first sample in the list made from 
          ## strings -- we cannot find strings in the normal robot list
          ## so we needed to convert the wells to strings.
        slice_sample_sources = slice(
            first_sample_index, 
            first_sample_index + number_of_samples)
          ## Determine the slice

        ## Determine position of the std_sample
        slice_std_sample = slice(
            first_sample_index + number_of_samples,
            first_sample_index + number_of_samples + 1)
        ## If you have a std sample included, this will be added as the last sample  
        std_source = sample_source_wells[slice_std_sample] * number_of_std_samples
          ## Makes a list of len number_of_std_samples of the std_source well
        
        ## Cut sample slice out of sample_source_wells list
        sample_sources = sample_source_wells[slice_sample_sources]
        ## If replicates are desired, this copies the sample_sources list
        sample_sources = sample_sources * replicates
       
        ## If you have a std sample included, this will add the std_samples 
        ## to the end of the sample_sources list
        sample_sources = sample_sources + std_source
# =============================================================================              

              
## PIPETTING===================================================================
## ============================================================================
## LIGHTS----------------------------------------------------------------------
    if qPCR:
        protocol.set_rail_lights(False)
    if not qPCR:
        protocol.set_rail_lights(True)
## ----------------------------------------------------------------------------
## ALIQUOTING MASTERMIX--------------------------------------------------------
    if dispension_vol >= 19:
        pipette = p300
    else:
        pipette = p20
    for i, well in enumerate(MasterMixAliquots):
      ## aliquot mix, for each well do the following:                       
        if i == 0: 
            pipette.pick_up_tip()
              ## If we are at the first well, start by picking up a tip.    
        elif i % 8 == 0:
            pipette.drop_tip()
            pipette.pick_up_tip()
              ## Then, after every 8th well, drop tip and pick up new       
    
        current_height, pip_height, bottom_reached = vt.volume_tracking(
                mastermix_tube_type, dispension_vol, current_height)
                  ## call volume_tracking function, obtain current_height,  
                  ## pip_height and whether bottom_reached.                 
        
        if bottom_reached:
            aspiration_location = MasterMix.bottom(z=1)
            protocol.comment("You've reached the bottom of the tube!")
              ## If bottom is reached keep pipetting from bottom + 1        
        else:
            aspiration_location = MasterMix.bottom(pip_height)
              ## Set the location of where to aspirate from.                

        #### The actual aliquoting of mastermix                             
        pipette.aspirate(aspiration_vol, aspiration_location)
          ## Aspirate the amount specified in aspiration_vol from the       
          ## location specified in aspiration_location.                     
        pipette.dispense(dispension_vol, well)
          ## Dispense the amount specified in dispension_vol to the         
          ## location specified in well (so a new well every time the       
          ## loop restarts)                                                 
        pipette.dispense(10, aspiration_location)
          ## Alternative for blow-out, make sure the tip doesn't fill      
          ## completely when using a disposal volume by dispensing some     
          ## of the volume after each pipetting step. (blow-out to many     
          ## bubbles)                                                       
    pipette.drop_tip()   
## ----------------------------------------------------------------------------
## ADDING SAMPLES--------------------------------------------------------------
    ## Loop through source and destination wells
    for sample_tube, well in zip(sample_sources, destination_plate.wells()):
        p20.pick_up_tip()
        p20.aspirate(sample_vol, sample_tube)
        p20.dispense(sample_vol, well)
        sample_mix_vol = sample_vol + 3
          ## primer_mix_vol = volume for pipetting up and down              
        p20.mix(3, sample_mix_vol, well)
        p20.dispense(10, well)
        p20.drop_tip()
# ----------------------------------------------------------------------------
## LIGHTS----------------------------------------------------------------------
    if not qPCR:
        protocol.set_rail_lights(False)
# ----------------------------------------------------------------------------
# =============================================================================