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

IBL tutorials #40

Merged
merged 2 commits into from
Sep 6, 2023
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
250 changes: 250 additions & 0 deletions 000409/IBL/01_list_datasets.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "f981241e-e235-4bdb-898d-81fba5ca95d6",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>path</th>\n",
" <th>subject</th>\n",
" <th>filesize</th>\n",
" <th>name</th>\n",
" </tr>\n",
" <tr>\n",
" <th>eid</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>ae8787b1-4229-4d56-b0c2-566b61a25b77</th>\n",
" <td>sub-NR-0027/sub-NR-0027_ses-ae8787b1-4229-4d56...</td>\n",
" <td>NR-0027</td>\n",
" <td>1209097503</td>\n",
" <td>sub-NR-0027_ses-ae8787b1-4229-4d56-b0c2-566b61...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ae8787b1-4229-4d56-b0c2-566b61a25b77</th>\n",
" <td>sub-NR-0027/sub-NR-0027_ses-ae8787b1-4229-4d56...</td>\n",
" <td>NR-0027</td>\n",
" <td>7173043026</td>\n",
" <td>sub-NR-0027_ses-ae8787b1-4229-4d56-b0c2-566b61...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ae8787b1-4229-4d56-b0c2-566b61a25b77</th>\n",
" <td>sub-NR-0027/sub-NR-0027_ses-ae8787b1-4229-4d56...</td>\n",
" <td>NR-0027</td>\n",
" <td>9430320168</td>\n",
" <td>sub-NR-0027_ses-ae8787b1-4229-4d56-b0c2-566b61...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1d4a7bd6-296a-48b9-b20e-bd0ac80750a5</th>\n",
" <td>sub-PL015/sub-PL015_ses-1d4a7bd6-296a-48b9-b20...</td>\n",
" <td>PL015</td>\n",
" <td>1394782933</td>\n",
" <td>sub-PL015_ses-1d4a7bd6-296a-48b9-b20e-bd0ac807...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1d4a7bd6-296a-48b9-b20e-bd0ac80750a5</th>\n",
" <td>sub-PL015/sub-PL015_ses-1d4a7bd6-296a-48b9-b20...</td>\n",
" <td>PL015</td>\n",
" <td>5918819563</td>\n",
" <td>sub-PL015_ses-1d4a7bd6-296a-48b9-b20e-bd0ac807...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" path \\\n",
"eid \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 sub-NR-0027/sub-NR-0027_ses-ae8787b1-4229-4d56... \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 sub-NR-0027/sub-NR-0027_ses-ae8787b1-4229-4d56... \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 sub-NR-0027/sub-NR-0027_ses-ae8787b1-4229-4d56... \n",
"1d4a7bd6-296a-48b9-b20e-bd0ac80750a5 sub-PL015/sub-PL015_ses-1d4a7bd6-296a-48b9-b20... \n",
"1d4a7bd6-296a-48b9-b20e-bd0ac80750a5 sub-PL015/sub-PL015_ses-1d4a7bd6-296a-48b9-b20... \n",
"\n",
" subject filesize \\\n",
"eid \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 NR-0027 1209097503 \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 NR-0027 7173043026 \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 NR-0027 9430320168 \n",
"1d4a7bd6-296a-48b9-b20e-bd0ac80750a5 PL015 1394782933 \n",
"1d4a7bd6-296a-48b9-b20e-bd0ac80750a5 PL015 5918819563 \n",
"\n",
" name \n",
"eid \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 sub-NR-0027_ses-ae8787b1-4229-4d56-b0c2-566b61... \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 sub-NR-0027_ses-ae8787b1-4229-4d56-b0c2-566b61... \n",
"ae8787b1-4229-4d56-b0c2-566b61a25b77 sub-NR-0027_ses-ae8787b1-4229-4d56-b0c2-566b61... \n",
"1d4a7bd6-296a-48b9-b20e-bd0ac80750a5 sub-PL015_ses-1d4a7bd6-296a-48b9-b20e-bd0ac807... \n",
"1d4a7bd6-296a-48b9-b20e-bd0ac80750a5 sub-PL015_ses-1d4a7bd6-296a-48b9-b20e-bd0ac807... "
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from pathlib import Path\n",
"import re\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"from dandi.dandiapi import DandiAPIClient\n",
"\n",
"DANDISET_ID = '000409'\n",
"\n",
"client = DandiAPIClient()\n",
"dandiset = client.get_dandiset(DANDISET_ID, 'draft')\n",
"meta_data = dandiset.get_metadata()\n",
"\n",
"assets = list(dandiset.get_assets())\n",
"\n",
"# I'm going to build a dataframe containing the asset paths and filesizes so I can navigate and filter the data files\n",
"df_assets = pd.DataFrame(index=np.arange(len(assets)), columns=['path', 'eid', 'subject', 'filesize', 'name'])\n",
"\n",
"for i, asset in enumerate(assets):\n",
" parts = asset.path.split('/')\n",
" # gets what is after 'sub-' in the first element of parts\n",
" subject = re.search('sub-(.*)', parts[0]).group(1)\n",
" eid = re.search(f'sub-{subject}_ses-(.*)', parts[1]).group(1)[:36]\n",
" df_assets.loc[i, 'subject'] = subject\n",
" df_assets.loc[i, 'eid'] = eid\n",
" df_assets.loc[i, 'path'] = asset.path\n",
" df_assets.loc[i, 'filesize'] = asset.size\n",
" df_assets.loc[i, 'name'] = Path(asset.path).name\n",
"df_assets = df_assets.set_index('eid')\n",
"df_assets.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e3f1acac-9b90-4388-921a-a82611d81ef5",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['sub-NYU-46/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e_behavior+ecephys+image/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e_OriginalVideoBodyCamera.mp4'\n",
" 'sub-NYU-46/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e_behavior+ecephys+image/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e_OriginalVideoRightCamera.mp4'\n",
" 'sub-NYU-46/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e_behavior+ecephys+image/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e_OriginalVideoLeftCamera.mp4'\n",
" 'sub-NYU-46/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e_behavior+ecephys+image.nwb'\n",
" 'sub-NYU-46/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e-processed-only_behavior.nwb']\n"
]
}
],
"source": [
"# pick the experiment ID from https://viz.internationalbrainlab.org/\n",
"eid = \"64e3fb86-928c-4079-865c-b364205b502e\"\n",
"print(df_assets.loc[eid, 'path'].values)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "1d3a9700-da45-4481-972c-01ec11db0e28",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"%%capture output\n",
"!pip install one-api\n",
"from one.api import ONE\n",
"ONE.setup(base_url='https://openalyx.internationalbrainlab.org', silent=True)\n",
"one = ONE(password='international')"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "7748fcf8-8c4f-472f-b6cf-ede765fbef33",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"No. of detected sessions: 7\n",
"sub-KS094/sub-KS094_ses-3f859b5c-e73a-4044-b49e-34bb81e96715-processed-only_behavior.nwb\n",
"sub-KS043/sub-KS043_ses-e5c75b62-6871-4135-b3d0-f6464c2d90c0-processed-only_behavior.nwb\n",
"sub-NYU-46/sub-NYU-46_ses-64e3fb86-928c-4079-865c-b364205b502e-processed-only_behavior.nwb\n",
"sub-ibl-witten-29/sub-ibl-witten-29_ses-821f1883-27f3-411d-afd3-fb8241bbc39a-processed-only_behavior.nwb\n",
"sub-CSH-ZAD-025/sub-CSH-ZAD-025_ses-ff48aa1d-ef30-4903-ac34-8c41b738c1b9-processed-only_behavior.nwb\n",
"sub-SWC-043/sub-SWC-043_ses-6fb1e12c-883b-46d1-a745-473cde3232c8-processed-only_behavior.nwb\n",
"sub-KS046/sub-KS046_ses-0ac8d013-b91e-4732-bc7b-a1164ff3e445-processed-only_behavior.nwb\n"
]
}
],
"source": [
"brain_acronym = 'SSs5'\n",
"# query sessions endpoint\n",
"_, insertions = one.search_insertions(atlas_acronym=brain_acronym, details=True)\n",
"sessions = list(set([ins['session'] for ins in insertions]))\n",
"\n",
"# print the name of assets that contain the desired brain regions\n",
"print(f'No. of detected sessions: {len(sessions)}')\n",
"for _, asset in df_assets.loc[sessions].iterrows():\n",
" if 'only_behavior' in asset.path:\n",
" print(asset.path)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading