Skip to content

Instantly share code, notes, and snippets.

@xgrg
Last active April 24, 2018 16:13
Show Gist options
  • Save xgrg/fcfb017a71747c21344b18b3b14b2756 to your computer and use it in GitHub Desktop.
Save xgrg/fcfb017a71747c21344b18b3b14b2756 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import sys, string\n",
"sys.path.append('/home/grg/git/xnat-monitor/')\n",
"from bbrc import xnat\n",
"from lxml import etree\n",
"\n",
"central = xnat.connect_xnat('/home/grg/.xnat_bsc.cfg')\n",
"ns = {'xnat':\"http://nrg.wustl.edu/xnat\"}"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>subject</th>\n",
" <th>scandate</th>\n",
" <th>xnatdate</th>\n",
" <th>has_bvec</th>\n",
" <th>project</th>\n",
" <th>accession_number</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>10019</td>\n",
" <td>2017-02-15</td>\n",
" <td>20170331</td>\n",
" <td>False</td>\n",
" <td>ALFA_PLUS</td>\n",
" <td>040510150217019</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>10044</td>\n",
" <td>2017-06-27</td>\n",
" <td>20170627</td>\n",
" <td>False</td>\n",
" <td>ALFA_PLUS</td>\n",
" <td>040510270617044</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>10065</td>\n",
" <td>2016-10-21</td>\n",
" <td>20170330</td>\n",
" <td>False</td>\n",
" <td>ALFA_OPCIONAL</td>\n",
" <td>030410211016065</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>10070</td>\n",
" <td>2017-06-13</td>\n",
" <td>20170621</td>\n",
" <td>False</td>\n",
" <td>ALFA_PLUS</td>\n",
" <td>040510130617070</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>10137</td>\n",
" <td>2017-06-07</td>\n",
" <td>20180117</td>\n",
" <td>False</td>\n",
" <td>ALFA_PLUS</td>\n",
" <td>040510070617137</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" subject scandate xnatdate has_bvec project accession_number\n",
"0 10019 2017-02-15 20170331 False ALFA_PLUS 040510150217019\n",
"1 10044 2017-06-27 20170627 False ALFA_PLUS 040510270617044\n",
"2 10065 2016-10-21 20170330 False ALFA_OPCIONAL 030410211016065\n",
"3 10070 2017-06-13 20170621 False ALFA_PLUS 040510130617070\n",
"4 10137 2017-06-07 20180117 False ALFA_PLUS 040510070617137"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"subjects = [string.atoi(e) for e in open('/tmp/amyloid_subjects.txt').read().split('\\n') if e != '']\n",
"# list of subjects with correct bvec/bval (but who failed the denoising step in my initial attempt\n",
"bvec_correct = [10162, 10515, 10627, 10649, 10711, 10949, 11262, 11514, 11745, 12279, 12741, 12991, 13035, 13105, 13107, 13193, 13259,\n",
" 21136, 21138, 44008, 44301, 44396, 55854, 66008, 66027, 66100, 66162, 66301, 77012, 77164]\n",
"\n",
"res = []\n",
"for subject in subjects:\n",
" # Looks for a matching scan in ALFA_PLUS first, then ALFA_OPCIONAL\n",
" project = 'ALFA_PLUS'\n",
" e = xnat.subject_experiments(central, 'ALFA_PLUS', str(subject))\n",
" if len(e) == 0:\n",
" project = 'ALFA_OPCIONAL'\n",
" e = xnat.subject_experiments(central, 'ALFA_OPCIONAL', str(subject))\n",
" \n",
" doc = etree.fromstring(e[0].get())\n",
" ans = doc.findall('.//xnat:date', ns)\n",
" scandate = ans[0].text # date of acquisition\n",
" ans = doc.findall('.//xnat:prearchivePath', ns)\n",
" xnatdate = ans[0].text.split('/')[-2].split('_')[0] # date of upload to xnat\n",
" ans = doc.findall('.//xnat:dcmAccessionNumber', ns)\n",
" accnum = ans[0].text\n",
" res.append((subject, scandate, xnatdate, subject in bvec_correct, project, accnum))\n",
"\n",
"# saving results in an Excel table and display the first lines\n",
"import pandas as pd\n",
"df = pd.DataFrame(res, columns=['subject', 'scandate', 'xnatdate', 'has_bvec', 'project', 'accession_number'])\n",
"df.to_excel('/tmp/bvec_bval_dates.xls')\n",
"df.head()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11+"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment