Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit b539332

Browse files
authored
Merge pull request #2 from Yambottle/master
sglx_process_probe .json & .env is ready | tested running on EC2 as well
2 parents 5144c4b + 5760a15 commit b539332

5 files changed

Lines changed: 89 additions & 24 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,6 @@ target/
8282

8383
# macOS
8484
.DS_Store
85+
86+
#temp config file
87+
ecephys_spike_sorting/scripts/config

ecephys_spike_sorting/modules/catGT_helper/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def run_CatGT(args):
1818
if sys.platform.startswith('win'):
1919
# build windows command line
2020
catGTexe_fullpath = catGTPath.replace('\\', '/') + "/runit.bat"
21-
elif sys.platform.starstwith('linux'):
21+
elif sys.platform.startswith('linux'):
2222
catGTexe_fullpath = catGTPath.replace('\\', '/') + "/runit.sh"
2323
else:
2424
print('unknown system, cannot run CatGt')
@@ -59,7 +59,7 @@ def run_CatGT(args):
5959
print('CatGT command line:' + catGT_cmd)
6060

6161
start = time.time()
62-
subprocess.call(catGT_cmd)
62+
subprocess.call(cmd_parts)
6363

6464
execution_time = time.time() - start
6565

ecephys_spike_sorting/modules/mean_waveforms/__main__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,21 @@ def calculate_mean_waveforms(args):
8585

8686
print(cwaves_cmd)
8787

88+
cmd_parts = list()
89+
cmd_parts.extend([exe_path, ' -spikeglx_bin=', spikeglx_bin])
90+
cmd_parts.extend([' -clus_table_npy=', clus_table_npy])
91+
cmd_parts.extend([' -clus_time_npy=', clus_time_npy])
92+
cmd_parts.extend([' -clus_lbl_npy=', clus_lbl_npy])
93+
cmd_parts.extend([' -dest=', dest])
94+
cmd_parts.extend([' -samples_per_spike=', repr(args['mean_waveform_params']['samples_per_spike'])])
95+
cmd_parts.extend([' -pre_samples=', repr(args['mean_waveform_params']['pre_samples'])])
96+
cmd_parts.extend([' -num_spikes=', repr(args['mean_waveform_params']['spikes_per_epoch'])])
97+
cmd_parts.extend([' -snr_radius=', repr(args['mean_waveform_params']['snr_radius'])])
98+
print(cmd_parts)
99+
88100
# make the C_Waves call
89-
subprocess.call(cwaves_cmd)
101+
#subprocess.call(cwaves_cmd)
102+
subprocess.call(cmd_parts)
90103

91104
# for first version, retain original names
92105
if clu_version == 0:

ecephys_spike_sorting/scripts/create_input_json.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ def create_samba_directory(samba_server, samba_share):
1717

1818
return data_dir
1919

