Skip to content

Commit c1ee721

Browse files
committed
exporting spike list
1 parent d00761f commit c1ee721

5 files changed

Lines changed: 83 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ ENV/
107107
patchview/*~
108108
patchview/.gitignor~
109109
patchview/hooks/*
110+
patchview/build/*
111+
patchview/dist/*
110112
.editorconfig
111113

112114
.vscode

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ PatchView
2323
:target: https://doi.org/10.21105/joss.04706
2424
.. image:: https://img.shields.io/pypi/dm/patchview?label=pypi%20downloads
2525

26+
27+
.. image:: docs/resources/images/patchview_ads.png
28+
:width: 800
29+
:alt: Alternative text
30+
2631
PatchView perform data analysis and visualization on multi channel whole-cell recording (multi-patch) data, including firing pattern analysis, event analysis,
2732
synaptic connection detection, morphological analysis and more.
2833

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'''
2+
Example of how to load the spike list output by Patchview.
3+
And plot the spike waveforms of the first sweep of each neuron
4+
'''
5+
import pickle
6+
import matplotlib.pyplot as plt
7+
8+
dataName = 'Aligned_spike_list3.pickle'
9+
# load the spike list
10+
with open(dataName, 'rb') as f:
11+
spike_list = pickle.load(f)
12+
13+
# get the names of the neurons
14+
neuronNames = list(spike_list.keys())
15+
16+
# an example of how to plot the spike waveforms of the first neuron
17+
firstSpikeOnly = True
18+
plt.figure()
19+
for neuron in neuronNames: # get the name of neuron
20+
sweep_names = sorted(list(spike_list[neuron].keys())) # get the names of the sweeps
21+
print(f'Cell {neuron} has {len(sweep_names)} sweeps')
22+
if len(sweep_names) > 0:
23+
24+
## plot the spike waveforms of this neuron's first sweep above rehbose
25+
sw = sweep_names[0]
26+
if firstSpikeOnly:
27+
plt.plot(spike_list[neuron][sw][:,0])
28+
else:
29+
plt.plot(spike_list[neuron][sw])
30+
31+
## all sweeps
32+
# for sw in sweep_names:
33+
# if firstSpikeOnly:
34+
# plt.plot(spike_list[neuron][sw][:,0])
35+
# else:
36+
# plt.plot(spike_list[neuron][sw])
37+
38+
plt.xlabel('Time (ms)')
39+
plt.ylabel('Voltage (mV)')
40+
plt.title(f'Spike waveforms of {neuron}')
41+
plt.show()

patchview/patchview.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import time as sysTime
3535
from copy import deepcopy
3636
import glob
37+
import pickle
3738
from patchview.utilitis.linecollection_update import FigureUpdater
3839
from patchview.utilitis.debugHelpers import debugInfo
3940
from patchview.utilitis.AnalysisMethods import (
@@ -1762,7 +1763,7 @@ def event_pd_stateChange(self, param, changes):
17621763
df.to_csv(f, header=True, line_terminator="\n")
17631764

17641765
def exportFile(self, title=None, defaultName=None, extension="all files (*.*)"):
1765-
fileName = QtGui.QFileDialog.getSaveFileName(
1766+
fileName = QtWidgets.QFileDialog.getSaveFileName(
17661767
None, title, defaultName, extension
17671768
)
17681769
if isinstance(fileName, tuple):
@@ -3715,7 +3716,7 @@ def save_clicked(self):
37153716

37163717
def saveSingleSeries(self, sel):
37173718
fileName = self.getSaveFileName()
3718-
import pickle
3719+
37193720

37203721
if fileName != "":
37213722
self.statusBar.showMessage("Saving " + fileName[:-4], 3000)
@@ -4169,7 +4170,8 @@ def getEphyFeatures(self):
41694170
baseline_interval=baseline_interval1,
41704171
baseline_detect_thresh=baseline_detect_thresh1,
41714172
)
4172-
4173+
self.ephyFpObjectList = {}
4174+
self.ephyFpObjectList[self.currentPulseTree.dat_file[:-4]] = self.EphyFeaturesObj
41734175
# fileName = self.currentPulseTree.dat_file[:-4]+'_Series' + str(sel.index[1]+1) + '_'+ sel.node.Label+'_PvSpikeFeatures.pdf'
41744176
self.plot_splitter.setStretchFactor(1, 3)
41754177
self.topPlot_splitter.setStretchFactor(1, 1)
@@ -4529,6 +4531,7 @@ def checkEvent_action_clicked(self):
45294531

45304532
def checkFP_action_clicked(self):
45314533
# debugInfo('', True)
4534+
self.ephyFpObjectList = {}
45324535
self.visulization_view.setCurrentIndex(1)
45334536
(
45344537
bundleFiles,
@@ -4556,7 +4559,7 @@ def checkFP_action_clicked(self):
45564559
pars = self.splitViewTab_FP.getParTreePars(
45574560
"Data selection"
45584561
) # self.fpParTree_data_view.p
4559-
4562+
45604563
for file_idx, bundle in enumerate(bundleFiles):
45614564
sel = serieIndex[file_idx]
45624565
stimChanIndex = stimChanLabels[file_idx]
@@ -4633,7 +4636,7 @@ def checkFP_action_clicked(self):
46334636
)
46344637

46354638
self.updateEphyTable(sw, self.splitViewTab_FP.tables["Sweep features"], ephObj.title)
4636-
4639+
self.ephyFpObjectList[cellName] = ephObj
46374640
print(cellName, "done!")
46384641
# except:
46394642
# print(cellName, 'failed!')
@@ -7238,6 +7241,7 @@ def plot_dvdt_v_phasePlot(self, v_spike, dvdt_spike, sweepNumber, plotWidget):
72387241
+ str(v_spike.shape[1])
72397242
)
72407243
return plt
7244+
72417245
def plot_alignedSpikes_SingleTrace_NWB(self, stim, data):
72427246
## TODO: make use of cached analysis data
72437247
pass
@@ -8037,7 +8041,24 @@ def spike_detection_event(self, param, changes):
80378041
)
80388042
)
80398043
self.showdialog(f"{seriesName} saved!")
8044+
elif childName == "Aligned spike list":
8045+
if hasattr(self, "ephyFpObjectList") and len(self.ephyFpObjectList)>0:
8046+
df = {}
8047+
for ephyFpObject in self.ephyFpObjectList:
8048+
eobj = self.ephyFpObjectList[ephyFpObject]
8049+
eobj.alignSpikes()
8050+
## convert a dictionary with key as sweep number and value as a list of spike times
8051+
## to a dataframe with columns as sweep number and rows as spike times
8052+
df[ephyFpObject] = eobj.spikeList
80408053

8054+
fileName = self.exportFile(
8055+
title="Save spike waveforms",
8056+
defaultName="Aligned_spike_list.pickle",
8057+
extension="Pickle files (*.pickle)",
8058+
)
8059+
if fileName != []:
8060+
with open(fileName, "wb") as fd:
8061+
pickle.dump(df, fd)
80418062
def main(app):
80428063
main = MainWindow(app)
80438064
main.mainFrame.show()

patchview/utilitis/AllMyParsHere.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,16 @@
252252
{"name": "Save all tables", "type": "action"},
253253
],
254254
},
255+
{
256+
"name": "Export",
257+
"type": "group",
258+
"children": [
259+
{"name": "Aligned spike list", "type": "action"},
260+
261+
],
262+
},
255263
]
264+
#self.ephyFpObjectList
256265

257266
fp_analysis_spikeDetection_help = [
258267
{

0 commit comments

Comments
 (0)