## LOADING IN OPENTRONS SOFTWARE
from opentrons import types
import subprocess

metadata = {
    'protocolName': 'Station B Zymo EUA',
    'author': 'Chaz <[email protected]>, Dipro <[email protected]>',
    'source': 'Covid-19 Diagnostics',
    'apiLevel': '2.2'
}

## SPECIFYING PLATE TYPE WITH DIMENSIONS
plate_type = 'labcon'
# plate_type (above) should be 'labcon', 'nest', or 'ils'

## LOADING IN AUDIO
AUDIO_FILE_PATH = '/etc/audio/speaker-test.mp3'


def run_quiet_process(command):
    subprocess.check_output('{} &> /dev/null'.format(command), shell=True)


def test_speaker():
    print('Speaker')
    print('Next\t--> CTRL-C')
    try:
        run_quiet_process('mpg123 {}'.format(AUDIO_FILE_PATH))
    except KeyboardInterrupt:
        pass
        print()

## DEFINING THE ENTIRE PROTOCOL - THIS IS THE BULK OF THE PROTOCOL
def run(protocol):

    # load labware and pipettes
    sample_no = 48
    samps = int(sample_no/8)
    tips200 = [
        protocol.load_labware(
            'opentrons_96_tiprack_300ul', s) for s in [
                '5', '6', '9', '7', '10'
                ]
            ]
    all_tips = [tr['A'+str(i)] for tr in tips200 for i in range(1, 13)]
    [tips1, tips2, tips3, tips4, tips5,
     tips6, tips7, tips8, tips9, tips10] = [
        all_tips[i:i+samps] for i in range(0, samps*10, samps)
        ]

    p300 = protocol.load_instrument(
        'p300_multi_gen2', 'left')

    magdeck = protocol.load_module('magdeck', '4')
    magheight = 13.7
    plate_defs = {
        'nest': 'nest_96_wellplate_2ml_deep',
        'labcon': 'labcon_96_wellplate_2ml_deep',
        'ils': 'ils_96_wellplate_2ml_deep'}
    magplate = magdeck.load_labware(plate_defs[plate_type])
    flatplate = protocol.load_labware('nest_96_wellplate_tempblock', '3')
    liqwaste = protocol.load_labware(
                'nest_1_reservoir_195ml', '11', 'Liquid Waste')
    waste = liqwaste['A1'].top()

    trough = protocol.load_labware(
                    'nest_12_reservoir_15ml', '2', 'Trough with Reagents')
    trough_eth = protocol.load_labware(
                    'nest_12_reservoir_15ml', '1', 'Trough with Ethanol')
    buffer = [trough[x] for x in ['A1', 'A2', 'A3'] for _ in range(2)][:samps]
    wb1 = [trough[x] for x in ['A5', 'A6'] for _ in range(3)][:samps]
    wb2 = [trough[x] for x in ['A8', 'A9'] for _ in range(3)][:samps]
    ethanol1 = [trough_eth['A'+str(i)] for i in range(1, 7)]
    ethanol2 = [trough_eth[x] for x in ['A7', 'A8'] for _ in range(3)]
    water = trough['A12']

    magsamps = [magplate['A'+str(i)] for i in range(1, 12, 2)][:samps]
    elutes = [flatplate['A'+str(i)] for i in range(1, 7)][:samps]

    p300.flow_rate.aspirate = 50
    p300.flow_rate.dispense = 150
    p300.flow_rate.blow_out = 300

    magdeck.disengage()

    ## EVERYTHING BEFORE THIS LOADS IN THE PLATES, PIPETTES, TIPRACKS, and DEFINES WHERE REAGENTS WILL BE PLACED TO TELL
    ## THE ROBOT WHERE ITS PIPETTE IS IN SPACE AND WHAT IT'S HANDLING

    ## THIS CREATES A REPEPTITIVE FUNCTION FOR A WASH MIX THAT WILL BE USED LATER
    # def wash mix - dispense on pellet

    def wash_mix(reps, loc, vol):
        loc1 = loc.bottom().move(types.Point(x=1, y=0, z=3))
        loc2 = loc.bottom().move(types.Point(x=-1, y=0, z=3))
        p300.aspirate(20, loc2)
        mvol = vol-20
        for _ in range(reps-1):
            p300.aspirate(mvol, loc2)
            p300.dispense(mvol, loc1)
        p300.dispense(20, loc2)

    ## 800 µL OF BUFFER IS TRANSFERRED AT THIS STEP AND WILL ADD THE BUFFER & BEADS TO THE SAMPLES
    protocol.comment('Adding viral buffer + beads to samples:')
    for well, reagent, tip in zip(magsamps, buffer, tips1):
        p300.pick_up_tip(tip)
        for _ in range(3):
            p300.aspirate(155, reagent)
            p300.dispense(155, well.top(-5))
            p300.aspirate(10, well.top(-5))
        p300.aspirate(155, reagent)
        p300.dispense(185, well.top(-10))
        wash_mix(5, well, 180)
        p300.blow_out()
        p300.aspirate(20, well.top(-5))
        p300.drop_tip()

    ## THE MAGNETIC BEADS WILL BE MIXED FOR 10 MINUTES HERE
    protocol.comment('Mixing samples+buffer+beads:')
    for well, tip, tret in zip(magsamps, tips2, tips1):
        p300.pick_up_tip(tip)
        wash_mix(15, well, 180)
        p300.blow_out()
        p300.aspirate(20, well.top(-5))
        p300.drop_tip(tret)

    ## THERE WAS A 5 MINUTE INCUBATION STEP FOR THE OPENTRONS MAGNET -- THIS TIME WILL LIKELY BE ADJUSTED FOR THE BIOMEK
    magdeck.engage(height=magheight)
    protocol.comment('Incubating on magdeck for 5 minutes')
    protocol.delay(minutes=5)

    ## THIS CREATES A REPETITIVE FUNCTION FOR REMOVING SUPERNATANT
    def supernatant_removal(vol, src, dest, ht):
        p300.flow_rate.aspirate = 20
        tvol = vol
        asp_ctr = 0
        while tvol > 180:
            p300.aspirate(
                180, src.bottom().move(types.Point(x=-1, y=0, z=2)))
            p300.dispense(180, dest)
            p300.aspirate(10, dest)
            tvol -= 180
            asp_ctr += 1
        p300.aspirate(
            tvol, src.bottom().move(types.Point(x=-1, y=0, z=ht)))
        dvol = 10*asp_ctr + tvol
        p300.dispense(dvol, dest)
        p300.flow_rate.aspirate = 50

    ## THIS EXECUTES REMOVING SUPERNATANT

    for well, tip in zip(magsamps, tips1):
        p300.pick_up_tip(tip)
        supernatant_removal(540, well, waste, 2)
        p300.aspirate(20, waste)
        p300.drop_tip()

    for well, tip in zip(magsamps, tips3):
        p300.pick_up_tip(tip)
        supernatant_removal(440, well, waste, 0.5)
        p300.aspirate(20, waste)
        p300.drop_tip()

    magdeck.disengage()


    ## THIS CREATES A REPETITIVE FUNCTION THAT IS USED FOR WASH STEPS. THE ZYMO PROTOCOL FEATURES FOUR WASH STEPS:
    ## THE FIRST WASH STEP IS FOR WASH BUFFER 1
    ## THE SECOND WASH STEP IS FOR WASH BUFFER 2
    ## THE THIRD AND FOURTH WASH STEPS UTILIZE ETHANOL

    ## EACH WASH STEP CONTAINS A SMALL 3 MIN INCUBATION PERIOD WHEN ON THE MAGNET, FOLLOWED BY REMOVING SUPERNATANT FROM THE WASH

    ## THE OT2 ROBOT WAS HANDLING 500 µL OF WASH BUFFER 1, 500 µL OF WASH BUFFER 2, 900 µL OF ETHANOL WASH 1, 500 µL OF ETHANOL WASH 2.

    def wash_step(src, vol, mtimes, tips, usedtips, msg, trash_tips=False):
        protocol.comment(f'Wash Step {msg} - Adding to samples:')
        for well, tip, tret, s in zip(magsamps, tips, usedtips, src):
            p300.pick_up_tip(tip)
            asp_ctr2 = 0
            mvol = vol
            while mvol > 180:
                p300.aspirate(180, s)
                p300.dispense(180, well.top(-3))
                p300.aspirate(10, well.top(-3))
                asp_ctr2 += 1
                mvol -= 180
            p300.aspirate(mvol, s)
            dvol = 10*asp_ctr2 + mvol
            p300.dispense(dvol, well.bottom(5))
            wash_mix(mtimes, well, 180)
            p300.blow_out()
            p300.drop_tip(tret)

        magdeck.engage(height=magheight)
        protocol.comment('Incubating on MagDeck for 3 minutes.')
        protocol.delay(minutes=3)

        protocol.comment(f'Removing supernatant from Wash {msg}:')
        svol = vol if vol == 900 else vol+40
        for well, tip in zip(magsamps, usedtips):
            p300.pick_up_tip(tip)
            supernatant_removal(svol, well, waste, 0.5)
            p300.aspirate(20, waste)
            if trash_tips:
                # p300.drop_tip()
                p300.drop_tip(tip)
            else:
                p300.drop_tip(tip)
                magdeck.disengage()

    wash_step(wb1, 500, 20, tips4, tips2, '1 Wash Buffer 1')

    wash_step(wb2, 500, 10, tips5, tips3, '2 Wash Buffer 2')

    wash_step(ethanol1, 900, 10, tips6, tips4, '3 Ethanol 1')

    wash_step(ethanol2, 500, 10, tips7, tips5, '4 Ethanol 2', trash_tips=True)


    ## THERE IS A STEP INCLUDED TO DRY ETHANOL. THIS IS BECAUSE ETHANOL IS A POWERFUL PCR INHIBITOR AND WE DON'T WANT THAT INCLUDED WITH THE SAMPLES.
    protocol.comment('Allowing beads to air dry for 2 minutes.')
    protocol.delay(minutes=2)

    ## THE ROBOT IS TOLD TO REMOVE EXCESS ETHANOLS FROM WELL
    p300.flow_rate.aspirate = 20
    protocol.comment('Removing any excess ethanol from wells:')
    for well, tip, tret in zip(magsamps, tips8, tips6):
        p300.pick_up_tip(tip)
        p300.transfer(
            180, well.bottom().move(types.Point(x=-0.5, y=0, z=0.4)),
            waste, new_tip='never')
        p300.drop_tip(tret)
    p300.flow_rate.aspirate = 50

    ## THERE IS A 10 MIN INCUBATION PERIOD BEFORE ADDING NUCLEASE FREE WATER -- THIS IS DONE IN THE MANUAL PROTOCOL AS WELL
    protocol.comment('Allowing beads to air dry for 10 minutes.')
    protocol.delay(minutes=10)

    magdeck.disengage()

    ## NUCLEASE FREE WATER IS ADDED TO THE WELLS TO PERFORM THE ELUTION
    protocol.comment('Adding NF-Water to wells for elution:')
    for well, tip, tret in zip(magsamps, tips9, tips7):
        p300.pick_up_tip(tip)
        p300.aspirate(20, water.top())
        p300.aspirate(60, water)
        # should we try 100 here
        for _ in range(15):
            p300.dispense(
                50, well.bottom().move(types.Point(x=1, y=0, z=2)))
            p300.aspirate(
                50, well.bottom().move(types.Point(x=1, y=0, z=0.5)))
        p300.dispense(50, well)
        p300.dispense(30, well.bottom(6))
        p300.aspirate(20, well.top(-3))
        p300.drop_tip(tret)

    ## THERE IS AN INCUBATION PERIOD AT WHICH POINT STAFF CAN READY THE PCR PLATE FOR ELUTION    
    protocol.comment('Incubating at room temp for 10 minutes. Add PCR plate')
    test_speaker()
    protocol.delay(minutes=10)

    ## THE OT2 TRANSFERS THE ELUTES TO THE CLEAN 96-WELL PCR PLATE
    magdeck.engage(height=magheight)
    protocol.comment('Incubating on MagDeck for 2 minutes.')
    protocol.delay(minutes=2)

    protocol.comment('Transferring elution to final plate:')
    p300.flow_rate.aspirate = 10
    for src, dest, tip, tret in zip(magsamps, elutes, tips10, tips8):
        p300.pick_up_tip(tip)
        p300.aspirate(60, src.bottom().move(types.Point(x=-1.5, y=0, z=0.5)))
        p300.dispense(60, dest)
        p300.aspirate(10, dest.top())
        p300.drop_tip(tret)

    protocol.comment('Congratulations!')
 