20-
def createInputJson(output_file,
20+
def createInputJson(
21+
output_file,
22+
ecephys_directory=None,
23+
kilosort_repository=None,
24+
KS2ver=None,
25+
npy_matlab_repository=None,
26+
catGTPath=None,
27+
tPrime_path=None,
28+
cWaves_path=None,
29+
kilosort_output_tmp=None,
2130
npx_directory=None,
2231
continuous_file = None,
2332
spikeGLX_data=True,
@@ -57,32 +66,32 @@ def createInputJson(output_file,
5766
ks_LTseed = 1,
5867
ks_templateRadius_um = 163,
5968
c_Waves_snr_um = 160,
60-
qm_isi_thresh = 1.5/1000
69+
qm_isi_thresh = 1.5/1000
6170
):
6271

6372
# hard coded paths to code on your computer and system
64-
ecephys_directory = r'D:\ecephys_fork\ecephys_spike_sorting\ecephys_spike_sorting'
65-
73+
# ecephys_directory = r'D:\ecephys_fork\ecephys_spike_sorting\ecephys_spike_sorting'
74+
# this is passed through arguements now
75+
6676
# location of kilosor respository and kilosort version
6777

68-
kilosort_repository = r'C:\Users\labadmin\Documents\jic\KS3_fork\Kilosort2'
69-
KS2ver = '2.0' # must equal '3.0', '2.5' or '2.0', and match the kiilosort_repository
70-
78+
# kilosort_repository = r'C:\Users\labadmin\Documents\jic\KS3_fork\Kilosort2'
79+
# KS2ver = '2.0' # must equal '3.0', '2.5' or '2.0', and match the kiilosort_repository
80+
# these are passed through arguements now
81+
7182
# KS 3.0 does not yet output pcs.
72-
if KS2ver == '3.0':
73-
include_pcs = False # set to false for KS2ver = '3.0'
74-
else:
75-
include_pcs = True
76-
77-
npy_matlab_repository = r'C:\Users\labadmin\Documents\jic\npy-matlab-master'
78-
catGTPath = r'C:\Users\labadmin\Documents\jic\CatGT-win'
79-
tPrime_path=r'C:\Users\labadmin\Documents\jic\TPrime-win'
80-
cWaves_path=r'C:\Users\labadmin\Documents\jic\C_Waves-win'
83+
include_pcs = KS2ver != '3.0'
8184

85+
#npy_matlab_repository = r'C:\Users\labadmin\Documents\jic\npy-matlab-master'
86+
#catGTPath = r'C:\Users\labadmin\Documents\jic\CatGT-win'
87+
#tPrime_path=r'C:\Users\labadmin\Documents\jic\TPrime-win'
88+
#cWaves_path=r'C:\Users\labadmin\Documents\jic\C_Waves-win'
89+
# these are passed through arguements now
90+
8291

8392
# for config files and kilosort working space
84-
kilosort_output_tmp = r'D:\kilosort_datatemp'
85-
93+
# kilosort_output_tmp = r'D:\kilosort_datatemp'
94+
# this is passed through arguements now
8695

8796
# derived directory names
8897

@@ -347,4 +356,4 @@ def createInputJson(output_file,
347356
with io.open(output_file, 'w', encoding='utf-8') as f:
348357
f.write(json.dumps(dictionary, ensure_ascii=False, sort_keys=True, indent=4))
349358

350-
return dictionary
359+
return dictionary

ecephys_spike_sorting/scripts/sglx_process_probe.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import sys
33
import subprocess
44
import json
5+
from dotenv import load_dotenv
56

7+
sys.path.append(os.path.dirname(__file__))
68
from helpers import SpikeGLX_utils
79
from helpers import log_from_json
810
from helpers import run_one_probe
@@ -22,6 +24,14 @@ def run_probe(prb, json_directory, npx_directory,
2224
catGT_loccar_min_um, catGT_loccar_max_um,
2325
catGT_cmd_string,
2426
ks_Th, refPerMS,
27+
ecephys_directory=None,
28+
kilosort_repository=None,
29+
KS2ver=None,
30+
npy_matlab_repository=None,
31+
catGTPath=None,
32+
tPrime_path=None,
33+
cWaves_path=None,
34+
kilosort_output_tmp=None,
2535
ks_remDup=0,
2636
ks_saveRez=1,
2737
ks_copy_fproc=0,
@@ -31,6 +41,19 @@ def run_probe(prb, json_directory, npx_directory,
3141
c_Waves_snr_um=160,
3242
ni_present=True,
3343
ni_extract_string=None):
44+
# load external tool path from .env if not given from .json
45+
dot_env_path = "config/sglx_process_probe.json"
46+
if os.path.exists(dot_env_path):
47+
load_dotenv(dot_env_path)
48+
ecephys_directory=ecephys_directory or os.getenv('ecephys_directory')
49+
kilosort_repository=kilosort_repository or os.getenv('kilosort_repository')
50+
KS2ver=KS2ver or os.getenv('KS2ver')
51+
npy_matlab_repository=npy_matlab_repository or os.getenv('npy_matlab_repository')
52+
catGTPath=catGTPath or os.getenv('catGTPath')
53+
tPrime_path=tPrime_path or os.getenv('tPrime_path')
54+
cWaves_path=cWaves_path or os.getenv('cWaves_path')
55+
kilosort_output_tmp=kilosort_output_tmp or os.getenv('kilosort_output_tmp')
56+
3457
# build path to the first probe folder; look into that folder
3558
# to determine the range of trials if the user specified t limits as
3659
# start and end
@@ -69,6 +92,14 @@ def run_probe(prb, json_directory, npx_directory,
6992
input_meta_fullpath = os.path.join(input_data_directory, metaName)
7093
print(input_meta_fullpath)
7194
createInputJson(catGT_input_json,
95+
ecephys_directory=ecephys_directory,
96+
kilosort_repository=kilosort_repository,
97+
KS2ver=KS2ver,
98+
npy_matlab_repository=npy_matlab_repository,
99+
catGTPath=catGTPath,
100+
tPrime_path=tPrime_path,
101+
cWaves_path=cWaves_path,
102+
kilosort_output_tmp=kilosort_output_tmp,
72103
npx_directory=npx_directory,
73104
continuous_file=continuous_file,
74105
kilosort_output_directory=catGT_dest,
@@ -105,6 +136,14 @@ def run_probe(prb, json_directory, npx_directory,
105136
print(continuous_file)
106137
print('ks_Th: ' + repr(ks_Th) + ' ,refPerMS: ' + repr(refPerMS))
107138
createInputJson(module_input_json,
139+
ecephys_directory=ecephys_directory,
140+
kilosort_repository=kilosort_repository,
141+
KS2ver=KS2ver,
142+
npy_matlab_repository=npy_matlab_repository,
143+
catGTPath=catGTPath,
144+
tPrime_path=tPrime_path,
145+
cWaves_path=cWaves_path,
146+
kilosort_output_tmp=kilosort_output_tmp,
108147
npx_directory=npx_directory,
109148
continuous_file=continuous_file,
110149
spikeGLX_data=True,
@@ -149,10 +188,11 @@ def run_probe(prb, json_directory, npx_directory,
149188
logFullPath)
150189

151190

152-
if __name__ == '__main__':
191+
#if __name__ == '__main__':
192+
def main():
153193
json_fp = sys.argv[1]
154194

155195
with open(json_fp) as f:
156196
kwargs = json.load(f)
157197

158-
run_one_probe(**kwargs)
198+
run_probe(**kwargs)

0 commit comments

Comments
 (0)