Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking units across state changes in chronic recordings (kilosort drift captures state changes) #388

Closed
TomBugnon opened this issue Apr 29, 2021 · 3 comments · Fixed by #595

Comments

@TomBugnon
Copy link

Hi all,

We (@grahamfindlay)would like to be able to track units reliably across state changes during chronic recordings (mostly through sleep/wake cycle, but also under various anesthetics). This is a broad and difficult topic but I thought it would be good to engage the discussion here as this is of interest to many.

As far as I understand, there are at least three ways that units could be "lost" by kilosort during recordings spanning multiple vigilance states:

  • 1- If neurons drastically change their firing rate across states (eg REM-active neurons are silent most of the time). I suppose setting minFR=0 might be sufficient to resolve this (although it's unclear to me how much noise this introduces ?).
  • 2- If the wave-shape changes depending on the vigilance stage (eg in some bursting thalamic neurons). This is a difficult issue in itself and probably the topic for another discussion, but worth mentioning.
  • 3- finally units may be lost across states if kilosort's drift correction captures changes in the patterns of activity than physical drift of the probe. This is what I'm more concerned about here, as we do observe that the drift computed by kilosort erroneously captures state changes in certain conditions. Moreover, I'm guessing that units with intermittent spiking (from point 1-) will be even more sensitive to any imprecision in the drift correction, since their templates won't have the chance to be progressively updated to reflect the drift while they are silent.

Below are the drift traces and drift maps (pre-correction), as computed by kilosort2.5 with default parameters from 2h of raw data, for 2 rats. Top is ~cortex and bottom is ~thalamus. On the drift traces, blue is deep channel blocks and yellow is superficial, and on the drift map dark dots are high amplitude spikes. These are from chronic recordings so there is very little acute drift.

image
image

In particular, this shows very fast (single batch) drift which is wholly artifactual, and overall different patterns of drift across states. Both are (I suppose) due to the image registration algorithm of the drift correction capturing differences in the patterns of activity across batches (for instance a change in the laminar distribution of spiking activity may be interpreted as a translation of the probe). I haven't systematically explored this but the error seems to be greater in the animals/blocks of channels where fewer spikes are detected.

I'm not expecting a definitive out-of-the-box solution for this issue but here are some ideas that I would be happy to discuss

On the user end:

  • a- Using rigid drift correction could help in some recordings since the channel blocks with many units seem to be tracked properly. Below is the drift trace for the second animal with rigid correction, which shows that artifactual fast drift is gone. This is however not ideal since it (obviously) fails to capture non-rigid drift even when the registration would have worked well.

  • b- Using longer batches may mitigate some of the artifactual fast drift due to rapid changes in activity, at the cost of temporal resolution

On kilosort's end (changing the drift correction algorithm), I can think of the following options:

  • c- Setting a more agressive smoothing of the drift traces across channel blocks and time (possibly weighted by the number of spikes in the batch/block? or by how much the batch's footprint histogram resembles the target histogram after registration?)

  • d- Ideally we would find a footprint for each channel/batch that would be better invariant to changes in patterns of activity. I understand from the npx 2.0 science paper that this might be in the works...

Looking forward to hearing your thoughts,
Best, Tom

@agbondy
Copy link
Contributor

agbondy commented Apr 29, 2021

Can you show data that this behavior of kilosort is actually producing spike sorting errors? Right now you've shown clear data that there are state changes which alter spiking in a way that kilosort tried to account for by slight spatial shifting. This might help or hurt tracking units across states. But you haven't shown which, unless I'm missing something.

@TomBugnon
Copy link
Author

Hi @agbondy,

I see your point. It seems that for the second animal I showed you, the large spatial shifting imposed for REM and Wake are indeed mostly artifactual and thus, to answer your question, may a priori only hurt tracking.

Apparently a lot of the artifactual drift estimation in this particular case is due not to the different patterns of activity across states as I suggested, but to the limitation on the number of spikes detected per batch during preprocessing by the standalone detector (#394)

Here are the drift traces with df parameters that I showed above, with the missing spikes
image

Here is the same drift traces with df parameters after increasing the maximum number of spikes detected to form the drift map (from 10000 per batch to 50000). The state-dependent drift that I was concerned about is mostly gone.
image

So in summary in this case it is a state-dependency of the overall firing rate (rather than of the patterns of activity) which tricked the algorithm.

This issue put aside, I'm still wondering whether changes in patterns of activity across states could be mistakingly interpreted as physical drift by kilosort... but this is after all not what my data shows at the moment

Best

@TomBugnon
Copy link
Author

In case anyone else wonders about the effects of a possible state-dependency of the fingerprints use for registration, this paper directly adresses the issue: Decentralized Motion Inference and Registration of Neuropixel Data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants