Friday, July 25, 2014

MScan 2.1. New feature: close-loop experiments

Two-photon close-loop experiments with MScan 2.1.


MScan can react in near real time to changes in image intensity to trigger a response. This feature opens the unique possibility to perform close-loop experiments either in brain slices or even in live animals.  Custom code can be easily written using the built-in scripting environment to perform specific actions when certain cells in the field of view become more active. These actions can include for instance the delivery of an analog or a digital stimulation pattern. Scripts allow developing complex experiments easily - you can imagine triggering an optogenetic stimulation when the difference in activity between two or more cells reaches a threshold. It might be even possible to obtain the phase-response curve of an entire neural network imaged by two-photon microscopy. These experiments can be programmed in scripts by using a combination of:

The OnNewFrames event. The OnNewFrames scripting event is triggered each time one or more frames have been received. In MScan 2.1, special care has been taken to ensure that OnNewFrames is called with the lowest latency possible. The code associated with OnNewFrames runs in its separate thread to ensure that it does not slow down frame acquisition while taking advantage of the multicore capability of the processor powering the the MScan computer. The CurrentFrameIndex property returns the current frame index, allowing for instance specific code to be run after waiting for a certain number of frames. A new protocol setting called Process Frames can be set to At Every Frame to ensure that OnNewFrames is called each time a new frame has been acquired.

The ROIs property. Intensity data from Regions Of Interest (ROIs) are now available in scripts in real-time. Arbitrary rectangular, elliptical or polygonal regions can be created around cells in the Viewer window. Intensity values can be used in scripts with the ROIs property, which returns the pixel intensity of a specific ROI averaged across all pixels of the ROI for the latest frame and those preceding it. ROIs(3, 0) will return the intensity of ROI number 3 in the latest frame acquired (0 is the index of the most recent frame in the ROIs buffers).

Analog and digital stimulation. Scripts can now generate analog or digital trains without having to use the Stimulator object. The StartAnalogTrain or StartDigitalTrain methods can be used to specify and deliver analog or digital train in scripts, for instance during the OnNewFrames event. Analog trains can use any of two analog outputs available on the PCIe-6321 board, while digital trains can be delivered on any of the eight digital input/output lines of the board. This gives plenty of flexibility to trigger either inhibitory or excitatory stimuli depending on the functional response of the network imaged by two-photon microscopy. A typical train consists of a delay and a series of one or more identical pulses, each composed of two steps with independent duration and value. For instance, StartDigitalTrain 1000000, 255, 15000, 0, 5000, 100 will deliver 100 pulses consisting first of  a step setting all 8 of the digital lines to 1 (11111111 in binary = 255) lasting 15000 microseconds (i.e., 15 ms) followed by a step where all the lines are back to 0 (000000000 in binary = 0) for a duration of 5 ms (5000 microseconds). The step is preceded by a delay of 1 s (1000000 microseconds) with all lines set to 0. StartAnalogTrain delivers a train consisting of analog values from -10 V to + 10 V on one of two possible analog output channels.

Putting all these elements together in a script is straightforward. In the OnNewFrames code editor, the line:

If ROIs(1, 0) > 1500 Then StartDigitalTrain 0, 255, 10000, 0, 10000, 100

will deliver a digital train each time ROI number 1 will be above a value set to 1500.



We hope far-reaching experiments will be possible with the script-based close-loop features of MScan.

No comments:

Post a Comment