Kilosort icon indicating copy to clipboard operation
Kilosort copied to clipboard

How to map clusters to position on probe?

Open SiddharthaJoshiLC opened this issue 3 years ago • 10 comments

How do I map the sorted clusters to a position on a linear probe (ie - the map that we provvide to Kilosort at the first step)?

thank you,

  • Siddhartha Joshi

SiddharthaJoshiLC avatar Oct 28 '21 21:10 SiddharthaJoshiLC

you can use rez.ops.chanMap, rez.xcoords, rex.ycoords in matlab or the channel_map.npy and channel_positions.npy file

rajatsaxena avatar Dec 01 '21 04:12 rajatsaxena

Thank you, Rajat. Those files only have channel maps but not the mapping from sorted cluster to channel (or channel position). However, we did find that this information is saved after running Phy.

Siddhartha Joshi, PhD Senior Staff Scientist Department of Neuroscience Baylor College of Medicine

Web: https://siddsrecipes.blogspot.com/

https://scholar.google.com/citations?user=X4EKHG4AAAAJ&hl=en

https://www.ncbi.nlm.nih.gov/myncbi/1TyYsjkdmK2Aa/bibliography/public/

https://twitter.com/SiddJoshi75

On Tue, Nov 30, 2021 at 10:14 PM Rajat Saxena @.***> wrote:

you can use rez.ops.chanMap, rez.xcoords, rex.ycoords in matlab or the channel_map.npy and channel_positions.npy file

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MouseLand/Kilosort/issues/454#issuecomment-983271258, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQMGBMWO34PF3LBRIGZSYDLUOWOJPANCNFSM5G53HTZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

SiddharthaJoshiLC avatar Feb 09 '22 16:02 SiddharthaJoshiLC

Hello Siddhartha,

Would you mind pointing me in the right direction for the cluster to probe channel mapping? Which phy output holds this information? I am trying to figure out the same issue.

Thanks,

Michael

GrimmSnark avatar Mar 10 '22 15:03 GrimmSnark

Hi Michael,

We stumbled on this "solution" while trying to figure out where Kilosort puts the cluster-to-channel mapping. There might still be a way to get it after running Kilosort alone, but I have not found that.

If you simply run Phy, hit the save button and close the Phy session, a file named "cluster_info.tsv" is generated. This has the channel numbers corresponding to each sorted cluster. Information about setting up and running Phy is on their GitHub page, to which a link is available on the Kilosort Github page (I'm not at our sorting computer right now so can't dig out that info asap, but I can do a bit later if you need it).

Hope that helps.

  • Siddhartha

On Thu, Mar 10, 2022 at 9:52 AM Michael Savage @.***> wrote:

Hello Siddhartha,

Would you mind pointing me in the right direction for the cluster to probe channel mapping? Which phy output holds this information? I am trying to figure out the same issue.

Thanks,

Michael

— Reply to this email directly, view it on GitHub https://github.com/MouseLand/Kilosort/issues/454#issuecomment-1064208749, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQMGBMWCRFJ2CPRTIHCBAGLU7ILDTANCNFSM5G53HTZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

SiddharthaJoshiLC avatar Mar 10 '22 16:03 SiddharthaJoshiLC

Hey Michael,

You can also use this function from the Spikes repo from the Cortex lab at UCL which will output, amongst other stuff, the depth of the template for each cluster. Then you simply find the closest channel to that (e.g. using the information in channel_map.npy and channel_positions.npy). Cheers

LaurenzMuessig avatar Mar 10 '22 17:03 LaurenzMuessig

@SiddharthaJoshiLC Thank you very much for the work-around. I am already playing with phy, which has lead me down this particular rabbit hole. I am trying to create my own plots based on kilosort/phy sorting. It really is very disappointing the kilosort documentation is so opaque when it comes to this kind of thing.

@LaurenzMuessig I have tried that function and it does not match the display for the output in phy. You can see the comparison for some of my clusters below:

