Repository navigation
Expand file tree
/
Copy pathquick_analysis_template.py
More file actions
executable file
·110 lines (88 loc) · 3.78 KB
/
Copy pathquick_analysis_template.py
File metadata and controls
executable file
·110 lines (88 loc) · 3.78 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
#!/usr/bin/env python
"""
Quick Analysis Template
Simple template for analyzing a single FOV. Just edit the paths below and run!
Usage:
python quick_analysis_template.py
"""
from pathlib import Path
from fov_utils import create_fov_from_stimfile
from ophys_analysis import (
extract_suite2p_traces,
save_extraction_hdf5,
create_full_analysis_report,
)
# ============================================================================
# EDIT THESE PATHS FOR YOUR ANALYSIS
# ============================================================================
# Path to your data directory (contains suite2p/, t00016/, etc.)
DATA_DIR = r'X:/Experimental_Data/BrainImaging/20251113_Derrick'
# Path to your stimulus file (or set to None to auto-detect)
# When None, it will search in Spk2 subdirectories (t00016/, t00017/, etc.)
STIM_FILE = None # Auto-detect .py file in t00016/ etc.
# Or specify exact path:
# STIM_FILE = r'X:/Experimental_Data/BrainImaging/20251113_Derrick/t00016/driftinggrating_orientation.py'
# Output directory for results
OUTPUT_DIR = r'X:/Experimental_Data/BrainImaging/20251113_Derrick/analysis_results'
# Experimental parameters
IMAGING_FILES = [0] # Which imaging file(s) to use
SPK2_FILES = [16] # ACTUAL Spk2 directory number (for t00016/, use [16] not [0]!)
BRAIN_REGION = 'V1' # Brain region
FACTOR = 1 # Downsampling factor
# Analysis filtering (optional)
FIT_R_THRESHOLD = None # Set to e.g. 0.9 to only include cells with good Gaussian fit
# ============================================================================
# ANALYSIS CODE (no need to edit below)
# ============================================================================
def main():
print("="*70)
print("QUICK FOV ANALYSIS")
print("="*70)
print(f"Data directory: {DATA_DIR}")
print(f"Output directory: {OUTPUT_DIR}")
print()
# Create output directory
output_path = Path(OUTPUT_DIR)
output_path.mkdir(parents=True, exist_ok=True)
# Stimulus file will be auto-detected by create_fov_from_stimfile
# It searches in Spk2 subdirectories (t00016/, etc.) automatically
# Step 1: Configure FOV
print("\n[1/4] Configuring FOV...")
fov = create_fov_from_stimfile(
stimfile=STIM_FILE, # None = auto-detect in Spk2 subdirectories
TifStack_path=DATA_DIR,
ImagingFile=IMAGING_FILES,
Spk2File=SPK2_FILES,
factor=FACTOR,
brain_region=BRAIN_REGION,
)
print(f" Animal: {fov.animal_name}")
print(f" Recording date: {fov.recording_date}")
print(f" Stim type: {fov.stim_type}")
# Step 2: Extract traces
print("\n[2/4] Extracting Suite2P traces...")
ce = extract_suite2p_traces(fov, fnum=0)
print()
ce.print_summary()
# Create output subdirectory named after ImagingFile (e.g., t0, t1, etc.)
imaging_file_num = fov.ImagingFile[0] if isinstance(fov.ImagingFile, list) else fov.ImagingFile
report_path = output_path / f"t{imaging_file_num}"
report_path.mkdir(parents=True, exist_ok=True)
# Step 3: Save to HDF5 in the same subdirectory
print("\n[3/4] Saving extraction results...")
h5_file = report_path / 'extraction_results.h5'
save_extraction_hdf5(ce, str(h5_file))
# Step 4: Generate full analysis report
print("\n[4/4] Generating analysis report...")
create_full_analysis_report(ce, output_dir=str(report_path), fit_r_threshold=FIT_R_THRESHOLD)
print(f"\n{'='*70}")
print("ANALYSIS COMPLETE!")
print(f"{'='*70}")
print(f"All outputs saved to: {report_path}")
print(f" - extraction_results.h5")
print(f" - population_summary.png")
print(f" - orientation_maps.png")
print(f" - tuning_distributions.png")
print(f" - cell_*_tuning.png (first 10 responsive cells)")
if __name__ == '__main__':
main()