Last active
April 15, 2020 19:46
-
-
Save xgrg/8ac0b489bc6266a40f9b40b24b238933 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"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>side</th>\n", | |
" <th>measurement</th>\n", | |
" <th>region</th>\n", | |
" <th>value</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>44</th>\n", | |
" <td>right</td>\n", | |
" <td>SurfArea</td>\n", | |
" <td>bankssts</td>\n", | |
" <td>969</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>45</th>\n", | |
" <td>right</td>\n", | |
" <td>SurfArea</td>\n", | |
" <td>caudalanteriorcingulate</td>\n", | |
" <td>679</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>46</th>\n", | |
" <td>right</td>\n", | |
" <td>SurfArea</td>\n", | |
" <td>caudalmiddlefrontal</td>\n", | |
" <td>2092</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>47</th>\n", | |
" <td>right</td>\n", | |
" <td>SurfArea</td>\n", | |
" <td>cuneus</td>\n", | |
" <td>1788</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>48</th>\n", | |
" <td>right</td>\n", | |
" <td>SurfArea</td>\n", | |
" <td>entorhinal</td>\n", | |
" <td>450</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" side measurement region value\n", | |
"44 right SurfArea bankssts 969\n", | |
"45 right SurfArea caudalanteriorcingulate 679\n", | |
"46 right SurfArea caudalmiddlefrontal 2092\n", | |
"47 right SurfArea cuneus 1788\n", | |
"48 right SurfArea entorhinal 450" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Let's first fetch some FreeSurfer results\n", | |
"import pyxnat\n", | |
"x = pyxnat.Interface(config='/home/grg/.xnat_bsc.cfg')\n", | |
"exp = x.select.experiment('BBRC_E00080')\n", | |
"res = exp.resource('FREESURFER6_HIRES')\n", | |
"aparc = res.aparc()\n", | |
"\n", | |
"# DataFrame should look like this\n", | |
"aparc.query('measurement == \"SurfArea\"').head()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2.338209274795409" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"regions = ['entorhinal', 'inferiortemporal', 'middletemporal', 'fusiform']\n", | |
"# ROIs from Jack et al., Alzheimers Dement. 2017; doi:10.1016/j.jalz.2016.08.005\n", | |
"\n", | |
"weighted_sum = 0\n", | |
"total_surf_area = 0\n", | |
"\n", | |
"# For each region/hemisphere\n", | |
"for r in regions:\n", | |
" for s in ['left', 'right']:\n", | |
" \n", | |
" # Filter the DataFrame using current region/hemisphere\n", | |
" roi = aparc.query('region == \"%s\" & side == \"%s\"'%(r, s))\n", | |
" \n", | |
" # Get cortical thickness\n", | |
" thickness = float(roi.query('measurement == \"ThickAvg\"').value)\n", | |
" \n", | |
" # Get surface area\n", | |
" surf_area = float(roi.query('measurement == \"SurfArea\"').value)\n", | |
" \n", | |
" # Add them to the total sum\n", | |
" weighted_sum += thickness * surf_area\n", | |
" total_surf_area += surf_area\n", | |
" \n", | |
"# The final result is the ratio between both values\n", | |
"final = weighted_sum / total_surf_area\n", | |
"final" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment