-
Notifications
You must be signed in to change notification settings - Fork 0
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 cell registration #19
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee00923
add interface for cell registration
alessandratrapani a41037b
remove unnecessary imports
alessandratrapani 4e74b0d
Merge branch 'main' into add_cell_registration
alessandratrapani 568951d
replace os with pathlib
alessandratrapani 6176097
add better description for module and tables
alessandratrapani c8b037d
add checks for filepaths
alessandratrapani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/cai_lab_to_nwb/zaki_2024/interfaces/zaki_2024_cell_registration_interface.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""Primary class for converting experiment-specific cell registration output.""" | ||
|
||
from neuroconv.basedatainterface import BaseDataInterface | ||
from neuroconv.utils import DeepDict | ||
from typing import Optional | ||
from pathlib import Path | ||
from pynwb import NWBFile | ||
from hdmf.common.table import DynamicTable, VectorData | ||
|
||
import pandas as pd | ||
|
||
|
||
class Zaki2024CellRegistrationInterface(BaseDataInterface): | ||
"""Adds a table to store the output of CellReg.""" | ||
|
||
keywords = ["cross sessions cell registration"] | ||
|
||
def __init__(self, file_paths: list[Path], verbose: bool = False): | ||
|
||
self.verbose = verbose | ||
self.file_paths = file_paths | ||
super().__init__(file_paths=file_paths) | ||
|
||
def get_metadata(self) -> DeepDict: | ||
# Automatically retrieve as much metadata as possible from the source files available | ||
metadata = super().get_metadata() | ||
|
||
return metadata | ||
|
||
def add_to_nwbfile( | ||
self, | ||
nwbfile: NWBFile, | ||
subject_id: str, | ||
stub_test: bool = False, | ||
metadata: Optional[dict] = None, | ||
): | ||
processing_module = nwbfile.create_processing_module( | ||
name="cell_registration", | ||
description="Processing module for cross session cell registration. " | ||
"Cells recorded across sessions were cross-registered using a previously published open-source " | ||
"cross-registration algorithm, CellReg, using the spatial correlations of nearby cells to " | ||
"determine whether highly correlated footprints close in space are likely to be the same cell across sessions." | ||
"Each offline recording was cross-registered with all the encoding and recall sessions, " | ||
"but not with the other offline sessions because cross-registering between all sessions would lead to too many conflicts and, " | ||
"therefore, to no cells cross-registered across all sessions." | ||
"Each table represents the output of the cross-registration between one offline sessions and all the encoding and recall sessions. " | ||
"A table maps the global ROI ids (row of the table) to the ROI ids in each of cross-registered session's plane segmentation.", | ||
) | ||
|
||
for file_path in self.file_paths: | ||
offline_session_name = Path(file_path).stem.split(f"{subject_id}_")[-1] | ||
name = offline_session_name + "vsConditioningSessions" | ||
data = pd.read_csv(file_path) | ||
|
||
columns = [ | ||
VectorData( | ||
name=col, | ||
description=f"ROI indexes of plane segmentation of session {col}", | ||
data=data[col].tolist()[:100] if stub_test else data[col].tolist(), | ||
) | ||
for col in data.columns | ||
] | ||
|
||
dynamic_table = DynamicTable( | ||
name=name, | ||
description="Table maps the global ROI ids (row of the table) to the ROI ids in each of cross-registered session's plane segmentation." | ||
"The column names refer to the cross-registered session's ids" | ||
"The values -9999 indicates no correspondence. ", | ||
columns=columns, | ||
) | ||
|
||
processing_module.add(dynamic_table) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about throwing errors when the expected folder_paths and the file_paths are not found? right now they are skipped silently but if the point of this interface is that those things should be added maybe it is better to stop the process at the tracks and throw an informative error so the user is aware of this.
I am not sure, maybe you have a good reason to skip instead of stopping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right! I added few lines to throw an error only when there is no file in the specific folder (matching the pattern) as expected. The
folder.is_dir()
"check" is just to select the folder paths among all the type Paths objects iterdir might iterate over (both folders and files), thus no need to throw an error if that object is not a directory.