NeuroPG - Open source software for optical pattern generation and data acquisition

22
NeuroPG: Open source software for optical pattern generation and data acquisition Benjamin W. Avants, Daniel B. Murphy, Joel A. Dapello and Jacob T. Robinson Journal Name: Frontiers in Neuroengineering ISSN: 1662-6443 Article type: Methods Article Received on: 24 Sep 2014 Accepted on: 09 Feb 2015 Provisional PDF published on: 09 Feb 2015 Frontiers website link: www.frontiersin.org Citation: Avants BW, Murphy DB, Dapello JA and Robinson JT(2015) NeuroPG: Open source software for optical pattern generation and data acquisition. Front. Neuroeng. 8:1. doi:10.3389/fneng.2015.00001 Copyright statement: © 2015 Avants, Murphy, Dapello and Robinson. This is an open-access article distributed under the terms of the Creative Commons Attribution License (CC BY). The use, distribution and reproduction in other forums is permitted, provided the original author(s) or licensor are credited and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is permitted which does not comply with these terms. This Provisional PDF corresponds to the article as it appeared upon acceptance, after rigorous peer-review. Fully formatted PDF and full text (HTML) versions will be made available soon.

Transcript of NeuroPG - Open source software for optical pattern generation and data acquisition

Page 1: NeuroPG - Open source software for optical pattern generation and data acquisition

   

 NeuroPG: Open source software for optical pattern generation and dataacquisition

  Benjamin W. Avants, Daniel B. Murphy, Joel A. Dapello and Jacob T. Robinson

Journal Name: Frontiers in Neuroengineering

ISSN: 1662-6443

Article type: Methods Article

Received on: 24 Sep 2014

Accepted on: 09 Feb 2015

Provisional PDF published on: 09 Feb 2015

Frontiers website link: www.frontiersin.org

Citation: Avants BW, Murphy DB, Dapello JA and Robinson JT(2015) NeuroPG:Open source software for optical pattern generation and dataacquisition. Front. Neuroeng. 8:1. doi:10.3389/fneng.2015.00001

Copyright statement: © 2015 Avants, Murphy, Dapello and Robinson. This is anopen-access article distributed under the terms of the CreativeCommons Attribution License (CC BY). The use, distribution andreproduction in other forums is permitted, provided the originalauthor(s) or licensor are credited and that the originalpublication in this journal is cited, in accordance with acceptedacademic practice. No use, distribution or reproduction ispermitted which does not comply with these terms.

 This Provisional PDF corresponds to the article as it appeared upon acceptance, after rigorous

peer-review. Fully formatted PDF and full text (HTML) versions will be made available soon.

 

Page 2: NeuroPG - Open source software for optical pattern generation and data acquisition

1 This is a provisional file, not the final typeset article

NeuroPG: Open Source Software for Optical Pattern Generation and 1

Data Acquisition 2

Benjamin W. Avants1†, Daniel B. Murphy1†, Joel A. Dapello2, Jacob T. Robinson1,3,4*, 3

1Department of Electrical and Computer Engineering, Rice University, Houston, TX, USA 4 2Hampshire College, Amherst, MA, USA 5 3Department of Bioengineering, Rice University, Houston, TX, USA 6 4Department of Neuroscience, Baylor College of Medicine, Houston, TX, USA 7 8 †These authors contributed equally to this work. 9

* Correspondence: Jacob T. Robinson, Department of Electrical and Computer Engineering, Rice University, Houston, 10 TX, 77005, USA 11 [email protected] 12

Keywords: optogenetics, electrophysiology, software, pattern stimulation, imaging, DMD, Polygon400. 13 14

Abstract 15

Patterned illumination using a digital micromirror device (DMD) is a powerful tool for optogenetics. 16

Compared to a scanning laser, DMDs are inexpensive and can easily create complex illumination 17

patterns. Combining these complex spatiotemporal illumination patterns with optogenetics allows 18

DMD-equipped microscopes to probe neural circuits by selectively manipulating the activity of many 19

individual cells or many subcellular regions at the same time. To use DMDs to study neural activity, 20

scientists must develop specialized software to coordinate optical stimulation patterns with the 21

acquisition of electrophysiological and fluorescence data. To meet this growing need we have 22

developed an open source optical pattern generation software for neuroscience - NeuroPG - that 23

combines, DMD control, sample visualization, and data acquisition in one application. Built on a 24

MATLAB platform, NeuroPG can also process, analyze, and visualize data. The software is 25

designed specifically for the Mightex Polygon400; however, as an open source package, NeuroPG 26

can be modified to incorporate any data acquisition, imaging, or illumination equipment that is 27

compatible with MATLAB’s Data Acquisition and Image Acquisition toolboxes. 28

29

1. Introduction 30

31 Optogenetic techniques allow scientists to rapidly manipulate cellular activity by illuminating 32

genetically encoded, light-sensitive proteins (Nagel et al. 2003; Boyden et al. 2005; Miesenböck 33

2009; Zhang et al. 2007). Photostimulation of these proteins can affect many cellular behaviors 34

including depolarization or hyperpolarization of the cellular membrane (Boyden et al. 2005; Zhang et 35

al. 2007), gene regulation (Motta-Mena et al. 2014; H. Liu et al. 2012), and signaling pathway 36

activity (Airan et al. 2009). One of the main advantages of optogenetics is the ability to modulate the 37

activity of specific subsets of cells. For example, optogenetic techniques can target groups of 38 genetically similar cells using cell-type-specific promoters (Kwan and Dan 2012; Palmer et al. 2011; 39

Sohal et al. 2009; Cardin et al. 2010), or transgenic animals (Gradinaru et al. 2009; X. Liu et al. 40

2012; Asrican et al. 2013). Even greater specificity is achieved by focusing light to the cell body or 41

Page 3: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

2 This is a provisional file, not the final typeset article

sub-cellular structure (Oron et al. 2012; K. Wang et al. 2011; Smedemark-Margulies and Trapani 42

2013;Hochbaum et al., 2014). In this way, scientists can modulate the precise spatiotemporal activity 43

patterns of many individual cells in a localized region with the hope of revealing how information is 44

