NEURON interfaces to MySQL and the SPUD feature extraction algorithm (Neymotin et al. 2007)

 Download zip file   Auto-launch 
Help downloading and running models
See the readme.txt for information on setting up this interface to a MySQL server from the NEURON simulator. Note the SPUD feature extraction algorithm includes its own readme in the spud directory.
1 . Neymotin S, Uhlrich DJ, Manning KA, Lytton WW (2008) Data mining of time-domain features from neural extracellular field data Applic. of Comput. Intel. in Bioinf. and Biomed.: Current Trends and Open Problems 151:119-140
Model Information (Click on a link to find other models with that property)
Model Type:
Brain Region(s)/Organism:
Cell Type(s):
Gap Junctions:
Simulation Environment: NEURON;
Model Concept(s): Methods;
Implementer(s): Lytton, William [billl at]; Neymotin, Sam [samn at];
Files displayed below are from the implementation
October 25th, 2009: This model was updated by Michael Hines to run
under NEURON 7

 $Id: readme.txt,v 1.2 2008/10/06 16:58:43 samn Exp $ 

Table of contents:

  1. SPUD feature extraction algorithm
  2. NEURON interface to MySQL


SPUD feature extraction algorithm implementation as appearing in
[1](see bottom of readme)

spud.mod - main implementation
spud.hoc - hoc utilities for ease of use
mosinit.hoc - sets up a GUI showing figure 2 from chapter - run this
  to see SPUD in action
rat_strobe_1.vec - single trace of electrocorticographic recordings
  from rat

//sample routine to demonstrate SPUD feature extraction algorithm (in
//spud.hoc) to use:
//on return, output will store the extracted "bumps" as an NQS

//$o1 = input data vector
//$2 = num threshold lines
//$3 = threshold spacing, 0=linear,1=log (optional)
//$o4 = user-specified thresholds to pass in to SPUD (optional)
proc testspud()

Once the source code is compiled (see below for instructions), run the
special file in ./arch/special , where arch is your system
architecture to start NEURON with the compiled libraries.  Then you
can use the command, load_file("mosinit.hoc"), from the NEURON prompt,
which will allow generation of figure 2 from [1].

2. NEURON interface to MySQL readme - S Neymotin , WW Lytton - 4/2007

