Skip to content

Commit 61fe418

Browse files
committed
code for the publication
1 parent c69956a commit 61fe418

File tree

120 files changed

+9505
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+9505
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
# models-and-analysis-of-theta-phase-coding
1+
Created by Eloy Parra Barrero; [email protected]; 2021-05-21
2+
3+
Code for the analyses included in:
4+
### Neuronal sequences during theta rely on behavior-dependent spatial maps
5+
### (Parra-Barrero, E., Diba, K., Cheng, S., 2021)
6+
7+
The files in the main folder define the classes used for the analyses included in the paper (and a bit more).
8+
The files in ./analyze run the analyses. ./analyze also contains the following folders:
9+
10+
- parameters - contains parameter files (paper.json defines the parameters used in the paper)
11+
- fields - contains the info defining the manually screened place fields
12+
- sessions - contains files with general info / parameters specific to each experimental session
13+
14+
#### Usage:
15+
1. Download the datasets hc-3 and hc-11 from crncs.org
16+
1. Change the paths defined in ./analyze/config.py
17+
1. Run individual analyses (e.g., ./analyze/run_firing_fields.py) or run a batch of analyses.
18+
19+
For running a batch of analyses, first choose what to analyze in ./analyze/batch_config.py,
20+
then run ./analyze/batch_analyses.py and plot the results with ./analyze/batch_plots.py.
21+
batch_plots.py produces all of the summary figures of the paper.
22+
23+
Some of the objects created for the analyses require a lot of computation, so they are saved as pickles and loaded again
24+
when required, unless the code or the parameters of the object or one of its dependencies has changed, in which case
25+
a new object is created.
26+
27+
To discard the manually screened fields and screen them again, delete the corresponding file(s) in ./analyze/fields and
28+
run any code that will initialize a FiringFields instance (e.g., ./analyze/batch_analyses.py). However, this will not
29+
work if an old pickle of FiringFields will be loaded, so delete the pickles or introduce some dummy change in the code
30+
or in the parameters to trigger a new instance of FiringFields to be initialized.

analyze/batch_analyses.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import json
3+
from data_analysis.initializer import initialize
4+
from data_analysis.analyze.batch_config import sessions, group_names, experimental_group_name
5+
from data_analysis.analyze.run_tracking import run_tracking, Tracking
6+
from data_analysis.lfp import LFP
7+
from data_analysis.analyze.run_firing_fields import run_firing_fields, FiringFields
8+
from data_analysis.analyze.run_phase_vs_position import run_phase_vs_position, PhaseVsPosition
9+
from data_analysis.analyze.run_decoder import run_path_lengths, PathLengths
10+
from data_analysis.analyze.run_cell_coordination import run_cell_coordination, CellCoordination
11+
12+
13+
def analyze(session, group_name):
14+
15+
if group_name == experimental_group_name:
16+
tracking = initialize((Tracking,), session, group_name)['Tracking']
17+
run_tracking(tracking)
18+
del tracking
19+
20+
# place field sizes and skews
21+
firing_fields = initialize((FiringFields,), session, group_name)['FiringFields']
22+
run_firing_fields(firing_fields)
23+
del firing_fields
24+
25+
# phase precession slopes
26+
phase_vs_position = initialize((PhaseVsPosition,), session, group_name)['PhaseVsPosition']
27+
run_phase_vs_position(phase_vs_position)
28+
del phase_vs_position
29+
30+
# theta trajectory lengths
31+
path_lengths = initialize((PathLengths,), session, group_name)['PathLengths']
32+
run_path_lengths(path_lengths)
33+
del path_lengths
34+
35+
# variance in pairwise spike phases
36+
cell_coordination = initialize((CellCoordination,), session, group_name)['CellCoordination']
37+
run_cell_coordination(cell_coordination)
38+
del cell_coordination
39+
40+
41+
for session in sessions:
42+
# check that there are fields defined for all sessions
43+
for group_name in group_names:
44+
if not os.path.exists(f"fields/{session}.{group_name}.json"):
45+
firing_fields = initialize((FiringFields,), session, group_name)
46+
del firing_fields
47+
# check that a best phase shift has been calculated
48+
with open(f"sessions/{session}.json", 'r') as f:
49+
session_dict = json.load(f)
50+
if 'phase_shift' not in session_dict:
51+
phase_vs_position = initialize((PhaseVsPosition, ), session, experimental_group_name)['PhaseVsPosition']
52+
phase_vs_position.find_theta_0(min_shift=-60, max_shift=60, num_shifts=61)
53+
54+
# run analyses and plot results
55+
for session in sessions:
56+
print(f"\nAnalyzing session {session}...")
57+
58+
for group_name in group_names:
59+
analyze(session, group_name)
60+
61+
62+
63+

analyze/batch_config.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os
2+
from data_analysis.analyze.config import experimental_group_name, figures_path
3+
4+
5+
# select which sessions to analyze
6+
sessions = [
7+
"ec013.156",
8+
"ec013.206",
9+
"ec013.374",
10+
"ec013.386",
11+
"ec013.388",
12+
"ec013.395",
13+
"ec013.412",
14+
"ec013.413",
15+
"ec013.440",
16+
"ec013.454",
17+
"ec013.466",
18+
"ec013.469",
19+
"ec013.502",
20+
"ec013.531",
21+
# only these three sessions were used in the models for ec013:
22+
"ec013.555",
23+
"ec013.556",
24+
"ec013.574",
25+
26+
"ec014.468",
27+
"ec014.639",
28+
29+
"ec016.233",
30+
"ec016.234",
31+
"ec016.269",
32+
33+
# These discard the first 5 minutes of the recordings:
34+
"Achilles.10252013_alt",
35+
"Buddy.06272013_alt",
36+
"Cicero.09012014_alt",
37+
"Cicero.09172014_alt",
38+
39+
# Original:
40+
# "Achilles.10252013",
41+
# "Buddy.06272013",
42+
# "Cicero.09012014",
43+
# "Cicero.09172014",
44+
# "Gatsby.08022013" # No phase precession
45+
46+
# "vvp01.1021",
47+
# "vvp01.1815",
48+
# "gor01.1315"
49+
]
50+
51+
rats = []
52+
for session in sessions:
53+
rat = session.split('.')[0]
54+
if rat not in rats:
55+
rats.append(rat)
56+
57+
# select what to analyze: experimental data and/or models
58+
group_names = [
59+
experimental_group_name, # experimental data
60+
# 'Time', # temporal sweep model
61+
# 'Position', # spatial sweep model
62+
# 'SpeedDep57', # behavior-dependent sweep model
63+
# 'VariableNoise' # variable noise model
64+
]
65+
66+
figures_path = f"{figures_path}/ALL"
67+
for group_name in group_names:
68+
path = f"{figures_path}/{group_name}"
69+
if not os.path.isdir(path):
70+
os.makedirs(path)
71+
72+

0 commit comments

Comments
 (0)