BCI Dataset

BCI Dataset#

This page describes how to access metadata for the Brain Computer Interface (BCI) dataset using the Allen Institute’s metadata API. The dataset contains two-photon calcium imaging sessions from primary motor cortex while mice perform a BCI task.

import pandas as pd
from datetime import datetime, date
import os
from aind_data_access_api.document_db import MetadataDbClient

API_GATEWAY_HOST = "api.allenneuraldynamics.org"
DATABASE = 'metadata_index'
COLLECTION = 'data_assets'

docdb_api_client = MetadataDbClient(
   host=API_GATEWAY_HOST,
   database=DATABASE,
   collection=COLLECTION,
)
print(docdb_api_client._base_url)
https://api.allenneuraldynamics.org/v1/metadata_index/data_assets
aggregate = [
  {
    "$match": {
      "session.session_type": "BCI single neuron stim",
      "data_description.data_level": "derived",
      "processing.processing_pipeline.data_processes.start_date_time": {"$gte": "2025-08-03"}
    }
  },
  {
    "$project": {
      "name": 1,
      "subject_id": "$data_description.subject_id",
      "genotype": "$subject.genotype",
      "virus": "$procedures.subject_procedures.procedures.injection_materials.name",
      "date_of_birth": "$subject.date_of_birth",
      "sex": "$subject.sex",
      "session_type": "$session.session_type",
      "session_start_time": "$session.session_start_time",
      "session_end_time": "$session.session_end_time",
      "stimulus_epochs": "$session.stimulus_epochs.stimulus_name",
      "project_name": "$data_description.project_name",
      "modality": "$data_description.modality.name",
      "targeted_structure": "$session.data_streams.stack_parameters.targeted_structure",
      "session_number": {
        "$filter": {
          "input": "$session.stimulus_epochs",
          "as": "epoch",
          "cond": {"$eq": ["$$epoch.stimulus_name", "single neuron BCI conditioning"]}
        }
      },
      "ophys_fov": {
        "$map": {
          "input": "$session.data_streams",
          "as": "stream",
          "in": {
            "$map": {
              "input": "$$stream.ophys_fovs",
              "as": "fov",
              "in": "$$fov.notes"
            }
          }
        }
      },
      "magnification": "$session.data_streams.stack_parameters.magnification",
    }
  },
  {
    "$project": {
      "name": 1,
      "subject_id": 1,
      "genotype": 1,
      "virus": 1,
      "date_of_birth": 1,
      "sex": 1,
      "session_type": 1,
      "session_start_time": 1,
      "session_end_time": 1,
      "stimulus_epochs": 1,
      "project_name": 1,
      "modality": 1,
      "targeted_structure": 1,
      "session_number": {"$arrayElemAt": ["$session_number.session_number", 0]},
      "ophys_fov": 1,
      "magnification": 1
    }
  },
  {"$unwind": {"path": "$ophys_fov", "preserveNullAndEmptyArrays": False}},
  {"$unwind": {"path": "$ophys_fov", "preserveNullAndEmptyArrays": False}},
  {"$unwind": {"path": "$virus", "preserveNullAndEmptyArrays": False}},
  {"$unwind": {"path": "$virus", "preserveNullAndEmptyArrays": False}},
  {"$unwind": {"path": "$virus", "preserveNullAndEmptyArrays": False}},
  {"$unwind": {"path": "$modality", "preserveNullAndEmptyArrays": False}},
  {"$unwind": {"path": "$targeted_structure", "preserveNullAndEmptyArrays": False}},
  {"$unwind": {"path": "$magnification", "preserveNullAndEmptyArrays": False}},
]

records = docdb_api_client.aggregate_docdb_records(pipeline=aggregate)

We can turn these records into a dataframe and reorganize some things:

df = pd.DataFrame(records)
df = df.drop_duplicates(subset="name")

