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

Separate conversion folder for benisty_2024 and lohani_2022 #14

Merged
merged 8 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ We recommend that you install the package inside a [virtual environment](https:/
### Running a specific conversion
Once you have installed the package with pip, you can run any of the conversion scripts in a notebook or a python file:

https://github.com/catalystneuro/higley-lab-to-nwb//tree/main/src/benisty_2022/benisty_2022_conversion_script.py
https://github.com/catalystneuro/higley-lab-to-nwb//tree/main/src/lohani_2022/lohani_2022_conversion_script.py



Expand Down Expand Up @@ -49,12 +49,12 @@ both of the methods above install the repository in [editable mode](https://pip.
### Running a specific conversion
To run a specific conversion, you might need to install first some conversion specific dependencies that are located in each conversion directory:
```
pip install -r src/higley_lab_to_nwb/benisty_2022/benisty_2022_requirements.txt
pip install -r src/higley_lab_to_nwb/lohani_2022/lohani_2022_requirements.txt
```

You can run a specific conversion with the following command:
```
python src/higley_lab_to_nwb/benisty_2022/benisty_2022_conversion_script.py
python src/higley_lab_to_nwb/lohani_2022/lohani_2022_conversion_script.py
```

## Repository structure
Expand All @@ -70,26 +70,26 @@ Each conversion is organized in a directory of its own in the `src` directory:
└── src
├── higley_lab_to_nwb
│ ├── conversion_directory_1
│ └── benisty_2022
│ ├── benisty_2022behaviorinterface.py
│ ├── benisty_2022_convert_session.py
│ ├── benisty_2022_metadata.yml
│ ├── benisty_2022nwbconverter.py
│ ├── benisty_2022_requirements.txt
│ ├── benisty_2022_notes.md
│ └── lohani_2022
│ ├── lohani_2022behaviorinterface.py
│ ├── lohani_2022_convert_session.py
│ ├── lohani_2022_metadata.yml
│ ├── lohani_2022nwbconverter.py
│ ├── lohani_2022_requirements.txt
│ ├── lohani_2022_notes.md

│ └── __init__.py
│ ├── conversion_directory_b

└── __init__.py

For example, for the conversion `benisty_2022` you can find a directory located in `src/higley-lab-to-nwb/benisty_2022`. Inside each conversion directory you can find the following files:
For example, for the conversion `lohani_2022` you can find a directory located in `src/higley-lab-to-nwb/lohani_2022`. Inside each conversion directory you can find the following files:

* `benisty_2022_convert_sesion.py`: this script defines the function to convert one full session of the conversion.
* `benisty_2022_requirements.txt`: dependencies specific to this conversion.
* `benisty_2022_metadata.yml`: metadata in yaml format for this specific conversion.
* `benisty_2022behaviorinterface.py`: the behavior interface. Usually ad-hoc for each conversion.
* `benisty_2022nwbconverter.py`: the place where the `NWBConverter` class is defined.
* `benisty_2022_notes.md`: notes and comments concerning this specific conversion.
* `lohani_2022_convert_sesion.py`: this script defines the function to convert one full session of the conversion.
* `lohani_2022_requirements.txt`: dependencies specific to this conversion.
* `lohani_2022_metadata.yml`: metadata in yaml format for this specific conversion.
* `lohani_2022behaviorinterface.py`: the behavior interface. Usually ad-hoc for each conversion.
* `lohani_2022nwbconverter.py`: the place where the `NWBConverter` class is defined.
* `lohani_2022_notes.md`: notes and comments concerning this specific conversion.

The directory might contain other files that are necessary for the conversion but those are the central ones.
2 changes: 0 additions & 2 deletions src/higley_lab_to_nwb/benisty_2022/__init__.py

This file was deleted.

102 changes: 0 additions & 102 deletions src/higley_lab_to_nwb/benisty_2022/benisty_2022_imaginginterface.py

This file was deleted.

This file was deleted.

58 changes: 0 additions & 58 deletions src/higley_lab_to_nwb/benisty_2022/benisty_2022nwbconverter.py

This file was deleted.

1 change: 1 addition & 0 deletions src/higley_lab_to_nwb/benisty_2024/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .benisty_2024_nwbconverter import Benisty2024NWBConverter
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Primary script to run to convert an entire session for of data using the NWBConverter."""

from pathlib import Path
from typing import Union
import os
from .benisty_2024_convert_session import session_to_nwb



# Parameters for conversion
root_path = Path("/media/amtra/Samsung_T5/CN_data")
data_dir_path = root_path / "Higley-CN-data-share"
output_dir_path = root_path / "Higley-conversion_nwb/"

session_ids = os.listdir(data_dir_path)
stub_test = True
for session_id in session_ids:
session_folder = data_dir_path / Path(session_id)
if os.path.isdir(session_folder):
session_to_nwb(
folder_path=session_folder,
output_dir_path=output_dir_path,
session_id=session_id,
stub_test=stub_test,
)
70 changes: 70 additions & 0 deletions src/higley_lab_to_nwb/benisty_2024/benisty_2024_convert_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Primary script to run to convert an entire session for of data using the NWBConverter."""

from pathlib import Path
from typing import Union
from neuroconv.utils import load_dict_from_file, dict_deep_update
from higley_lab_to_nwb.benisty_2024 import Benisty2024NWBConverter
import os
import glob


def session_to_nwb(
folder_path: Union[str, Path], output_dir_path: Union[str, Path], session_id: str, stub_test: bool = False
):

output_dir_path = Path(output_dir_path)
if stub_test:
output_dir_path = output_dir_path / "nwb_stub"
output_dir_path.mkdir(parents=True, exist_ok=True)

nwbfile_path = output_dir_path / f"{session_id}_new.nwb"

source_data = dict()
conversion_options = dict()

search_pattern = "_".join(session_id.split("_")[:2])

converter = Benisty2024NWBConverter(
source_data=source_data,
)

# Add datetime to conversion
metadata = converter.get_metadata()
date = read_session_start_time(folder_path=folder_path)
metadata["NWBFile"]["session_start_time"] = date
subject_id = session_id.split("_")[1]
metadata["Subject"].update(subject_id=subject_id)
metadata["NWBFile"].update(session_id=session_id)

# Update default metadata with the editable in the corresponding yaml file
editable_metadata_path = Path(__file__).parent / "benisty_2024_metadata.yaml"
editable_metadata = load_dict_from_file(editable_metadata_path)
metadata = dict_deep_update(metadata, editable_metadata)

# Add ophys metadata
ophys_metadata_path = Path(__file__).parent / "metadata" / "benisty_2024_ophys_metadata.yaml"
ophys_metadata = load_dict_from_file(ophys_metadata_path)
metadata = dict_deep_update(metadata, ophys_metadata)

# Run conversion
converter.run_conversion(
metadata=metadata, nwbfile_path=nwbfile_path, conversion_options=conversion_options, overwrite=True
)


if __name__ == "__main__":

# Parameters for conversion
root_path = Path("/media/amtra/Samsung_T5/CN_data")
data_dir_path = root_path / "Higley-CN-data-share"
output_dir_path = root_path / "Higley-conversion_nwb/"
stub_test = True
session_ids = os.listdir(data_dir_path)
session_id = "11222019_grabAM06_vis_stim"
folder_path = data_dir_path / Path(session_id)
session_to_nwb(
folder_path=folder_path,
output_dir_path=output_dir_path,
session_id=session_id,
stub_test=stub_test,
)
12 changes: 12 additions & 0 deletions src/higley_lab_to_nwb/benisty_2024/benisty_2024_nwbconverter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Primary NWBConverter class for this dataset."""

from typing import Dict, List
from neuroconv import NWBConverter



class Benisty2024NWBConverter(NWBConverter):
"""Primary conversion class."""

data_interface_classes = dict(
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nwb-conversion-tools==0.11.1 # Example of specific pinned dependecy
some-extra-package==1.11.3 # Example of another extra package that's necessary for the current conversion
roiextractors
neuroconv @ git+https://github.com/catalystneuro/neuroconv.git@facemap
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Ophys:
Device:
OnePhotonSeries:
ImagingPlane:
Loading
Loading