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

Commit 6a15c93

Browse files
authored
Merge branch 'master' into master
2 parents 4561de4 + 86de15d commit 6a15c93

5 files changed

Lines changed: 22 additions & 15 deletions

File tree

ecephys_spike_sorting/modules/kilosort_helper/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def run_kilosort(args):
4040
# chanMap.mat section
4141
metaName = (Path(args['ephys_params']['ap_band_file']).parent / Path(args['ephys_params']['ap_band_file']).stem).as_posix()
4242

43+
4344
if not args['kilosort_helper_params'].get('chanMap_pregenerated', False):
4445
# generate and write chanMap.mat file - different implementation for SpikeGLX and Open Ephys
4546
if args['kilosort_helper_params']['spikeGLX_data']:
@@ -88,7 +89,8 @@ def run_kilosort(args):
8889
os.path.basename(args['ephys_params']['ap_band_file']),
8990
args['kilosort_helper_params']['kilosort_params'])
9091

91-
elif args['kilosort_helper_params']['kilosort_version'] == 2:
92+
elif args['kilosort_helper_params']['kilosort_version'] == 2 \
93+
or args['kilosort_helper_params']['kilosort_version'] == 3:
9294

9395
matlab_file_generator.create_config2(args['kilosort_helper_params']['matlab_home_directory'],
9496
output_dir_forward_slash,

ecephys_spike_sorting/modules/kilosort_helper/_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ class OutputParameters(OutputSchema):
9292
mask_channels = NumpyArray()
9393
nTemplate = Int()
9494
nTot = Int()
95-
95+

ecephys_spike_sorting/modules/tPrime_helper/__main__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
def call_TPrime(args):
15-
1615
# Run TPrime on a "standard" multiprobe + NI, using NP 1.0 or 2.0, with run
1716
# folder and probe folders
1817
# inputs:
@@ -114,7 +113,7 @@ def call_TPrime(args):
114113
toStream_path = os.path.join(run_directory, prb_dir, c_name)
115114

116115
# convert events in the toStream to sec; they will not be adjusted
117-
ks_outdir = 'imec' + str(toStream_prb) + '_ks2'
116+
ks_outdir = 'imec' + str(toStream_prb) + '_ks' + args['kilosort_helper_params']['kilosort2_params']['KSver']
118117
st_file = os.path.join(run_directory, prb_dir, ks_outdir, 'spike_times.npy')
119118
# convert to seconds; if bNPY = True, returned file is an npy file
120119
# otherwise, text.
@@ -151,7 +150,7 @@ def call_TPrime(args):
151150
from_list.append(os.path.join(run_directory, prb_dir, c_name))
152151
c_index = len(from_stream_index)
153152
# build path to spike times npy file
154-
ks_outdir = 'imec' + str(c_prb) + '_ks2'
153+
ks_outdir = 'imec' + str(c_prb) + '_ks' + args['kilosort_helper_params']['kilosort2_params']['KSver']
155154
st_file = os.path.join(run_directory, prb_dir, ks_outdir, 'spike_times.npy')
156155
st_file_sec = spike_times_npy_to_sec(st_file, 0, bNPY)
157156
events_list.append(st_file_sec)
@@ -236,7 +235,7 @@ def call_TPrime(args):
236235
from_list.append(os.path.join(run_directory, prb_dir, c_name))
237236
c_index = len(from_stream_index)
238237
# build path to spike times npy file
239-
ks_outdir = 'imec' + str(c_prb) + '_ks2'
238+
ks_outdir = 'imec' + str(c_prb) + '_ks' + args['kilosort_helper_params']['kilosort2_params']['KSver']
240239
st_file = os.path.join(run_directory, prb_dir, ks_outdir, 'spike_times.npy')
241240
st_file_sec = spike_times_npy_to_sec(st_file, 0, bNPY)
242241
events_list.append(st_file_sec)
@@ -262,25 +261,27 @@ def call_TPrime(args):
262261
# Essential in linux where TPrime executable is only callable through runit
263262
if sys.platform.startswith('win'):
264263
exe_path = os.path.join(args['tPrime_helper_params']['tPrime_path'], 'runit.bat')
265-
elif sys.platform.starstwith('linux'):
264+
elif sys.platform.startswith('linux'):
266265
exe_path = os.path.join(args['tPrime_helper_params']['tPrime_path'], 'runit.sh')
267266
else:
268267
print('unknown system, cannot run TPrime')
269268

270269
# Print out command for help with debugging
271-
tcmd = exe_path + ' -syncperiod=' + repr(sync_period) + \
272-
' -tostream=' + toStream_path
270+
tcmd = list()
271+
tcmd.append(exe_path)
272+
tcmd.append(' -syncperiod=' + repr(sync_period))
273+
tcmd.append(' -tostream=' + toStream_path)
273274

274275
for i, fp in enumerate(from_list):
275-
tcmd = tcmd + ' -fromstream=' + repr(i) + ',' + fp
276+
tcmd.append(' -fromstream=' + repr(i) + ',' + fp)
276277

277278
for i, ep in enumerate(events_list):
278-
tcmd = tcmd + ' -events=' + repr(from_stream_index[i]) + ',' + ep + ',' + out_list[i]
279+
tcmd.append(' -events=' + repr(from_stream_index[i]) + ',' + ep + ',' + out_list[i])
279280

280281
# write out file to record the TPrime command for a record
281282
bat_path = os.path.join(run_directory, run_name + '_TPrime_cmd.txt')
282283
with open(bat_path, 'w') as batfile:
283-
batfile.write(tcmd)
284+
batfile.write(str(tcmd))
284285

285286

286287
# make the TPrime call
@@ -347,7 +348,7 @@ def call_TPrime_3A(args):
347348
# convert events in the toStream to sec; they will not be adjusted
348349
# search the directory the edges file to get the ks2 output
349350
# get name of ks2 output dir and convert to sec
350-
ks_outdir = fnmatch.filter(file_list, 'imec_*_ks2')[0]
351+
ks_outdir = fnmatch.filter(file_list, 'imec_*_ks' + args['kilosort_helper_params']['kilosort2_params']['KSver'])[0]
351352
st_file = os.path.join(toStream_parent, ks_outdir, 'spike_times.npy')
352353
toStream_events_sec = spike_times_npy_to_sec(st_file, 0, bNPY)
353354
# for later data analysis with spike times as sec, also save as npy
@@ -367,7 +368,7 @@ def call_TPrime_3A(args):
367368
return
368369
fS_name = flt_list[0]
369370
fS_file_list.append(os.path.join(fS_parent,fS_name))
370-
ks_outdir = fnmatch.filter(file_list, 'imec_*_ks2')[0]
371+
ks_outdir = fnmatch.filter(file_list, 'imec_*_ks' + args['kilosort_helper_params']['kilosort2_params']['KSver'])[0]
371372
st_file = os.path.join(fS_parent, ks_outdir, 'spike_times.npy')
372373
st_file_sec = spike_times_npy_to_sec(st_file, 0, bNPY)
373374
events_list.append(st_file_sec)

ecephys_spike_sorting/modules/tPrime_helper/_schemas.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from argschema.fields import Nested, InputDir, String, Float, Dict, Int, List, Boolean
44
from ...common.schemas import EphysParams, Directories
55
from ..catGT_helper._schemas import CatGTParams
6+
from ..kilosort_helper._schemas import KilosortHelperParameters
67

78

89
class tPrimeParams(DefaultSchema):
@@ -19,6 +20,7 @@ class tPrimeParams(DefaultSchema):
1920
class InputParameters(ArgSchema):
2021
tPrime_helper_params = Nested(tPrimeParams)
2122
catGT_helper_params = Nested(CatGTParams)
23+
kilosort_helper_params = Nested(KilosortHelperParameters)
2224
directories = Nested(Directories)
2325
ephys_params = Nested(EphysParams)
2426

@@ -31,4 +33,4 @@ class OutputSchema(DefaultSchema):
3133
class OutputParameters(OutputSchema):
3234

3335
execution_time = Float()
34-
36+

ecephys_spike_sorting/scripts/create_input_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,7 @@ def createInputJson(
396396

397397
with io.open(output_file, 'w', encoding='utf-8') as f:
398398
f.write(json.dumps(dictionary, ensure_ascii=False, sort_keys=True, indent=4))
399+
if sys.platform == 'linux':
400+
os.chmod(output_file, 0o664)
399401

400402
return dictionary

0 commit comments

Comments
 (0)