df['session_date'] = df.apply(lambda x: datetime.fromisoformat(x['session_start_time']).date(), axis=1)
df['session_start_time'] = df.apply(lambda x: datetime.fromisoformat(x['session_start_time']).time(), axis=1)
df['session_end_time'] = df.apply(lambda x: datetime.fromisoformat(x['session_end_time']).time(), axis=1)
df['date_of_birth'] = df.apply(lambda x: datetime.strptime(x['date_of_birth'], '%Y-%m-%d').date(), axis=1)
df['age'] = df.apply(lambda x: (x['session_date'] - x['date_of_birth']).days, axis=1)

order = ['project_name', 'session_type', '_id', 'name', 'subject_id', 'genotype', 'virus',
         'date_of_birth', 'age', 'sex', 'modality', 'session_date', 'session_start_time',
         'session_end_time', 'targeted_structure', 'ophys_fov', 'session_number']
df = df[order]

We’ll filter df for only the data assets shared for SWDB.

v2_assets = ['single-plane-ophys_731015_2025-01-10_18-06-31_processed_2025-08-03_20-39-09',
 'single-plane-ophys_731015_2025-01-24_20-00-44_processed_2025-08-04_06-27-07',
 'single-plane-ophys_731015_2025-01-28_18-56-35_processed_2025-08-03_21-58-28',
 'single-plane-ophys_731015_2025-01-31_20-37-19_processed_2025-08-06_05-37-58',
 'single-plane-ophys_740369_2025-01-09_17-18-37_processed_2025-08-06_03-49-53',
 'single-plane-ophys_740369_2025-01-13_17-31-04_processed_2025-08-04_17-59-13',
 'single-plane-ophys_740369_2025-01-24_21-18-11_processed_2025-08-04_06-39-23',
 'single-plane-ophys_740369_2025-01-30_18-44-54_processed_2025-08-04_13-31-14',
 'single-plane-ophys_740369_2025-02-03_19-18-31_processed_2025-08-03_23-27-56',
 'single-plane-ophys_754303_2025-01-22_18-22-38_processed_2025-08-06_18-52-36',
 'single-plane-ophys_754303_2025-01-23_19-48-32_processed_2025-08-08_15-29-29',
 'single-plane-ophys_754303_2025-01-27_20-01-31_processed_2025-08-07_06-00-10',
 'single-plane-ophys_754303_2025-01-29_16-07-41_processed_2025-08-04_04-39-41',
 'single-plane-ophys_754303_2025-01-31_15-13-50_processed_2025-08-05_20-00-52',
 'single-plane-ophys_766719_2025-01-22_16-45-18_processed_2025-08-06_17-55-43',
 'single-plane-ophys_766719_2025-01-23_18-24-57_processed_2025-08-04_05-56-15',
 'single-plane-ophys_766719_2025-01-27_18-25-39_processed_2025-08-07_04-04-45',
 'single-plane-ophys_767715_2025-01-31_18-15-21_processed_2025-08-06_07-02-58',
 'single-plane-ophys_767715_2025-02-03_17-30-05_processed_2025-08-03_23-22-19',
 'single-plane-ophys_767715_2025-02-06_18-59-24_processed_2025-08-06_19-25-46',
 'single-plane-ophys_767715_2025-02-10_16-04-20_processed_2025-08-05_12-52-18',
 'single-plane-ophys_767715_2025-02-17_17-41-50_processed_2025-08-05_01-05-20']

