def get_values(*names):
    import json
    _all_values = json.loads("""{"number_of_samples":96,"right_pipette":"p20_multi_gen2", "pipMnt":"right","left_pipette":"p20_single_gen2", "pipMnt2":"left","well_vol":12.5, "MM_vol":10.5, "template_vol":2}""")
    return [_all_values[n] for n in names]


import math

metadata = {
    'protocolName':'Automated Opentrons Pipeline for PCR Preparation V2.2 ISL',
    'protocolVersion': 'V2.2',
    'Author': 'Jhakelin Reyes Vasquez Date: 13Nov22',
    'source': 'Modified from v2.0',
    'changes': 'Edited to use one box to transfer all samples',
    'apiLevel': '2.6'
    }

def run(protocol):
    [number_of_samples, left_pipette, pipMnt, right_pipette, pipMnt2,well_vol, MM_vol, template_vol] = get_values(  # noqa: F821
        "number_of_samples", "left_pipette", "pipMnt", 'right_pipette',"pipMnt2",'well_vol', "MM_vol", "template_vol")

    #COLS
    numCols = math.ceil(number_of_samples/8)
    
    #PLATES AND MODULES
    thermocycler = protocol.load_module('thermocycler')
    final_PCR_plate = thermocycler.load_labware('nest_96_wellplate_100ul_pcr_full_skirt','7')
    MM_and_samples_plate = protocol.load_labware('denville_96_aluminumblock_200ul','1', 'MM/gDNA cleaned samples')
    
    #SAMPLES
    #gDNA cleaned samples: Template. Samples that have been previously cleaned 
    template = [col for col in MM_and_samples_plate.rows()[0][:numCols]]
    #PCR samples: Template + Master Mix 
    pcr_samples = [col for col in final_PCR_plate.rows()[0][:numCols]]
    #Master Mix: PCR Master Mix 
    MMix= MM_and_samples_plate.wells()[0]


	#TIPS
    tips20m = [protocol.load_labware('opentrons_96_tiprack_20ul', s) for s in ['3','6']]
    tips20s = [protocol.load_labware('opentrons_96_tiprack_20ul', s) for s in ['9']]
    
    #TIPS definitions
    allTips = [t for rack in tips20m for t in rack.rows()[0]]
    #MM tips
    mmTips = allTips[numCols:] 
    
    #PIPETTES
    p20m = protocol.load_instrument(right_pipette, pipMnt,tip_racks= tips20m)
    p20s = protocol.load_instrument(left_pipette, pipMnt2,tip_racks= tips20s)

    #set modules to 10°C
    thermocycler.open_lid()
    thermocycler.set_block_temperature(10)
    
    #FLOW RATES
    p20m.flow_rate.aspirate = 50
    p20m.flow_rate.dispense = 50
    p20m.flow_rate.blow_out = 30
    
    p20s.flow_rate.aspirate = 50
    p20s.flow_rate.dispense = 50
    p20s.flow_rate.blow_out = 30
    
    
#START PROTOCOL   

	#1. Transferring Master Mix to final_PCR_plate
    protocol.comment('1. Transferring Master Mix to final_PCR_plate')
    p20m.pick_up_tip(mmTips[0])
    for dest in pcr_samples:
        p20m.aspirate(MM_vol, MMix)
        p20m.dispense(MM_vol + 2, dest)
        p20m.blow_out()
    p20m.drop_tip()

    #Comments
    
    protocol.comment('Take out tips for positive and negative controls')
    protocol.comment('Place DNA plate in the Slot 1')
    protocol.pause("If you have put your samples plate click 'resume'")
    
    #2. Transferring gDNA cleaned samples to final_PCR_plate
    
    protocol.comment('2. Transferring gDNA cleaned samples to final_PCR_plate')

    for well, dest in zip(template,pcr_samples):
        p20m.pick_up_tip()
        p20m.mix(5,6, well)
        p20m.aspirate(template_vol, well)
        p20m.dispense(template_vol, dest)
        p20m.mix(5,4)
        p20m.blow_out()
        p20m.drop_tip()
    
            
    #End of protocol
    thermocycler.deactivate_lid()
    
    protocol.comment('Congratulations!')
