-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistractionBehaviourAnalysis.py
More file actions
243 lines (219 loc) · 11.4 KB
/
Copy pathDistractionBehaviourAnalysis.py
File metadata and controls
243 lines (219 loc) · 11.4 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 16 11:18:00 2018
@author: u1490431 (kp)
DATA EXTRACTION - DISTRACTION BEHAVIOUR PAPER PETERS ET AL.
DATA EXTRACTION - CHAPTER 3 PCPvSAL
Information on what this script does start to finish and which other
functions need to be run first
(1) Reads in metafiles from filepath, contains information on filenames and basic descriptives
(2) Extracts lick data from MED files. Uses the names files in metafile and stores licking
data into variables by chosen day (ie. last lick day / distraction day). Stores lick data
by group as large list of lists. Eg. last_lick_sal_M contains 16 lists of lick onsets for
just the last day of licking, each list is a rat, with onsets and offsets stored.
(3) Lick analysis -
(4) Distraction analysis -
(5) Post distractor pauses and predistractor pauses - calculates the time periods
for both distracted and non distracted trials separately for all groups
"""
################################################################################
# LICK ANALYSIS DPCP (1,2,3)
################################################################################
# (1) Find and extract info from the metafile(s)
#
metafile_males = '/Volumes/KP_HARD_DRI/kp259/DPCP_ALL/DPCP12Masterfile.csv'
metafile_females = '/Volumes/KP_HARD_DRI/kp259/DPCP_ALL/DPCP3_Metafile.csv'
extract_males = MetaExtractor(metafile_males)
extract_females = MetaExtractor(metafile_females)
# Folder with all medfiles (DPCP1, DPCP2, DPCP3)
medfolder = '/Volumes/KP_HARD_DRI/kp259/DPCP_ALL/' # sometimes need space1 after DRI
# (2) - Get all lick onset/offset data for all rats/sessions (make this a function later)
'''
Info DPCP1(16) and DPCP2(16) males, DPCP3(24) females :
DPCP1 |DPCP2 |DPCP3 |CONDITION
------|------|------|-----------
170417|171006|171124|last lick
170418|171007|171125|dis
170419|171008|171126|hab 1
170420|171009|171127|hab 2
170423|171012|171128|amphetamine
'''
# Subsetting all data by day / drug
# MALES ***********************************************************************
# SALINE
last_lick_sal_M = subsetter(extract_males, ['170417','171006'], 'SAL')
distraction_sal_M = subsetter(extract_males, ['170418','171007'], 'SAL', dis=True)
hab1_sal_M = subsetter(extract_males, ['170419','171008'], 'SAL')
hab2_sal_M = subsetter(extract_males, ['170420','171009'], 'SAL')
amph_sal_M = subsetter(extract_males, ['170423','171012'], 'SAL')
# PCP
last_lick_pcp_M = subsetter(extract_males, ['170417','171006'], 'PCP')
distraction_pcp_M = subsetter(extract_males, ['170418','171007'], 'PCP', dis=True)
hab1_pcp_M = subsetter(extract_males, ['170419','171008'], 'PCP')
hab2_pcp_M = subsetter(extract_males, ['170420','171009'], 'PCP')
amph_pcp_M = subsetter(extract_males, ['170423','171012'], 'PCP')
# FEMALES **********************************************************************
# SALINE
last_lick_sal_F = subsetter(extract_females, ['171124'], 'SAL')
distraction_sal_F = subsetter(extract_females, ['171125'], 'SAL',dis=True)
hab1_sal_F = subsetter(extract_females, ['171126'], 'SAL')
hab2_sal_F = subsetter(extract_females, ['171127'], 'SAL')
amph_sal_F = subsetter(extract_females, ['171128'], 'SAL')
# PCP
last_lick_pcp_F = subsetter(extract_females, ['171124'], 'PCP')
distraction_pcp_F = subsetter(extract_females, ['171125'], 'PCP',dis=True)
hab1_pcp_F = subsetter(extract_females, ['171126'], 'PCP')
hab2_pcp_F = subsetter(extract_females, ['171127'], 'PCP')
amph_pcp_F = subsetter(extract_females, ['171128'], 'PCP')
# (3) Lick calc for last lick day (by group) for male PCP and SAL, for female PCP and SAL
# Licking analysis section, just last lick day
# assign empty variables to store outputs from lick calc (to find means/groups stats)
# lists where each item is a dictionary (25) derived from lickCalc for each rat / day
lick_analysis_sal_M = lickanalysis(last_lick_sal_M)
lick_analysis_pcp_M = lickanalysis(last_lick_pcp_M)
lick_analysis_sal_F = lickanalysis(last_lick_sal_F)
lick_analysis_pcp_F = lickanalysis(last_lick_pcp_F)
# ***********************************************************************************!!!!!
## LICK DAY ANALYSIS - BY GROUP
# Produce medians/means for individual rats and group means
# Males
# Saline
sal_M_mean_n_bursts, sal_M_mean_n_runs, sal_M_mean_mean_IBI, sal_M_mean_mean_IRI,\
all_n_bursts_sal_M, all_n_runs_sal_M, all_mean_IBI_sal_M, all_mean_IRI_sal_M, \
all_mean_burst_length_sal_M, all_mean_run_length_sal_M = grouped_lickanalysis(lick_analysis_sal_M)
# PCP
pcp_M_mean_n_bursts, pcp_M_mean_n_runs, pcp_M_mean_mean_IBI, pcp_M_mean_mean_IRI,\
all_n_bursts_pcp_M, all_n_runs_pcp_M, all_mean_IBI_pcp_M, all_mean_IRI_pcp_M, \
all_mean_burst_length_pcp_M, all_mean_run_length_pcp_M = grouped_lickanalysis(lick_analysis_pcp_M)
# Females
# Saline
sal_F_mean_n_bursts, sal_F_mean_n_runs, sal_F_mean_mean_IBI, sal_F_mean_mean_IRI,\
all_n_bursts_sal_F, all_n_runs_sal_F, all_mean_IBI_sal_F, all_mean_IRI_sal_F, \
all_mean_burst_length_sal_F, all_mean_run_length_sal_F = grouped_lickanalysis(lick_analysis_sal_F)
# PCP
pcp_F_mean_n_bursts, pcp_F_mean_n_runs, pcp_F_mean_mean_IBI, pcp_F_mean_mean_IRI,\
all_n_bursts_pcp_F, all_n_runs_pcp_F, all_mean_IBI_pcp_F, all_mean_IRI_pcp_F, \
all_mean_burst_length_pcp_F, all_mean_run_length_pcp_F = grouped_lickanalysis(lick_analysis_pcp_F)
################################################################################
# DISTRACTION ANALYSIS DPCP (1,2,3)
################################################################################
# Distraction day analysis (including modalities)
modalitykey = {'whitenoise':[1,4], 'tone':[2,5], 'combined3':[3,6]}
# MALES
# Saline
discalc_sal_M, percent_dis_whitenoise_sal_M, percent_dis_tone_sal_M,\
percent_dis_combined_sal_M, mean_percent_WHITENOISE_sal_M, mean_percent_TONE_sal_M,\
mean_percent_COMBINED_sal_M = discalc_modalities(distraction_sal_M, modalitykey)
# PCP
discalc_pcp_M, percent_dis_whitenoise_pcp_M, percent_dis_tone_pcp_M,\
percent_dis_combined_pcp_M, mean_percent_WHITENOISE_pcp_M, mean_percent_TONE_pcp_M,\
mean_percent_COMBINED_pcp_M = discalc_modalities(distraction_pcp_M, modalitykey)
# FEMALES
# Saline
discalc_sal_F, percent_dis_whitenoise_sal_F, percent_dis_tone_sal_F,\
percent_dis_combined_sal_F, mean_percent_WHITENOISE_sal_F, mean_percent_TONE_sal_F,\
mean_percent_COMBINED_sal_F = discalc_modalities(distraction_sal_F, modalitykey)
# PCP
discalc_pcp_F, percent_dis_whitenoise_pcp_F, percent_dis_tone_pcp_F,\
percent_dis_combined_pcp_F, mean_percent_WHITENOISE_pcp_F, mean_percent_TONE_pcp_F,\
mean_percent_COMBINED_pcp_F = discalc_modalities(distraction_pcp_F, modalitykey)
# Modelled distractors ˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚˚
# Not including modalities just where distractors occur and dis vs notdis
# Modelled distractors by group (last lick day)
mod_dis_sal_M = disbygroup(last_lick_sal_M)
mod_dis_pcp_M = disbygroup(last_lick_pcp_M)
mod_dis_sal_F = disbygroup(last_lick_sal_F)
mod_dis_pcp_F = disbygroup(last_lick_pcp_F)
# Habituation days by group
hab1_dis_sal_M = disbygroup(hab1_sal_M)
hab2_dis_sal_M = disbygroup(hab2_sal_M)
hab1_dis_pcp_M = disbygroup(hab1_pcp_M)
hab2_dis_pcp_M = disbygroup(hab2_pcp_M)
hab1_dis_sal_F = disbygroup(hab1_sal_F)
hab2_dis_sal_F = disbygroup(hab2_sal_F)
hab1_dis_pcp_F = disbygroup(hab1_pcp_F)
hab2_dis_pcp_F = disbygroup(hab2_pcp_F)
# Amphetamine days by group
amph_dis_sal_M = disbygroup(amph_sal_M)
amph_dis_pcp_M = disbygroup(amph_pcp_M)
amph_dis_sal_F = disbygroup(amph_sal_F)
amph_dis_pcp_F = disbygroup(amph_pcp_F)
# POST DISTRACTION PAUSES
# For both distracted and non-distracted trials
###################################################################################
'''
Info: Structure of the calculated distractors lists
discalc_sal_M[0][0][0] # [rat][list][licktimestamp]
'''
# CALCULATE THE PDP FOR SPECIFIC GROUPS - finds where in the licks the distractor
# occurred and then finds the pause before the next lick (ignoring distractors occurring
# on the final lick in a session)
# SALINE MALES
pdps_dis_sal_M, med_pdps_dis_sal_M, preDPs_dis_sal_M,\
pdps_notdis_sal_M, med_pdps_notdis_sal_M, preDPs_notdis_sal_M,\
= pdpbygroup(discalc_sal_M, distraction_sal_M)
# PCP MALES
pdps_dis_pcp_M, med_pdps_dis_pcp_M, preDPs_dis_pcp_M,\
pdps_notdis_pcp_M, med_pdps_notdis_pcp_M, preDPs_notdis_pcp_M,\
= pdpbygroup(discalc_pcp_M, distraction_pcp_M)
# SALINE FEMALES
pdps_dis_sal_F, med_pdps_dis_sal_F, preDPs_dis_sal_F,\
pdps_notdis_sal_F, med_pdps_notdis_sal_F, preDPs_notdis_sal_F,\
= pdpbygroup(discalc_sal_F, distraction_sal_F)
# PCP FEMALES
pdps_dis_pcp_F, med_pdps_dis_pcp_F, preDPs_dis_pcp_F,\
pdps_notdis_pcp_F, med_pdps_notdis_pcp_F, preDPs_notdis_pcp_F,\
= pdpbygroup(discalc_pcp_F, distraction_pcp_F)
'''
# Corelations
Find mean for each list of pre / post DPs and then correlate and plot
using the sb.jointplot(x='Attack', y='Defense', data=df) seaborn joint plots
(find out how to get distributions too
sb.jointplot(x=df['nRuns'], y=df['nRuns'], kind='hex')) or type 'reg' for kernel estimation and regression
plt.plot()
How to plot different colours? If values in the plotted points
Meet certain condition point should be blue
Else it should be black
OR separate them by condition first and add 2 plots, the blue and black
for index, value in enumerate(salMdistractors):
if value > 1 :
add the pdp / predp to this list
and add the predp to this list too (of the same index)
else:
add to this list
Not sure if this works yet - 2 variables to compare so do i need
both in the list or just one indices???
###################################################################################
'''
##################################################################
# Percentage distracted ##################################################################
# Saline Males
percent_dis_dis_sal_M = percentdisgroup(discalc_sal_M)
percent_dis_modelled_sal_M = percentdisgroup(mod_dis_sal_M)
percent_dis_hab1_sal_M = percentdisgroup(hab1_dis_sal_M)
percent_dis_hab2_sal_M = percentdisgroup(hab2_dis_sal_M)
percent_dis_amph_sal_M = percentdisgroup(amph_dis_sal_M)
## PCP Males
percent_dis_dis_pcp_M = percentdisgroup(discalc_pcp_M)
percent_dis_modelled_pcp_M = percentdisgroup(mod_dis_pcp_M)
percent_dis_hab1_pcp_M = percentdisgroup(hab1_dis_pcp_M)
percent_dis_hab2_pcp_M = percentdisgroup(hab2_dis_pcp_M)
percent_dis_amph_pcp_M = percentdisgroup(amph_dis_pcp_M)
############# FEMALES - percent distracted
## Remember might have an issue with the last PCP rat on amphetamine day
# division by zero potential problem/ Might remove this rat from ALL days for the plots??
# SALINE
percent_dis_dis_sal_F = percentdisgroup(discalc_sal_F)
percent_dis_modelled_sal_F = percentdisgroup(mod_dis_sal_F)
percent_dis_hab1_sal_F = percentdisgroup(hab1_dis_sal_F)
percent_dis_hab2_sal_F = percentdisgroup(hab2_dis_sal_F)
percent_dis_amph_sal_F = percentdisgroup(amph_dis_sal_F)
# PCP
percent_dis_dis_pcp_F = percentdisgroup(discalc_pcp_F[0:-1])
percent_dis_modelled_pcp_F = percentdisgroup(mod_dis_pcp_F[0:-1])
percent_dis_hab1_pcp_F = percentdisgroup(hab1_dis_pcp_F[0:-1])
percent_dis_hab2_pcp_F = percentdisgroup(hab2_dis_pcp_F[0:-1])
percent_dis_amph_pcp_F = percentdisgroup(amph_dis_pcp_F[0:-1])
######################### INDIVIDUAL DIFFERENCES #######################
#sb.jointplot(x=df['nRuns'], y=df['nBursts'], kind='hex')) #or type 'reg' for kernel estimation and regression