create table pmMap ( -- numbers below are column in original MatLab PyrIntMap.Map matrix
 id integer,       -- 0, Id used to match original row number in MatLab PyrIntMap.Map matrix
 file_ID integer,  -- 1, Id of merged files.  Links to pmFileBase to give merged base names
 cell_ID integer,  -- 2, cell id within merged session, starting at 1 to number of cells
 ele integer,	   -- 3, electrode number
 clu integer,      -- 4, ID # in cluster files
 exciting integer,  -- 5, Based on cross-correlogram analysis, the cell monosynaptically excites other cells
 inhibiting integer, --6, Based on cross-correlogram analysis, the cell monosynaptically inhibits other cells
 excited integer,  -- 7, Based on cross-correlogram analysis, the cell is monosynaptically excited other cells
 inhibited integer, --8, Based on cross-correlogram analysis, the cell is monosynaptically excited other cells
 wide integer,	    --9,
 narrow integer,    --10, 
 IsPositive integer, --11,
 eDist real,	     --12,
 RefracRatio real,   --13,
 RefracViol real,    --14,
 eDist_ind real,     --15,
 RefracRatio_ind real, --16,
 RefracViol_ind real, --17,
 FileID integer,      --18, links to column 4 of file ElecPositions.txt, fileId in table elPos
 RegionID integer,    --19, links to MatLab PyrIntMap.whichRegion; sqlite3 table pmWhichRegion
 AnimalID integer,    --20, links to MatLab PhyIntMap.WhichFile; sqlite3 pmWhichFile
 FireRate real,	      --21, MeanISI = mean(bootstrp(100,'mean',ISI)); FireRate = SampleRate/MeanISI; ISI is interspike intervals.
 totalFireRate real,  --22, num of spikes divided by total recording length
 Clean_G integer,     --23,
 Clean_ind integer,   --24
 COM_15_msec real,    --25,
 COM_20_msec real,    --26,
 COM_25_msec real,    --27,
 COM_30_msec real,    --28
 COM_40_msec real,    --29,
 COM_50_msec real,    --30,
 Wide_ind_WidthR_AmpSym real, --31,
 Wide_ind_WidthR_COM real, --32,
 Wide_ind_WidthR_totalFireRate real, --33,
 Wide_ind_WidthC100_AmpSym real, --34,
 Narrow_ind_WidthR_AmpSym real,	 --35,
 Narrow_ind_WidthR_COM real, --36,
 Narrow_ind_WidthR_totalFireRate real, --37,
 Narrow_ind_WidthC100_AmpSym real, --38,
 Wide_visual_correction,     --39,
 Narrow_visual_correction,   --40,
 Wide_final,		     --41,
 Narrow_final,		     --42,
 Big_Which_Region integer    --43 links to MatLab PyrIntMap.whichRegion; sqlite3 table pmWhichRegion
);

-- Fields from MatLap PyrIntMap.Content:
-- file_ID,cell_ID,ele,clu,exciting,inhibiting,excited,inhibited,wide,narrow,IsPositive,eDist,
-- RefracRatio,RefracViol,eDist_ind,RefracRatio_ind,RefracViol_ind,FileID,RegionID,AnimalID,
-- FireRate,totalFireRate,Clean_G,Clean_ind,COM_15_msec,COM_20_msec,COM_25_msec,COM_30_msec,COM_40_msec,
-- COM_50_msec,Wide_ind_WidthR_AmpSym,Wide_ind_WidthR-COM,Wide_ind_WidthR_totalFireRate,Wide_ind_WidthC100_AmpSym,
-- Narrow_ind_WidthR_AmpSym,Narrow_ind_WidthR-COM,Narrow_ind_WidthR_totalFireRate,Narrow_ind_WidthC100_AmpSym,
-- Wide_visual_correction,Narrow_visual_correction,Wide_final,Narrow_final,Big_Which_Region(EC=1,CA1=2,CA3,DG=3)


CREATE TABLE elepos
-- from data in file ElePositionFixed.txt
 (topdir string,  -- directory in data set containing data (tar.gz) file
  mergen string,  -- merged session names (not used)
  unit string,    -- hard drive used to store original data (not used)
  fileid integer, -- id for record, links to MatLab PyrIntMap.map column 18 (table pmMap field FileId)
  e1 string,      -- region for electrode 1 
  e2 string,      -- region for electrode 2
  e3 string,      -- region for electrode 3
  e4 string,      -- region for electrode 4
  e5 string,      -- region for electrode 5
  e6 string,      -- region for electrode 6
  e7 string,      -- region for electrode 7
  e8 string,      -- region for electrode 8
  e9 string,      -- region for electrode 9
  e10 string,     -- region for electrode 10
  e11 string,     -- region for electrode 11
  e12 string,     -- region for electrode 12
  e13 string,     -- region for electrode 13
  e14 string,     -- region for electrode 14
  e15 string,     -- region for electrode 15
  e16 string      -- region for electrode 16
);