processed in neural microcircuits (Kwan and Dan 2012; Silasi et al. 2013; Hooks et al. 2013). 45

46

One of the main challenges for using optogenetics to study the roles of individual neurons in a 47

neural network lies in generating the spatiotemporal pattern of illumination necessary to modulate 48

specific combinations of single cells. The three main approaches to activate neurons with cellular 49

resolution include scanning lasers (Oron et al. 2012; Paz et al. 2013; J. Wang, Hasan, and Seung 50

2009), spatial phase modulation (Smedemark-Margulies and Trapani 2013; Shoham 2010), and 51

digital mirror devices (DMDs) (Smedemark-Margulies and Trapani 2013; Packer, Roska, and 52

Häusser 2013; (Hochbaum et al., 2014; Leifer, Fang-Yen, Gershow, Alkema, & Samuel, 2011)). 53

Each approach has unique advantages. Scanning lasers deliver the entire source power to a small 54

focal spot, making this approach ideal for multiphoton microscopy. Because the focal spot is 55

typically much smaller than the cell body, to efficiently stimulate neural activity the beam is often 56

scanned rapidly over the cell body (Smedemark-Margulies and Trapani 2013; K. Wang et al. 2011). 57

However, since the laser can typically only illuminate one location at a time, it is difficult to activate 58

combinations of individual neurons simultaneously. One approach to illuminate many spots 59

simultaneously employs spatial phase modulation (SPM) to form multiple focal points for a single 60

laser (Reutsky-Gefen et al. 2013; Andrasfalvy et al. 2010). The main advantage of the spatial phase 61

modulation is the ability to focus a laser to arbitrary points in 3D; however, the power at each focal 62

point decreases with the number of focal spots, limiting the total number of neurons that can be 63

simultaneously activated (Peron and Svoboda 2011). As an alternative to laser-based systems, DMDs 64

can simultaneously illuminate hundreds of thousands of points simultaneously (limited by the pixel 65

count of the DMD). Furthermore, because the power is distributed equally to each mirror, the power 66

delivered to each point is independent of the number of points illuminated. The drawbacks of DMDs 67

compared to scanning lasers and phase modulation include higher black levels of illumination 68

(typically some light reaches the sample when the mirrors are switched to the off state), and lower 69

power at each point since each mirror uses only a fraction of the source power. Regardless of these 70

drawbacks, DMDs can effectively stimulate neurons expressing ChR2 (Farah, Reutsky, & Shoham, 71

2007; Zhu, Fajardo, Shum, Zhang Schärer, & Friedrich, 2012) and cost significantly less than laser-72

based systems. For example, most microscopes can be upgraded to incorporate DMD illumination for 73

less than $10,000. Considering the many advantages of DMD illumination we developed the 74

NeuroPG software suite to streamline DMD-based optogenetic experiments. 75

The NeuroPG software we developed for DMD-based neural circuit studies combines and 76

synchronizes optical pattern generation with image and electrophysiology data acquisition. While 77

similar open source software exists for laser-scanning systems (Suter et al. 2010), we found no open 78

source solution for automating DMD illumination and neural data acquisition. In an effort to reduce 79

the software development time for labs interested in a low cost method for spatiotemporal 80

manipulation of neural circuit activity, we developed our flexible software platform to combine the 81

control and coordination of both the stimulation and acquisition hardware. As a DMD illumination 82

device we chose the Polygon 400 DMD from Mightex since it can be configured with up to three 83

different LEDs and easily adapted to most commercial microscopes. 84

The NeuroPG software consists of independent software control modules that can be easily 85

modified and expanded. As an example, we have developed several routines to aid with neural circuit 86

mapping and have included these routines in the software package. Specifically we have created tools 87

Page 4: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

3 This is a provisional file, not the final typeset article

to define stimulation patterns and to automate simultaneous stimulation and data collection. Once a 88

stimulation protocol is complete, NeuroPG automatically associates the measured responses with the 89

corresponding stimulation region and presents this information graphically, so it may be easily 90

reviewed in real-time. In addition to the graphical output, the raw data and metadata describing the 91

parameters used for the routine are stored in separate files. To aid in subsequent data analysis, 92

NeuroPG includes MatPad, a logging system that records details of the experimental protocols and 93

allows the user to enter and edit notes. Also included is CameraWindow, a MATLAB based camera 94

control suite that can be configured to any camera compatible with MATLAB’s Image Acquisition 95

Toolbox. CameraWindow can run independently or alongside NeuroPG and provides controls and 96

visualization tools useful for cell patching and image acquisition. 97

98

2. Methods 99

2.1. Web Site 100

The nueroPG website can be found at https://github.com/RobinsonLab-Rice/NeuroPG. The site 101

includes downloads and documentation for all related software. Any bugs or technical support issues 102

should be reported through the website. Updates and support information will be posted as available. 103

104

2.2. Software Development 105 NeuroPG was developed and tested on computers running Windows 7 64-bit and Windows 8 64-bit 106

and should work properly on any such system. Running NeuroPG on 32-bit systems is not 107

recommended. NeuroPG has not been tested on computers running Linux or OSX. 108

109

2.3. Hardware and Software Setup 110

2.3.1. MATLAB 111

NeuroPG runs in MATLAB (version 2012b and higher; Mathworks, Natick, MA, USA) as a 112

collection of graphical user interfaces (GUIs), classes, and functions. It requires that the Image 113

Acquisition Toolbox be installed for camera functionality. It also requires the Data Acquisition 114

Toolbox for timing, triggering, and data acquisition. 115

2.3.2. Workstation 116

To run NeuroPG, a computer must have an interface with a data acquisition board (DAQ) either 117 through PCI/PCIe expansion slots or via USB2/3 as required by the DAQ. For imaging, it must also 118

connect to a compatible camera. It is strongly recommended to run a 64-bit version of Windows and 119

have 8 GB or more of high speed RAM. It is also suggested that the workstation have more than one 120

monitor so that image and data acquisition, as well as DMD-control can be viewed simultaneously on 121

the desktop. 122

2.3.3. Data acquisition hardware 123

Page 5: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

4 This is a provisional file, not the final typeset article

