-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_ADNI_total_volumes.py
23 lines (18 loc) · 1.07 KB
/
add_ADNI_total_volumes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pandas as pd
import numpy as np
import re
df = pd.read_csv("/nfs2/kimm58/ADNI_TICV_volumes.csv")
#get the BIDS tags from the filenames
#get the total brain volumes (all labels except TICV and posterior fossa)
#get the total TICV volume (all labels)
#first, get the total brain volume (all comlumns except TICV and posterior fossa and filename)
df['Total_Brain_Volume'] = df.drop(columns=['file', 'TICV', 'PosteriorFossa']).sum(axis=1, skipna=True)
#next get the total TICV volume (total brain volume + posterior fossa + TICV)
df['Total_TICV'] = df[['Total_Brain_Volume', 'TICV', 'PosteriorFossa']].sum(axis=1, skipna=True)
#get the BIDS tags
df['sub'] = df['file'].apply(lambda x: x.split('_')[0])
df['ses'] = df['file'].apply(lambda x: x.split('_')[1])
df['acq'] = df['file'].apply(lambda x: re.search(r'acq-[A-Za-z0-9]+', x).group(0) if re.search(r'acq-[A-Za-z0-9]+', x) else '')
df['run'] = df['file'].apply(lambda x: re.search(r'run-[0-9]+', x).group(0) if re.search(r'run-[0-9]+', x) else '')
#save the dataframe
df.to_csv('/nfs2/kimm58/ADNI_TICV_volumes_BIDS.csv', index=False)