In [1]:
import common
reload(common)


importing IPython notebook from common.ipynb
importing IPython notebook from common.ipynb
Out[1]:
<module 'common' from 'common.ipynb'>

In [2]:
import os
from datetime import datetime
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', 25)
pd.set_option('display.max_columns', 50)

In [3]:
full = np.zeros((148, 148, len(common.subject_list)))
for i, subject in enumerate(common.subject_list):
    scdir = common.sc_dir(subject)
    conn, processed_seed_list, N = common.single_process(scdir)
    full[:, :, i] = conn

Define the "English->Freesufer" mapping.


In [4]:
rois_of_interest = {'BA44': 'G_front_inf-Opercular',
                    'AG': 'G_pariet_inf-Angular',
                    'MTG': 'G_temporal_middle',
                    'BA45': 'G_front_inf-Triangul',
                    'BA47': 'S_orbital_lateral', # or G_orbital?
                    }

For each hemisphere:

  1. For each ROI:
    1. Make the seed as it exists in processed_seed_list.
    2. Find the index where it exists in full.
    3. For each target (not where seed == target):
      1. Make the human readable column name
      2. Find the target index in full.
      3. Extract the connection series and save it to data[column_name].

In [5]:
data = {}
for hemi in ('lh', 'rh'):
    for seed_name, seed_label in rois_of_interest.items():
        seed = '{}.{}'.format(hemi, seed_label)
        seed_index = processed_seed_list.index(seed)
        for target_name, target_label in rois_of_interest.items():
            if seed_name == target_name:
                continue
            target = '{}.{}'.format(hemi, target_label)
            column_temp = "{hemi}.{seed_name}-{hemi}.{target_name}"
            column_name = column_temp.format(hemi=hemi,
                                             seed_name=seed_name,
                                             target_name=target_name)            
            target_index = processed_seed_list.index(target)
            data[column_name] = full[seed_index, target_index, :]

Make a dataframe out of the data, using the subject list as the index.


In [6]:
df = pd.DataFrame(data, index=common.subject_list)
# sanity check
ag_index = processed_seed_list.index('lh.G_pariet_inf-Angular')
mtg_index = processed_seed_list.index('lh.G_temporal_middle')
assert df['lh.AG-lh.MTG']['061_206924'] == full[ag_index, mtg_index, 0]
df