Currently, only National Instruments (NI; Austin, TX, USA) DAQ hardware supporting session 124

based control (NI-DAQmx drivers) is supported by NeuroPG. At least three analog input channels 125

and one counter/timer output are required but do not need to be on the same device. NeuroPG was 126

tested using the NI USB-6259 and the NI PCIe-63321 X Series. 127

2.3.4. Amplifier 128

nueroPG has been tested using Axon Instruments Multiclamp 700B amplifiers but should be 129

compatible with any electrophysiology amplifier with analog output signals that can interface with an 130

NI DAQ module. Scaling of data signals can be done manually within nueroPG so that signal values 131

match actual data values. 132

133

2.3.5. Camera 134

NeuroPG, through CameraWindow, supports any camera compatible with the Image Acquisition 135

Toolbox. To control specific camera properties within CameraWindow, the user must generate a 136

configuration file specific to the camera in use. This can be done manually or with the included 137

NeuroPG configuration tool. Example configuration files are available on the website. 138

139

2.3.6. Digital micromirror device 140

The Mightex Polygon400 (Mightex, Toronto, Ontario, Canada) is currently the only supported DMD; 141

however, the basic pattern generation and triggering routines are not specific to the Polygon400 142

hardware. Because NeuroPG accesses the Polygon400 through a MATLAB class any device with a 143

MATLAB control class can be adapted for use with NeuroPG. Creating a MATLAB control class 144

requires access to the device’s software development kit (SDK) and serves as a wrapper that enables 145

MATLAB to interact with the device through its drivers. Because of the differences between DMD 146

systems and their SDKs, we cannot guarantee that all the NeuroPG functions will be compatible with 147

other DMD systems. However NeuroPG can in principle be used with any DMD system that has an 148

SDK by writing similar MATLAB control classes. These control classes will be hosted on the 149

NeuroPG GitHub repository as they become available. 150

151

2.3.7. Rat Hippocampal Cell Culture 152

All animal experiments described were carried out in accordance with the National Institutes of 153

Health Guidelines for the Care and Use of Laboratory Animals. Neurons were cultured on an 154

astrocyte feeder layer as described in various protocols, with minor modifications (Albuquerque et al, 155

2009; Brewer et al, 1993). Both cell types were derived from hippocampal tissue from E18 Sprague 156

Dawley rats that was purchased from BrainBits, LLC. Astrocyte cultures were established by 157

growing cells from dissociated hippocampal tissue in NbAstro medium (BrainBits). Astrocytes were 158

harvested with Tryple (Life Technologies) and plated on PDL-coated 12 mm coverslips at a density 159

of 5,000 cells/mm2. E18 hippocampal neurons (BrainBits, LLC) were plated on astrocyte substrate at 160

a density of 10,000 cells/mm2 in NbActiv1 medium supplemented with 3% fetal bovine serum. 50% 161

Page 6: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

5 This is a provisional file, not the final typeset article

of the medium was replaced with fresh medium every 3-4 days. Experiments described herein were 162

performed at DIV 7-14. 163

164

2.3.8. Lentiviral transduction 165

Neuron cultures were transduced with Lenti GFP-ChR2 lentivirus purchased from UNC Vector Core 166

(Chapel Hill, NC). Transductions were performed at 0 DIV at 25 MOI, based on concentration of 167

lentivirus stock provided by UNC Vector Core. 168

169

3. Results and Discussion: Description of the software 170

3.1. Overview 171

To demonstrate how NeuroPG can be used for neuroscience experiments that require coordinated 172

DMD stimulation and electrical recording, we mapped the response of cultured rat hippocampal 173

neurons to optical stimulus at different locations. The hardware configuration for this experiment is 174

shown in Figure 1. NeuroPG runs on a Dell desktop computer and communicates with a Hamamatsu 175

ORCA-03G camera, an NI USB-6259, two patch clamp headstages, an amplifier, and the Mightex 176

Polygon400 DMD. 177

178

For our example experiment, NeuroPG generated grid patterns with increasing resolution, stimulated 179

an E18 rat primary hippocampal neuron transduced with Lenti GFP-ChR2, and generated heat maps 180

based on the magnitude of the resulting depolarization as measured with whole-cell patch clamp 181

electrophysiology. With minor changes to the code or an imported evaluation function, heat maps 182

could alternatively be generated based on hyperpolarization or firing rate. Instructions for generating 183

custom evaluation functions are posted in the documentation available in the NeuroPG GitHub code 184

repository. The experiment is discussed further in Section 3.3 and the final heat maps can be seen in 185

Figure 5. 186

187

3.1.1. Pattern Generation 188

NeuroPG offers users two methods to define the regions of interest (ROIs) for illumination. Manual 189

pattern generation allows the user to design ROIs of variable size and shape using simple graphic 190

editing tools. Alternatively, patterns can be designed via the SmartGrid tool segments the entire field 191

of view into user-defined rectangles. ROIs are independent of one another and can be composed of 192

any combination or number of DMD pixels. Currently, SmartGrid only generates non-overlapping 193

ROIs but overlapping ROIs can be easily created with the built-in manual ROI generation tool. It is 194

important to note that with most DMD spatial light modulators the optical stimuli will be in focus in 195

the focal plane of the objective lens. To change the depth of the stimulus one can raise or lower the 196

objective lens. 197

Page 7: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

6 This is a provisional file, not the final typeset article

Manual Generation 198

Manual pattern generation allows the user to define ROIs as rectangular regions, elliptical regions, or 199

vertex specified polygons. Regions are defined graphically in an intuitive click-and-drag style on top 200

of an image specified by the user. In conjunction with CameraWindow or other microscope imaging 201

software, an image of a sample can be captured and used as a reference for manually creating these 202

regions (Figure 2). Based on the user-defined ROIs NeuroPG then creates pattern masks and uploads 203

these masks to the DMD onboard memory. 204

205

SmartGrid Generation 206

The SmartGrid pattern generator allows the user to quickly divide the visible area of the microscope 207

into regularly shaped rectangular regions. After loading a background image, the entire field of view 208

is designated as a single region. This region can be divided into a user specified grid where each grid 209

element can be subdivided to the pixel limit of the DMD. Any adjacent regions may also be 210

