JorritMontijn / zetapy

Python code implementing the ZETA-test
GNU General Public License v3.0
23 stars 9 forks source link

Assessing flexibility of ZETA test, plus aside on inhibition #13

Open RejwanSalih opened 9 months ago

RejwanSalih commented 9 months ago

First of all, thanks again for writing this useful package.

I am analysing neuropixel data of simple sensory perception experiments. However, the stimulation structure doesn't seem amenable to the ZETA test. The stimulation protocol is a series of alternating forward and backward whisker stimulations separated by 500ms. The figure below illustrates this:

stim_protocol

My plan was to treat the first stimulation separately, and group the other stimulations in the trial together.

I would like to use the 15 second inter-trial interval as the baseline, but this necessitates using the whole 5 second window.

For the first stimulation I thought I could use the baseline before the stimulation. However, the code was not intended for this purpose. Another idea was to take each trial's stimulation time and subtract a few seconds from these times. Then, I would just subtract this time from the calculated onset latencies.

Do you have any insights on this? Apologies if I am misunderstanding something fundamental!

As an aside, I notice that the code has a harder time with onset latencies of inhibitory responses, which partly drove me to wanting to include some baseline before the stimulus time. My rationale was that if the IFR uses the spike times as anchors for the calculation, then it may be able to more accurately interpolate the firing rate in the inhibition window if some baseline was included before the stimulation.

Any clarification on this would be appreciated.

Thank you for your time and patience.

JorritMontijn commented 9 months ago

Hi Rejwan,

Thank you for your message. I'm not entirely sure what you want to test here, so if this answer is not what you want, maybe you can explain a bit more what you want to test exactly? In any case, if you want to look only at the response to the first stimulus, I would just set the window length to 1.0 s (so it ends just before the onset of the second stimulus). That way you only include the response to the first stimulus.

If you want the latencies of the other stimuli, you can do the same as above, but change the event times. I'm not sure why you would want to use a different baseline period. If you want to compare the event-evoked response to a baseline spontaneous rate, I would probably use the two-sample zetatest2 instead. Then you can pick a set of "event" times where you're not presenting any stimuli, and compare the stimulus response to the spontaneous rate.

As for inhibitory responses: it's true that it's harder to reliably detect those, but that also has to do with the intrinsic difference between an excitatory and inhibitory peak. Theoretically speaking, excitatory peaks can be localized into an infinitesimally small period, making their detection very simple. Inhibitory periods, however, by definition, are more spread-out. After all, between each consecutive pair of spikes is a "silent" period, so only the length of that silent period is indicative of cessation of neuronal activity. This also means that how significant this cessation is, will depend on what precedes it; i.e., a silent period of 100ms is quite significant for a cell that was spiking at 100 Hz for multiple seconds, but the same cannot be said for a cell that was spiking at 10 Hz. So to see a cessation of activity, you indeed want to have some sort of plateau prior to it, so you can observe the drop.

I hope this helps, but let me know if I misunderstood your questions, or anything (else) is still unclear.

Best wishes, Jorrit

RejwanSalih commented 9 months ago

Hi Jorrit,

Thank you for the thorough response! I have written quite a few questions below, so please feel no obligation to answer them all!

Let me first better explain - the trace shown in the figure is essentially the position of a pipette, meaning it moves up and remains there for 500ms before moving back. These are the "forward" and "backward" whisker stimulations I referred to. Therefore, there is an event every 500ms.

The crux of the issue is that during the 5 second stimulation period (of 5 forward and 5 backward stimulations), many neurons behave differently than during the 15 second baseline period, beyond the initial peaked response to the stimulus. As a result, some neurons are not classed as modulated when using a window of 0-500ms, but when looking at the baseline activity, they seem to be modulated.

As an example, I show three figures when taking the same neuron and choosing different windows. First is 0-500ms:

105092_Barrel_30_Bilateral_ZETA

This suggests that the neuron isn't modulated. Second is 0-5s:

105092_Barrel_30_Bilateral_ZETA

In this case, the neuron is classed as modulated. Finally, I did -2.5s up to 7.5s (I took the event times and subtracted 2.5s so it is essentially the case above but including 2.5s of baseline before the start of each trial, and 2.5s after the trial. Hence, each trial starts at 2.5s):

105092_Barrel_30_Bilateral_ZETA

I show this third case to illustrate the difference in firing behaviour in the baseline compared to the 5s stimulus window.

There are many combinations of modulation assessment outcomes between these three window sizes across the neurons in our dataset. As a result, my plan was to take each of the 10 stimulations (5 forward and 5 backward) in a window of 0-500ms, but to also stitch some of the baseline that comes after these 10 stimulations to each one. This would make the 0-500ms window, say, 0-1000ms, where the added 500ms is from the baseline.

Does this make sense to do, or would that negatively impact the ZETA test? As far as I can tell, it shouldn't, but I'd love to hear your thoughts. Otherwise, I could use the zetatest2 as you mentioned - thanks for the suggestion!

As for the inhibition, does that mean I should take some baseline prior to the event? Say, instead of 0-500ms, I take -100ms up to 400ms? I'm also not sure about how to infer whether the neuron is positively or negatively modulated just from the metrics that result from the ZETA test. Could I do this programmatically, or will I need to visually inspect each neuron?

Thanks again for your time and patience. This has been really useful!