(for questions/comments contact samn at neurosim dot downstate dot

This is an interface that allows access to a MySQL server from
directly within the NEURON simulation environment [1]. It allows for
performing SQL queries and returning the results into NEURON data
structures. It also works with the Neural Query System (NQS)[2] and
can convert between NQS databases and MySQL tables.

The MySQL C API is required. The version used was mysql-5.0.37. Some
modifications were made to it in order to compile it as a NEURON
module. The main change was mysql/my_list.h had #undef LIST so it
wouldn't conflict with NEURON's list type. The C header files for the
modified version are available in this package. You'll also need to
compile the API to a lib file and link to it. The MySQL server must be
running when using this interface.

NEURON mod files: 

  MySQL.mod - main interface to MySQL
  vecst.mod - used by NQS
  misc.h,misc.mod - used by NQS

HOC files:

  mosinit.hoc - demo file
  declist.hoc - used by NQS
  decnqs.hoc - used by NQS
  decvec.hoc - used by NQS
  grvec.hoc - graphics utils.
  drline.hoc - graphics utils.
  mysql_utils.hoc - MySQL interface utilities
  nqs.hoc - NQS
  setup.hoc - setup simulation utils.

mysql directory: MySQL API header files for version 5.0.37

For help with compilation/usage, contact samn at neurosim dot
downstate dot edu .

The interface has only been tested on Linux machines with version
5.0.37 of MySQL. If you are using a different version of MySQL , this
is not guaranteed to work/compile, and you may need to make some small
changes to get it to compile.

* to build:

make sure you are in the directory containing mod files, and have the
mysql header files in a subdir named mysql (or a symbolic link will be
fine). for example, if you have the MySQL lib files in
/usr/local/src/mysql-5.0.37-linux-x86_64-glibc23/lib , you would use
the following command:

nrnivmodl -loadflags "-L/usr/local/src/mysql-5.0.37-linux-x86_64-glibc23/lib -lmysqlclient -lz"

if you have the MySQL lib files in a more standard location, such as
/usr/lib/mysql , you would use the following command:

nrnivmodl -loadflags "-L/usr/lib/mysql/ -lmysqlclient -lz"

-L should have the full path to the mysql lib files (that are already

-lz is for zlib

The mysql include dir must be in mod subdir (with a link is fine)

note: build can only be done once MySQL has been built on the system.

* sample usage similar to that found in mysql_test.hoc


Init_mysql("localhost","username","password") //connect
Query_mysql("show databases") //perform a sql query ListDBs_mysql()

see below for more example code and function descriptions

* MySQL.mod function descriptions:

all functions described below should have _mysql suffix added to them
when running from NEURON.

there is one main MYSQL object : MYSQL g_mysql;
since only one connection allowed

: closes any open connection to MySQL server

: initialize MySQL engine & connect to MySQL server
: user must supply host-name , user-name, password
: to connect to MySQL server
: returns 1.0 iff successful
: Init(host,user,pass)

: SelectDB(dbname)
: returns 1.0 iff successful

: frees results of Select, responsibility of hoc user
FUNCTION FreeResults()

: check # of columns from previous Select call

: check # of rows from previous Select call

: get rows from previous Select
: into list of vectors (each vec is dimension/column)
: returns -1.0 on error, otherwise number of rows

: takes vector and returns # of times it exists as a row in table_name
: Find(table_name,Vector) also allows partial row match on first 
: min(vector.size,table.columns) columns stores results in g_result for later
: retrieval returns -1.0 on error, otherwise num_rows found matching vector

: updates a single col of
: a table. 
: UpdateCol(table_name,col_name,order_by_column_name,vector_of_values,start_idx)
: col_name is the column that will be updated
: order_by_column_name is the column that stores
: ids, if no column stores ids, updating a column
: does not make much sense because the storage
: order of column values may not be what the
: user is expecting. start_idx is starting value
: of order by column index. it is incremented
: for each row of a column.
: so it will be 
: update table set col_name = vec[0] where order_by_column_name=start_idx;
: update table set col_name = vec[1] where order_by_column_name=start_idx+1;
:   ...
: update table set col_name = vec[n] where order_by_column_name=start_idx+n;
FUNCTION UpdateCol()

: inserts data into existing table
: Insert(table_name,list_of_vectors or vector)
: Vector should have same size as # of columns in table , so Insert
: will add 1 row for Vector arg if arg is List, it should have
: num_cols vectors and vectors.size rows will be inserted into table
: returns 1.0 iff success

: does a sql select and keeps results around for hoc user to retrieve
: hoc user must free results at a certain point
: returns -1.0 on error, otherwise # of rows found
** if you do the select from NEURON with Select_mysql, it doesn't display
all the rows onto screen. after that you can do GetRows_mysql to
get the rows or NumRows_mysql to see the # of rows returned from the

: gets col names from last sql select must pass in correct # of
: char* 's and they must have sufficient length to store col names
FUNCTION GetColNames()

: lists all available dbs
: returns -1 iff error, otherwise # of dbs

: executes a sql command but doesnt store results for hoc user
: can execute any type of SQL command, i.e. create,select,insert,etc.
: displays results on screen
: returns -1.0 on error
: Query(query_string)

: display client & server versions
PROCEDURE VersionInfo()

* sample hoc code

the following proc works only if there is
a pre-existing database named "test"
to create it do: Query_mysql("create database test")

objref lv,myv[2],lvres
proc TestInsert(){
  Query_mysql("create table junk (d1 double,d2 double)")
  lv=new List()
  myv[0]=new Vector(10)
  myv[1]=new Vector(10)
  Query_mysql("select * from junk")

Insert can take a Vector or List of Vectors

objref myv
proc TestInsert2(){
  Query_mysql("use test")
  Query_mysql("create table jnk (d1 double,d2 double)")
  myv=new Vector(2)
  Query_mysql("select * from jnk")

there are some hoc utility functions in mysql_utils.hoc (don't add _mysql to call them):

//creates a table in db currently connected to
//$s1 = table name
//$o2 = list of column names (as String objects or strdefs)
//$3 = whether to create index for each col
func CreateTable () 

// SelectedColNames()
// returns List containing column names from last Select call
obfunc SelectedColNames()

//converts the results of a sql select
//into an nqs db & returns it
//$s1 = sql query
obfunc sql2nqs ()

//converts nqs database to sql format automatically creates indices
//$o1 = nqs
//$s2 = name of table in mysql db
//$3 = whether to create column nqs_row_id storing orig nqs row index
//$4 = whether to create mysql index on each col
// NB: table must not have 'index' as a col name: mysql reserved word
func nqs2sql () 

example usage:

objref ls
objref cols[5]
proc TestCreateTable(){ local ii,makeindex
  ls=new List()
  for ii=0,4{
    cols[ii]=new String()
  makeindex = 1
    Query_mysql("show tables")
    Query_mysql("describe hoc_table")
  } else {
    Query_mysql("show tables")

this will create a table named "hoc_table" in current database with
indices on each column


(1) Data mining of time-domain features from neural extracellular
    field data chapter in book

Applications of Computational Intelligence in Bioinformatics and Biomedicine:
Current Trends and Open Problems
Series: Studies in Computational Intelligence (peer-reviewed),
151:119-140, 2008, Springer.
S Neymotin, DJ Uhlrich, KA Manning, WW Lytton

(2) Neural Query System: Data-mining from within the NEURON simulator.
    Neuroinformatics. 2006;4(2):163-76.
    WW Lytton

Neymotin S, Uhlrich DJ, Manning KA, Lytton WW (2008) Data mining of time-domain features from neural extracellular field data Applic. of Comput. Intel. in Bioinf. and Biomed.: Current Trends and Open Problems 151:119-140

References and models cited by this paper

References and models that cite this paper

Neymotin SA, Hilscher MM, Moulin TC, Skolnick Y, Lazarewicz MT, Lytton WW (2013) Ih Tunes Theta/Gamma Oscillations and Cross-Frequency Coupling In an In Silico CA3 Model PLoS ONE 8(10):e76285 [Journal] [PubMed]

   Ih tunes oscillations in an In Silico CA3 model (Neymotin et al. 2013) [Model]

Neymotin SA, Lee H, Park E, Fenton AA, Lytton WW (2011) Emergence of physiological oscillation frequencies in a computer model of neocortex. Front Comput Neurosci 5:19-75 [Journal] [PubMed]

   Emergence of physiological oscillation frequencies in neocortex simulations (Neymotin et al. 2011) [Model]

(2 refs)