Python Online Compiler

Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.

Taking inputs (stdin)

OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.

import sys
name = sys.stdin.readline()
print("Hello "+ name)

About Python

Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.

Tutorial & Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition IF-ELSE is used.

if conditional-expression
    #code
elif conditional-expression
    #code
else:
    #code

Note:

Indentation is very important in Python, make sure the indentation is followed correctly

2. For:

For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.

Example:

mylist=("Iphone","Pixel","Samsung")
for i in mylist:
    print(i)

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while condition  
    #code 

Collections

There are four types of collections in Python.

1. List:

List is a collection which is ordered and can be changed. Lists are specified in square brackets.

Example:

mylist=["iPhone","Pixel","Samsung"]
print(mylist)

2. Tuple:

Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.

Example:

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)

Below throws an error if you assign another value to tuple again.

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)

3. Set:

Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.

Example:

myset = {"iPhone","Pixel","Samsung"}
print(myset)

4. Dictionary:

Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.

Example:

mydict = {
    "brand" :"iPhone",
    "model": "iPhone 11"
}
print(mydict)

Supported Libraries

Following are the libraries supported by OneCompiler's Python compiler

NameDescription
NumPyNumPy python library helps users to work on arrays with ease
SciPySciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation
SKLearn/Scikit-learnScikit-learn or Scikit-learn is the most useful library for machine learning in Python
PandasPandas is the most efficient Python library for data manipulation and analysis
DOcplexDOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling