-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonLog.py
More file actions
2856 lines (1980 loc) · 109 KB
/
Copy pathPythonLog.py
File metadata and controls
2856 lines (1980 loc) · 109 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 7 16:40:12 2017
@author: kp259
"""
'''Log of Python coding and ideas, what was done and when, what needs to be
written next. Who's code was used, where resources were found etc.
by Kate Peters'''
'''07/07/17'''
# 15:30 - 16:40
# Worked out how to read in MED file, make data rows and work out total licks
# Wrote code in DIS1_analysis
# Used JEM code as guide, used "is numeric" function written by JEM
# Next step:
# Calculate frequency of 3 lick burst - Y
# Check MED saving format on distraction days (still -22?)
# Logical indexing and x matrix from metafile
# Separate by rat over time
# Separate by day (group all rats and average)
# Plot data, histograms, timings of licks - Y
# Plot mean data across animals
# Will write all code in full and modularise it to functions / classes later
# Ask JEM for help with modularisation and looping through cohorts
# 19:40 - 20:00
# Added 2 lines of plotting, to see how hist works
# Noted to check whether toggle was on in dis1, cannot use onse/offset
# Work out ILIs using diff, wrote instructions for burst calculation
'''08/08/17'''
# 13:40 - 14:40
# Plotting with matplotlib.plt histogram of ILIs (find most common)
# Trying to work out lick lengths based on ILIs. Not possible with dis1 data
# Adding text to licks histogram for total licks, customizing
# This evening:
# Read in metafile, set path
# Calculate 3 lick bursts (and mean or median burst length)
# Calculate longest burst and shortest burst
# 17:30 - 18:10
# Reading documentation for matplotlib
# Edited burstlengthanalysis (JEM) function to include median, check it works
#with my variables
#Things to consider:
#Think about exactly what we want to know for the sessions
# What does normal licking look like?
# Choice of summary statistic here, is the proportion of 3 lick bursts significantly higher than
# the proportion of non-3lick bursts? T-test? Multiple comparisons problems?
# (1 t-test of ALL animals on distraciton-1)
# Note: Use F11, full screen mode less distracting
# Wrote code to calculate non-3-lick bursts, but missing 2%! Need to work out why
# Maybe single licks not included? Looks like they are
# Fixed the percentage issues (was not using %, was using n of non3Lick bursts)
'''09/08/17'''
# 12:30 - 13:00
# Read in metafile
# !! Problems of multiple variables with the same name (will be fixed when modular)
# Looking at how to split lines / read in variables, split strings to make cols
# How to get data into usable structure
# How can I index into a list of lists, all the values in position 3 or each list?
# 15:00 - 17:30
# Figured out indexing problem, spliting the strings into character by mistake
# Indexed and wrote code to separate out lists into "Rat", "Session" etc.
# Unsure how useful, how can I logically index these to get all data from rats 2
# Some code to find the index then use that / those indices to index the other columns
# Seems overly complicated, maybe put them back together but as columns in data frame?
# Created pandas data frame to include all information
# Trying to understand how mean works in pd.dataframe, odd reuslt when finding mean in column
# ! Realised not numbers, converted to np.array, still need to convert to floats
# Converted pd array to numeric and found how to avoid NaNs, so far only column by column though
# 20:30 - 21:10
# Looking up cummulative plots
# Writing code to plot cummulative licks
# Problems with "height" unsure why
# Trying to fix height issue on cumulative plot
# Found much simpler code with options in hist (and list is fine no need for np.array)
# Figured out how to make line thicker and readable on cumulative plot
''' 10/08/17'''
# 14:30 - 15:30
# Printed and read over existing script, what I have done and what needs doing
# How it works / doesn't work
# Looking at event plots
# Neatening code, tidying up the way the code looks to explain/understand it better
# Try logical indexing to separate days and rats etc.
# Wrote code to index rats, need to figure out how to access other column data using the
# indexes found (for loop or function)
# Writing code to loop through filenames in metafile
# Turn medfile reading code into function (like JEM medfilereader)
# Halfway there, need to remember how to call function bear in mind return
# 20:10 - 20:30
# Reverting from function back to code, to test logical indexing
# Indexing not working, error 'series not callable'
# Same error with both pd.dataframe and np.array
''' 11/08/17 '''
# 19:45 - 20:30
# Turned on SelfControl for 120mins and Noisli to concentrate
# Fixing function definition after discussion with JEM about returns
# Wrote code to output more than one variable from function;
#return lickdata, totallicks
#filename = '/Volumes/KPMSB352/R drive ...'
#data, totallicks = MedReader(filename)
# Adding start and end assigned variables to MedReader function for readablity
# Changed working directory to find files in for loop
# Realised it is NOT always -22 (saving structure of MED, has the 26 variables)
# The distraction programme has many more zeroes, will need to use new code
# Writing this code, cound n lines, n = value before -2 (saved in MED)
# Making code modular with function definitions and calls
# Problems with logical indexing
# How to define the distraction with code (not just yes or no)
# More than percent distracted
# Percent 3 lick bursts
# Mean post distraction pause vs mean post 3lick burst pause
# DPCP vs controls
''' 12/08/17 '''
# 20:00 - 21:00
# Reading over code, trying to understand how to fix start:end issue
# Want to access the number in the index, maybe need to conver it?
# Converted using asnumeric within function
# Error, value error about -3 not in list
# Not cutting off at the correct value still, extra 0's at the end
# Isolated the code in file 'scratchPadTest' found -3 is at the end of file
# Realised total licks is incorrect for distraction files, not indexed correctly
# Including zeroes at the end of file
# Trying to fix this
# Confusion over the index and value, want to find the value in a given index
# Odd values coming out of the indexing, start works correctly, end doesn't
# Think problem is because the index (defined by the number before the -2) is counted
# From the start, not accounting for the previous numbers cut off for the start
# Got frustrated with it, take a break come back tomorrow
''' 13/08/17 '''
# 19:30 - 20:10
# Scratchpad file corrupted, all code lost -_-
# Starting again at trying to fix indexing / value problem
# Figured out the difference between getting the index and getting the value
# Realised that it was finding the 492th index from the start of the file
# NOT from the FIRST lick value, wrote code to add this in, works!
# Re-introduce code into original function and test
# Checked that for loop to read filenames from med does access all
# Checked that MedReader works for distraction and lick training files
# It does! Figured out how to access just one of the returns from a function
# NEXT
# Figure out the logical indexing, maybe alter the data frame or structure to do this
# Make plots funciton
# Make PDF outputs for each rat across days
# Make output of mean distracted and mean 3lick t-test
''' 14/08/17 '''
# 18:50 - 19:20
# Making plots a function, get it to run through all files in meta (later logical)
# Thinking about the ILIs calculation, includes very long gaps between bursts
# Want the ILIs wihin bursts only, exclude on a threshold (anything over 0.25)
# Tring to get plotting function and medreader to work together (call reader inside)
# How do you return figures? Function not returning anything
# Look at Jaime figure function and try to figure out
# Function works
# Remember the difference between return and print is important!
# For loop did the plot funciton for all 152 files, does take a long time
# Successfully ran through all files though
# Until logical indexinf is sorted comment for loop out (or shorten to one case)
''' 15/08/17 '''
# 08:30 - 9:00
# Logical indexing trying to fix
# Wrote code to separate days, rats and session type
# Errors, noted append does not work on empty list as type none
# Used + instead to concatenate (for list this works, cannot be integer)
# 10:00 - 11:00 (#SUWT)
#Discovered that ctrl+! comments and uncomments!
# Fixed logicla indexing with enumerate, find the logical index of 1 and use
# the index of the 1's as indices for the other variables
# now trying to add in multiple conditions, if x and y == 1 then give vlaues
# Cleaning up code, making more readable for later interpretation
''' 16/08/17 '''
# 20:00 - 21:00
# Deciding on next steps for analysis
# Altering for loop of logical indexing, maybe don't need a 1/0 column
# If statement is true the use the index of the true value as index for
# desired value in another column, used append here, make new list of distractions
# for just day 8 (modify to be percent distracted)
# Make an average histogram of lick data (get all into one cumulative histogram)
# Could plot n values of bursts, density of bursts as histograms
# Day -1 = 7
# Distraction = 8
# Distraction2 = 9
# Saline = 11
# Amphetamine = 14
# Nicotine = 17
# Figured out how to get means, need to work on plotting these and making function
# generalised not specific cases
# test cases for non-distracted days (throw up error or text)
# For t-tests, maybe just produce an output of the numbers needed for another
# stats package to calculate (can work out and then test in SPSS)
# Maybe JEM 'include' column is a good idea here, to limit the lick analysis
# to just days that we're interested in
# TO DO :
# Get 3 lick percentages for each rat on each day, compare in spss each day
# one way ANOVA with 3lick percentage as measured, day as IV
''' 17/08/17 '''
# 16:00 - 16:30
# Writing metaextractor function, modularising code into funcitons
# consider what the returns will be and how these can be used by other functions
# Need to consider how to get logical indexing to work with the returned values
# from the function
# Tired, took break, considering how best to calculate means and logical indexes
# in the most general way possible. Working on testscript2 to run sections
# of code before altering main script that works
# 17:00 - 18:40
# Worked out how to use returned variables in for loop to perform logical indexing
# not intuitive looking and confusing
# consider a better way to do this (names of variables not numerical indexes alone)
# Maybe return dictionary with keys and not just the multiple variables?
# Writing code to return dictionary of metafile data from metaextractor funciton
# Working out how to make logical index funciton more general
# Thinking about what I actually want to do
# Get percentage distracted in a list, get non-distracted in a list (info from meta file)
# More important to get the percentage of 3 lick burst into a list and compare
# Days this way (! For the files identified in the 'DAY' logical indexer)
# identify the file name
# open this file, find 3 lick bursts (make that long code at the end a function and only run on days)
# Writing test code in TestScript2 file, looking at optional and named arguments
# Writing code for IndexByDay function
# Do I need a list or code for which days are which treatments?
# How will this work for dpcp?
# Re-insert code into main script, copy from TestScript2 to dis1_analysis
# Fixing introduced bugs
''' 18/08/17 '''
# 17:00 - 18:40
# Fixed data frame, not 'Distractions' = Distractions
# Now 'Distractions' = metaDataDict['Distractions'], filling in correct indexes
# Go through all licks, check ILIs and calculate when distracted vs non-distracted
# Checking 3 lick bursts calculated with the number of distractors given
# Does not match up
# Trying to figure out why
# Less 3 lick bursts than actual distractors given (haven't worked out distracted vs non-distracted yet)
# Looking at JEM function 'distractoranalysis' trying to see how it works
# and if i works with DIS1 (uses timestamps and differences which weren't coded in med here)
# Modifying this function does almost work, clculates distractors as a few too many
# DOES NOT work for distraxted vs not distracted
# Editing and testing in TestScript2
# Trying to calculate distractors using ILIs in different way (not doubling ILIs)
# can we compare pairs of ILIs and see if they are > a threshold AND that is a 3 lick burst
# ie the proceeding ILI was less than burst interval
# Need to go back to med and see criteria for distractors and bursts, ILIs set in med
# Inter lick for part of a burst, inter burst and distraction definitions (write these for thesis)
------------------------------------------------------------------------------
''' 19/08/17 '''
# 20:30 - 21:30
# Trying different parameters in distractors function
# Looking through MED file (MPC code) to see saving format / distraction calculator
# 3 licks within 1 second
# so every 2 ILIs plus every 3 licks must be <1000ms
# For ILIs find sums of every 2 ILIs
# For lick data find sums of every 3 licks
# Add these together
# Will it work?
# What about long pauses and single licks? May need to do a 3 lick separation first
# Tomorrow, look at the Matlab conversion script and see what needs adapting
# Look at key for TTLs and check correct (1 is not)
# Figure out what the original script does before adapting it
# Add in doc strings to all written functions (look at Michael's email)
''' 20/08/17 '''
# 12:20 - 13:20 # Motivation 4, productivity 4
# Added doc string for main script and doc strings to all functions inside
# included the purpose of the funciton, arguments expected/required and returns
# thinking about arguments and returns from function, esp. plotting functions
# improving readability of code
# Still trying to find where the problem with distracted or not is
# not categorising correctly
# Brain not working, stuck. Take a break and come back later
''' 21/08/17 '''
# 20:11 - 21:20 # Motivation 4, productivity 2
# Making metafile for THPH2, started by checking all data and started to fill in
# Will add tankfailes when access to R drive more reliable (faster)
# Reading scripts and working out what needs modifying
# To do:
# Check THPH1 and THPH2 metafiles are the same
# Fill in fully both metafules with tanks and info from google sheets
# Run and edit matlab script
# Find all functions (like nan etc.) that are needed for MATLAB to run
# Start DPCP1/DPCP2 script and metafiles (1 and 2 the same for comparison)
# Added motivation/productivity info to log to see when best times to code
''' 22/08/17 '''
# 11:30 - 12:00
# Trying to figure out this line;
# doubleilis = ILIs[1:] + ILIs[0:-1]
# get completely different value if use [0:] in both, why did JEM use this indexing here?
# Still not right, indexing confusing and double if statement
# changed (y > 1) to (y >2) closer to correct number! 62 if 60 and 87 when 83
# rationale for changing is the cut off may be 1 second not 500ms
# changed distractedornot = [(lickdata[i+3]-lickdata[i+2]) > 1 for i in distractors]
# switched 1 for 0.5 (increased n distracted but still not correct!)
# 16:30 - 17:30
# MATLAB - switched to look at the tdt2mat2py function
# modifying to process the 2 boxes (4 streams, 2 UV and 2 Blue)
# writing code to add in second set of data and labelling all with box 2
# looking over skipping function and others JEM has written, modifying to add second box
# adding comments to the funciton in new folder
# changing paths and directories, saving folders etc.
# trying to make funciton flexible, make "second box" an optional parameter
# want to analyse signals ONLY if the stream exists, otherwise just do those that do
# Labelling of streams has changed no longer Dv1A, now Dv1B, Dv2B, Dv3B, Dv4B (1 and 2 box1)
# 3 and 4 box 2
# Added in a boxes arg to the function, if ==1 just do as before
# If == 2 give both signals
# else --> spit out error message and stop (need to add this into code)
# To get variable informaiton maybe need to run a single file through ealrier matlab script (TDT2MATBIN)
# see how everything is named and indexed
''' 23/08/17 '''
# 9:00 - 11:45
# MATLAB - editing tdt2mat2py function
# Thinking about how to access data about 1 rat not both in the tank
# input of function could be changed to give names from both rats, option for 1 or 2?
# TTLs missing distracted or not TTL?
# Why?
# NB error one is miss labelled (DIS1 missing DID1 is the distractors not distracted or not)
# output epoch field names to figure out where other 2 TTLs are. Just got rid of ;
# odd that it is the distracted TTLs (even wrongly named one)
# Load into TDT - check if TTLs exist in the data (read in issue or saving)
# Not a distraction file ! So no distracted
# need to find out why there is distractors but not distracted in this file
# look over the tanks (TDT programme on Synapse computer)
# JEM came to look at MATLAB script
# Talked about the distraction script issue with calculating distractors
# Will now use lickdata rather than ILIs (indexing gets confusing otherwise)
# Writing code to calculate distractors and distracted or not based on licking data not ILIs
# ---- Break for lunch
# 15:00 - 16:10
# Calculated lick n+2 - lick n accidentally used ILIs (calculated these incorrectly)
# Need to work this out before calculating distraction
# Figured out how to get n+2 on the lick data and calculate distractors given, but
# 1 distractor out, first? second last? add in condition
# Writing code to work out distracted or not
# Help! Not working
# Number of distractors is one out, either one too many distractors or one less
# think that is because it misses the last value
# Calculaiton for distravted or not is out, for sme files it is out by only 5
# seems to add 5 to not distracted and miss 5 from distracted
# For other files (like this one) it is totally out! But total distractors is still only 1 out
''' 24/08/17 '''
# 10:40 - 11:30
# Trying to fix distraction script
# Reading JEM comments on script, fixed NDistractors (needed to include the first lick not exclude)
# Now counts correct number
# Distracted vs not distracted still odd, either completely distracted or strange values!
# Following JEM advice, checked MED file cut offs, seem to be correct at 1 second
# Checked with another file NDistractors STILL not right, one out for some
#files correct for others
# Special case if the last lick received a distractor? Check this
# 13:20 - 14:40
# Try appending values to the end of the lists so that indexes don't break (include all numbers)
# Writing code to add zeroes to the end of licks
# Did not work
# Writing conditional for if the arrayD index value is less than 4 from the end of licks
# exclude these values and you cannot do "index+4 if there are not 4 vlaues left
# Special case for 1st 3 licks (cannot decide if there is 1 second before ans there is no before)
# Changed if lickdataNum[index+3] - lickdataNum[index+2] > 0.5: from >1 (must be 0.5) ? NO it's 1
# not very different between 0.5 and 1
# Adding in multiple print statements, checking the indexing and seeing what is
# passed from each seciton of code to the next is what I expect
# 16:00 - 18:00
''' Discussion with Jaime over Slack and parallel coding / troubleshooting '''
# Calculated the 4th lick - 3rd lick again, print it before testing the conditions
# Ran up to if statement and printed the non-distracted with each iteration
# Got rid of if clause after the else (if it isn't <1 it must be >1)
# Checking the addition of distracted/nondistracted in med file (correct)
# N distractors is right but is the classification of dis vs nondis?
# Checked and double checked that 1second was post distractor cut off (and tested other
#values just in case)
# Jaime made raster plot of licks and distractors, I made lick plot with distractors overlaid
# Aim to see where dodgy distractors are
# Are they close to a single lick or what is off?
# JEM tested Python vs med distracted or not array
# Extracted the distracted or not array from the med file and compared it to Python
# Possibly problem with MED not Python script, it is correctly identifying distractors
# JEM sent code for DistractionRasterFigures, reading over and will test tomorrow
''' 25/08/17 '''
# 12:00 - 13:15
# Meeting with Jaime to discuss MED problem and try to work out solution
# Discussed approach, try running the script with a file from when we had the
# timings of the distractors (*med was edited in distraction programme to
# create an array of distractor times, THPH1 data is the first to use it)
# JEM added in his medreader and isnumeric (returns variables as arrays, a, b, c etc..)
# Manually comapred the timings of the Python and Med outputs
# Python correctly identifying 3 lick bursts and distractors, MED missing some
# Med ACTUALLY delivering distractors at the wrong time, ocassionally missing 1 or 2 licks
# 3 licks in 1 second have occurred but med doesn't actually give distractor until next lick
# Need to determine HOW this is happening, what is the cut off or threshold for MED
# missing a distractor? Or delaying it to next lick
# JEM looking at this, plotted ILIs and pairs of ILIs, calculated discrepency in excel
# made raster plots and discussed code of these plots
# KP to also try plotting the ilis and looking visually at the data
# Frustrating and confusing. Come back tomorrow morning with fresh eyes
''' 26/08/17 '''
# 20:00 - 20:30
# Looking over DIS1 script
# Need to find alternative method to analyse data from DIS1 and DPCP1 where
# we don't have the times of the distractors
# will be informative once we have DPCP2 data
# Adding code to calculate 4 and 5 lick bursts as well as 3 licks
# work out percentage of these, added the following code:
# threeLickBurstsPercent = threeLickBursts/len(bursts)*100
# fourLickBurstsPercent = fourLickBursts/len(bursts)*100
# fiveLickBurstsPercent = fiveLickBursts/len(bursts)*100
# fig = plt.figure(figsize=(8, 4)) # Normal, standard size
# plt.hist(bursts, bins=50, histtype="step", cumulative='True', color='green', linewidth=2.0)
# plt.title('Cumulative HistogramBursts')
# plt.show()
# Cumulative percentage plots of 3,4 and 5 lick bursts using histogram func.
# Adapted the lick plots function, attempting to get cumulative plots
# think the axes are not right, step function not especially informative
# Need to add documentation, fix plotting axes and determine how to get the
# correct data on the plot
# Need to shorted and simplify the whole DIS1 script and add documentation
''' Slack discussion
1) Average burst length
2) Distribution of burst lengths. When the distractor is there,
even if python isn't detecting it at the same time as med,
we would expect this to go down as rats were more distracted
3) Percentage of 3,4 and 5lick bursts, compared to the rest
'''
''' 27/08/17 '''
# 20:00 - 21:00
# Editing lickplots to include all previously made figures
# Temporarily removing for loop (now uses a test case, or set list of test cases)
# does not make all figures for the entire metafile list
# can also fix this by adding an 'include' col and a conditional if include = 1
# Started basic version control by copying dis1_analysis and adding [2]
# Should look into GitHub and set this up for ease of use later
# Planning next steps to troubleshoot
# TOMORROW / TUESDAY
# 1) THPH 1 - matlab extraction script
# 2) THPH 1 - Python to accept matlab conversion files
# 3) THPH 1 - Find Python / Med mismatches
# 4) THPH 1 - calculate correct distraction times (if mismatch check next lick, if mismatch check next end)
# 5) DIS 1 - Plotting, fix cumalitive plots
# 6) DIS 1 - statistics, make means as table, info as table, percentages as tables
# Run t-tests in SPSS or Python/R, preliminary result
''' 28/08/17 '''
# 8:00 - 9:00
# Running THPH1 extraction script to see how it is working or not
# Find cas12 figure script and edit / re-write for THPH1 (and 2)
# Errors in matlab code, look at what cas12cols functions and
# cas12 plotting functions are doing
# what inputs are expected, what are given?
# Figure out what the script is doing then re-name and edit everything for THPH1/2
# ! THPH1_2_DataExtractionKP is the long version of the script (does what we
#want to be doing in Python, takes a long time for a single file as extracts
#everything)
# Remembered why JEM switched to the conversion script
# Need to find out why no distracted if no distractors (but why distractors?)
# Conversion script: TDT2MAT2PY, need to loop through all file paths in metafile
# (like Python meta file reader) to get function inputs
# trying to remember how to do for loops in matlab and what will be iterated over
# Started THPH1_analysisKP script to take matlab conversion files and work with them
# Reading through code in JM_custom_figs and JM_general_functions, for now adding in
# the functions I need to the script
# will eventually make my own modules to import (must be flexible and al purpose)
# at test stage I want to see everything in the script so debugging easier
# 14:30 - 15:00
# Reading through JM_Custom_figs and JM_CustomFunctions
# trying to see what I want to do and what JEM has already written
# Writing list of what outputs are needed from THPH1 analysis
''' 29/08/17 '''
# 12:45 - 14:00
# Discussing the MEd/Python issue with JEM, he identified the problem
# Issue is with MED, counting 1 second
# if the iteration or when it returns to the start of counting, happens
# to be in the middle of a 3 lick burst it will miss the licks which straddle
# the border
# JEM wrote function to check if the licks have fallen on the boundary / around it
# Together editing the script to remove redundant code and neaten it (DistractionCalc2)
# Writing postdistractionpause function, discussing how to implement this
# Not outputting plot, unsure why - need to give licks info
''' 30/08/17 '''
# 14:30 - 15:30
# Editing JEM_distractionCheckerScript to work without JM_CustomFig etc. imports
# Changing the letter index from JM medfilereader to work with dpcp files
# Figure out how to do this with dis1 files --> can this be done with dis 1 files?
# Yes, if we know from the licks when the distractors actially would be (Include the
# functions that calculate if on a boundary or not) we can back calculate when
# distracted or not from this
# Looking at changing styles, how to make points transparent, different properties
# PDP - work out if distracted or not, pause over which threshold (check med)
# 20:00 - 20:30
# Adding comments for readability
# Figured out how to add modules to PYTHONPATH with sys.append, add the string
# of the file location to the search path when importing modules
# Deciding convention and names for renaming modules of Jaime's
# and putting functions in a logical order within modules
# adding clear documentation
# 1) dataproc(for data processing, manipulation, import)
# 2) medfuncs (med pc related functions)
# 3) distcalcs (distraction calculations and processing)
# 4) distplts (distraction plots and figures)
#TO DO:
# Clean up all modules and add to the names listed above with all doc-strings
# Move end section of code to dis1/dpcp script (figure out how to read in and
# organise dis1)
# Start dpcp1, analyse data completely
''' 31/08/17 '''
# 15:30 - 16:10
# Creating medfuncs, writing docstrings for module and functions
# Creating dataproc, adding metafile reader and asnumeric functions with docstrings
# Creating distcals, adding functions from JEM and documentations
# Creating displts - looking through own function adn JEM custom figs *
''' 01/09/17 '''
# 20:00 - 20:30
# Working out what needs to be done for results section (very little actual Python, planning)
# 1) Dis1 - get data in (using KP or JEM medreader function, check both)
# 2) Analyse the percentage distracted and not distracted percentage (check same as before)
# 3) Calculate mean post distraction pause (each day, each rat, saved to array)
# 4) Do SPSS statistics
#a - ANOVA 1-Way on distracted or not
#b - ANOVA 1-Way on mean post distraction pause
#c - Make figures, typical licking figure (distracted vs not distracted example)
#d - Figure, percentage of 3,4 and 5 lick bursts distraction vs normal licking
#e - SPSS stats, percentage of 3 lick bursts (lick train and distraction) ANOVA
#f - average figure of some sort?
#g - GraphPad figures, licks, percent distracted, n distractors, post distraction pause
#g1 - pdp for distracted trials AS WELL as PDP for all trials
# 5) Dpcp1 - get data in using JEM medreader
# 6) Analyse percentage distracter vs notdistracted
#a - possible indexing issue, attempt to fix
# 7) Calculate mean post distraction pause (save to an array)
# 8) SPSS statistics
#a - ANOVA, pcp vs sal (percentage distracted - distracted or not)
#b - ANOVA, pcp vs sal, mean post distraction pause
#c - figure, cumulative licks (normal days) pcp vs sal
#d - figure cumulative licks
#e - figure, frequency of 3,4,5 lick bursts (distracted vs not), PCP vs SAL
#e1 - compare these percentages using SPSS ANOVA
#f - GraphPad figures, licks, percent distracted, n distractors, post distraction pause
#g1 - pdp for distracted trials AS WELL as PDP for all trials
# 9) THPH1/2 - finish matlab conversion script and run for all files (thph1 and thph2)
# 10) Figure out variable names and streams (may have problem combining thph1 and 2)
# 11) Get same behavioural results as DIS1 and DPCP1
#a - process in the same way as DIS1, info on licks in bursts etc.
# 12) THPH1 analysis
#a) Get the med/py problem fix into THPH script (test)
#b) Work out distracted vs not and post distraction pause
#c) Correlation graph between post distraction pause and percentage distracted?
#d) Allign data to distractors (all)
#e) Allign data to distracted and not distracted
''' Ran some test files through distraction checker, calculated mean and median PDPs
looked at plots, concerned over how often (or not) pause is long enough
Will be useful to make plots of ONLY distracted trials, or order by distracted
and not distracted, could attempt and then ask JEM about this
'''
''' 02/09/17 '''
# 10:30 - 13:30
# Removed code from JEM_distractionCalc module and saved only functions
# Created final DIS1 script
# Writing fo loop to go through all medfiles listed in metafile and calculate the
#Python times of distractors (before correcting with JEM calculation to actual med)
# Problem with for loop, want to loop all files and make a distracted array for
# each file which is then added to an array of those arrays
# currently keeps adding all to one long array with NDistractors being ALL
# possibly fixed, nested for loop, added a reset for pydis and moved the array
#of arrays to the end of the second loop (should equal 152 as 152 files)
# has calculated distractors on non-distracted days too
# edit to exlude these days (need to have an include column or some way to remove)
# for now, hard coded edit to just start the loop from the distracted days only
# [56:], working out dictionary indexing to access elements of a list
# Working out how to back calculate the ACTUAL distractor times using the med lick
# timestamps and the expected distractor times, with adjustment for the
# med problem using JEM py/med comparison
# Adding remcheck, distractioncalc2 and postdistractionpause to DIS1 script
# writing code to execute these functions on DIS1 data and find actual timings
# of distractors
# Trying to figure out the PDP for loop, want to calculate pdp for each distractor
# array in the array of arraysD (arrayofarrayD, rename this! - theroeticalDisAll)
# for loop problem again, not correctly updating the pdpALL list
# not sure about the indexing here, maybe need to enumerate?
# List comprehension index error
'''
pdp = [licks[idx+1]-val for idx, val in enumerate(licks) if val in distractions]
IndexError: index 1290 is out of bounds for axis 0 with size 1290
'''
# This was a problem earlier with single files, looks like there should be an extra
#value or a +1 , -1 somewhere? Breaks the for loop as cannot process the PDP
# re-wrote the list comprehension PDP code as a for loop and added conditional
# that value must not be greater than
# Adding try, except block into the PDP function to avoid index errors / bypass
'''
def postdistpause(distractions, licks):
try:
pdp = [licks[idx+1]-val for idx, val in enumerate(licks) if val in distractions]
return pdp
except IndexError:
pass
'''
# Noticed pdpAll is offset by 1 as the zero index is the first empty PDP assignment
# May want to go an delete the first or stop it saving the first
# For now REMEMBER this when looking for values indexing out by 1
# 14:00 - 15:30
# First item in pdpAll is an empty list, all files appart from the first worked
# try/except has not fixed the indexing issue, just ignored that first one
# didn't run the entire thing not just the last index
# Probelm with the try, except block as list comprehension
# Converting to for loop, index issues, added in try here and was infinately slow
# Think there is a problem with the multiple for loops
# Is the pdp function getting the correct inputs on each iteration?
# the correct licks and distractors?
# why is that variable not a global variabel?
# Function below seems to return the pdp, but only the first one of the list
'''
def postdistpause(distractions, licks):
count = 0
for val in licks:
if val in distractions:
pdp = licks[licks.index(val)+1] - val
return pdp
'''
#TODO
# 1) Use PDPs to caclulate distracted or not and check against metafile/med
# 2) Find means and medians of the PDPs in each sublist of AllPDP
# 3) Export this info to excel
# 4) Figure out why allPDP isn't a global variable but adjusted distractors is
''' 03/09/17 '''
# 13:00 - 13:30
# Made new DPCP1 script
# Put JEM medfile reader function in, read in a test file and checked which
# letters correspond to which arrays (want lick onset array)
# Checking layout of DPCP metafile, editing metafile reader for headers etc.
# Testing metaextractor and medfile reader on DPCP1 data files with test cases
# comparing to excel and sheets files. Correct n distractors calculated
# 19:00 - 20:00
# Checked that adjusted/calculated distractors were the same as meddistractors
# for dpcp1 files (they are)
# Trying to calculate distracted or not again, using distractors time list and post
# distraction pause
# FOllowing code (doesn't work but is closer)
'''
for ind, lists in enumerate(adjustedDistractors):
for value in lists:
if value in allLickDataArray[ind]: #if the value is in this list of licks (from all)
index = allLickDataArray[ind].index(value)
count += 1
pdp = allLickDataArray[ind][index+1] - allLickDataArray[ind][index]
pdpAll.append(pdp)
# For each index and list of distractors in the whole list of lists (112 lists)
within the list of distractors for the current file (the current list)for each value
(each distractor time in that list)
If the distractor time is in the alllickdataarray list of the same file (same index)
(otherwise doesn't access the correct licks, goes to the last array of licks)
Then finds the index of where it is in the licks array for that file
Uses the index to work out pdp
BUT - cannot get it to save the pdps back into lists (which for loop? just lon appended list)
AND - need to fix the try/except issue for index problems or add conditional
to exclude the distractor value where there is no PDP (last value)
'''
# Realised there is a difference between & and and! Use 'and' for boolean, & is bitwise
''' 04/09/17 '''
# 20:50 - 21:30
# Moving for loops around, trying to fix pdp issues
# Writing a work around, indexing / slicing the list into the length of distractors
''' 05/09/17 '''
# 20:30 - 21:00
# Reading through THPH1 script
# To do:
# read in data, metafile reader needs editing
# check format of metafile (end col?)
# thinking about differences between THPH1 and THPH2
# Reading about list comprehension (after earlier discussion with JEM about pdp issue)
''' 06/09/17 '''
# 13:00 - 14:00
# Talking about PDP loop issue with JEM
# PDP variable was not resetting inside the loop, so was carrying previous value
# back to next iteration and not adding correctly to the pdp list
# JEM moved pdp assignment into the first loop and it works!
# Looking at the debugger with JEM, seeing how it can be used to mark blocks of code
# looking at variables updating as iterations of the loops progress
# useful to see problems like the pdp one, exactly where the issue is
# tool can be very useful
''' 07/09/17 '''
# 10:00 - 11:00
# Discussing paper stats with JEM (Cas9 data)
# Talking about 2 way ANOVA and t-tests, why post hocs not needed
# Working out how to get R and Python integration to work
# Writing code to import csv. into r and getting that code to run in Python
# Anova produced same results as SPSS and ran from Python with the ro.r command
''' 08/09/17 '''
# Planning only no Python, deed to :
# Add PDP problem fix to the dis and dpcp1 scripts and check it works
# Add code for distracted and non-distracted
# Cross check with the information on the excel spreadsheet
# Produce plots, especially licking
''' 09/09/17 '''
# 11:00 - 12:00
# Found method to call R scripts (not commands, but whole scripts) in Python
# JEM method for calling commands is better, cannot install as admin so work around
# Useful to perform stats and pass output back to Python
# Writing distracted or not loop calculator (dpcp1)
# Working out how to store distracted or not for ALL in array (not just for a single test
# case)
# Storing values in the loop now fine, but distracted or not is out by a bit
# In most cases only wrong by 1, by 1 or 2 sometimes more)
# When working out total distractors Python is 1 less for some files, why? This contributes
# to the incorrect classificaiton but doesn't explain all of it
''' NEXT STEPS '''
'''
# 1) Put working PDP code from dpcp into dis 1 (and make a th behaviour only file do the same)
# 2) Figure out total distractors (why sometimes out by 1)
# 3) Figure out what is wrong with distracted or not calculation (not always out, but often 1 wrong)
4) Plots