combined to form a larger single region. Any number of regions in the SmartGrid can be selected and 211

exported as patterns for the DMD. The user can also choose to export selected regions as a grouped 212

pattern, allowing for simultaneous stimulation of non-adjacent areas (Figure 3). 213

214

3.1.2. Pattern projection and real time analysis 215

Manual mode 216

nueroPG allows the user to set Polygon400 parameters, load patterns, start or stop pattern sequences, 217

and trigger the next pattern manually all within the GUI. The user can also manually start and stop 218

data recording. Manual control gives the user the most flexibility in controlling the parameters of the 219

experiment. However, because the parameters can be varied throughout an experiment NeuroPG does 220

not currently have any automated routines for analyzing or plotting data recorded during manual 221

control. 222

AutoStim mode 223

Once a user has defined at least one stimulation pattern, the AutoStim function can automate the 224

process of stimulating the sample and acquiring data. AutoStim initializes the DMD’s settings and 225

places it into external trigger mode. AutoStim then uploads the stimulation patterns in the list and 226

coordinates triggering and data acquisition. Timing for the routine is controlled by the real-time clock 227

in the DAQ board to ensure accuracy and precision. Once the stimulation routine has finished, 228

AutoStim saves parameters, patterns, and recorded data to a user-specified file. AutoStim 229

automatically associates sections of the electrophysiological data recorded during the stimulation 230

routine with their respective stimulation patterns based on the output trigger of the DMD. The 231

stimulation patterns and associated data can be then passed to the HeatMap visualization tool. In 232

AutoStim mode NeuroPG generates a TTL signal that precedes the illumination of each ROI. This 233

TTL signal triggers the DMD and can be split and routed to other systems such as pClamp or 234

automated stages to trigger other events related to the stimulus. The time between the trigger signal 235

and the beginning of stimulation can be adjusted with the Trig Delay property of the DMD to allow 236

for external systems to prepare for each stimulus. 237

Page 8: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

7 This is a provisional file, not the final typeset article

PairedStim mode 238

The PairedStim routine facilitates the investigation of time-dependent processes by illuminating two 239

patterns with a specified delay between exposures. To initialize PairedStim, the user specifies two 240

stimulation patterns and the latency between the stimuli. The two patterns can be identical, 241

independent, or partially overlapping. PairedStim then generates the necessary patterns and settings 242

for the stimulation and uploads this data to the DMD. After PairedStim has executed the routine the 243

recorded data is automatically analyzed and plotted. 244

HeatMap 245

Included in NeuroPG is a tool that associates collected data with the corresponding stimulation 246

region, evaluates the data, and presents it graphically as a heat map. The default evaluation function 247

plots the maximum depolarization following stimulation. This function identifies the stimulation 248

periods in the data using the DMD output trigger signal and then calculates the difference between 249

the maximum membrane potential within a user-specified time window following stimulation and the 250

average membrane potential prior to stimulation (Figure 4). The regions are mapped onto an area 251

corresponding to the field of view and the alpha values (or color intensity values) of each region are 252

set according to the determined “heat” value. Right clicking any region will open a plot of the 253 electrophysiology waveforms used to calculate the “heat” for that particular region. The function 254

used to evaluate the “response magnitude” can easily be changed as described in Customizing 255

Evaluation Functions. Heat maps that are saved as MATLAB figure files will retain all data and 256

functionality when opened by any instance of MATLAB that has access to the HeatMapBDF 257

function. 258

259

3.2. Example 1: Heat map generation 260

One of the advantages of DMD illumination is simple control of the illumination spot size and 261

position. As an example, we used NeuroPG to measure and plot the magnitude of the depolarization 262

as a function of illumination position using a coarse and fine grid size. Adaptive sampling based on 263

the ability to increase the sampling resolution may help to efficiently identify ROIs that have specific 264

influence on neural cells or circuits. To demonstrate our ability to generate heat maps at different 265

resolutions, we used dissociated hippocampal neurons from E18 Sprague Dawley rats, transduced 266

with Lentivirus-ChR2-GFP-CamKII (Boyden et al. 2005) and cultured on hippocampal astrocytes 267

from E18 Sprague Dawley rats. We located a GFP positive neuron using fluorescence microscopy 268

and recorded the transmembrane potential using the whole-cell patch clamp method in current clamp 269

mode. Using SmartGrid, we then divided the field of view into regular rectangular patterns that were 270

exported to the Pattern List and randomized. We then used AutoStim to stimulate each of the ROIs in 271

a randomized order and collect the corresponding electrophysiology data. Once the stimulation was 272

complete, AutoStim divided the recording into sections associated with each ROI and exported the 273

data to HeatMap. To remove any artifacts related to spontaneous activity, we used a simple algorithm 274

in HeatMap to scan for regions that contained spontaneous action potentials that overlapped periods 275

of stimulation and discarded those data. As described in the previous section, HeatMap’s default 276

evaluation function calculated the local baseline membrane potential and determined the “heat” value 277

based on the maximum depolarization relative to this local baseline. The function then generated a 278

figure from this data by coloring each pattern’s area according to the heat value (Figure 5). Selecting 279

any ROI in this figure generates a plot of the data used to calculate that region’s heat value. This 280

interactive feature allows the user to easily examine the waveform of specific ROIs. Over the course 281

Page 9: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

8 This is a provisional file, not the final typeset article

of this experiment, NeuroPG automatically saved the raw recorded data, the patterns used for the 282

stimulation, the parameters used in all the evaluation functions, an image of the HeatMap figure, and 283

the interactive MATLAB figure itself. 284

285

3.3. Example 2: Dendritic integration 286

Another advantage of DMD illumination is the ability to simultaneously illuminate multiple 287

arbitrarily shaped ROIs. For example, stimulating two regions within the dendritic arbor can reveal 288

how those currents sum at the cell body. To demonstrate how NeuroPG can be used to study 289

dendritic integration we used dissociated E18 rat hippocampal neurons transduced with the Lenti-290

ChR2-GFP-CaMKII as discussed above. Using manual ROI generation, we targeted two non-291

overlapping segments of a single dendritic branch. We then stimulated each ROI both individually 292

and together and measured the resulting depolarization at the cell body using whole cell patch-clamp 293

electrophysiology. The results of these measurements are shown in Figure 6. In this case, we found 294

that stimulating the two ROIs together resulted in a depolarization that was larger than the summed 295

depolarization resulting from individual ROI stimulation. This ability to simultaneously illuminate 296

complex spatial patterns makes NeuroPG well suited to study the electrical properties of dendrites 297

and dendritic integration. 298

299

3.4. Customizing Evaluation Functions 300

We have written the NeuroPG data processing and evaluation functions to allow easy modification 301

and support a variety of experiments. In particular the HeatMap tool is designed to allow users to 302

create as many of their own evaluation functions as they would like. These functions must follow a 303

general template but may have variable numbers and types of input parameters. The template 304

specifies the structure of input parameters and the way in which HeatMap queries the function to 305

learn what parameters need to be passed. An example function using the template is included with the 306

NeuroPG package to facilitate customization. In this way, data collected from an experiment may be 307

processed and visualized using multiple, customizable evaluation methods. For example, the heat 308

maps may be based on the maximum depolarization, latency, or rise time. While the default 309

visualization is a heat map, this visualization can be easily modified by the user to best represent their 310

data. 311

312

3.5. Peripheral Functionality 313

3.5.1. CameraWindow 314

CameraWindow is a microscope camera visualization and control utility designed to control any 315

camera compatible with the Image Acquisition Toolbox. It was designed with cell patching in mind 316

and includes a marker that can be repositioned in the camera window by simply right clicking the 317

desired position. It also has digital 2x and 4x zoom that centers the image wherever the mouse is 318

clicked. CameraWindow provides a histogram of image intensity and allows for auto or manual 319

scaling of image intensity in both grayscale and color modes. The user can easily switch between 320

Page 10: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

9 This is a provisional file, not the final typeset article

viewing a sample in bright field and in fluorescence by clicking a radio button. Fluorescence mode 321

changes the exposure and contrast settings to user specified values to enhance low light visualization. 322

Changing back to bright field mode restores the settings to their previous state. The Snapshot 323

functionality allows the user to capture images in one of two ways. In brightfield mode, the raw 324

image data is captured using the current settings of the camera. In fluorescent mode, CameraWindow 325

uses a short exposure time to display the live camera image, but switches to a longer exposure time to 326

capture the raw image data. This allows the user to view their sample at a higher frame rate during 327

focusing and positioning and then capture images with longer exposure times. In either mode, the 328

image data is written to a tif file that is named by appending an incrementing number to the specified 329

file name. The user can also display captured images in one of two ways. New images can be 330

displayed by either creating a new window for each image or stacked on top one another in the same 331

window. Stacked images can be cycled through by mouse click and can be used as time-lapse videos 332

or for comparing bright field and fluorescence images. Stacked images are still saved as individual tif 333

files, not tif stacks. CameraWindow also has a video capture function. When the video button is 334

clicked, video frames are captured from the visualization window and stored in a buffer until system 335

RAM is 90% full or the video button is clicked again. The captured frames are then saved to disk as 336

uncompressed AVI files named with the specified name. CameraWindow tracks the amount of 337

available system RAM and calculates approximately how many seconds of video may be captured at 338

any point in time. Any number of camera properties can be adjusted from the CameraWindow 339

control window. The number of camera properties and order with which they appear is specified in 340

the configuration file. The configuration file can be edited manually or through the included 341

configuration functions. The exposure and contrast properties will always appear at the beginning of 342

the property list if they are defined for the camera. 343

344

3.5.2. MatPad 345

MatPad is a logging and note utility that NeuroPG uses to log events. MatPad logs changes to 346

NeuroPG settings, as well as the parameters for AutoStim, PairedStim, and all pattern generation 347

methods. MatPad also allows the user to enter their own notes in the log, remove lines from the log, 348

or edit the text of the log directly. The log file name and path are user specified and can be saved in 349

the configuration file or changed manually. If MatPad is directed to use a log file that already exists, 350

it will append new entries into the file without changing any previous data. MatPad is designed to 351

minimizes data loss due to unexpected crashes, shutdowns, or failures by regularly saving the log file 352

to disk. Log files are saved as txt files and can be viewed or edited in any text editor. 353

354

3.6. Installation and Set Up 355

The current version of NeuroPG along with download and installation instructions can be found on 356

the NeuroPG website. It is distributed as open-source software under the GNU General Public 357

License version 3.0 (GPL-3.0). 358

Software is included with NeuroPG that will automatically generate the configuration file required 359

for each workstation. It is comprised of four configuration utilities that allow the user to specify 360

default settings and parameters. The utilities for configuring DAQ hardware and cameras will auto-361

detect available hardware and settings for devices present on the workstation and allow the user to 362

customize how these devices are utilized. All NeuroPG settings are stored in a single file that may be 363

Page 11: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

10 This is a provisional file, not the final typeset article

edited manually by the user. Settings are stored in MATLAB mat file format to allow for easy access 364

and editing. Detailed instructions for editing the file manually are included in the documentation 365

provided on the website. 366

367

4. Software Architecture Discussion for Developers 368

The NeuroPG platform is modular and uses an object oriented programming approach. Each 369

interfaced piece of hardware is realized within the software as its own object, allowing it to be 370

accessed and controlled by multiple modules without conflict. This means that MATLAB functions 371

which are not native to the NeuroPG platform can share the system’s resources, allowing for 372

customized expansion of NeuroPG’s functionality. NeuroPG is also designed to be event driven. This 373

allows multiple tasks to run in tandem without blocking thereby enabling the user to run their own 374

functions or operations while NeuroPG is active. The event driven design also allows NeuroPG to 375

adjust camera settings or record video while patterns are being stimulated and data is recorded. The 376

extent to which tasks may be run in parallel is impacted by the hardware capability of the computer 377

and resource intensive operations like saving large amounts of data to disk. Because of this, timing 378

and signaling are handled by the DAQ hardware, ensuring precision for both pattern stimulation and 379

data recording. Memory management is carefully handled within NeuroPG using a combination of 380

shared data structures, persistent variables, and class properties. The approach for memory 381