Out[6]:
lh.AG-lh.BA44 lh.AG-lh.BA45 lh.AG-lh.BA47 lh.AG-lh.MTG lh.BA44-lh.AG lh.BA44-lh.BA45 lh.BA44-lh.BA47 lh.BA44-lh.MTG lh.BA45-lh.AG lh.BA45-lh.BA44 lh.BA45-lh.BA47 lh.BA45-lh.MTG lh.BA47-lh.AG lh.BA47-lh.BA44 lh.BA47-lh.BA45 lh.BA47-lh.MTG lh.MTG-lh.AG lh.MTG-lh.BA44 lh.MTG-lh.BA45 lh.MTG-lh.BA47 rh.AG-rh.BA44 rh.AG-rh.BA45 rh.AG-rh.BA47 rh.AG-rh.MTG rh.BA44-rh.AG rh.BA44-rh.BA45 rh.BA44-rh.BA47 rh.BA44-rh.MTG rh.BA45-rh.AG rh.BA45-rh.BA44 rh.BA45-rh.BA47 rh.BA45-rh.MTG rh.BA47-rh.AG rh.BA47-rh.BA44 rh.BA47-rh.BA45 rh.BA47-rh.MTG rh.MTG-rh.AG rh.MTG-rh.BA44 rh.MTG-rh.BA45 rh.MTG-rh.BA47
061_206924 0.000000 0 0 0.157720 0.000000 7.597387 0.000630 0.000000 0 6.176972 6.351575 0.000000 0 0.000243 24.666533 0 0.337543 0.000011 0.000000 0 0.000000 0 0 0.692000 0.000000 4.257740 0.003771 0.000017 0 11.034320 3.693136 0.000000 0 0.018388 5.872389 0 1.189093 0.000000 0.000000 0.000000
063_207046 0.000000 0 0 2.376613 0.000000 13.446513 0.003892 0.000000 0 11.814914 8.375411 0.000000 0 0.000344 23.394029 0 0.488966 0.000000 0.000000 0 0.000000 0 0 1.109729 0.000000 6.425975 0.086003 0.000000 0 11.343252 8.164955 0.000000 0 0.006380 7.341089 0 1.068244 0.000000 0.000000 0.000000
064_207264 0.000000 0 0 0.040651 0.000000 9.038170 0.019948 0.000000 0 4.831545 7.747275 0.000000 0 0.003750 12.781205 0 0.067520 0.000000 0.000000 0 0.000000 0 0 1.685884 0.000000 7.303924 0.000372 0.000000 0 12.537670 3.965944 0.000116 0 0.001860 7.735717 0 1.421538 0.000000 0.000302 0.000011
067_207215 0.000000 0 0 0.016048 0.000000 7.549609 0.004389 0.000025 0 8.122663 11.258398 0.000000 0 0.005075 22.591915 0 0.008047 0.000000 0.000000 0 0.000000 0 0 0.291557 0.000000 10.722138 0.000374 0.000318 0 9.480692 5.348796 0.000000 0 0.004595 10.168598 0 0.050294 0.000023 0.000000 0.000000
072_207335 0.000000 0 0 1.392457 0.000000 4.604864 0.002755 0.000000 0 9.028822 15.095617 0.000000 0 0.001584 31.105881 0 0.916250 0.000020 0.000000 0 0.000000 0 0 0.677608 0.000000 5.339868 0.007158 0.000000 0 11.621804 6.086802 0.000000 0 0.007556 6.693580 0 0.637682 0.000000 0.000000 0.000000
130_208994 0.000000 0 0 0.066259 0.000000 6.944583 0.013497 0.000000 0 13.056373 10.675082 0.000000 0 0.024344 13.848921 0 0.215500 0.000000 0.000000 0 0.000000 0 0 1.209590 0.000000 6.816534 0.000240 0.000000 0 7.175570 0.226674 0.000262 0 0.000157 0.355760 0 1.086393 0.000000 0.000072 0.000000
131_209154 0.000000 0 0 1.399444 0.000000 5.539667 0.000452 0.000000 0 4.420631 15.829731 0.000000 0 0.000000 16.429309 0 1.894137 0.000000 0.000000 0 0.000000 0 0 2.740349 0.000020 6.512012 0.450767 0.000000 0 5.834982 13.456793 0.000000 0 0.221865 20.982435 0 2.016866 0.000000 0.000000 0.000000
140_209143 0.000000 0 0 0.592180 0.000000 8.107615 0.000000 0.000000 0 12.796186 4.191018 0.000000 0 0.000000 7.610084 0 0.752431 0.000000 0.000000 0 0.000000 0 0 0.034867 0.000000 16.776108 0.001855 0.000000 0 13.262060 7.905899 0.000000 0 0.000941 24.489124 0 0.007429 0.000000 0.000012 0.000000
141_209157 0.000000 0 0 0.682789 0.000000 9.501505 0.000581 0.000180 0 9.787052 5.326759 0.000000 0 0.000081 7.086435 0 0.205386 0.000000 0.000000 0 0.001981 0 0 1.273084 0.003237 9.996298 0.000000 0.000072 0 4.402040 0.613478 0.013102 0 0.000000 1.554572 0 1.426850 0.000000 0.004034 0.000000
144_209407 0.000000 0 0 0.058792 0.000000 12.666353 0.000409 0.000000 0 10.356388 11.345866 0.000000 0 0.000446 18.482759 0 0.012404 0.000009 0.000000 0 0.000000 0 0 1.321402 0.000000 12.500253 0.000064 0.000000 0 9.911237 3.201448 0.000000 0 0.000236 4.072993 0 1.729493 0.000000 0.000000 0.000000
146_209355 0.000013 0 0 1.124411 0.000000 12.019397 0.000020 0.000000 0 9.311112 3.593819 0.000000 0 0.000000 17.381464 0 0.208337 0.000018 0.000000 0 0.000000 0 0 0.096273 0.000000 6.855068 0.003226 0.000000 0 16.242869 12.897910 0.000000 0 0.001272 11.853666 0 0.109368 0.000000 0.000000 0.000000
147_209378 0.000000 0 0 0.067167 0.000000 13.585009 0.000269 0.001457 0 6.123319 13.563181 0.000000 0 0.000114 23.619830 0 0.239824 0.000696 0.000000 0 0.000000 0 0 2.362807 0.000000 7.895535 0.000000 0.000086 0 4.946964 2.196396 0.004058 0 0.000000 5.546668 0 3.592246 0.000037 0.003674 0.000000
148_209625 0.000000 0 0 0.780187 0.000000 4.708594 0.000000 0.000000 0 3.720676 3.602988 0.006437 0 0.000000 14.167479 0 0.833114 0.000000 0.000176 0 0.000000 0 0 1.615183 0.000000 11.537575 0.000159 0.000000 0 7.543368 1.629710 0.027337 0 0.000178 1.886011 0 2.753623 0.000040 0.007107 0.000010
162_210032 0.000000 0 0 1.093976 0.000000 8.648791 0.000020 0.000060 0 11.665640 9.696132 0.000050 0 0.000000 16.887572 0 0.707897 0.000000 0.000028 0 0.000000 0 0 0.688764 0.000000 9.751946 0.000083 0.000000 0 8.942529 10.083573 0.003667 0 0.000491 13.361565 0 0.367840 0.000000 0.001623 0.000000
170_210044 0.000000 0 0 1.669295 0.000000 6.057113 0.000108 0.000000 0 3.842181 6.317742 0.000000 0 0.000084 16.291318 0 1.137329 0.000018 0.000000 0 0.000000 0 0 1.625524 0.000000 9.435173 0.000293 0.000027 0 7.622461 3.402648 0.000000 0 0.001380 6.351387 0 1.395404 0.000000 0.000000 0.000000
172_209736 0.000000 0 0 0.662067 0.000000 11.972047 0.000945 0.002582 0 11.073302 6.062751 0.000404 0 0.005139 16.227269 0 0.358963 0.000055 0.000014 0 0.000000 0 0 0.323698 0.000000 8.479707 0.002006 0.000000 0 12.528087 3.722647 0.000000 0 0.000716 4.345505 0 0.748129 0.000000 0.000000 0.000000
188_210443 0.000012 0 0 0.346441 0.000020 3.904215 0.035363 0.001737 0 4.590099 10.372509 0.000000 0 0.009995 22.102858 0 0.310394 0.000860 0.000000 0 0.000000 0 0 0.946620 0.000000 13.821494 0.000267 0.000000 0 11.314516 2.276171 0.000000 0 0.000087 4.734041 0 0.778437 0.000000 0.000000 0.000000
191_210512 0.000000 0 0 0.096580 0.000000 8.371783 0.005492 0.000000 0 8.358503 11.079175 0.000000 0 0.000160 15.457040 0 0.064425 0.000000 0.000000 0 0.000000 0 0 0.802871 0.000000 14.567033 0.250089 0.000000 0 16.820049 12.818592 0.000000 0 0.111693 6.782209 0 1.012022 0.000000 0.000000 0.000000
196_210780 0.000000 0 0 0.148037 0.000000 7.435902 0.004176 0.000126 0 10.519697 9.034839 0.000000 0 0.003353 13.651319 0 0.275750 0.000000 0.000000 0 0.000024 0 0 0.082200 0.000025 5.934112 0.071493 0.000000 0 5.693473 6.572440 0.000000 0 0.837926 8.797537 0 0.024932 0.000000 0.000000 0.000000
197_210808 0.000000 0 0 0.021057 0.000000 11.382996 0.000190 0.000000 0 10.851272 12.198652 0.000000 0 0.000059 33.916498 0 0.018884 0.000000 0.000000 0 0.000000 0 0 0.129322 0.000000 13.595554 0.000166 0.000000 0 8.490369 5.164119 0.000000 0 0.000403 12.162691 0 0.057016 0.000000 0.000000 0.000000
203_211015 0.000000 0 0 0.064279 0.000023 19.081822 0.000023 0.000046 0 12.695397 6.778202 0.000000 0 0.000000 26.829378 0 0.004955 0.000000 0.000000 0 0.000000 0 0 1.119028 0.000000 8.489777 0.000025 0.000000 0 8.129867 3.652942 0.000026 0 0.000174 12.195935 0 2.651228 0.000000 0.000000 0.000000
208_211122 0.000000 0 0 0.034232 0.000000 12.842132 0.045281 0.000016 0 14.252085 8.259085 0.000000 0 0.149193 15.195776 0 0.005775 0.000000 0.000000 0 0.000009 0 0 0.138936 0.000000 6.348079 0.282818 0.000000 0 9.035715 5.556995 0.000000 0 0.088492 2.354418 0 0.104764 0.000000 0.000000 0.000000
216_211291 0.000000 0 0 0.955567 0.000000 11.781005 0.009882 0.000803 0 9.544898 11.884373 0.000000 0 0.000449 28.845504 0 0.175158 0.000500 0.000000 0 0.000000 0 0 0.106995 0.000000 2.654160 0.001023 0.000000 0 10.054285 7.432013 0.000000 0 0.002061 6.354666 0 0.232466 0.000000 0.000000 0.000000
228_211662 0.000000 0 0 0.021239 0.000000 6.471975 0.006829 0.000041 0 11.993069 10.452645 0.000000 0 0.008337 24.050894 0 0.009863 0.000000 0.000000 0 0.000000 0 0 1.928628 0.000000 4.389717 0.000040 0.071786 0 3.427070 3.379996 0.031522 0 0.000044 4.138305 0 1.752143 0.000873 0.010763 0.000000

Connect to redcap and join the databases?