filtered_df = df[df['name'].isin(v2_assets)]
filtered_df = filtered_df.sort_values(by=['subject_id']).reset_index(drop=True)
filtered_df
project_name session_type _id name subject_id genotype virus date_of_birth age sex modality session_date session_start_time session_end_time targeted_structure ophys_fov session_number
0 Brain Computer Interface BCI single neuron stim b8827d25-495f-46a8-9f33-ffb24da527a5 single-plane-ophys_731015_2025-01-10_18-06-31_... 731015 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-03-14 302 Female Planar optical physiology 2025-01-10 16:46:51.981999 18:06:30.818756 Primary Motor Cortex FOV_04; FOV_04 18.0
1 Brain Computer Interface BCI single neuron stim b9a4c361-66b0-4cd5-9392-75d116ef3385 single-plane-ophys_731015_2025-01-31_20-37-19_... 731015 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-03-14 323 Female Planar optical physiology 2025-01-31 20:37:19.623000 22:03:59.609761 Primary Motor Cortex FOV_04 23.0
2 Brain Computer Interface BCI single neuron stim 0162d41c-613c-4215-b0aa-9690f85a9fda single-plane-ophys_731015_2025-01-28_18-56-35_... 731015 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-03-14 320 Female Planar optical physiology 2025-01-28 17:40:57.996000 18:56:35.136165 Primary Motor Cortex FOV_04 22.0
3 Brain Computer Interface BCI single neuron stim 127a3e78-729c-4df7-bf34-1b9308939587 single-plane-ophys_731015_2025-01-24_20-00-44_... 731015 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-03-14 316 Female Planar optical physiology 2025-01-24 18:41:22.550000 20:00:44.080193 Primary Motor Cortex FOV_04 20.0
4 Brain Computer Interface BCI single neuron stim 30006aee-36db-44d9-a1fb-1b6583619434 single-plane-ophys_740369_2025-01-09_17-18-37_... 740369 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-05-03 251 Female Planar optical physiology 2025-01-09 16:01:04.455000 17:18:37.082809 Primary Motor Cortex FOV_05 22.0
5 Brain Computer Interface BCI single neuron stim 17ae1324-de6d-433e-9aec-7f174d22e89a single-plane-ophys_740369_2025-01-13_17-31-04_... 740369 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-05-03 255 Female Planar optical physiology 2025-01-13 16:02:50.863999 17:31:04.545427 Primary Motor Cortex FOV_05 24.0
6 Brain Computer Interface BCI single neuron stim c32e7e98-1104-4e24-a830-53d54f06b518 single-plane-ophys_740369_2025-01-24_21-18-11_... 740369 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-05-03 266 Female Planar optical physiology 2025-01-24 20:08:49.286000 21:18:10.700832 Primary Motor Cortex FOV_05 25.0
7 Brain Computer Interface BCI single neuron stim a9b68b93-c445-4809-9cab-d6282ae64483 single-plane-ophys_740369_2025-01-30_18-44-54_... 740369 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-05-03 272 Female Planar optical physiology 2025-01-30 18:44:54.865000 19:30:22.882962 Primary Motor Cortex None NaN
8 Brain Computer Interface BCI single neuron stim cf8baa51-6086-4f5a-aeca-b685b59f1662 single-plane-ophys_740369_2025-02-03_19-18-31_... 740369 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-05-03 276 Female Planar optical physiology 2025-02-03 19:18:31.580999 20:39:25.810362 Primary Motor Cortex FOV_06 27.0
9 Brain Computer Interface BCI single neuron stim 737557e6-4bb3-423f-8fae-a2a63ee600e7 single-plane-ophys_754303_2025-01-31_15-13-50_... 754303 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-07-17 198 Male Planar optical physiology 2025-01-31 15:13:50.595999 16:27:06.146720 Primary Motor Cortex FOV_01 8.0
10 Brain Computer Interface BCI single neuron stim 5fa54429-8887-48b7-a3db-5526d7fa3fe5 single-plane-ophys_754303_2025-01-29_16-07-41_... 754303 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-07-17 196 Male Planar optical physiology 2025-01-29 16:07:41.655000 17:22:19.941818 Primary Motor Cortex FOV_01 6.0
11 Brain Computer Interface BCI single neuron stim aaf560f4-bb1f-449a-aaf9-5054432b47ae single-plane-ophys_754303_2025-01-23_19-48-32_... 754303 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-07-17 190 Male Planar optical physiology 2025-01-23 18:36:30.521000 19:48:31.718661 Primary Motor Cortex FOV_01 3.0
12 Brain Computer Interface BCI single neuron stim 7efb85e4-0dba-43fe-a0fd-2b8348e05b69 single-plane-ophys_754303_2025-01-27_20-01-31_... 754303 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-07-17 194 Male Planar optical physiology 2025-01-27 18:46:54.109999 20:01:31.296917 Primary Motor Cortex FOV_01 5.0
13 Brain Computer Interface BCI single neuron stim 3aac9323-c4f9-4172-9f1a-6c12cb3bc44e single-plane-ophys_754303_2025-01-22_18-22-38_... 754303 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-07-17 189 Male Planar optical physiology 2025-01-22 16:59:35.618000 18:22:38.048685 Primary Motor Cortex FOV_01 2.0
14 Brain Computer Interface BCI single neuron stim 7ebc1acf-e7d2-4d04-9d59-e3556dfc107b single-plane-ophys_766719_2025-01-27_18-25-39_... 766719 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-09-16 133 Female Planar optical physiology 2025-01-27 17:02:50.868000 18:25:39.333757 Primary Motor Cortex FOV_01 5.0
15 Brain Computer Interface BCI single neuron stim ea2ea4a7-8270-4712-bf5c-df7480cb276f single-plane-ophys_766719_2025-01-22_16-45-18_... 766719 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-09-16 128 Female Planar optical physiology 2025-01-22 15:36:39.563000 16:45:18.542092 Primary Motor Cortex FOV_01 2.0
16 Brain Computer Interface BCI single neuron stim e3e8dd63-0bc4-4fc7-aedf-2abe9416149f single-plane-ophys_766719_2025-01-23_18-24-57_... 766719 Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt pAAV-CaMKIIa-ChRmine-oScarlet-Kv2.1-WPRE - 7413 2024-09-16 129 Female Planar optical physiology 2025-01-23 16:53:55.722000 18:24:57.281617 Primary Motor Cortex FOV_01 3.0
17 Brain Computer Interface BCI single neuron stim b28d6321-1b1b-4110-87fb-0e19325c1dfe single-plane-ophys_767715_2025-02-17_17-41-50_... 767715 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-09-15 155 Female Planar optical physiology 2025-02-17 17:41:50.758000 18:59:57.064824 Primary Motor Cortex FOV_03 8.0
18 Brain Computer Interface BCI single neuron stim c7470968-816b-49ae-9ebd-b4579e458cb4 single-plane-ophys_767715_2025-01-31_18-15-21_... 767715 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-09-15 138 Female Planar optical physiology 2025-01-31 18:15:21.158999 19:28:33.805721 Primary Motor Cortex FOV_01 2.0
19 Brain Computer Interface BCI single neuron stim 3788a435-4e4d-42b7-8718-44cd9c43b6b7 single-plane-ophys_767715_2025-02-06_18-59-24_... 767715 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-09-15 144 Female Planar optical physiology 2025-02-06 18:59:24.815999 20:10:05.205702 Primary Motor Cortex FOV_01 4.0
20 Brain Computer Interface BCI single neuron stim 81b6cb9b-5885-4b29-8354-5d44065fc5a7 single-plane-ophys_767715_2025-02-03_17-30-05_... 767715 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-09-15 141 Female Planar optical physiology 2025-02-03 17:30:05.458999 18:51:18.288579 Primary Motor Cortex FOV_02 3.0
21 Brain Computer Interface BCI single neuron stim 3a82e844-4bd9-4f0e-a017-56419a967c79 single-plane-ophys_767715_2025-02-10_16-04-20_... 767715 Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-IC... pAAV-hSyn1-RiboL1-GCaMP8s-WPRE 2024-09-15 148 Female Planar optical physiology 2025-02-10 16:04:20.109000 17:23:23.686046 Primary Motor Cortex FOV_03 5.0

The total number of sessions:

print(len(filtered_df))
22

What are the unique subjects:

print(filtered_df['subject_id'].unique())
['731015' '740369' '754303' '766719' '767715']

What are the unique genotypes:

print(filtered_df['genotype'].unique())
['Slc17a6-IRES-Cre/wt;Ai230(TIT2L-XCaMPG-WPRE-ICL-ChRmine-oScarlet-IRES2-tTA2-WPRE)-hyg/wt'
 'Camk2a-tTA/wt;TetO-jGCaMP8s-01/wt']

How many sessions per subject:

filtered_df.groupby('subject_id')['name'].count()
subject_id
731015    4
740369    5
754303    5
766719    3
767715    5
Name: name, dtype: int64