SETUP


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

from acqpack import utils as ut
from acqpack import gui

%matplotlib inline

Autosampler


In [2]:
from acqpack import Motor, AsiController, Autosampler
a = Autosampler(Motor('acqpack/config/motor.yaml'), AsiController('acqpack/config/asicontroller.yaml'))
a.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]:
gui.stage_control(a)


(0.0, 0.0, 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']))]
j=0
for i in range(0,12,2):
    platemap['contents'].iloc[i] = "cmu"+str(j)
    j+=1
    
j=0
for i in range(1,12,2):
    platemap['contents'].iloc[i] = "water"+str(j)
    j+=1

a.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 cmu0
1 1 1 0 1 A02 -10.8792 32.4500 95.0000 water0
2 2 2 0 2 A03 -19.8792 32.4500 95.0000 cmu1
3 3 3 0 3 A04 -28.8792 32.4500 95.0000 water1
4 4 4 0 4 A05 -37.8792 32.4500 95.0000 cmu2
5 5 5 0 5 A06 -46.8792 32.4500 95.0000 water2
6 6 6 0 6 A07 -55.8792 32.4500 95.0000 cmu3
7 7 7 0 7 A08 -64.8792 32.4500 95.0000 water3
8 8 8 0 8 A09 -73.8792 32.4500 95.0000 cmu4
9 9 9 0 9 A10 -82.8792 32.4500 95.0000 water4
10 10 10 0 10 A11 -91.8792 32.4500 95.0000 cmu5
11 11 11 0 11 A12 -100.8792 32.4500 95.0000 water5
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 [5]:
a.goto('hardware', 'name', 'W02',zh_travel=50)

Manifold


In [2]:
from acqpack import Manifold
m = Manifold('192.168.1.3', 'acqpack/valvemaps/valvemap.csv', 512)
m.valvemap.fillna('', inplace=True)
m.valvemap[m.valvemap.chip<>'']


Out[2]:
valve chip line
40 40 in1
41 41 in2
42 42 out1
43 43 out2
44 44 hep1
45 45 hep2
46 46 bsa1
47 47 bsa2

In [3]:
gui.manifold_control(m, 'chip')

Micromanager


In [ ]:
# !!!! 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 [ ]:
# core.getDevicePropertyNames(core.getCameraDevice())
camera = core.getCameraDevice()
shutter = core.getShutterDevice()
stage_xy = core.getXYStageDevice()

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

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

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

Channel:

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

Other


In [ ]:
data_dir = "Z:/User_Storage/Scott/"
timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
data_dir += timestamp+"/"
os.makedirs(data_dir)

In [ ]:
position_list = ut.load_mm_positionlist("Z:/Data/Setup 2/Arjun/170609_FlippedMITOMI/170609_mwm.pos")
position_list

In [ ]:
# ONE ACQUISITION / SCAN
def timecourse(channel_list, exposure_list, note_list, dt_list, plate_n):
    """
    SUBROUTINE
    
    channel_list (list)
    exposure_list (list) - List of lists
    note_list (list)
    dt_list (list)
    plate_n (int)
    """
    for channel, exposures, note, dt, plate_n in izip(channel_list, exposure_list, note_list, dt_list):
        
        scan(channel, exposures, note, plate_n)
        
        t_start = time.time()
        x,y = position_list[['x','y']].iloc[0]
        core.setXYPosition(x,y)
        core.waitForDevice(core.getXYStageDevice())
        t_remaining = dt - (time.time() - t_start)
        time.sleep(t_remaining) 

        
def scan(channel, exposures, note, plate_n):
    """
    SUBROUTINE
    
    channel (str)
    exposures (list)
    note (str)
    plate_n (int)
    """
    core.setConfig('Channel', channel)
    time.sleep(.2)
    
    timestamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
    solution = a.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())
        
        for exposure in exposures:
            core.setProperty(core.getCameraDevice(), "Exposure", exposure)
            core.waitForDevice(core.getCameraDevice())
            
            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, exposure))

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
## all inputs close
## sandwhich

# prime inlet tree (wash)
m.open('chip', 'bBSA_2')  ## wash open
m.open('chip', 'Waste_2') ## waste open
time.sleep(60*0.5)                          ## wait 0.5 min
m.close('chip', 'Waste_2')   ## waste close

# backflush tubing (wash)
a.goto('hardware', 'name', 'W02', zh_travel=40) ## W02 move
m.open('chip', 'NA_2')                  ## inlet open
time.sleep(60*1)                        ## wait 15 min
m.close('chip', 'NA_2')                 ## inlet close
m.close('chip', 'bBSA_2')               ## wash close

# prime tubing (1st input)
m.close('chip', 'Out_2')                # chip_out close
m.close('chip', 'In_2')                 # chip_in close

a.goto('hardware', 'name', 'W01', zh_travel=40)
a.goto('hardware', 'n', n0, zh_travel=40)
m.open('chip', 'NA_2')                  # inlet open
m.open('chip', 'Waste_2')               # waste open
time.sleep(60*15)                       # filling inlet, 15 min...

m.close('chip', 'Waste_2')              # waste close

In [ ]:
# 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):
    if i==0:
        continue
    
    plate_n = n0+i
    
    # flow on chip
    m.open('chip', 'NA_2') # inlet open
    m.open('chip', 'In_2') # chip_in open
    m.open('chip', '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
    m.close('chip', 'Sandwich1_2') # sandwhiches close
    m.close('chip', 'Sandwich2_2') # "
    time.sleep(1) # pause
    m.open('chip', 'Button1_2') # buttons open
    m.open('chip', 'Button2_2') # "
    incubate_start = time.time()
    
    # b1) prime inlet tube with next INPUT
    m.close('chip', 'Out_2') # chip_out close
    m.close('chip', 'In_2') # chip_in close

    m.close('chip', 'NA_2') # inlet close
    a.goto('hardware', 'name', 'W01', zh_travel=40)
    a.goto('hardware', 'n', plate_n+1, zh_travel=40)
    m.open('chip', 'NA_2') # inlet open
    m.open('chip', 'Waste_2') # waste open
    time.sleep(60*15) # filling inlet, 15 min...
    
    m.close('chip', 'NA_2') # inlet close

    # b2) prime inlet tree with wash
    m.open('chip', 'bBSA_2') # wash open
    m.close('chip', 'Waste_2') # waste close
    
    for v in [19,20,21,22,23]:
        m.open(v)
        time.sleep(.2)
        m.close(v)
    
    m.open('chip', 'Waste_2') # waste open
    time.sleep(60*1)
    m.close('chip', '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
    m.close('chip', 'Button1_2') # buttons close
    m.close('chip', 'Button2_2') # "
    time.sleep(1) # pause
    m.open('chip', 'Sandwich1_2') # sandwhiches open
    m.open('chip', 'Sandwich2_2') # "
        
    m.open('chip', 'In_2') # chip_in open
    m.open('chip', 'Out_2') # chip_out open
    time.sleep(60*10) # washing chip, 10 min...
    
    m.close('chip', 'Out_2') # chip_out close
    m.close('chip', 'In_2') # chip_in close
    m.close('chip', '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 [ ]:
a.exit()
m.exit()
core.unloadAllDevices()
core.reset()
print 'closed'