management is designed to reduce redundant data and prevent unnecessary copying or relocation, 382

and is built around MATLAB’s memory management system. Data processing takes advantage of 383

MATLAB’s optimized vector mathematics algorithms to minimize processing time and memory 384

usage. Data recorded during a stimulation routine is kept in pre-allocated buffers within system 385

memory and written to disk only once the routine is complete. These techniques make NeuroPG 386

robust and reliable, with the primary goal of ensuring the accuracy and reliability of experimental 387

data. 388

389

5. Conclusion 390

The flexibility, speed and usability built in to our NeuroPG software package in combination with 391

any DMD-equipped microscope provides a powerful platform to support experiments using any 392

variety of proteins from the optogenetic toolkit (Smedemark-Margulies and Trapani 2013). 393

Specifically the real-time data analysis and visualization as well as flexible stimulation routines allow 394

NeuroPG to improve experimental efficiency for many optogenetic experiments. NeuroPG is 395

currently configured to record two analog electrical signals but could be modified to accept more 396

input channels. The output from any device that can be encoded as an analog voltage signal (e.g. 397

MultiElectrode Arrays, photodetectors collecting bulk fluorescence) could take the place of patch 398

clamp electrophysiology in our example implementation of NeuroPG.. While we have discussed 399

neural circuit studies and dendritic integration as potential applications, because NeuroPG can be 400

easily modified to support a vast array of applications, we see this software toolkit as a key building 401

block for the general optogenetic community. 402

403

6. Acknowledgement 404

Page 12: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

11 This is a provisional file, not the final typeset article

This work was supported in part by NSF-1308014. We thank Eva Dyer, Caleb Kemere, Xaq Pitkow, 405

and Behnaam Aazhang for useful discussions. We thank Marissa Garcia, Alice Xie, Erin Anderson 406

and Martin Bell for technical assistance with neuron and glial cell culture. We thank Joe Duman and 407

other members of the Kim Tolias group for advice regarding neuron cell culture and lentiviral 408

transduction protocols. We thank Miles Li and his technical support team at Mightex Corporation for 409

providing the Polygon400 digital micromirror device, the SDK (software development kit) which 410

was incorporated into NeuroPG as well as helpful discussions throughout the development of 411

NeuroPG. Finally, we thank Ken Reese at BrainBits for advising on cell culture protocols and Tal 412

Kafri and his group at the UNC Vector Core for providing the purified lentivirus and for advising on 413

lentiviral transduction protocols. 414

415

7. References 416

Airan, Raag D, Kimberly R Thompson, Lief E Fenno, Hannah Bernstein, and Karl Deisseroth. 2009. 417

“Temporally Precise in Vivo Control of Intracellular Signalling.” Nature 458 (7241). Nature 418

Publishing Group: 1025–29. doi:10.1038/nature07926. 419

Andrasfalvy, Bertalan K, Boris V Zemelman, Jianyong Tang, and Alipasha Vaziri. 2010. “Two-420

Photon Single-Cell Optogenetic Control of Neuronal Activity by Sculpted Light.” Proceedings 421

of the National Academy of Sciences of the United States of America 107 (26): 11981–86. 422

doi:10.1073/pnas.1006620107. 423

Albuquerque, Cristovao, Joseph, Donald J., Choudhury, Papiya, & MacDermott, Amy B. 2009. 424

“Dissection, plating, and maintenance of cortical astrocyte cultures.” Cold Spring Harbor 425

Protocols, 2009(8), pdb.prot5273. doi:10.1101/pdb.prot5273 426

Asrican, Brent, George J Augustine, Ken Berglund, Susu Chen, Nick Chow, Karl Deisseroth, 427

Guoping Feng, et al. 2013. “Next-Generation Transgenic Mice for Optogenetic Analysis of 428

Neural Circuits.” Frontiers in Neural Circuits 7 (November): 160. 429

doi:10.3389/fncir.2013.00160. 430

Boyden, Edward S, Feng Zhang, Ernst Bamberg, Georg Nagel, and Karl Deisseroth. 2005. 431

“Millisecond-Timescale, Genetically Targeted Optical Control of Neural Activity.” Nature 432

Neuroscience 8 (9): 1263–68. doi:10.1038/nn1525. 433

Brewer, G. J., Torricelli, J. R., Evege, E. K., & Price, P. J. (1993). Optimized Survival of 434

Hippocampal Neurons in B27-Supplemented Neurobasalm , a New Serum-free Medium 435

Combination. Journal of Neuroscience Research, 35567476. doi:10.1002/jnr.490350513 436

Cardin, Jessica a, Marie Carlén, Konstantinos Meletis, Ulf Knoblich, Feng Zhang, Karl Deisseroth, 437

Li-Huei Tsai, and Christopher I Moore. 2010. “Targeted Optogenetic Stimulation and Recording 438

Page 13: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

12 This is a provisional file, not the final typeset article

of Neurons in Vivo Using Cell-Type-Specific Expression of Channelrhodopsin-2.” Nature 439

Protocols 5 (2): 247–54. doi:10.1038/nprot.2009.228. 440

Farah, N., Reutsky, I., & Shoham, S. (2007). Patterned optical activation of retinal ganglion cells. 441

Conference Proceedings : ... Annual International Conference of the IEEE Engineering in 442

Medicine and Biology Society. IEEE Engineering in Medicine and Biology Society. Conference, 443

2007, 6368–70. doi:10.1109/IEMBS.2007.4353812 444

Gradinaru, Viviana, Murtaza Mogri, Kimberly R Thompson, Jaimie M Henderson, and Karl 445

Deisseroth. 2009. “Optical Deconstruction of Parkinsonian Neural Circuitry.” Science (New 446

York, N.Y.) 324 (5925): 354–59. doi:10.1126/science.1167093. 447

Hochbaum, D. R., Zhao, Y., Farhi, S. L., Klapoetke, N., Werley, C. a, Kapoor, V., … Cohen, A. E. 448

(2014). All-optical electrophysiology in mammalian neurons using engineered microbial 449

rhodopsins. Nature Methods, (May). doi:10.1038/nmeth.3000 450

