8000 add ibl_reproducible_ephys_2022 by mazabou · Pull Request #5 · neuro-galaxy/brainsets · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add ibl_reproducible_ephys_2022 #5

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ repos:
rev: 24.3.0
hooks:
- id: black
language_version: python3.9
language_version: python3
6 changes: 6 additions & 0 deletions brainsets_pipelines/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ module pei_pandarinath_nlb_2021_module:
config: config
use rule * from pei_pandarinath_nlb_2021_module as pei_pandarinath_nlb_2021_*
use rule all from pei_pandarinath_nlb_2021_module as pei_pandarinath_nlb_2021

module ibl_reproducible_ephys_2022_module:
snakefile: "ibl_reproducible_ephys_2022/Snakefile"
config: config
use rule * from ibl_reproducible_ephys_2022_module as ibl_reproducible_ephys_2022_*
use rule all from ibl_reproducible_ephys_2022_module as ibl_reproducible_ephys_2022
33 changes: 33 additions & 0 deletions brainsets_pipelines/ibl_reproducible_ephys_2022/README.md
10000
Original file line numberDiff line number Diff line change
@@ -0,0 +1,33 @@
# ibl_reproducible_ephys_2022

Repeatedly inserted Neuropixels multi-electrode probes targeting the same brain locations (called the repeated site, including posterior parietal cortex, hippocampus, and thalamus) in mice performing a behavioral task. Mice were trained to use a steering wheel to indicate the position of visual stimuli. In the **basic task**, the probability of a stimulus appearing on the left or the right was equal(50:50). In the **full task**, the probability of stimuli appearing on the left vs. right switched in blocks of trials between 20:80 and 80:20.

### Publication:
- International Brain Laboratory, Banga Kush, Benson Julius, Bhagat Jai, Biderman Dan, Birman Daniel, Bonacchi Niccolò, Bruijns Sebastian A, Buchanan Kelly, Campbell Robert AA, Carandini Matteo, Chapuis Gaëlle A, Churchland Anne K, Davatolhagh M Felicia, Lee Hyun Dong, Faulkner Mayo, Gerçek Berk, Hu Fei, Huntenburg Julia, Hurwitz Cole, Khanal Anup, Krasniak Christopher, Langfield Christopher, Meijer Guido T, Miska Nathaniel J, Mohammadi Zeinab, Noel Jean-Paul, Paninski Liam, Pan-Vazquez Alejandro, Roth Noam, Schartner Michael, Socha Karolina, Steinmetz Nicholas A, Svoboda Karel, Taheri Marsa, Urai Anne E, Wells Miles, West Steven J, Whiteway Matthew R, Winter Olivier, Witten Ilana B (2024) Reproducibility of in vivo electrophysiological measurements in mice eLife 13:RP100840. https://doi.org/10.7554/eLife.100840.1.

### Subject(s)
- 83 mice aged 111 - 442 days.

### Neural variables
- Spike-sorted neural activity

### Task Variables
- Choice: The direction in which the mouse turned the steering wheel (left or right; discrete).
- Block prior: The block identity which determines the probability of stimuli appearing on the left vs. right (discrete).
- Wheel speed: The velocity at which the mouse moved the steering wheel (continuous).
- Whisker motion energy: A measure of whisker movement activity (continuous).

### Installation

This pipeline requires `ONE-api` and `ibllib` to be installed.

```bash
pip install ONE-api
pip install ibllib
```

To process a single session, run the following command:

```bash
python3 prepare_data.py --eid db4df448-e449-4a6f-a0e7-288711e7a75a
```
86 changes: 86 additions & 0 deletions brainsets_pipelines/ibl_reproducible_ephys_2022/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
######################################################
# IBL Reproducible Ephys (2022)
######################################################

DATASET = "ibl_reproducible_ephys_2022"
RAW_DIR = config["RAW_DIR"]
PROCESSED_DIR = config["PROCESSED_DIR"]

import os

# Ensure paths are resolved relative to the Snakemake file location
BASE_DIR = os.path.abspath(os.getcwd())
SPLIT_PATH = os.path.join(BASE_DIR, "brainsets_pipelines", DATASET, "splits.npy")

def read_eids(file):
filepath = os.path.join(BASE_DIR, "brainsets_pipelines", DATASET, file)
if os.path.exists(filepath):
with open(filepath) as f:
return [line.strip() for line in f]
else:
print(f"Warning: {file} not found in {filepath}")
return []

TEST_EIDS = read_eids("test_eids.txt")
TRAIN_EIDS = read_eids("train_eids.txt")

# Rule to prepare data for a single session
rule prepare_data:
output:
h5_file = os.path.join(PROCESSED_DIR, DATASET, "{eid}.h5"),
txt_file = os.path.join(PROCESSED_DIR, DATASET, "tmp", "{eid}.txt")
log:
os.path.join(".snakemake", "logs", DATASET, "prepare_data.{eid}.log")
params:
eid = "{eid}",
split_path = SPLIT_PATH,
output_dir = os.path.join(PROCESSED_DIR, DATASET),
dataset = DATASET
shell:
"""
mkdir -p {params.output_dir}/tmp
mkdir -p $(dirname {log})
python -m brainsets_pipelines.{params.dataset}.prepare_data \
--eid {params.eid} \
--split_path {params.split_path} \
--output_dir {params.output_dir} 2>&1 | tee {log}
echo "{output.h5_file}" > {output.txt_file}
"""

# Function to aggregate input files for merge_manifests
def aggregate_input(wildcards):
eids = TEST_EIDS + TRAIN_EIDS
if not eids:
print("Warning: No EIDs found in test_eids.txt or train_eids.txt")
return expand(os.path.join(PROCESSED_DIR, DATASET, "tmp", "{eid}.txt"), eid=eids)

# Rule to merge manifests
rule merge_manifests:
input:
aggregate_input
output:
manifest = os.path.join(PROCESSED_DIR, DATASET, "manifest.txt")
log:
os.path.join(".snakemake", "logs", DATASET, "merge_manifests.log")
params:
processed_dir = PROCESSED_DIR, # Pass PROCESSED_DIR as a parameter
dataset = DATASET, # Pass DATASET as a parameter
tmp_dir = os.path.join(PROCESSED_DIR, DATASET, "tmp") # Path to the tmp directory
shell:
"""
# Create the manifest file
find {params.processed_dir}/{params.dataset}/ -type f -name "*.h5" | sed "s|^{params.processed_dir}/{params.dataset}/||" > {output.manifest}

# Remove the tmp directory
if [ -d {params.tmp_dir} ]; then
echo "Removing tmp directory: {params.tmp_dir}" >> {log}
rm -rf {params.tmp_dir}
else
echo "Warning: tmp directory not found: {params.tmp_dir}" >> {log}
fi
"""

# Default rule to run the entire workflow
rule all:
input:
os.path.join(PROCESSED_DIR, DATASET, "manifest.txt")
Loading
0