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

Add Minian segmentation extractor #368

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Add Minian segmentation extractor #368

wants to merge 10 commits into from

Conversation

alessandratrapani
Copy link
Collaborator

@alessandratrapani alessandratrapani commented Oct 7, 2024

Add segmentation extractor for Minian output.
Supported output format: Zarr (for now)
Similarly to Caiman uses CNMF to perform cell identification.

Output structure (example):

minian/
 ├── A.zarr 
 │   ├── A (851, 608, 608) float64
 │   ├── animal () <U7
 │   ├── height (608,) int64
 │   ├── session_id () <U9
 │   ├── unit_id (851,) int64
 │   └── width (608,) int64
 ├── C.zarr
 │   ├── C (851, 8931) float64
 │   ├── animal () <U7
 │   ├── frame (8931,) int64
 │   ├── session () <U14
 │   └── session_id () <U9
 │   └── unit_id (851,) int64
 ├── b.zarr
 │   ├── animal () <U7
 │   ├── b (608, 608) float64
 │   ├── height (608,) int64
 │   ├── session () <U14
 │   ├── session_id () <U9
 │   ├── unit_id () int64
 │   └── width (608,) int64
 ├── b0.zarr
 │   ├── animal () <U7
 │   ├── b0 (851, 8931) float64
 │   ├── frame (8931,) int64
 │   ├── session () <U14
 │   ├── session_id () <U9
 │   └── unit_id (851,) int64
 ├── c0.zarr
 │   ├── animal () <U7
 │   ├── c0 (851, 8931) float64
 │   ├── frame (8931,) int64
 │   └── session () <U14
 ├── f.zarr
 │   ├── animal () <U7
 │   ├── f (8931,) float64
 │   └── frame (8931,) int64
 ├── S.zarr
 │   ├── S (851, 8931) float64
 │   ├── animal () <U7
 │   ├── frame (8931,) int64
 │   ├── session () <U14
 │   └── session_id () <U9
 │   └── unit_id (851,) int64
 ├── max_proj.zarr
 │   ├── animal () <U7
 │   ├── max_proj (608, 608) float64
 │   ├── height (608,) int64
 │   ├── session () <U14
 │   ├── session_id () <U9
 │   └── width (608,) int64
  • A: Spatial footprints of cells. Should have dimensions (“unit_id”, “height”, “width”). --> image_masks
  • C: Temporal components of cells. Should have dimensions “frame” and “unit_id”. --> roi_response_denoised
  • b: Spatial footprint of background. Should have dimensions (“height”, “width”). --> background_image_masks
  • f: Temporal dynamic of background. Should have dimension “frame”. --> roi_response_neuropil
  • b0: Baseline fluorescence for each cell. Should have dimensions (“frame”, “unit_id”) and same shape as C --> roi_response_baseline
  • c0: Initial calcium decay, in theory triggered by calcium events happened before the recording starts. Should have dimensions (“frame”, “unit_id”) and same shape as C
  • S: Deconvolved spikes for each cell. Should have dimensions (“frame”, “unit_id”) and same shape as C --> roi_response_deconvolved
  • max_proj: the maximum projection --> summary_image

TODOs

  • add extractor
  • update CHANGELOG
  • implement tests

@h-mayorquin
Copy link
Collaborator

Do tag me when this is ready for review.

@alessandratrapani
Copy link
Collaborator Author

I am uploading on the s3 bucket the testing folder for the minian segmentation data

@alessandratrapani alessandratrapani marked this pull request as ready for review October 9, 2024 15:25
@alessandratrapani
Copy link
Collaborator Author

@h-mayorquin ready for review

Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the first look. Looks good and simple to me.

  1. Is the structured documented? (the one that you shared on the PR) I am inferring the meaning of A, C, b, f, etc from the equation of CNMF here:

https://minian.readthedocs.io/en/stable/pipeline/notebook_5.html

But maybe there is other place in the documentation where this is stated more precisely, if so, we probably should link that in the docstring.

  1. The example that you uploaded, can you add a readme and share it with me so that I can upload it to gin.

class MinianSegmentationExtractor(SegmentationExtractor):
"""A SegmentationExtractor for Minian.

This class inherits from the SegmentationExtractor class, having all
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this docstring is very helpful, I think it should be oriented to explain things to final users and not implementation details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure! I just wanted to be consistent with all the other extractors, but I guess a more detailed docstring won't hurt.

self.folder_path = folder_path
self._roi_response_denoised = self._trace_extractor_read(field="C")
self._roi_response_baseline = self._trace_extractor_read(field="b0")
self._roi_response_neuropil = self._trace_extractor_read(field="f")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how the "f" (the temporal activities of the background) is the response neuropill. Can you say how those concepts match?

Copy link
Collaborator Author

@alessandratrapani alessandratrapani Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say first that the background can contain neuropil signal. The problem is that I wanted to map this "f" signal with something already in the SegmentationExtractor.

Now, I am not super happy with this formulation I think we should have two separate variables:

  1. _roi_response_neuropil with the respective _neuropil_images_masks. This can be used to store the actual neuropil signals that sometimes refer to the area surrounding the ROIs
  2. _roi_response_background with the respective _background_images_masks. This can be used more generally to store the signal in the field of view that excludes the areas in the identified ROIs (as in this case).

I opened an issue on roiextractor to discuss this with the others: #375

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense.

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 this pull request may close these issues.

2 participants