-
Notifications
You must be signed in to change notification settings - Fork 1
/
deltaPETH_shortcut.py
150 lines (99 loc) · 4.68 KB
/
deltaPETH_shortcut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 15 08:46:57 2022
@author: dhruv
"""
import numpy as np
import pandas as pd
import scipy.io
from functions import *
from wrappers import *
import os, sys
import neuroseries as nts
import time
import matplotlib.pyplot as plt
import pynapple as nap
from Wavelets import MyMorlet as Morlet
import seaborn as sns
from scipy.stats import wilcoxon
import matplotlib.cm as cm
data_directory = '/media/DataDhruv/Dropbox (Peyrache Lab)/Peyrache Lab Team Folder/Data/AdrianPoSub/###AllPoSub'
datasets = np.loadtxt(os.path.join(data_directory,'dataset_Hor_DM.list'), delimiter = '\n', dtype = str, comments = '#')
# datasets = np.loadtxt(os.path.join(data_directory,'dataset_test.list'), delimiter = '\n', dtype = str, comments = '#')
rwpath = '/media/DataDhruv/Dropbox (Peyrache Lab)/Peyrache Lab Team Folder/Projects/PoSub-UPstate/Data'
n_pyr = []
n_int = []
for s in datasets:
print(s)
name = s.split('/')[-1]
path = os.path.join(data_directory, s)
rawpath = os.path.join(rwpath,s)
data = nap.load_session(rawpath, 'neurosuite')
data.load_neurosuite_xml(rawpath)
###############################################################################################
# LOADING DATA
###############################################################################################
spikes = data.spikes
epochs = data.epochs
channelorder = data.group_to_channel[0]
seq = channelorder[::8].tolist()
filepath = os.path.join(path, 'Analysis')
mouse_pos = pd.read_csv(filepath + '/Tracking_data.csv', header = None)
position = pd.DataFrame(index = mouse_pos[0].values*1e6, data = mouse_pos[[1,2,3]].values, columns=['x', 'y', 'ang'])
position = position.loc[~position.index.duplicated(keep='first')]
position['ang'] = position['ang'] *(np.pi/180) #convert degrees to radian
position['ang'] = (position['ang'] + 2*np.pi) % (2*np.pi) #convert [-pi, pi] to [0, 2pi]
position = nts.TsdFrame(position)
filepath = os.path.join(path, 'Analysis')
listdir = os.listdir(filepath)
file = [f for f in listdir if 'BehavEpochs' in f]
behepochs = scipy.io.loadmat(os.path.join(filepath,file[0]))
file = [f for f in listdir if 'CellDepth' in f]
celldepth = scipy.io.loadmat(os.path.join(filepath,file[0]))
depth = celldepth['cellDep']
file = [f for f in listdir if 'MeanFR' in f]
mfr = scipy.io.loadmat(os.path.join(filepath,file[0]))
r_wake = mfr['rateS']
filepath = os.path.join(path, 'Analysis')
position = pd.read_csv(filepath + '/Tracking_data.csv', header = None)
file = [f for f in listdir if 'CellTypes' in f]
celltype = scipy.io.loadmat(os.path.join(filepath,file[0]))
pyr = []
interneuron = []
hd = []
for i in range(len(spikes)):
if celltype['ex'][i] == 1 and celltype['gd'][i] == 1:
pyr.append(i)
for i in range(len(spikes)):
if celltype['fs'][i] == 1 and celltype['gd'][i] == 1:
interneuron.append(i)
for i in range(len(spikes)):
if celltype['hd'][i] == 1 and celltype['gd'][i] == 1:
hd.append(i)
n_pyr.append(len(pyr))
n_int.append(len(interneuron))
# ###############################################################################################
# # LOAD UP AND DOWN STATE, NEW SWS AND NEW WAKE EPOCHS
# ###############################################################################################
file = os.path.join(rawpath, name +'.DM.new_sws.evt')
new_sws_ep = data.read_neuroscope_intervals(name = 'new_sws', path2file = file)
file = os.path.join(rawpath, name +'.DM.new_wake.evt')
new_wake_ep = data.read_neuroscope_intervals(name = 'new_wake', path2file = file)
peaks = pd.read_pickle(rawpath + '/' + s + '_LFP_peaks.pkl')
lfp_all = pd.read_pickle(rawpath + '/' + s + '_LFP_all.pkl')
fig, ax = plt.subplots()
cax = ax.imshow(lfp_all[-0.75:0.75].T,extent=[-0.75 , 0.75, data.nChannels , 1],aspect = 'auto', cmap = 'inferno')
plt.xlabel('lag (s)')
plt.ylabel('Channel number')
plt.title('Delta PETH_' + s)
cbar = fig.colorbar(cax, ticks=[lfp_all[-0.75:0.75].values.min(), lfp_all[-0.75:0.75].values.max()], label = 'LFP magnitude')
# plt.figure()
# plt.title('Delta PETH_' + s)
# plt.xlabel('lag (s)')
# plt.ylabel('LFP magnitude')
# j = 0
# for i in seq:
# plt.plot(lfp_all[-0.75:0.75][i], color=cm.inferno(j/8), label = j)
# plt.legend(loc = 'upper right')
# j+=1