<jupyter_start><jupyter_text>Google drive 에 data 파일이 있을 경우 Path 를 설정해줍니다.<jupyter_code>from google.colab import drive
drive.mount('/content/drive')  

!ls "/content/drive/My Drive"  
!cp "/content/drive/My Drive/mtSpikeTimes.mat" "mtSpikeTimes.mat"  #copy 를 합니다. 
!cp "/content/drive/My Drive/Data.mat" "Data.mat"  #copy 를 합니다. 
!cp "/content/drive/My Drive/ChaData.mat" "ChaData.mat"  #copy 를 합니다. 
!cp "/content/drive/My Drive/20200707_WT3_stim_info.xlsx" "20200707_WT3_stim_info.xlsx"  #copy 를 합니다. 



from scipy.io import loadmat  #MATLAB file 을 불러올 수 있게 library 를 import 한다. 
mtSpikes = loadmat('mtSpikeTimes.mat')
import numpy

import numpy
from scipy.io import loadmat  #MATLAB file 을 불러올 수 있게 library 를 import 한다. 
import matplotlib.pyplot as plt
import seaborn as sns  #more beautiful tool for drawing 

raw_rgc_spikes = loadmat('ChaData.mat')
# Readout Excel file of Stimulation information
import pandas as pd

stim_info = pd.read_excel('20200707_WT3_stim_info.xlsx', index_col=0)  
np_stim = stim_info.to_numpy()  #panda data type을 numpy 형태로 불러냅니다. 

#put the information as matrix form<jupyter_output><empty_output><jupyter_text>우선은 가장 센 stimulus를 대상으로 분석하였습니다.<jupyter_code>light_start_index = 4 #light stimulation 

es_index = 18 #Electrical stimulation starting index


ls50_column = 0
ls100_column = 4


ls100_stim = np_stim[light_start_index:light_start_index+10,4]
es_stim = np_stim[es_index:es_index+20,4]<jupyter_output><empty_output><jupyter_text>Channel 의 이름과 Spike 정보들을 연결시켜서 dictionary 형태로 담아줍니다.<jupyter_code>ch_label = []  
ch_spikes = []

for key, value in raw_rgc_spikes.items():
    ch_label.append(key)
    ch_spikes.append(value)
    
    
spike_dict = {}
total_channel_n = len(raw_rgc_spikes.keys())

for i in range(4,total_channel_n):
    chN = int(ch_label[i][3:5])  #Channel number ex) '12'
    chN_string = ch_label[i][3:6]
    spike_dict[chN_string] = ch_spikes[i]
spike_labels = list(spike_dict.keys())
print(spike_labels[0])  # 순서대로 spike 들을 볼 수 있다.
spikes = spike_dict[spike_labels[0]]


spikes_by_trial = []
trial_spikes = []


stim_duration = es_stim[1] - es_stim[0]
for stim_index in range(len(es_stim)):
    spikes_by_trial.append([i for i in spikes if (es_stim[stim_index] <i < es_stim[stim_index] + stim_duration)])
    trial_spikes.append( [i - es_stim[stim_index] for i in spikes if (es_stim[stim_index] <i < es_stim[stim_index] + stim_duration)]) 
    plt.vlines(trial_spikes[stim_index], stim_index-.5 , stim_index+.5)
    


plt.xlabel('time(s)')
plt.ylabel('Trial')

plt.rcParams.update({'font.size': 15})
plt.rc('xtick', labelsize=15) 
plt.rc('ytick', labelsize=15) 
flat_list = [item for sublist in trial_spikes for item in sublist]

Spikes_in_oneLine = numpy.asarray(flat_list)

ax = sns.histplot(Spikes_in_oneLine, bins = 10,legend = None)
ax.set(xlabel='time(s)', ylabel='Number of Spikes')
plt.show()
def show_me_the_spikes(cell_id):
    spikes = spike_dict[spike_labels[cell_id]]
    ch_id = spike_labels[cell_id] #string in channel ID
    spikes_by_trial = []
    trial_spikes = []


    stim_duration = es_stim[1] - es_stim[0]
    for stim_index in range(len(es_stim)):
        spikes_by_trial.append([i for i in spikes if (es_stim[stim_index] <i < es_stim[stim_index] + stim_duration)])
        trial_spikes.append( [i - es_stim[stim_index] for i in spikes if (es_stim[stim_index] <i < es_stim[stim_index] + stim_duration)]) 
        plt.vlines(trial_spikes[stim_index], stim_index-.5 , stim_index+.5)



    plt.xlabel('time(s)')
    plt.ylabel('Trial')
    plt.title(ch_id)

    plt.rcParams.update({'font.size': 15})
    plt.rc('xtick', labelsize=15) 
    plt.rc('ytick', labelsize=15) 
    
    flat_list = [item for sublist in trial_spikes for item in sublist]

    Spikes_in_oneLine = numpy.asarray(flat_list)
    plt.figure()

    ax = sns.histplot(Spikes_in_oneLine, bins = 10,legend = None)
    ax.set(xlabel='time(s)', ylabel='Number of Spikes')
    plt.show()



    
    
    
    
show_me_the_spikes(101)  #101 번째 neuron의 반응을 봅니다.<jupyter_output><empty_output><jupyter_text>Evoked Spikes numbers histogram<jupyter_code>import numpy 
from scipy.io import loadmat  #MATLAB file 을 불러올 수 있게 library 를 import 한다. 
import matplotlib.pyplot as plt
import seaborn as sns  #more beautiful tool for drawing 

raw_rgc_spikes = loadmat('ChaData.mat')  #load matlab 

# Readout Excel file of Stimulation information
import pandas as pd

stim_info = pd.read_excel('20200707_WT3_stim_info.xlsx', index_col=0)  

np_stim = stim_info.to_numpy()  #panda data type을 numpy 형태로 


df = pd.DataFrame(data =np_stim )



light_start_index = 4 #light stimulation 

es_index = 18 #Electrical stimulation starting index


ls50_column = 0
ls100_column = 4


ls100_stim = np_stim[light_start_index:light_start_index+10,4]
es_stim = np_stim[es_index:es_index+20,4]
ch_label = []  
ch_spikes = []

for key, value in raw_rgc_spikes.items():
    ch_label.append(key)
    ch_spikes.append(value)
    
    
spike_dict = {}  #dictionary initialization
total_channel_n = len(raw_rgc_spikes.keys())

for i in range(4,total_channel_n):
    chN = int(ch_label[i][3:5])  #Channel number ex) '12'
    chN_string = ch_label[i][3:6]
    spike_dict[chN_string] = ch_spikes[i]
    

    
spike_labels = list(spike_dict.keys())
spikes_by_trial = []
trial_spikes = []


stim_duration = es_stim[1] - es_stim[0]
for stim_index in range(len(es_stim)):
    spikes_by_trial.append([i for i in spikes if (es_stim[stim_index] <i < es_stim[stim_index] + stim_duration)])
    trial_spikes.append( [i - es_stim[stim_index] for i in spikes if (es_stim[stim_index] 
                                                                      <i < es_stim[stim_index] + stim_duration)]) 
    
    
    plt.vlines(trial_spikes[stim_index], stim_index-.5 , stim_index+.5)
    


plt.xlabel('time(s)')
plt.ylabel('Trial')

plt.rcParams.update({'font.size': 15})
plt.rc('xtick', labelsize=15) 
plt.rc('ytick', labelsize=15) 
num_spikes = numpy.zeros((20,1))



for i in range(len(trial_spikes)):
    
    num_spikes[i] = len(trial_spikes[i])
ax = sns.histplot(num_spikes, legend = None)


def spike_num(cell_id):
    spikes_by_trial = []
    trial_spikes = []
    spikes = spike_dict[spike_labels[cell_id]]
    stim_duration = es_stim[1] - es_stim[0]
    for stim_index in range(len(es_stim)):
        spikes_by_trial.append([i for i in spikes if (es_stim[stim_index] <i < es_stim[stim_index] + stim_duration)])
        trial_spikes.append( [i - es_stim[stim_index] 
                              for i in spikes if 
                              (es_stim[stim_index] <i < es_stim[stim_index] + stim_duration)]) 


    num_spikes = numpy.zeros((len(trial_spikes),1))

    for i in range(len(trial_spikes)):

        num_spikes[i] = len(trial_spikes[i])
        
    return num_spikes
num_spikes = numpy.zeros((20,1))



for i in range(len(trial_spikes)):
    
    num_spikes[i] = len(trial_spikes[i])
n_spTrain = len(spike_dict)
spike_mat = spike_num(0)              
for i in range(1,n_spTrain):
    spike_mat = numpy.concatenate((spike_mat, spike_num(i) ), axis=1)
    print (i)
import pickle

with open('spikeNum.pickle', 'wb') as f:
    pickle.dump(spike_mat, f)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup