-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFilterConfounds.py
27 lines (22 loc) · 1.13 KB
/
FilterConfounds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pandas as pd
import sys
import numpy as np
#ifile = 'sub-100301_task-wm_run-001_desc-confounds_regressors.tsv'
ifile = str(sys.argv[1])
df = pd.read_csv(ifile, sep = '\t')
df.reset_index(inplace = True)
nine_params = ['trans_x', 'trans_y', 'trans_z', 'rot_x', 'rot_y', 'rot_z', 'csf', 'white_matter', 'global_signal']
df[nine_params].to_csv(ifile.replace('.tsv', '-9p.txt'), header = None, index = None, sep = ' ')
#Get framewise displacement > 0.5
fd_outliers = df[df['framewise_displacement'] > 0.5][['index','framewise_displacement']]
fd_ofile = ifile.replace('confounds_regressors.tsv','fd_outliers_0pt5.txt')
fd_outliers[['index']].to_csv(fd_ofile, index = False, header = False)
#Get dvars outliers (> 75th percentile + (1.5 * IQR))
dvars = [float(x) for x in df['dvars'].values][1:]
q25, q75 = np.percentile(dvars, 25), np.percentile(dvars, 75)
iqr = q75 - q25
cut_off = iqr * 1.5
lower, upper = q25 - cut_off, q75 + cut_off
dvars_outliers = df[df['dvars'] > upper][['dvars','index']]
dvars_ofile = ifile.replace('confounds_regressors.tsv','dvars_outliers.txt')
dvars_outliers[['index']].to_csv(dvars_ofile, index = False, header = False)