create table region_pm1943 (
-- region names computed from MatLab PyrIntMap.Map columns 19 and 43 and PyrIntMap.whichRegion
  id integer,   -- row in PyrIntMap.Map
  region string -- region name
);

create table region_elepos (
-- region names found from file ElePositionFixed.txt (table elepos) using electrode number 
-- (field 'ele' in etable pmMap).  Records in pmMap and elepos linked using field 'fileid'.
  id integer,   -- row in PyrIntMap.Map
  region string -- region name
);

create table region (
-- Contains region id's, stored in MatLab Region array
  id integer,       -- row on PyrIntMap.Map
  region_id integer -- matches region names in table region_name
);

create table region_name (
  region_id integer,  -- region_id in region table
  region_name string  -- name of region
);



create table beh (
-- Behavior used in each session.  Loaded from MatLab Beh cell array.
  id integer,  -- row in Beh
  topdir string,  -- directory in data set containing data (tar.gz) files
  mergen string,  -- merged session names (not used)
  unit string,    -- hard drive used to store original data (not used)
  session string, -- individual session name (corresponds to name of tar.gz file having data)
  behavior string, -- behavior, one of: Mwheel, Open, Tmaze, Zigzag, bigSquare, bigSquarePlus, circle
                   -- linear, linearOne, linearTwo, midSquare, plus, sleep, wheel, wheel_home
  familiarity integer, -- number of times animal has done task, 1=animal did task for first time, 
                       -- 2=second time, 3=third time, 10=10 or more
  duration real,   -- recording length in seconds
  problem string   -- if this column is not empty, there was a problem: the session was too short,
                   -- or the animal did not do the task well, or the video tape did not start  
);

create table clean (
-- from MatLab Clean matrix.
  id integer,  -- row in Beh
  good integer -- ==0 if bad cell
);

create table iCell (
-- from MatLab iCell
  id integer,  -- row in pmMap
  pyramidal integer, -- == 1 if Pyramidal cell
  interneuron integer, -- == 1 if interneuron
  not_pyin integer, -- == 1 if not pyramidal and not interneuron
  exciting integer, -- == 1 if physiologically identified exciting cells based on CCG analysis
  inhibiting integer  -- == 1 if physiologically identified inhibiting cells based on CCG analysis.
        -- Detailed method can be found in Mizuseki  Sirota Pastalkova and Buzsaki., 2009 Neuron paper.
);

create table hc3_session (
-- List of sessions included in hc3 data set
-- This will be a subset of all sessions in the beh table since not all recorded sessions are included
-- in the data set.
  id integer, -- session number in crcns.org hc3.  Used as unique id, but not as a foreign key
              -- (Does not correspond to any number in any other table)
  topdir string, -- directory in data set containing data
  session string, -- individual session name (corresponds to name of tar.gz file having data)
  size integer    -- number of bytes in tar.gz file for session neural data
);

create table hc3_topdir (
-- Top directories in hc3 data set
-- Used in joins to filter out results that are not in the data set
-- also provides name of animal associated with each topdir
  topdir string, -- directory in data set containing data
  animal string  -- name of animal from which data in topdir was collected
);



create table hc3_mpg (
-- List of sessions included in hc3 data set that have a mpg file (video of animal movements).
-- This will be a subset of all sessions in the beh table since not all recorded sessions are included
-- in the data set; and not all sessions in the data set include a .mpg file
  id integer, -- number of mpg file crcns.org hc3.  Used as unique id, but not as a foreign key
              -- (Does not correspond to any number in any other table)
  topdir string, -- directory in data set containing data
  session string -- individual session name (corresponds to name of mpg.tar.gz file having data)
);


create table to_remove (
-- had file_id, electrode number, 
  fileid integer,  -- id if file, matches Map column 18 (fileid)
  ele integer,     -- electrode number, matches Map column 3 (ele)
  clu integer      -- cluster, matches Map column 4 (clu)
);

create table animal (
-- contains animal names in MatLab PyrIntMap.WhichFile
  id integer,  -- corresponds to value in pmMap column 20 (AnimalID)
  name string  -- animal name, e.g. 'ec012'
);


create table map_cell_counts (
-- contains counts of cells in each topdir from table pmMap
  topdir string,  -- name of top level directory
  ncells integer  -- number of cells
);

create table clu_cell_counts (
-- contains counts of cells in each topdir from .clu files in data seta
  topdir string,   -- name of top level directory
  nshanks integer, -- number of shanks
  ncells integer   -- number of cells
);

create table video_files (
-- contains location of all video files (mpg, m1v) in data set
  topdir string,  -- name of top level directory
  session string, -- name of session
  file string,    -- name of video file, will have extension .mpg or .m1v
  size integer    -- size of video file in bytes
);