Hooks, Bryan M, Tianyi Mao, Diego a Gutnisky, Naoki Yamawaki, Karel Svoboda, and Gordon M 451

G Shepherd. 2013. “Organization of Cortical and Thalamic Input to Pyramidal Neurons in 452

Mouse Motor Cortex.” The Journal of Neuroscience : The Official Journal of the Society for 453

Neuroscience 33 (2): 748–60. doi:10.1523/JNEUROSCI.4338-12.2013. 454

Kwan, Alex C, and Yang Dan. 2012. “Dissection of Cortical Microcircuits by Single-Neuron 455

Stimulation in Vivo.” Current Biology : CB 22 (16): 1459–67. doi:10.1016/j.cub.2012.06.007. 456

Leifer, A. M., Fang-Yen, C., Gershow, M., Alkema, M. J., & Samuel, A. D. T. (2011). Optogenetic 457

manipulation of neural activity in freely moving Caenorhabditis elegans. Nature Methods, 8(2), 458

147–52. doi:10.1038/nmeth.1554 459

Liu, Hongtao, Gustavo Gomez, Sophia Lin, Shuo Lin, and Chentao Lin. 2012. “Optogenetic Control 460

of Transcription in Zebrafish.” PloS One 7 (11): e50738. doi:10.1371/journal.pone.0050738. 461

Liu, Xu, Steve Ramirez, Petti T Pang, Corey B Puryear, Arvind Govindarajan, Karl Deisseroth, and 462

Susumu Tonegawa. 2012. “Optogenetic Stimulation of a Hippocampal Engram Activates Fear 463

Memory Recall.” Nature 484 (7394). Nature Publishing Group: 381–85. 464

doi:10.1038/nature11028. 465

Miesenböck, Gero. 2009. “The Optogenetic Catechism.” Science (New York, N.Y.) 326 (5951): 395–466

99. doi:10.1126/science.1174520. 467

Motta-Mena, Laura B, Anna Reade, Michael J Mallory, Spencer Glantz, Orion D Weiner, Kristen W 468

Lynch, and Kevin H Gardner. 2014. “An Optogenetic Gene Expression System with Rapid 469

Activation and Deactivation Kinetics.” Nature Chemical Biology 10 (3). Nature Publishing 470

Group: 196–202. doi:10.1038/nchembio.1430. 471

Page 14: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

13 This is a provisional file, not the final typeset article

Nagel, Georg, Tanjef Szellas, Wolfram Huhn, Suneel Kateriya, Nona Adeishvili, Peter Berthold, 472

Doris Ollig, Peter Hegemann, and Ernst Bamberg. 2003. “Channelrhodopsin-2, a Directly Light-473

Gated Cation-Selective Membrane Channel.” Proceedings of the National Academy of Sciences 474

of the United States of America 100 (24): 13940–45. 475

Oron, Dan, Eirini Papagiakoumou, F Anselmi, and Valentina Emiliani. 2012. Two-Photon 476

Optogenetics. Progress in Brain Research. 1st ed. Vol. 196. Elsevier B.V. doi:10.1016/B978-0-477

444-59426-6.00007-0. 478

Packer, Adam M, Botond Roska, and Michael Häusser. 2013. “Targeting Neurons and Photons for 479

Optogenetics.” Nature Neuroscience 16 (7). Nature Publishing Group: 805–15. 480

doi:10.1038/nn.3427. 481

Palmer, Amy E, Yan Qin, Jungwon Genevieve Park, and Janet E McCombs. 2011. “Design and 482

Application of Genetically Encoded Biosensors.” Trends in Biotechnology 29 (3). Elsevier Ltd: 483

144–52. doi:10.1016/j.tibtech.2010.12.004. 484

Paz, Jeanne T, Thomas J Davidson, Eric S Frechette, Bruno Delord, Isabel Parada, Kathy Peng, Karl 485

Deisseroth, and John R Huguenard. 2013. “Closed-Loop Optogenetic Control of Thalamus as a 486

Tool for Interrupting Seizures after Cortical Injury.” Nature Neuroscience 16 (1): 64–70. 487

doi:10.1038/nn.3269. 488

Peron, Simon, and Karel Svoboda. 2011. “From Cudgel to Scalpel : Toward Precise Neural Control 489

with Optogenetics” 8 (1): 30–34. doi:10.1038/NMETH.F.325. 490

Reutsky-Gefen, Inna, Lior Golan, Nairouz Farah, Adi Schejter, Limor Tsur, Inbar Brosh, and Shy 491

Shoham. 2013. “Holographic Optogenetic Stimulation of Patterned Neuronal Activity for Vision 492

Restoration.” Nature Communications 4 (January). Nature Publishing Group: 1509. 493

doi:10.1038/ncomms2500. 494

Shoham, Shy. 2010. “Optogenetics Meets Optical Wavefront Shaping.” Nature Methods 7 (10). 495

Nature Publishing Group: 798–99. doi:10.1038/nmeth1010-798. 496

Silasi, Gergely, Jamie D Boyd, Jeff Ledue, and Timothy H Murphy. 2013. “Improved Methods for 497

Chronic Light-Based Motor Mapping in Mice: Automated Movement Tracking with 498

Accelerometers, and Chronic EEG Recording in a Bilateral Thin-Skull Preparation.” Frontiers 499

in Neural Circuits 7 (July): 123. doi:10.3389/fncir.2013.00123. 500

Smedemark-Margulies, Niklas, and Josef G Trapani. 2013. “Tools, Methods, and Applications for 501

Optophysiology in Neuroscience.” Frontiers in Molecular Neuroscience 6 (July): 18. 502

doi:10.3389/fnmol.2013.00018. 503

Page 15: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

14 This is a provisional file, not the final typeset article

Sohal, Vikaas S, Feng Zhang, Ofer Yizhar, and Karl Deisseroth. 2009. “Parvalbumin Neurons and 504

Gamma Rhythms Enhance Cortical Circuit Performance.” Nature 459 (7247). Nature Publishing 505

Group: 698–702. doi:10.1038/nature07991. 506

Suter, Benjamin a, Timothy O’Connor, Vijay Iyer, Leopoldo T Petreanu, Bryan M Hooks, Taro 507

