catalystneuro / neuroconv

Create NWB files by converting and combining neural data in proprietary formats and adding essential metadata.
https://neuroconv.readthedocs.io
BSD 3-Clause "New" or "Revised" License
50 stars 21 forks source link

[Feature]: Anatomical annotation of units in spike sorting? #1064

Closed vigji closed 2 weeks ago

vigji commented 2 weeks ago

What would you like to see added to NeuroConv?

I am sorry if I missed this feature. I am using the KiloSortSortingInterface to load some units sorted using KS4 via spikeinterface.

For each unit, I also have a pipeline that produces the brain area where the unit is located. I am wondering what is the way you would recommend to include that information in the sorting data. Is this something advisable? What would be a neuroconv-itonic way of doing it?

Is your feature request related to a problem?

No response

Do you have any interest in helping implement the feature?

Yes.

Code of Conduct

h-mayorquin commented 2 weeks ago

Hi, the most straightforward way would be to do the following

from neuroconv.tools.testing import MockSortingInterface

# Here use your KiloSortSortingInterface instead
interface = MockSortingInterface()
key = "brain_area"
interface.sorting_extractor.set_property(key=key, values=["Hippocampus", "CA1", "Motor Cortex", "Another Location"])

nwbfile_path = "test.nwb"
interface.run_conversion(nwbfile_path=nwbfile_path, overwrite=True)

from pynwb import NWBHDF5IO
with NWBHDF5IO(nwbfile_path, 'r') as io:
    nwbfile = io.read()
    units_table_df = nwbfile.units.to_dataframe()
units_table_df

image

Are you also writing a raw ecephys data? If so, the "best" way would be to annotate the channels/electrodes in the electrodes table and then make a reference from the units table there.

vigji commented 2 weeks ago

Well that was another question I was about to ask :)

Am I correct in thinking that by looking at the RecordingEstractorImage there is no way to link the bulk of the raw data as I do for the video recordings?

I would like to bundle everything together in a single nwb file, but I was wondering if I could keep those ~100 GBs out of it, as lab policy is still not deleting OEphys source data even after succesfull nwb import.

h-mayorquin commented 2 weeks ago

Am I correct in thinking that by looking at the RecordingEstractorImage there is no way to link the bulk of the raw data as I do for the video recordings?

No, unless your original data is in hdf5 but that is not dandi friendly and introduces more complexity in your workflow as you need to be sure to keep the paths aligned:

https://pynwb.readthedocs.io/en/stable/tutorials/advanced_io/plot_linking_data.html

Did the annotation method above worked for you? Let me know so I can close this question. Feel free to open more for any question you might have.

vigji commented 2 weeks ago

YEs it does! thank you very much :) And thanks for the clarification!