cluster_id Phy Channel KiloSort Channel
0 1 4.337685898
1 2 7.434809397
2 0 4.249345704
3 0 1
4 0 1
5 2 5.033467761
6 2 2.56780306
7 1 2.543675956
8 0 5.953745745
9 0 1.593878343
10 0 3.906452029
11 4 8.566465077
13 4 5
14 12 4.729088481
15 12 8.412247114
16 4 9.048718057
17 6 5
18 7 7
19 7 8
20 12 7.052152784
21 8 9.381769805
22 8 7.193596625
23 6 8.187918861
25 6 6.376646827
27 8 5
28 8 7
29 9 8
30 9 9
31 8 9
32 12 10.73152474
33 9 11.1555891
34 9 9
35 7 9.058844705
36 6 11.48928203
37 7 10
38 14 9.633896556
39 14 8.650992148
40 13 10.46675859

GrimmSnark avatar Mar 11 '22 10:03 GrimmSnark

Hi Michael. Note that the function calculates the centre of mass to assign the template depths, rather than just using the peak channel itself (which I think phy uses). Are all of these clusters in your list nice units or simply the first 40 in your recording, so might contain mua/noise? In the latter case the centre of mass and the peak channel might differ by a number of channels Also not sure I understand why your KiloSort channels aren't a list of integers?

Cheers

Laurenz

LaurenzMuessig avatar Mar 11 '22 13:03 LaurenzMuessig

Hello Laurenz,

These are just the first forty clusters in this particular recording so a mix of good cells and MUA. I understand that kilosort calculates center of mass and I would be willing to believe the result if it matched remotely the phy output or even mean waveform templates when I plot then. I just don't understand what phy is doing differently from kilosort.

The kilosort channel is just the templateDepths variable from the templatePositionsAmplitudes function in the spikes library, so I have no idea why it would contain decimal places.

Best,

Michael

GrimmSnark avatar Mar 11 '22 15:03 GrimmSnark

So, 'templateDepths' will be the actual depths of the cluster in um, not a channel ID. you'd need to use the depths to find the closest channel to that according to your channel map. However, I can see that the values you are getting don't seem to make much sense (in comparison to the channel phy gives you) as it should increment by 20um every 2 channels (assuming you are using neuropixels 1.0). For my data (neuropixels), I get a match of mainly +/-20um between phy and using the code in templatePositionsAmplitudes for any decent cluster that is not noise or a mix of different units. Not sure what's going wrong in your case.

Cheers

Laurenz

LaurenzMuessig avatar Mar 11 '22 15:03 LaurenzMuessig

Thanks for all the useful information in this discussion, Laurenz and Michael.

Michael - I wonder if the mismatch might be due to the electrode map file that you provide to Kilosort (the file that maps Channel number to the x,y,x coordinates of the actual channel)? Probably not, but may be worth a quick check...

  • Siddhartha

Siddhartha Joshi, PhD Senior Staff Scientist Department of Neuroscience Baylor College of Medicine

Web: https://siddsrecipes.blogspot.com/

https://scholar.google.com/citations?user=X4EKHG4AAAAJ&hl=en

https://www.ncbi.nlm.nih.gov/myncbi/1TyYsjkdmK2Aa/bibliography/public/

https://twitter.com/SiddJoshi75

On Fri, Mar 11, 2022 at 9:56 AM LaurenzMuessig @.***> wrote:

So, 'templateDepths' will be the actual depths of the cluster in um, not a channel ID. you'd need to use the depths to find the closest channel to that according to your channel map. However, I can see that the values you are getting don't seem to make much sense (in comparison to the channel phy gives you) as it should increment by 20um every 2 channels (assuming you are using neuropixels 1.0). For my data (neuropixels), I get a match of mainly +/-20um between phy and using the code in templatePositionsAmplitudes for any decent cluster that is not noise or a mix of different units. Not sure what's going wrong in your case.

Cheers

Laurenz

— Reply to this email directly, view it on GitHub https://github.com/MouseLand/Kilosort/issues/454#issuecomment-1065243537, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQMGBMR3THYTKGHH36NRERTU7NULJANCNFSM5G53HTZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

SiddharthaJoshiLC avatar Mar 11 '22 16:03 SiddharthaJoshiLC