SETUP


In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
import time

from config import utils as ut
from config import gui

%matplotlib inline

Autosipper


In [2]:
# config directory must have "__init__.py" file
# from the 'config' directory, import the following classes:
from config import Motor, ASI_Controller, Autosipper
autosipper = Autosipper(Motor('config/motor.yaml'), ASI_Controller('config/asi_controller.yaml'))
autosipper.coord_frames


Initializing stage...
Out[2]:
hardware deck
transform [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, ... [[-1, 0, 0], [0, 1, 0], [0, 0, -1], [0, 0, 93]]
position_table None None

In [3]:
from config import gui
gui.stage_control(autosipper.XY, autosipper.Z)


(0.0,)

In [4]:
platemap = ut.generate_position_table((8,12),(9,9),95.0)
platemap['x'] = -platemap['x'] - 1.8792
platemap['y'] = platemap['y'] + 32.45
platemap.loc[platemap.shape[0]] = [96, 99, 99, 99, 'W01', -8.2492, 1.1709, 68.3999]
platemap.loc[platemap.shape[0]] = [97, 99, 99, 99, 'W02', -36.9737, 1.1709, 68.3999]

platemap['contents'] = ["" for i in range(len(platemap['name']))]

for i in range(12):
    platemap['contents'].iloc[i] = "conc"+str(i)

autosipper.coord_frames.hardware.position_table = platemap
platemap


c:\python27\lib\site-packages\pandas\core\indexing.py:141: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self._setitem_with_indexer(indexer, value)
Out[4]:
n s r c name x y z contents
0 0 0 0 0 A01 -1.8792 32.4500 95.0000 conc0
1 1 1 0 1 A02 -10.8792 32.4500 95.0000 conc1
2 2 2 0 2 A03 -19.8792 32.4500 95.0000 conc2
3 3 3 0 3 A04 -28.8792 32.4500 95.0000 conc3
4 4 4 0 4 A05 -37.8792 32.4500 95.0000 conc4
5 5 5 0 5 A06 -46.8792 32.4500 95.0000 conc5
6 6 6 0 6 A07 -55.8792 32.4500 95.0000 conc6
7 7 7 0 7 A08 -64.8792 32.4500 95.0000 conc7
8 8 8 0 8 A09 -73.8792 32.4500 95.0000 conc8
9 9 9 0 9 A10 -82.8792 32.4500 95.0000 conc9
10 10 10 0 10 A11 -91.8792 32.4500 95.0000 conc10
11 11 11 0 11 A12 -100.8792 32.4500 95.0000 conc11
12 12 23 1 0 B01 -1.8792 41.4500 95.0000
13 13 22 1 1 B02 -10.8792 41.4500 95.0000
14 14 21 1 2 B03 -19.8792 41.4500 95.0000
15 15 20 1 3 B04 -28.8792 41.4500 95.0000
16 16 19 1 4 B05 -37.8792 41.4500 95.0000
17 17 18 1 5 B06 -46.8792 41.4500 95.0000
18 18 17 1 6 B07 -55.8792 41.4500 95.0000
19 19 16 1 7 B08 -64.8792 41.4500 95.0000
20 20 15 1 8 B09 -73.8792 41.4500 95.0000
21 21 14 1 9 B10 -82.8792 41.4500 95.0000
22 22 13 1 10 B11 -91.8792 41.4500 95.0000
23 23 12 1 11 B12 -100.8792 41.4500 95.0000
24 24 24 2 0 C01 -1.8792 50.4500 95.0000
25 25 25 2 1 C02 -10.8792 50.4500 95.0000
26 26 26 2 2 C03 -19.8792 50.4500 95.0000
27 27 27 2 3 C04 -28.8792 50.4500 95.0000
28 28 28 2 4 C05 -37.8792 50.4500 95.0000
29 29 29 2 5 C06 -46.8792 50.4500 95.0000
... ... ... ... ... ... ... ... ... ...
68 68 63 5 8 F09 -73.8792 77.4500 95.0000
69 69 62 5 9 F10 -82.8792 77.4500 95.0000
70 70 61 5 10 F11 -91.8792 77.4500 95.0000
71 71 60 5 11 F12 -100.8792 77.4500 95.0000
72 72 72 6 0 G01 -1.8792 86.4500 95.0000
73 73 73 6 1 G02 -10.8792 86.4500 95.0000
74 74 74 6 2 G03 -19.8792 86.4500 95.0000
75 75 75 6 3 G04 -28.8792 86.4500 95.0000
76 76 76 6 4 G05 -37.8792 86.4500 95.0000
77 77 77 6 5 G06 -46.8792 86.4500 95.0000
78 78 78 6 6 G07 -55.8792 86.4500 95.0000
79 79 79 6 7 G08 -64.8792 86.4500 95.0000
80 80 80 6 8 G09 -73.8792 86.4500 95.0000
81 81 81 6 9 G10 -82.8792 86.4500 95.0000
82 82 82 6 10 G11 -91.8792 86.4500 95.0000
83 83 83 6 11 G12 -100.8792 86.4500 95.0000
84 84 95 7 0 H01 -1.8792 95.4500 95.0000
85 85 94 7 1 H02 -10.8792 95.4500 95.0000
86 86 93 7 2 H03 -19.8792 95.4500 95.0000
87 87 92 7 3 H04 -28.8792 95.4500 95.0000
88 88 91 7 4 H05 -37.8792 95.4500 95.0000
89 89 90 7 5 H06 -46.8792 95.4500 95.0000
90 90 89 7 6 H07 -55.8792 95.4500 95.0000
91 91 88 7 7 H08 -64.8792 95.4500 95.0000
92 92 87 7 8 H09 -73.8792 95.4500 95.0000
93 93 86 7 9 H10 -82.8792 95.4500 95.0000
94 94 85 7 10 H11 -91.8792 95.4500 95.0000
95 95 84 7 11 H12 -100.8792 95.4500 95.0000
96 96 99 99 99 W01 -8.2492 1.1709 68.3999
97 97 99 99 99 W02 -36.9737 1.1709 68.3999

98 rows × 9 columns


In [ ]:
autosipper.go_to('hardware', 'name', 'W01')

Manifold


In [5]:
from config import Manifold

manifold = Manifold('192.168.1.3', 'config/valvemaps/valvemap.csv', 512)
manifold.valvemap[manifold.valvemap.name>0]


Out[5]:
valve name
0 0 inlet_out
2 2 inlet_in
8 8 chip_out
9 9 N
10 10 B1
11 11 S1
12 12 S2
13 13 B2
14 14 chip_in
16 16 Waste_2
17 17 bBSA_2
18 18 NA_2
19 19 antibody_2
20 20 Extra1_2
21 21 Extra2_2
22 22 Protein_2
23 23 Wash_2
24 24 Out_2
25 25 Neck_2
26 26 Button2_2
27 27 Sandwich2_2
28 28 Sandwich1_2
29 29 Button1_2
30 30 In_2
32 32 Waste_3
33 33 bBSA_3
34 34 NA_3
35 35 antibody_3
36 36 Extra1_3
37 37 Extra2_3
38 38 Protein_3
39 39 Wash_3
40 40 Out_3
41 41 Neck_3
42 42 Button2_3
43 43 Sandwich2_3
44 44 Sandwich1_3
45 45 Button1_3
46 46 In_3

In [6]:
gui.manifold_control(manifold)

Micromanager


In [7]:
# !!!! Also must have MM folder on system PATH
mm_version = 'C:\Program Files\Micro-Manager-2.0beta'
cfg = 'C:\Program Files\Micro-Manager-2.0beta\Setup2_20170614.cfg'

import sys
sys.path.insert(0, mm_version) # make it so python can find MMCorePy
import MMCorePy
from PIL import Image

core = MMCorePy.CMMCore()
core.loadSystemConfiguration(cfg)

In [8]:
# core.getDevicePropertyNames(core.getCameraDevice())
camera = core.getCameraDevice()
shutter = core.getShutterDevice()
stage_xy = core.getXYStageDevice()

In [9]:
core.setConfig('Channel','2bf')
# core.setProperty(core.getCameraDevice(), "Exposure", 10)
core.setProperty(core.getCameraDevice(), "Binning", "3x3")

In [10]:
gui.snap(core, 'cv2')

In [11]:
gui.video(core, loop_pause=0.05)


LIVE
To stop, click window + press ESC
STOPPED

Channel:

  • 1pbp
  • 2bf
  • 3dapi
  • 4egfp
  • 5cy5
  • 6attophos

Other


In [12]:
data_dir = "Z:/Data/Setup 2/Arjun/170618_FlippedMITOMI" + "/"
# timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
# data_dir += timestamp+"/"
# os.makedirs(data_dir)

In [13]:
position_list = ut.load_mm_positionlist("Z:/Data/Setup 2/Arjun/170618_FlippedMITOMI/170619_AKA.pos")
position_list


Out[13]:
r c name x y
0 0 0 1-Pos_000_000 -52296.03416 -9719.13416
1 0 1 1-Pos_001_000 -51245.53592 -9719.13416
2 0 2 1-Pos_002_000 -50195.03768 -9719.13416
3 0 3 1-Pos_003_000 -49144.53944 -9719.13416
4 0 4 1-Pos_004_000 -48094.04120 -9719.13416
5 0 5 1-Pos_005_000 -47043.54296 -9719.13416
6 0 6 1-Pos_006_000 -45993.04472 -9719.13416
7 0 7 1-Pos_007_000 -44942.54648 -9719.13416
8 0 8 1-Pos_008_000 -43892.04824 -9719.13416
9 0 9 1-Pos_009_000 -42841.55000 -9719.13416
10 0 10 1-Pos_010_000 -41791.05176 -9719.13416
11 0 11 1-Pos_011_000 -40740.55352 -9719.13416
12 0 12 1-Pos_012_000 -39690.05528 -9719.13416
13 0 13 1-Pos_013_000 -38639.55704 -9719.13416
14 0 14 1-Pos_014_000 -37589.05880 -9719.13416
15 0 15 1-Pos_015_000 -36538.56056 -9719.13416
16 0 16 1-Pos_016_000 -35488.06232 -9719.13416
17 0 17 1-Pos_017_000 -34437.56408 -9719.13416
18 0 18 1-Pos_018_000 -33387.06584 -9719.13416
19 1 18 1-Pos_018_001 -33387.06584 -8668.63592
20 1 17 1-Pos_017_001 -34437.56408 -8668.63592
21 1 16 1-Pos_016_001 -35488.06232 -8668.63592
22 1 15 1-Pos_015_001 -36538.56056 -8668.63592
23 1 14 1-Pos_014_001 -37589.05880 -8668.63592
24 1 13 1-Pos_013_001 -38639.55704 -8668.63592
25 1 12 1-Pos_012_001 -39690.05528 -8668.63592
26 1 11 1-Pos_011_001 -40740.55352 -8668.63592
27 1 10 1-Pos_010_001 -41791.05176 -8668.63592
28 1 9 1-Pos_009_001 -42841.55000 -8668.63592
29 1 8 1-Pos_008_001 -43892.04824 -8668.63592
... ... ... ... ... ...
331 17 10 1-Pos_010_017 -41791.05176 8139.33592
332 17 9 1-Pos_009_017 -42841.55000 8139.33592
333 17 8 1-Pos_008_017 -43892.04824 8139.33592
334 17 7 1-Pos_007_017 -44942.54648 8139.33592
335 17 6 1-Pos_006_017 -45993.04472 8139.33592
336 17 5 1-Pos_005_017 -47043.54296 8139.33592
337 17 4 1-Pos_004_017 -48094.04120 8139.33592
338 17 3 1-Pos_003_017 -49144.53944 8139.33592
339 17 2 1-Pos_002_017 -50195.03768 8139.33592
340 17 1 1-Pos_001_017 -51245.53592 8139.33592
341 17 0 1-Pos_000_017 -52296.03416 8139.33592
342 18 0 1-Pos_000_018 -52296.03416 9189.83416
343 18 1 1-Pos_001_018 -51245.53592 9189.83416
344 18 2 1-Pos_002_018 -50195.03768 9189.83416
345 18 3 1-Pos_003_018 -49144.53944 9189.83416
346 18 4 1-Pos_004_018 -48094.04120 9189.83416
347 18 5 1-Pos_005_018 -47043.54296 9189.83416
348 18 6 1-Pos_006_018 -45993.04472 9189.83416
349 18 7 1-Pos_007_018 -44942.54648 9189.83416
350 18 8 1-Pos_008_018 -43892.04824 9189.83416
351 18 9 1-Pos_009_018 -42841.55000 9189.83416
352 18 10 1-Pos_010_018 -41791.05176 9189.83416
353 18 11 1-Pos_011_018 -40740.55352 9189.83416
354 18 12 1-Pos_012_018 -39690.05528 9189.83416
355 18 13 1-Pos_013_018 -38639.55704 9189.83416
356 18 14 1-Pos_014_018 -37589.05880 9189.83416
357 18 15 1-Pos_015_018 -36538.56056 9189.83416
358 18 16 1-Pos_016_018 -35488.06232 9189.83416
359 18 17 1-Pos_017_018 -34437.56408 9189.83416
360 18 18 1-Pos_018_018 -33387.06584 9189.83416

361 rows × 5 columns


In [14]:
# ONE ACQUISITION / SCAN
def scan(channel, exposure, note, plate_n):
    core.setConfig('Channel', channel)
    core.setProperty(core.getCameraDevice(), "Exposure", exposure)
    time.sleep(.2)
    
    timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
    solution = autosipper.coord_frames.hardware.position_table.contents.iloc[plate_n]
    scan_dir = '{}_{}_{}_{}_{}'.format(timestamp, solution, note, channel, exposure)
    os.makedirs(data_dir + scan_dir)
    
    for i in xrange(len(position_list)):
        si = str(i)
        x,y = position_list[['x','y']].iloc[i]
        core.setXYPosition(x,y)
        core.waitForDevice(core.getXYStageDevice())
        
        core.snapImage()
        img = core.getImage()
        image = Image.fromarray(img)
        
        timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
        positionname = position_list['name'].iloc[i]
        image.save('{}/{}_{}.tif'.format(data_dir+scan_dir, timestamp, positionname))

    x,y = position_list[['x','y']].iloc[0]
    core.setXYPosition(x,y)
    core.waitForDevice(core.getXYStageDevice())

def get_valve(name):
    return ut.lookup(manifold.valvemap,'name',name,'valve',0)[0]

ACQUISITION


In [ ]:
scan('4egfp', 125, 'pre',0)

In [ ]:
n0 = 0
# PUT PINS IN ALL INPUTS
# in0 WASTE LINE
# in1 WASH LINE, 4.5 PSI
# in2 PEEK LINE, 4.5 PSI
#----------------------------------

# initialize valve states
## inputs:    pressurize
## chip_io:   pressurize
## sandwhich: pressurize
## neck:      pressurize
## button:    pressurize

# prime inlet tree (wash)
manifold.depressurize(get_valve('bBSA_2'))  ## wash open
manifold.depressurize(get_valve('Waste_2')) ## waste open
time.sleep(60*0.5)                          ## wait 0.5 min
manifold.pressurize(get_valve('Waste_2'))   ## waste close

# backflush tubing (wash)
autosipper.go_to('hardware', 'name', 'W02', zh_travel=40) ## W02 move
manifold.depressurize(get_valve('NA_2'))                  ## inlet open
time.sleep(60*15)                                         ## wait 15 min
manifold.pressurize(get_valve('NA_2'))                    ## inlet close
manifold.pressurize(get_valve('bBSA_2'))                  ## wash close

In [16]:
n0=0
# prime tubing (1st input)
manifold.pressurize(get_valve('Out_2'))                   # chip_out close
manifold.pressurize(get_valve('In_2'))                    # chip_in close

autosipper.go_to('hardware', 'name', 'W01', zh_travel=40)
autosipper.go_to('hardware', 'n', n0, zh_travel=40)
manifold.depressurize(get_valve('NA_2'))                  # inlet open
manifold.depressurize(get_valve('Waste_2'))               # waste open
time.sleep(60*20)                                         # filling inlet, 20 min...

manifold.pressurize(get_valve('Waste_2'))                 # waste close

In [17]:
# 16,Waste_2
# 17,bBSA_2
# 18,NA_2
# 19,antibody_2
# 20,Extra1_2
# 21,Extra2_2
# 22,Protein_2
# 23,Wash_2

exposures = [1250,1250,1250,1250,1000,600,300,180,70,30]
for i, exposure in enumerate(exposures):
    plate_n = n0+i
    
    # flow on chip
    manifold.depressurize(get_valve('Sandwich1_2')) # sandwhiches open
    manifold.depressurize(get_valve('Sandwich2_2')) # "
    manifold.depressurize(get_valve('NA_2')) # inlet open
    manifold.depressurize(get_valve('In_2')) # chip_in open
    manifold.depressurize(get_valve('Out_2')) # chip_out open
    time.sleep(60*10) # filling chip, 10 min...
    
    # CONCURRENTLY:
    incubate_time = 60*30 # 30 min
    
    # a) incubate DNA with protein
    manifold.pressurize(get_valve('Sandwich1_2')) # sandwhiches close
    manifold.pressurize(get_valve('Sandwich2_2')) # "
    time.sleep(1) # pause
    manifold.depressurize(get_valve('Button1_2')) # buttons open
    manifold.depressurize(get_valve('Button2_2')) # "
    incubate_start = time.time()
    
    # b1) prime inlet tube with next INPUT
    manifold.pressurize(get_valve('Out_2')) # chip_out close
    manifold.pressurize(get_valve('In_2')) # chip_in close

    manifold.pressurize(get_valve('NA_2')) # inlet close
    autosipper.go_to('hardware', 'name', 'W01', zh_travel=40)
    autosipper.go_to('hardware', 'n', plate_n+1, zh_travel=40)
    manifold.depressurize(get_valve('NA_2')) # inlet open
    manifold.depressurize(get_valve('Waste_2')) # waste open
    time.sleep(60*20) # filling inlet, 20 min...
    
    manifold.pressurize(get_valve('NA_2')) # inlet close

    # b2) prime inlet tree with wash
    manifold.depressurize(get_valve('bBSA_2')) # wash open
    manifold.pressurize(get_valve('Waste_2')) # waste close
    
    for v in [18,19,20,21,22,23]:
        manifold.depressurize(v)
        time.sleep(.25)
        manifold.pressurize(v)
    
    manifold.depressurize(get_valve('Waste_2')) # waste open
    time.sleep(60*1)
    manifold.pressurize(get_valve('Waste_2')) # waste close

    remaining_time = incubate_time - (time.time() - incubate_start)
    time.sleep(remaining_time)    
    
    # prewash Cy5
    scan('5cy5', exposure, 'pre', plate_n)
    
    # wash
    manifold.pressurize(get_valve('Button1_2')) # buttons close
    manifold.pressurize(get_valve('Button2_2')) # "
    time.sleep(1) # pause
    manifold.depressurize(get_valve('Sandwich1_2')) # sandwhiches open
    manifold.depressurize(get_valve('Sandwich2_2')) # "
        
    manifold.depressurize(get_valve('In_2')) # chip_in open
    manifold.depressurize(get_valve('Out_2')) # chip_out open
    time.sleep(60*10) # washing chip, 10 min...
    
    manifold.pressurize(get_valve('Out_2')) # chip_out close
    manifold.pressurize(get_valve('In_2')) # chip_in close
    manifold.pressurize(get_valve('bBSA_2')) # wash close

    # postwash eGFP and postwash Cy5
    scan('4egfp', 125, 'post', plate_n)
    scan('5cy5', 1250, 'post', plate_n)

OLD STUFF


In [ ]:
def acquire():
    for i in xrange(len(position_list)):
        si = str(i)
        x,y = position_list[['x','y']].iloc[i]
        core.setXYPosition(x,y)
        core.waitForDevice(core.getXYStageDevice())
        logadd(log, 'moved '+si)
        
        core.snapImage()
#         core.waitForDevice(core.getCameraDevice())
        logadd(log, 'snapped '+si)
        
        img = core.getImage()
        logadd(log, 'got image '+si)
        
        image = Image.fromarray(img)
        image.save('images/images_{}.tif'.format(i))
        logadd(log, 'saved image '+si)
    
    x,y = position_list[['x','y']].iloc[0]
    core.setXYPosition(x,y)
    core.waitForDevice(core.getXYStageDevice())
    logadd(log, 'moved '+ str(0))
        
def logadd(log,st):
    log.append([time.ctime(time.time()), st])
    print log[-1]

EXIT


In [ ]:
autosipper.exit()
manifold.exit()
core.unloadAllDevices()
core.reset()
print 'closed'

In [ ]:
# ONE ACQUISITION / SCAN
def scan(channel, exposure, note, plate_n):
    core.setConfig('Channel', channel)
    core.setProperty(core.getCameraDevice(), "Exposure", exposure)
    time.sleep(.2)
    
    timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
    solution = autosipper.coord_frames.hardware.position_table.contents.iloc[plate_n]
    scan_dir = '{}_{}_{}_{}_{}'.format(timestamp, solution, note, channel, exposure)
    os.makedirs(data_dir + scan_dir)
    
    for i in xrange(len(position_list)):
        si = str(i)
        x,y = position_list[['x','y']].iloc[i]
        core.setXYPosition(x,y)
        core.waitForDevice(core.getXYStageDevice())
        
        core.snapImage()
        img = core.getImage()
        image = Image.fromarray(img)
        
        timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
        positionname = position_list['name'].iloc[i]
        image.save('{}/{}_{}.tif'.format(data_dir+scan_dir, timestamp, positionname))

    x,y = position_list[['x','y']].iloc[0]
    core.setXYPosition(x,y)
    core.waitForDevice(core.getXYStageDevice())

def get_valve(name):
    return ut.lookup(manifold.valvemap,'name',name,'valve',0)[0]