Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeitgeberH committed May 19, 2024
2 parents 02fa9d9 + 968233b commit 2a68234
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
63 changes: 38 additions & 25 deletions patchview/patchview.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

patchview_dir, this_filename = os.path.split(__file__)
appname = "Patchview"
__version__ = "0.3.0.0"
__version__ = "0.3.2"

class MainWindow(QtWidgets.QMainWindow):
"""
Expand Down Expand Up @@ -625,16 +625,14 @@ def updateEventMarker(self, ltype, lineIdx, lval):
if self.events.eventMarker != None:
scatterPlot = self.events.eventMarker
penColor = (
scatterPlot.getSpotOpts(scatterPlot.data[lineIdx])[2]
.color()
.getRgb()
scatterPlot.data[lineIdx][-2].pen().color().getRgb()
)
if penColor[0] > 0:
pc = "g" ## change r to g
else:
pc = "r" ## change g to r
spotsPen = [scatterPlot.getSpotOpts(yy)[2] for yy in scatterPlot.data]
spotsBrush = [scatterPlot.getSpotOpts(yy)[3] for yy in scatterPlot.data]
spotsPen = [yy[-2].pen() for yy in scatterPlot.data]
spotsBrush = [yy[-2].brush() for yy in scatterPlot.data]
spotsPen[lineIdx] = pg.mkPen(pc)
spotsBrush[lineIdx] = pg.mkBrush(pc)
scatterPlot.setPen(spotsPen)
Expand Down Expand Up @@ -2058,9 +2056,12 @@ def event_save2TableAllSweep(self):
return
eventMarkers = self.events.eventMarker
eventPenRvalue = [
eventMarkers.getSpotOpts(yy)[2].color().getRgb()[0]
# eventMarkers.getSpotOpts(yy)[2].color().getRgb()[0]
# eventMarkers.opts[idx]["pen"].color().getRgb()[0]
yy[-2].pen.color().getRgb()[0] if yy[-2] else 0
for yy in eventMarkers.data
] # red is for disabled one

autoType = [
True if eventPenRvalue[idx] == 0 else False
for idx, index in enumerate(self.events.peakIndex)
Expand Down Expand Up @@ -2706,14 +2707,15 @@ def detectEventForAllSweeps_abf(self):

self.events.isConcat = True
self.events.traceYUnit = self.currentPulseTree.abf.yUnits
if self.events.traceYUnit == "V" or self.events.traceYUnit == "mV":
if 'v' in self.events.traceYUnit.lower():
outlierCutoff_LV = pv["PSP Outliers"][1][
"Outlier voltage (mV) - lower bound"
][0]
outlierCutoff_UV = pv["PSP Outliers"][1][
"Outlier voltage (mV) - upper bound"
][0]
outlierCutoff_rv = pv["PSP Outliers"][1]["replacement value"][0]
rmSpks = True
else:
outlierCutoff_LV = pv["PSC Outliers"][1][
"Outlier voltage (pA) - lower bound"
Expand All @@ -2722,6 +2724,7 @@ def detectEventForAllSweeps_abf(self):
"Outlier voltage (pA) - upper bound"
][0]
outlierCutoff_rv = pv["PSC Outliers"][1]["replacement value"][0]
rmSpks = False

## read data
time, data = self.extractSingleSeries_ABF(series_index)
Expand All @@ -2734,19 +2737,19 @@ def detectEventForAllSweeps_abf(self):
data, highCutOff=hfcut, lowCutOff=lfcut, useButter=True
)
time = np.arange(len(data)) / self.parameters["fs"]

baseline_ = np.mean(data)
## remove spiking and/or stimuli artifacts
data_ = data.copy()
baseline_ = np.mean(data_)
std_ = np.std(data_)
data_[data > baseline_ + 3 * std_] = baseline_
data_[data < baseline_ - 3 * std_] = baseline_
baseline_ = np.mean(data_) ## iterative estamtion of baseline
if pv["Spikes"][1]["Removing spikes"][0]:
dvdt_th = pv["Spikes"][1]["dv/dt (V/s) - threhold"][0]
peaks_lv = self.removeStimulationArtifacts(data.copy(), dvdt_th)
for p in peaks_lv:
data[p - 20 : p + 20] = baseline_
if rmSpks:
data_ = data.copy()
std_ = np.std(data_)
data_[data > baseline_ + 3 * std_] = baseline_
data_[data < baseline_ - 3 * std_] = baseline_
baseline_ = np.mean(data_) ## iterative estamtion of baseline
if pv["Spikes"][1]["Removing spikes"][0]:
dvdt_th = pv["Spikes"][1]["dv/dt (V/s) - threhold"][0]
peaks_lv = self.removeStimulationArtifacts(data.copy(), dvdt_th)
for p in peaks_lv:
data[p - 20 : p + 20] = baseline_

currentTrace = pv["Data selection"][1]["Trace"][0] - 1
self.events.node = []
Expand All @@ -2760,7 +2763,7 @@ def detectEventForAllSweeps_abf(self):
self.events.data = data
mean_data = np.mean(data)
median_data = np.median(data)

print(f"mean: {mean_data}, median: {median_data}")
if outlierCutoff_rv == "bound":
data[data <= outlierCutoff_LV] = outlierCutoff_LV
data[data >= outlierCutoff_UV] = outlierCutoff_UV
Expand Down Expand Up @@ -3075,8 +3078,9 @@ def marker_mouseClicked(scatterPlot, spots):
pc = "g" # change r to g
else:
pc = invalidColor ## change g to r
spotsPen = [scatterPlot.getSpotOpts(yy)[2] for yy in scatterPlot.data]
spotsBrush = [scatterPlot.getSpotOpts(yy)[3] for yy in scatterPlot.data]
print(f"pc, {pc}")
spotsPen = [yy[-2].pen() for yy in scatterPlot.data]
spotsBrush = [yy[-2].brush() for yy in scatterPlot.data]
spotsPen[spots[0].index()] = pg.mkPen(pc)
spotsBrush[spots[0].index()] = pg.mkBrush(pc)
scatterPlot.setPen(spotsPen)
Expand Down Expand Up @@ -3767,6 +3771,7 @@ def updateRecordingParameterTable(self, stimInfo, traceInfo):

def extractStimData_ABF(self):
rawP = self.currentPulseTree.abf.read_raw_protocol()
print(self.currentPulseTree.abf.yUnits)
nProtocol = len(rawP[0]) ## should be the same as nSegments for firing pattern.
stimChanIdx = 0 ## channel index where stimuli is applied to
stimUnit = rawP[2][stimChanIdx] ## 'pA'
Expand Down Expand Up @@ -3807,7 +3812,11 @@ def extractSingleSeries_ABF(self, selIdx):
for idx, seg in enumerate(block.segments): # enumerate(block.segments):
data[:, idx] = seg.analogsignals[0].transpose()[0]
time = np.arange(nSamples) / self.parameters["fs"]
return time, data / 1000.0 ## convert it back to Volt for downstream analaysis
if 'm' in self.currentPulseTree.abf.yUnits.lower():
sfactor = 1e3
elif 'p' in self.currentPulseTree.abf.yUnits.lower():
sfactor = 1e12
return time, data/sfactor ## convert it back to Volt for downstream analaysis

def extractSingleSeries(self, sel):
"""Extract single series (multiple sweep) data"""
Expand Down Expand Up @@ -5989,13 +5998,17 @@ def update_trace_plot(self, selected=None):
.analogsignals[0]
.transpose()[0]
)
if 'v' in self.currentPulseTree.abf.yUnits.lower():
getSpikes = True
else:
getSpikes = False ## skip analysing spikes if not voltage
self.plotSingleTrace_ABF(
plotHandle,
segmentIdx,
trace,
None,
highCutOff=None,
analaysisSpike=True,
analaysisSpike=getSpikes,
)
elif self.currentPulseTree.filetype == ".nwb": # sweep level
if len(selected) == 1: # if one sweep is slected.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.0
current_version = 0.3.2
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/zeitgeberH/patchview',
version = "0.3.0",
version = "0.3.2",
zip_safe=False,
entry_points={
'gui_scripts': [
Expand Down

0 comments on commit 2a68234

Please sign in to comment.