Kiritani, Karel Svoboda, and Gordon M G Shepherd. 2010. “Ephus: Multipurpose Data 508

Acquisition Software for Neuroscience Experiments.” Frontiers in Neural Circuits 4 (August): 509

100. doi:10.3389/fncir.2010.00100. 510

Wang, Jennifer, Mazahir T Hasan, and H Sebastian Seung. 2009. “Laser-Evoked Synaptic 511

Transmission in Cultured Hippocampal Neurons Expressing Channelrhodopsin-2 Delivered by 512

Adeno-Associated Virus.” Journal of Neuroscience Methods 183 (2): 165–75. 513

doi:10.1016/j.jneumeth.2009.06.024. 514

Wang, Kaiyu, Yafeng Liu, Yiding Li, Yanmeng Guo, Peipei Song, Xiaohui Zhang, Shaoqun Zeng, 515

and Zuoren Wang. 2011. “Precise Spatiotemporal Control of Optogenetic Activation Using an 516

Acousto-Optic Device.” PloS One 6 (12): e28468. doi:10.1371/journal.pone.0028468. 517

Zhang, Feng, Li-Ping Wang, Martin Brauner, Jana F Liewald, Kenneth Kay, Natalie Watzke, Phillip 518

G Wood, et al. 2007. “Multimodal Fast Optical Interrogation of Neural Circuitry.” Nature 446 519

(7136): 633–39. doi:10.1038/nature05744. 520

Zhu, P., Fajardo, O., Shum, J., Zhang Schärer, Y.-P., & Friedrich, R. W. (2012). High-resolution 521

optical control of spatiotemporal neuronal activity patterns in zebrafish using a digital 522

micromirror device. Nature Protocols, 7(7), 1410–25. doi:10.1038/nprot.2012.072 523

524

8. Figure legends 525

Figure 1: Connection Diagram for the example procedures discussed in this paper. The DMD 526

output trigger and the signal measured by the head stage are recorded as analog signals by the DAQ 527

to facilitate precise temporal alignment between stimulation and response in the experiment. The 528

DAQ signals the DMD using timed TTL pulses as configured by NeuroPG. All connections with 529

NeuroPG are bi-directional, digital signals. The blue beam represents excitation light reflecting off 530

the DMD and the green beam represents light fluorescently emitted from the sample. 531

Figure 2: Manual Pattern Generation. ROIs are manually defined as overlays on an image of the 532

field of view that will be stimulated. (A) Screenshot of circular, rectangular and spline ROIs, 533

manually defined by drawing on top of the acquired image. (B) Screenshot of the main window of 534

NeuroPG, which is updated with the list of ROIs defined in panel A 535

Page 16: NeuroPG - Open source software for optical pattern generation and data acquisition

Avants et al. NeuroPG: Open source software for optical pattern generation and data acquisition

15 This is a provisional file, not the final typeset article

Figure 3: SmartGrid Pattern Generation. A grid of ROIs is generated based on user-defined grid 536

dimensions (number of rows and columns – highlighted in panel B) and the grid is overlaid on an 537

image of the field of view to be stimulated. SmartGrid can subdivide any of the selected ROIs into a 538

smaller grid based on user-defined dimensions. Selected regions can be uploaded to the DMD, 539

merged or further subdivided. Selected ROIs appear in green, unselected ROIs appear in red. 540

Figure 4: Real-time HeatMap Analysis. The HeatMap tool visualizes the magnitude of the 541

neuron’s depolarization in response to optical stimulation. Patterns that cause a large depolarization 542

within the stimulation window appear as a “hot spots”. (A) Screenshot of SmartGrid being used to 543

generate a grid of patterns. Inset: illustration of how the heat value is calculated. Baseline is 544

calculated from the signal preceding the stimulation period and compared to the maximum 545

depolarization within a user-specified time interval, Δt, following stimulation. (B) Screenshot of 546

HeatMap GUI; if the user clicks on an ROI in the heat map (highlighted in magenta) a figure, (C), 547

appears with a plot of the waveform of the selected ROI. 548

Figure 5: Coarse and fine heat mapping. To demonstrate how NeuroPG can perform both coarse 549

and fine sampling of neuronal responses we used the built-in HeatMap function of NeuroPG to map 550

the magnitude of the depolarization resulting from patterned optical stimulation of rat hippocampal 551

neuron expressing ChR2-GFP (not shown) and backfilled with AlexaFluor 594 (black). To prevent 552

action potentials from dwarfing subthreshold depolarization any depolarization greater than 30 mV is 553

plotted as a 30 mV maximum response. Heat maps generated using SmartGrid and HeatMap: (A) 3x3 554

grid with each ROI having dimensions of 724µm x 551µm, (B) 9x9 grid with each ROI having 555

dimensions of 241 µm x 184 µm, and (C) a 6x6 grid with each ROI having dimensions of 80 µm x 61 556

µm. Scale bars are 100 µm. Color bar units are in mV. 557

Figure 6: Subcellular dendritic stimulation. (A) Neuron expressing ChR2-GFP was stimulated by 558

with blue light (470 nm) illumination with patterns I (magenta) and II (cyan) for 20 ms (blue bar). 559

(B) The depolarization in response to stimulation was recorded by whole cell patch-clamp 560

electrophysiology. The depolarization in response to stimulating two ROIs simultaneously (solid 561

black I & II) is greater than the summed depolarization of I and II stimulated individually (dashed 562

black I + II). Data is averaged from three trials; scale bars: A: 25 um, B: 4 mV and 20 ms. 563

Page 17: NeuroPG - Open source software for optical pattern generation and data acquisition

Figure 1.TIF

Page 18: NeuroPG - Open source software for optical pattern generation and data acquisition

Figure 2.TIF

Page 19: NeuroPG - Open source software for optical pattern generation and data acquisition

Figure 3.TIF

Page 20: NeuroPG - Open source software for optical pattern generation and data acquisition

Figure 4.TIF

Page 21: NeuroPG - Open source software for optical pattern generation and data acquisition

Figure 5.TIF

Page 22: NeuroPG - Open source software for optical pattern generation and data acquisition

Figure 6.TIF