petersaj / AP_histology

Histology processing
63 stars 20 forks source link

Is 'template_depths' reverse version of Kilosort ouput depths? #18

Closed geonung closed 1 year ago

geonung commented 1 year ago

Hi, Andy.
Thanks for your amazing compatible histology code, and I have a small question about [template_depths] input in 'AP_align_probe_histology.m'

Kilosort output depth seems to be from 'shank tip (0 um) to probe base (3840 um)'. I'm calculating the center of mass depth([templateDepths]) using 'templatePositionsAmplitudes.m' function from github/spikes.

And in your code, [template_depths] input seems to reverse version of Kilosort output depth. (e.g. [template_depths] = 3840(max_depths) - [templateDepths])

You already said top(3840) and end(0) in wiki, I'm a little bit confused about whether it's correct to reverse the Kilosort depth and put it as an input.

And MUA correlation and LFP power seems to be rotate for matching brain area.

So, in my case, for using original [templateDepths] as [template_depths] I changed some code

set( get(unit_ax, 'YLabel'), 'String', 'Depth from tip (\mum)');
% set(unit_ax,'YDir','reverse');       % delete
set(multiunit_ax,'YDir','normal');   % add
set(lfp_ax,'YDir','normal');             % add

If I'm doing wrong, your advice is big help to me :)

geonung commented 1 year ago

1 2

petersaj commented 1 year ago

Right sorry that's confusing - I use "depth" reversed from the standard Kilosort output. It's always made more sense to me to have a small "depth" be superficial, and a large "depth" to be deep.

I tried clarifying that on the wiki:

probe_ccf.probe_depths: the relative depth of the probe to that point (e.g. 0 is the top towards headstage of the probe and ~3840 is the tip of the probe). Note that this is reversed from the standard Kilosort output, which from 0 = tip to 3840 = top towards headstage.

So you can flip your depths as you said by doing templateDepths_flipped = 3840 - templateDepths;

Your plots flipped just because you changed the Y direction: set(lfp_ax,'YDir','normal');

That'll make them backwards relative to the units, unless you also flip the units direction.

geonung commented 1 year ago

Oh I got it, sorry. I should flip all the units location for spike plot and MUA plot.

Then, did you also flip the LFP channel location so that the superficial side has a smaller depth? (Kilosort LFP channels are also tip(0) to base(3840))

If so, it seems to work well without any modification. Thanks so much, and sorry for confusing.

petersaj commented 1 year ago

Both LFP and units should be base (0) tip (3840) to go from low numbers = superficial, high numbers = deep, so hopefully everything should work if you flip all your depths?

geonung commented 1 year ago

Yes, after flipping the Kilosort outputs, everything worked well.

templateDepths_flipped = 3840 - templateDepths;
lfp_channel_position_flip = flip(ycoords);

AP_align_probe_histology(st,slice_path,spike_times,spike_templates,template_depths_flip,...
                             lfp,lfp_channel_position_flip,use_probe)

I learned a lot from your codes. Thanks, Andy! 🥇 👍